Skip to content

Configuration

Comprehensive user-configurable settings management system for the Lilia framework.


Overview

The configuration library provides comprehensive functionality for managing user-configurable settings in the Lilia framework. It handles the creation, storage, retrieval, and persistence of various types of options including boolean toggles, numeric sliders, color pickers, text inputs, and dropdown selections. The library operates on both client and server sides, with automatic persistence to JSON files and optional networking capabilities for server-side options. It includes a complete user interface system for displaying and modifying options through the configuration menu, with support for categories, visibility conditions, and real-time updates. The library ensures that all user preferences are maintained across sessions and provides hooks for modules to react to option changes.

lia.config.add(key, name, value, callback, data)

Purpose

Register a config entry with defaults, UI metadata, and optional callback.

When Called

During schema/module initialization to expose server-stored configuration.

Parameters

string key Unique identifier for the config entry.

string name Display text or localization key for UI.

any value Default value; type inferred when data.type is omitted.

function callback optional Invoked server-side as callback(oldValue, newValue) after set().

table data Fields such as type, desc, category, options/optionsFunc, noNetworking, etc.

Example Usage

  lia.config.add("MaxThirdPersonDistance", "maxThirdPersonDistance", 100, function(old, new)
      lia.option.set("thirdPersonDistance", math.min(lia.option.get("thirdPersonDistance", new), new))
  end, {category = "Lilia", type = "Int", min = 10, max = 200})

lia.config.getDisplayName(key)

Purpose

Retrieve the localized display name of a config entry.

When Called

When rendering config entries in the UI or when a human-readable name is needed.

Parameters

string key The config key to look up.

Returns

string Localized display name, or the raw key if the entry does not exist.

Example Usage

  local name = lia.config.getDisplayName("MaxCarryWeight")
  print("Config name:", name)

lia.config.getDisplayDesc(key)

Purpose

Retrieve the localized description of a config entry.

When Called

When populating tooltips or description fields in the config UI.

Parameters

string key The config key to look up.

Returns

string Localized description string, or an empty string if none exists.

Example Usage

  local desc = lia.config.getDisplayDesc("MaxCarryWeight")
  print("Config description:", desc)

lia.config.getDisplayCategory(key)

Purpose

Retrieve the localized category of a config entry for grouping in the UI.

When Called

When building the config UI to sort entries into category sections.

Parameters

string key The config key to look up.

Returns

string Localized category name, or "character" as the default fallback.

Example Usage

  local cat = lia.config.getDisplayCategory("MaxCarryWeight")
  print("Config category:", cat)

lia.config.getOptions(key)

Purpose

Resolve a config entry's selectable options, static list or generated.

When Called

Before rendering dropdown-type configs or validating submitted values.

Parameters

string key Config key to resolve options for.

Returns

table Options array or key/value table; empty when unavailable.

Example Usage

  local opts = lia.config.getOptions("Theme")

lia.config.setDefault(key, value)

Purpose

Override the default value for an already registered config entry.

When Called

During migrations, schema overrides, or backward-compatibility fixes.

Parameters

string key Config key to override.

any value New default value.

Example Usage

  lia.config.setDefault("StartingMoney", 300)

lia.config.forceSet(key, value, noSave)

Purpose

Force-set a config value and fire update hooks without networking.

When Called

Runtime adjustments (admin tools/commands) or hot reload scenarios.

Parameters

string key Config key to change.

any value Value to assign.

boolean noSave optional When true, skip persisting to disk.

Example Usage

  lia.config.forceSet("MaxCharacters", 10, false)

lia.config.set(key, value)

Purpose

Set a config value, fire update hooks, run server callbacks, network to clients, and persist.

When Called

Through admin tools/commands or internal code updating configuration.

Parameters

string key Config key to change.

any value Value to assign and broadcast.

Example Usage

  lia.config.set("RunSpeed", 420)

lia.config.get(key, default)

Purpose

Retrieve a config value with fallback to its stored default or a provided default.

When Called

Anywhere configuration influences gameplay or UI logic.

Parameters

string key Config key to read.

any default Optional fallback when no stored value or default exists.

Returns

any Stored value, default value, or supplied fallback.

Example Usage

  local walkSpeed = lia.config.get("WalkSpeed", 200)

lia.config.load()

Purpose

Load config values from JSON files (server) or request them from the server (client).

When Called

On initialization to hydrate lia.config.stored from JSON file storage.

Example Usage

  hook.Add("Initialize", "LoadLiliaConfig", lia.config.load)

lia.config.getChangedValues(includeDefaults)

Purpose

Get all configuration values that have been changed from their defaults.

When Called

During config synchronization to determine what needs to be sent to clients.

Parameters

boolean includeDefaults When true, includes all values even if they match defaults.

Returns

table Key/value pairs of changed configuration entries.

Example Usage

  local changes = lia.config.getChangedValues()

lia.config.send(client)

Purpose

Send configuration data to a specific client or all clients.

When Called

During initial connection or when config values change.

Parameters

Player client optional Specific client to send to, or nil for all clients.

Example Usage

  lia.config.send() -- Send to all clients
  lia.config.send(client) -- Send to specific client

lia.config.save()

Purpose

Persist configuration values to JSON file storage.

When Called

After configuration changes to ensure values are saved between server restarts.

Example Usage

  lia.config.save()

lia.config.reset()

Purpose

Reset all configuration values to their defaults.

When Called

During administrative operations or troubleshooting.

Example Usage

  lia.config.reset()