70 строки
Без EOL
985 Б
Lua
70 строки
Без EOL
985 Б
Lua
|
|
local currentMap
|
|
local cache = {}
|
|
|
|
file.CreateDir("permanent")
|
|
|
|
function permanent.GetTable()
|
|
|
|
return cache
|
|
|
|
end
|
|
|
|
function permanent.Pull()
|
|
|
|
cache = util.JSONToTable(file.Read("permanent/"..currentMap..".json"))
|
|
|
|
end
|
|
|
|
function permanent.Push()
|
|
|
|
currentMap = currentMap or game.GetMap()
|
|
file.Write("permanent/"..currentMap..".json", util.TableToJSON(cache))
|
|
|
|
end
|
|
|
|
function permanent.Get(id)
|
|
|
|
assert(isstring(id), "invalid index")
|
|
|
|
return cache[id]
|
|
|
|
end
|
|
|
|
function permanent.Add(id, data)
|
|
|
|
id = id or tostring(os.time())
|
|
assert(istable(data))
|
|
|
|
cache[id] = data
|
|
|
|
end
|
|
|
|
function permanent.Remove(id)
|
|
|
|
assert(isstring(id), "invalid index")
|
|
|
|
cache[id] = nil
|
|
|
|
end
|
|
|
|
hook.Add("ShutDown", "Permanent", function()
|
|
|
|
permanent.Push()
|
|
|
|
end)
|
|
|
|
hook.Add("PostGamemodeLoaded", "Permanent", function()
|
|
|
|
currentMap = game.GetMap()
|
|
|
|
if !file.Exists("permanent/"..currentMap..".json", "DATA") then
|
|
|
|
file.Write("permanent/"..currentMap..".json", "[]")
|
|
return
|
|
|
|
end
|
|
|
|
permanent.Pull()
|
|
|
|
end) |