tibia-client/modules/corelib/settings.lua

79 lines
1.8 KiB
Lua
Raw Normal View History

2012-06-26 00:13:30 +02:00
-- @docclass
g_settings = g_configs.getSettings()
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)
g_settings.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)
print(g_settings.exists)
2012-06-26 00:13:30 +02:00
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_settings.get(key)
2012-01-06 09:48:59 +01:00
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