Compare commits

..

2 commits

Author SHA1 Message Date
Simon Brodtmann
6937a3c828 Add class Settings 2025-11-12 00:32:17 +01:00
Simon Brodtmann
6ca6034186 Add table.filterKey 2025-11-12 00:31:56 +01:00
2 changed files with 44 additions and 0 deletions

View file

@ -0,0 +1,32 @@
--- Utility class for manipulating settings
--- @class Settings
local Settings = {}
local settingTypes = { "bool-setting", "int-setting", "double-setting", "string-setting", "color-setting" }
local function getSetting(name)
for _, settingType in pairs(settingTypes) do
local setting = data.raw[settingType][name]
if setting then return setting end
end
error("getSetting: Setting with name '" .. name .. "' not found.")
end
Settings.getSetting = getSetting
function Settings.force(name, value)
local setting = getSetting(name)
setting.hidden = true
if setting.type == "bool-setting" or setting.type == "color-setting" then
setting.forced_value = value
else
setting.allowed_values = { value }
end
end
function Settings.default(name, value)
local setting = getSetting(name)
setting.default_value = value
end
return Settings

View file

@ -70,6 +70,18 @@ function table.filter(target, predicate)
return result
end
--- Filters a table by removing given key.
--- @param target table The table to filter
--- @param key string The key to remove
function table.filterKey(target, key)
return table.filter(
target,
function(_, currentKey)
return currentKey ~= key
end
)
end
--- Concatenates two tables into a new table.
--- @param table1 table The first table
--- @param table2 table The second table