tibia-client/modules/corelib/settings.lua

86 lines
2.0 KiB
Lua
Raw Normal View History

2012-06-26 00:13:30 +02:00
-- @docclass
g_settings = {}
2012-01-06 09:48:59 +01:00
2012-06-26 00:13:30 +02:00
g_settings.exists = g_configs.exists
g_settings.setNode = g_configs.setNode
g_settings.mergeNode = g_configs.mergeNode
g_settings.getNode = g_configs.getNode
g_settings.remove = g_configs.remove
g_settings.setList = g_configs.setList
g_settings.getList = g_configs.getList
2012-01-06 09:48:59 +01:00
local function convertSettingValue(value)
if type(value) == 'table' then
if value.x and value.width then
return recttostring(value)
elseif value.x then
return pointtostring(value)
elseif value.width then
return sizetostring(value)
elseif value.r then
return colortostring(value)
else
return value
2012-01-06 09:48:59 +01:00
end
2012-01-07 01:34:40 +01:00
elseif value == nil then
return ''
2012-01-06 09:48:59 +01:00
else
return tostring(value)
end
end
2012-06-26 00:13:30 +02:00
function g_settings.set(key, value)
2012-01-07 01:46:41 +01:00
g_configs.set(key, convertSettingValue(value))
2012-01-06 09:48:59 +01:00
end
2012-06-26 00:13:30 +02:00
function g_settings.setDefault(key, value)
if g_settings.exists(key) then return false end
g_settings.set(key, value)
2012-01-06 09:48:59 +01:00
return true
end
2012-06-26 00:13:30 +02:00
function g_settings.get(key, default)
if not g_settings.exists(key) and default ~= nil then
g_settings.set(key, default)
2012-01-06 09:48:59 +01:00
end
return g_configs.get(key)
end
2012-06-26 00:13:30 +02:00
function g_settings.getString(key, default)
return g_settings.get(key, default)
2012-01-06 09:48:59 +01:00
end
2012-06-26 00:13:30 +02:00
function g_settings.getInteger(key, default)
2012-07-31 06:09:55 +02:00
local v = tonumber(g_settings.get(key, default)) or 0
return v
2012-01-06 09:48:59 +01:00
end
2012-06-26 00:13:30 +02:00
function g_settings.getNumber(key, default)
2012-07-31 06:09:55 +02:00
local v = tonumber(g_settings.get(key, default)) or 0
return v
2012-01-06 09:48:59 +01:00
end
2012-06-26 00:13:30 +02:00
function g_settings.getBoolean(key, default)
return toboolean(g_settings.get(key, default))
2012-01-06 09:48:59 +01:00
end
2012-06-26 00:13:30 +02:00
function g_settings.getPoint(key, default)
return topoint(g_settings.get(key, default))
2012-01-06 09:48:59 +01:00
end
2012-06-26 00:13:30 +02:00
function g_settings.getRect(key, default)
return torect(g_settings.get(key, default))
2012-01-06 09:48:59 +01:00
end
2012-06-26 00:13:30 +02:00
function g_settings.getSize(key, default)
return tosize(g_settings.get(key, default))
2012-01-06 09:48:59 +01:00
end
2012-06-26 00:13:30 +02:00
function g_settings.getColor(key, default)
return tocolor(g_settings.get(key, default))
2012-01-06 09:48:59 +01:00
end
2012-06-26 00:13:30 +02:00
function g_settings.getColor(key, default)
return tocolor(g_settings.get(key, default))
2012-01-06 09:48:59 +01:00
end