diff --git a/FactorioSoftmodManager.lua b/FactorioSoftmodManager.lua index 07807b07..a93ce44b 100644 --- a/FactorioSoftmodManager.lua +++ b/FactorioSoftmodManager.lua @@ -174,19 +174,24 @@ Manager.global=setmetatable({__defaults={},__global={ return next_pair, tbl, nil end }},{ - __call=function(tbl,default,tbl2) + __call=function(tbl,default,metatable_src) + -- creates varible link to global and module information, use of a metatable is for already formed globals local Global = _G.global - local tbl2 = type(tbl2) == 'table' and getmetatable(tbl2) or nil - local module_name = type(default) == 'string' and default or tbl2 and tbl2.name or module_name - local module_path = type(default) == 'string' and moduleIndex[default] or tbl2 and tbl2.path or module_path + local metatable = getmetatable(metatable_src) + local module_name = type(default) == 'string' and default or metatable and metatable._module_name or module_name + local module_path = type(default) == 'string' and moduleIndex[default] or metatable and metatable._module_path or module_path + -- if there is no name or path then it will return and unedited version of global if not module_path or not module_name then return _G.global end - if type(default) == 'table' then Manager.verbose('Default global has been set for: global'..string.sub(module_path:gsub('/','.')),2) rawset(rawget(tbl,'__defaults'),tostring(module_name),default) end + -- edits the link to global to be the corrected dir, path varible is also created local path = 'global' for dir in module_path:gmatch('%a+') do path = path..'.'..dir if not rawget(Global,dir) then Manager.verbose('Added Global Dir: '..path) rawset(Global,dir,{}) end Global = rawget(Global,dir) end + -- the default value is set if there was a default given + if type(default) == 'table' then Manager.verbose('Default global has been set for: global'..string.sub(module_path:gsub('/','.')),2) rawset(rawget(tbl,'__defaults'),tostring(module_name),default) end + -- if the default value is true then it will reset the global to its default if default == true and rawget(rawget(tbl,'__defaults'),tostring(module_name)) then Manager.verbose('Reset Global Dir to default: '..path) -- cant set it to be equle otherwise it will lose its global propeity @@ -194,7 +199,8 @@ Manager.global=setmetatable({__defaults={},__global={ for key,value in pairs(Global) do rawset(Global,key,nil) end for key,value in pairs(rawget(rawget(tbl,'__defaults'),tostring(module_name))) do rawset(Global,key,deepcopy(value)) end end - return setmetatable(Global,{ + -- the metatable is remade if not already present + metatable = metatable or { __call=function(tbl,default) return Manager.global(default,tbl) end, __index=function(tbl,key) return rawget(Manager.global(nil,tbl),key) or moduleIndex[key] and Manager.global(key) end, __newindex=function(tbl,key,value) rawset(Manager.global(nil,tbl),key,value) end, @@ -206,8 +212,9 @@ Manager.global=setmetatable({__defaults={},__global={ end return next_pair, tbl, nil end, - path=module_path,name=module_name - }) + _module_path=module_path,_module_name=module_name + } + return setmetatable(Global,metatable) end, __index=function(tbl,key) return rawget(tbl(),key) or rawget(_G.global,key) or moduleIndex[key] and Manager.global(key) end, __newindex=function(tbl,key,value) rawset(tbl(),key,value) end, diff --git a/modules/ExpGamingCore/Command/control.lua b/modules/ExpGamingCore/Command/control.lua index 523152ab..902acefe 100644 --- a/modules/ExpGamingCore/Command/control.lua +++ b/modules/ExpGamingCore/Command/control.lua @@ -209,7 +209,7 @@ local function run_custom_command(command) local player = Game.get_player(command) or SERVER -- runs all middle ware if any, if there is no middle where then it relyis on .default_admin_only if #middleware > 0 then for _,callback in pairs(middleware) do - local success, err = pcall(callback,player_name,command.name,command) + local success, err = pcall(callback,player,command.name,command) if not success then error(err) elseif not err then player_return({'ExpGamingCore_Command.unauthorized'},defines.textcolor.crit) diff --git a/modules/ExpGamingCore/Role/src/commands.lua b/modules/ExpGamingCore/Role/src/commands.lua index 17fd46e9..a915b462 100644 --- a/modules/ExpGamingCore/Role/src/commands.lua +++ b/modules/ExpGamingCore/Role/src/commands.lua @@ -23,6 +23,6 @@ commands.add_validation('player-rank-alive',function(value,event) return player end) -commands.add_middleware(function(player_name,command_name,event) - return Role.allowed(player_name,command_name) +commands.add_middleware(function(player,command_name,event) + return Role.allowed(player,command_name) end) \ No newline at end of file diff --git a/modules/ExpGamingCore/Sync/src/ranking.lua b/modules/ExpGamingCore/Sync/src/ranking.lua index 4d1d5c71..73bbd043 100644 --- a/modules/ExpGamingCore/Sync/src/ranking.lua +++ b/modules/ExpGamingCore/Sync/src/ranking.lua @@ -25,10 +25,12 @@ function Sync.count_roles() local _roles = {} for name,role in pairs(Role.roles) do local players = role:get_players() - for k,player in pairs(players) do players[k] = player.name end + local _players = {} + for k,player in pairs(players) do _players[k] = player.name end local online = role:get_players(true) - for k,player in pairs(online) do online[k] = player.name end - _roles[role.name] = {players=players,online=online,n_players=#players,n_online=#online} + local _online = {} + for k,player in pairs(online) do _online[k] = player.name end + _roles[role.name] = {players=_players,online=_online,n_players=#_players,n_online=#_online} end return _roles end