mirror of
https://github.com/lifestorm/wnsrc.git
synced 2025-12-16 05:13:46 +03:00
63 lines
1.3 KiB
Lua
63 lines
1.3 KiB
Lua
--[[
|
|
| This file was obtained through the combined efforts
|
|
| of Madbluntz & Plymouth Antiquarian Society.
|
|
|
|
|
| Credits: lifestorm, Gregory Wayne Rossel JR.,
|
|
| Maloy, DrPepper10 @ RIP, Atle!
|
|
|
|
|
| Visit for more: https://plymouth.thetwilightzone.ru/
|
|
--]]
|
|
|
|
if SAM_LOADED then return end
|
|
|
|
local sam = sam
|
|
local mp = sam.mp
|
|
local config = sam.config
|
|
|
|
function config.set(key, value, force)
|
|
if not sam.isstring(key) then
|
|
error("invalid setting name")
|
|
end
|
|
|
|
if not mp.packers[sam.type(value)] then
|
|
error("not supported value type")
|
|
end
|
|
|
|
if not force and config.get(key) == value then return end
|
|
sam.netstream.Start("Config.Set", key, value)
|
|
end
|
|
|
|
function config.get(key, default)
|
|
local value = sam.get_global("Config")[key]
|
|
if value ~= nil then
|
|
return value
|
|
end
|
|
return default
|
|
end
|
|
|
|
local menu_settings = {}
|
|
function config.add_menu_setting(title, func)
|
|
local i = #menu_settings + 1
|
|
for k, v in ipairs(menu_settings) do
|
|
if v.title == title then
|
|
i = k
|
|
break
|
|
end
|
|
end
|
|
menu_settings[i] = {
|
|
title = title,
|
|
func = func,
|
|
}
|
|
end
|
|
|
|
function config.get_menu_settings()
|
|
return menu_settings
|
|
end
|
|
|
|
hook.Add("SAM.ChangedGlobalVar", "SAM.CheckLoadedConfig", function(key, value)
|
|
if key == "Config" then
|
|
config.loaded = true
|
|
hook.Call("SAM.LoadedConfig", nil, value)
|
|
hook.Remove("SAM.ChangedGlobalVar", "SAM.CheckLoadedConfig")
|
|
end
|
|
end) |