79 lines
1.8 KiB
Lua
79 lines
1.8 KiB
Lua
local ServerBaseData = class("ServerBaseData")
|
|
|
|
function ServerBaseData:ctor(...)
|
|
self.data = {}
|
|
-- self.data.__parent = self
|
|
|
|
-- local innerData = nil
|
|
-- innerData = {
|
|
-- __index = function (t, key)
|
|
-- return innerData[key]
|
|
-- end,
|
|
-- __newindex = function (t, key, value)
|
|
-- innerData[key] = value
|
|
-- end
|
|
-- }
|
|
-- setmetatable(self.data, innerData)
|
|
end
|
|
|
|
function ServerBaseData:init()
|
|
end
|
|
|
|
function ServerBaseData:clear()
|
|
end
|
|
|
|
function ServerBaseData:loadLocalData()
|
|
local data = LocalData:getString(self:_getLocalSaveKey(), "")
|
|
local dataObj = nil
|
|
if data and data ~= "" then
|
|
dataObj = json.decode(data)
|
|
end
|
|
return dataObj
|
|
end
|
|
|
|
function ServerBaseData:saveLocalData()
|
|
local str = json.encode(self.data) or ""
|
|
LocalData:setString(self:_getLocalSaveKey(), str)
|
|
end
|
|
|
|
function ServerBaseData:_getLocalSaveKey()
|
|
if self._localSaveKey == nil then
|
|
self._localSaveKey = "ServerData_" .. self.__cname
|
|
end
|
|
return self._localSaveKey
|
|
end
|
|
|
|
function ServerBaseData:getCloneData()
|
|
local cloneData = {}
|
|
local function _copy(object)
|
|
if type(object) ~= "table" then
|
|
return object
|
|
elseif cloneData[object] then
|
|
return cloneData[object]
|
|
end
|
|
local newObject = {}
|
|
cloneData[object] = newObject
|
|
for key, value in pairs(object) do
|
|
newObject[_copy(key)] = _copy(value)
|
|
end
|
|
return newObject
|
|
end
|
|
return _copy(self.data)
|
|
end
|
|
|
|
function ServerBaseData:_clear()
|
|
self._localSaveKey = nil
|
|
self:clear()
|
|
end
|
|
|
|
if NOT_PUBLISH then
|
|
ServerBaseData._editorGetLocalSaveKey = ServerBaseData._getLocalSaveKey
|
|
function ServerBaseData:_getLocalSaveKey()
|
|
if self._localSaveKey == nil then
|
|
self._localSaveKey = LocalData:getDistinctId() .. "ServerData_" .. self.__cname
|
|
end
|
|
return self._localSaveKey
|
|
end
|
|
end
|
|
|
|
return ServerBaseData |