源战役客户端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

110 lines
2.3 KiB

ConfigItem = ConfigItem or BaseClass()
local ConfigItem = ConfigItem
local TimeUtil_getClientTime = TimeUtil.getClientTime
function ConfigItem:__init(res, max_count, callback)
self.node_list = {}
self.max_count = max_count
self.count = 0
self.load_succeed = false
self.lua_config_name = false
if res == "data_skill" then
self.lua_config_name = "Skill"
if Config.Skill then end
elseif res == "data_mon" then
self.lua_config_name = "Mon"
if Config.Mon then end
elseif res == "data_goods" then
self.lua_config_name = "Goods"
if Config.Goods then end
else
--加载外部cdn资源
local load_call_back = function(bytes)
if bytes then
self.data = dbParser:OpenDb(bytes)
end
if callback then
callback()
end
end
lua_resM:loadOutsideTextAsset(self,"client/luaconfig/"..res..".db",load_call_back)
end
--独立文件
--local full_puth = res
--self.data = dbParser:OpenDb(full_puth)
end
function ConfigItem:__delete()
if self.data then
self.data:deleteMe()
self.data = nil
end
self.node_list = {}
end
function ConfigItem:GetItem(id)
if id==nil then
return nil
end
local node = self.node_list[id]
if node ~= nil then
node.time = TimeUtil_getClientTime()
return node.item
end
node = {time = TimeUtil_getClientTime(),item = nil}
self.count = self.count + 1
ConfigItem.CheckCount(self, node.time + 100)
node.item = ConfigItem.GetConfigItem(self, id)
TmpCfgObj = nil
self.node_list[id] = node
return node.item
end
function ConfigItem:CheckCount(time)
if self.count > self.max_count then
local id = nil
for key, node in pairs(self.node_list) do
if node.time < time then
time = node.time
id = key
end
end
if id ~= nil then
self.node_list[id] = nil
self.count = self.count - 1
end
end
end
function ConfigItem:GetConfigItem(id)
if self.lua_config_name and id then
local cfg = Config[self.lua_config_name]
if type(id) == "string" then
id = tonumber(id)
end
if cfg then
local str = cfg[id]
-- print("str =", id, str == nil)
if str then
local func = loadstring(str)
if func then
return func()
end
end
end
elseif self.data then
local str = self.data:GetConfigItem(id)
if str then
local func = loadstring(str)
if func then
func()
return TmpCfgObj
end
end
end
end