Compare commits
2 commits
e4ad298324
...
6937a3c828
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6937a3c828 | ||
|
|
6ca6034186 |
2 changed files with 44 additions and 0 deletions
32
cf-lib/settings/Settings.lua
Normal file
32
cf-lib/settings/Settings.lua
Normal 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
|
||||||
|
|
@ -70,6 +70,18 @@ function table.filter(target, predicate)
|
||||||
return result
|
return result
|
||||||
end
|
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.
|
--- Concatenates two tables into a new table.
|
||||||
--- @param table1 table The first table
|
--- @param table1 table The first table
|
||||||
--- @param table2 table The second table
|
--- @param table2 table The second table
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue