Add class Settings
This commit is contained in:
parent
6ca6034186
commit
6937a3c828
1 changed files with 32 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
|
||||||
Loading…
Add table
Add a link
Reference in a new issue