Skip to content

Commit

Permalink
重构Module兼容部分代码
Browse files Browse the repository at this point in the history
  • Loading branch information
Muscipular committed Oct 8, 2021
1 parent dd7ccb7 commit b57a99b
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 89 deletions.
4 changes: 2 additions & 2 deletions libs/Module/LegacyModule.lua
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ function LegacyModule:createDelegate()
return
end
self['_t_' .. key] = fn;
self:regCallback(key, function(...)
regGlobalEvent(key, function(...)
return self:callInCtx(fn, ...);
end)
end, self.name)
elseif type(fn) == 'function' then
self:regCallback(key, fn);
end
Expand Down
87 changes: 0 additions & 87 deletions libs/Module/ModuleSystem.lua
Original file line number Diff line number Diff line change
Expand Up @@ -25,93 +25,6 @@ end
---@field simpleModule boolean 是否兼容老的luaModule
---@field absolutePath boolean

--[[
---解决兼容普通lua的问题
local function forSimpleModule()
local callInCtx;
local function loadFile(file, cb)
if file then
local moduleName;
for i, v in pairs(Modules) do
if v.___aPath == file then
moduleName = i;
end
end
loadModule(moduleName or file, { path = file, simpleModule = true, forceReload = true, absolutePath = true });
end
local key = '__callInCtx' .. cb;
_G[key] = Func.bind(callInCtx, cb);
return key;
end
local simpleModuleCtx = {
string = {},
table = {},
VaildChar = Char.IsValidCharIndex,
NL = {
CreateNpc = function(file, cb)
return NL.CreateNpc(nil, loadFile(file, cb));
end
},
Char = {},
Battle = {},
};
callInCtx = function(name, ...)
return simpleModuleCtx[name](...)
end
for f, n in pairs({ Char = Char, Battle = Battle }) do
for i, v in pairs(n) do
if string.sub(i, 1, 3) == 'Set' and string.sub(i, #i - 4) == 'Event' then
simpleModuleCtx[f][i] = function(file, cb, ...)
return v(nil, loadFile(file, cb), ...)
end
end
end
end
for i, v in pairs(NL) do
if string.sub(i, 1, 3) == 'Reg' then
simpleModuleCtx.NL[i] = function(file, cb, ...)
return v(nil, loadFile(file, cb), ...)
end
end
end
simpleModuleCtx.string = setmetatable(simpleModuleCtx.string, { __index = string });
simpleModuleCtx.table = setmetatable(simpleModuleCtx.table, { __index = table });
simpleModuleCtx.NL = setmetatable(simpleModuleCtx.NL, { __index = NL });
simpleModuleCtx.Char = setmetatable(simpleModuleCtx.Char, { __index = Char });
simpleModuleCtx.Battle = setmetatable(simpleModuleCtx.Battle, { __index = Battle });
print(simpleModuleCtx.NL, simpleModuleCtx.NL.CreateNpc, NL, NL.CreateNpc)
local Delegate = {}
for k, _ff in pairs(NL) do
if string.sub(k, 1, 3) == 'Reg' then
Delegate['RegDel' .. string.sub(k, 4)] = function(fn)
if type(fn) == 'string' then
if simpleModuleCtx['__delegate_tmp_' .. fn] then
return
end
simpleModuleCtx['__delegate_tmp_' .. fn] = function(...)
if simpleModuleCtx[fn] then
return simpleModuleCtx[fn](...);
end
end
regGlobalEvent(string.sub(k, 4), simpleModuleCtx['__delegate_tmp_' .. fn], 'Delegate')
elseif type(fn) == 'function' then
regGlobalEvent(string.sub(k, 4), fn, 'Delegate');
end
end
Delegate['Reg' .. string.sub(k, 4)] = Delegate['RegDel' .. string.sub(k, 4)];
end
end
simpleModuleCtx.Delegate = Delegate;
return simpleModuleCtx;
end
local simpleModuleCtx = forSimpleModule();
]]

local function loadModuleFile(path, moduleName, forceReload)
local ctx = {}
local rG = {
Expand Down

0 comments on commit b57a99b

Please sign in to comment.