Skip to content

Commit

Permalink
LoadModules、GetModuleListWithFunc递归查找子节点文件夹
Browse files Browse the repository at this point in the history
  • Loading branch information
lilith-avatar-richardzhou committed Jul 9, 2021
1 parent cea577f commit 496fdb7
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
-- @copyright Lilith Games, Avatar Team, Dead Ratman
-- @author Dead Ratman
_G.C = Client
ModuleUtil.LoadModules(world.C_Code.Module, C)
ModuleUtil.LoadModules(world.Client.Module, C)
C:Run()
10 changes: 1 addition & 9 deletions Code/['World']['Global']['ModuleRequireScript'].Script.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
-- Game Defines
GAME_ID = 'X0000'
print('GAME_ID = ', GAME_ID)
PluginConfig = {
'FUNC_Guide'
}

-- Utilities
ModuleUtil = require(Utility.ModuleUtilModule)
Expand Down Expand Up @@ -37,9 +34,4 @@ ModuleUtil.LoadModules(Framework.Client)

-- Globle Defines
ModuleUtil.LoadModules(Define)
ModuleUtil.LoadXlsModules(Xls, Config)

-- Plugin Modules
for _, v in pairs(PluginConfig) do
ModuleUtil.LoadPlugin(Plugin[v])
end
ModuleUtil.LoadXlsModules(Xls, Config)
Original file line number Diff line number Diff line change
Expand Up @@ -8,35 +8,19 @@ local ModuleUtil = {}
--- 加载模块目录
-- @param _root 模块目录的节点
-- @param _scope 载入后脚本的作用域
function ModuleUtil.LoadModules(_root, _scope)
-- @param _isRec 是否递归寻找子节点文件夹
function ModuleUtil.LoadModules(_root, _scope, _isRec)
_scope = _scope or _G
_isRec = _isRec or true
assert(_root, '[ModuleUtil] Node does NOT exist!')
local tmp, name = _root:GetChildren()
for _, v in pairs(tmp) do
local nodes, name = _root:GetChildren()
for _, v in pairs(nodes) do
if v.ClassName == 'ModuleScriptObject' then
name = (v.Name):gsub('Module', '')
print('[ModuleUtil] Load Module: ', name)
_scope[name] = require(v)
end
end
end

--- 加载插件模块目录
-- @author Xinwu Zhang
-- @param _root 插件文件夹节点
-- @param _scope 载入后脚本的作用域
function ModuleUtil.LoadPlugin(_root, _scope)
_scope = _scope or _G
assert(_root, '[ModuleUtil] Plugin Node does NOT exist!')
_scope[_root.Name] = {}
local tmp, name = _root:GetChildren()
for _, v in pairs(tmp) do
for _, j in pairs(v:GetChildren()) do
if j.ClassName == 'ModuleScriptObject' then
name = (j.Name):gsub('Module', '')
print('[ModuleUtil] Load Module: ', _root.Name, name)
_scope[_root.Name][name] = require(j)
end
elseif v.ClassName == 'FolderObject' and _isRec then
ModuleUtil.LoadModules(v, _scope, _isRec)
end
end
end
Expand Down Expand Up @@ -70,18 +54,22 @@ end
-- @param @string _fn 方法名 function_name
-- @param @table _list 存放的table
-- @param _scope 该脚本的作用域
function ModuleUtil.GetModuleListWithFunc(_root, _fn, _list, _scope)
-- @param _isRec 是否递归寻找子节点文件夹
function ModuleUtil.GetModuleListWithFunc(_root, _fn, _list, _scope, _isRec)
assert(_root, '[ModuleUtil] Node does NOT exist!')
assert(not string.isnilorempty(_fn), '[ModuleUtil] Function name is nil or empty!')
assert(_list, '[ModuleUtil] List is NOT initialized!')
_scope = _scope or _G
local tmp, name = _root:GetChildren()
for _, v in pairs(tmp) do
name = (v.Name):gsub('Module', '')
print(name, _fn)
print(_scope[name] and 1 or 0)
if _scope[name] and _scope[name][_fn] and type(_scope[name][_fn]) == 'function' then
table.insert(_list, _scope[name])
_isRec = _isRec or true
local nodes, name = _root:GetChildren()
for _, v in pairs(nodes) do
if v.ClassName == 'ModuleScriptObject' then
name = (v.Name):gsub('Module', '')
if _scope[name] and _scope[name][_fn] and type(_scope[name][_fn]) == 'function' then
table.insert(_list, _scope[name])
end
elseif v.ClassName == 'FolderObject' and _isRec then
ModuleUtil.GetModuleListWithFunc(v, _fn, _list, _scope, _isRec)
end
end
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
--- 服务器代码入口
-- @script Server Awake Function
-- @copyright Lilith Games, Avatar Team
-- @author Yuancheng Zhang
-- @author Yuancheng Zhang, Dead Ratman
_G.S = Server
ModuleUtil.LoadModules(world.S_Code.Module, S)
ModuleUtil.LoadModules(world.Server.Module, S)
S:Run()


0 comments on commit 496fdb7

Please sign in to comment.