Display Data Module
Persistent display settings, favourites, and recent items manager for grid selectors.
Persistent display settings, favourites, and recent items manager for grid selectors.
Overview
displayDataModule provides a factory that creates instances managing display preferences (group mode, sort order, tile size), favourite tracking, and recent item history. Data is persisted to a JSON file.
Module path: lua/ge/extensions/ui/gridSelectorUtils/displayDataModule.lua (loaded via require)
Exports (M)
| Function | Signature | Description |
|---|---|---|
create | (dataFile, options, updateFn, backendName, targetVersion) | Creates a display data manager instance. |
Instance Methods
| Method | Signature | Description |
|---|---|---|
getDisplayData | () | Returns current display settings (lazy-initialized). |
setDisplayDataOption | (key, value) | Updates a setting and persists to disk. |
resetDisplayDataToDefaults | () | Resets all saveable options to defaults. |
getDisplayDataOptions | () | Returns option definitions with current values for UI. |
toggleFavourite | (itemKey) | Toggles favourite status (stores timestamp). |
isFavourite | (itemKey) | Returns timestamp if favourited, nil otherwise. |
isRecentItem | (itemKey) | Returns index in recent list, or false. |
trackRecentItem | (itemKey) | Adds/moves item to front of recent list. |
clearAllFavourites | () | Clears all favourites. |
clearAllRecentItems | () | Clears recent item history. |
Internals
Persistence
Data is saved to a JSON file (e.g., /settings/gameplaySelectorData.json):
local data = {
favourites = favourites, -- {itemKey: timestamp}
recentItems = recentItems, -- ordered list of keys
version = currentVersion,
displayData = displayData -- {groupMode: "system", ...}
}
jsonWriteFile(dataFile, data, true, nil, true)Version Migration
An updateDisplayDataFunction callback handles migrations when saved data is older:
if data.version < currentVersion then
data.displayData = updateDisplayDataFunction(data.displayData, data.version, currentVersion)
endOption Types
Options support dropdown, checkbox, and number types. Options with settingsKey sync to engine settings. Special handling:
showAuxContentdefaults based onshipping_buildshowCareerContentrespects shipping status
Recent Items
Recent items are stored as an ordered list (LIFO), capped at 100:
local function trackRecentItem(itemKey)
local idx = arrayFindValueIndex(recentItems, itemKey)
if idx then table.remove(recentItems, idx) end
table.insert(recentItems, 1, itemKey)
while #recentItems > maxRecentItems do
table.remove(recentItems, #recentItems)
end
endHow It Works
- Backend creates instance:
displayDataModule.create("/settings/data.json", options, migrateFn, "mySelector", 11) - First
getDisplayData()loads from disk, applies defaults, handles migrations - UI reads options via
getDisplayDataOptions()for rendering controls - Setting changes call
setDisplayDataOption(key, value)→ persist + hook - Favourites/recents are tracked alongside display data in the same file
Additional Exports
The following exports are available but not yet documented in detail:
M.create