mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2025-12-30 20:41:41 +09:00
Sync Now Ready
This commit is contained in:
@@ -145,20 +145,18 @@ Manager.setVerbose = setmetatable(
|
|||||||
-- call to verbose to show start up, will always be present
|
-- call to verbose to show start up, will always be present
|
||||||
Manager.verbose('Current state is now: "selfInit"; The verbose state is: '..tostring(Manager.setVerbose.selfInit),true)
|
Manager.verbose('Current state is now: "selfInit"; The verbose state is: '..tostring(Manager.setVerbose.selfInit),true)
|
||||||
|
|
||||||
--- An optinal feature that can be used if you dont want to worry about conflicting global paths
|
--- Used to avoid conflicts in the global table
|
||||||
-- @usage local global = Manager.global() -- sets up the global struture
|
-- @usage global[key] -- used like the normal global table
|
||||||
-- @usage global{'foo','bar'} -- sets the default value
|
-- @usage global{'foo','bar'} -- sets the default value
|
||||||
-- @tparam[opt={}] table default the default value of global
|
-- @tparam[opt={}] table default the default value of global
|
||||||
-- @treturn table the new global table for that module
|
-- @treturn table the new global table for that module
|
||||||
function Manager.global(default)
|
Manager.global=setmetatable({__global=global,__defaults={}},{
|
||||||
local default = default or {}
|
|
||||||
return setmetatable(default,{
|
|
||||||
__call=function(tbl,default)
|
__call=function(tbl,default)
|
||||||
if default then rawset(tbl,'default',default) end
|
local global = rawget(tbl,'__global')
|
||||||
local global = _G.global
|
if not module_path or not module_name then return global end
|
||||||
if not module_path then return global end
|
if default then rawset(rawget(tbl,'__defaults'),tostring(module_name),default) end
|
||||||
local path = 'global'
|
local path = 'global'
|
||||||
local new_dir = false -- this is to test if the default should be used
|
local new_dir = false
|
||||||
for dir in module_path:gmatch('%a+') do
|
for dir in module_path:gmatch('%a+') do
|
||||||
path = path..'.'..dir
|
path = path..'.'..dir
|
||||||
if not rawget(global,dir) then new_dir=true Manager.verbose('Added Global Dir: '..path) rawset(global,dir,{}) end
|
if not rawget(global,dir) then new_dir=true Manager.verbose('Added Global Dir: '..path) rawset(global,dir,{}) end
|
||||||
@@ -166,7 +164,7 @@ function Manager.global(default)
|
|||||||
end
|
end
|
||||||
if new_dir then
|
if new_dir then
|
||||||
Manager.verbose('Set Global Dir: '..path..' to its default')
|
Manager.verbose('Set Global Dir: '..path..' to its default')
|
||||||
for key,value in pairs(rawget(tbl,'default')) do rawset(global,key,value) end
|
for key,value in pairs(rawget(rawget(tbl,'__defaults'),tostring(module_name))) do rawset(global,key,value) end
|
||||||
end
|
end
|
||||||
return global
|
return global
|
||||||
end,
|
end,
|
||||||
@@ -174,8 +172,8 @@ function Manager.global(default)
|
|||||||
__newindex=function(tbl,key,value) rawset(tbl(),key,value) end,
|
__newindex=function(tbl,key,value) rawset(tbl(),key,value) end,
|
||||||
__pairs=function(tbl) return pairs(tbl()) end,
|
__pairs=function(tbl) return pairs(tbl()) end,
|
||||||
__ipairs=function(tbl) return ipairs(tbl()) end
|
__ipairs=function(tbl) return ipairs(tbl()) end
|
||||||
})
|
})
|
||||||
end
|
global=Manager.global
|
||||||
|
|
||||||
--- Creates a sand box envorment and runs a callback in that sand box; provents global pollution
|
--- Creates a sand box envorment and runs a callback in that sand box; provents global pollution
|
||||||
-- @function Manager.sandbox
|
-- @function Manager.sandbox
|
||||||
@@ -188,6 +186,7 @@ Manager.sandbox = setmetatable({
|
|||||||
-- can not use existing keys of _G
|
-- can not use existing keys of _G
|
||||||
verbose=Manager.verbose,
|
verbose=Manager.verbose,
|
||||||
loaded_modules=ReadOnlyManager,
|
loaded_modules=ReadOnlyManager,
|
||||||
|
global=Manager.global,
|
||||||
module_verbose=false,
|
module_verbose=false,
|
||||||
module_exports=false
|
module_exports=false
|
||||||
},{
|
},{
|
||||||
@@ -265,7 +264,7 @@ Manager.loadModules = setmetatable({},
|
|||||||
if rawget(_G,module_name) and type(tbl[module_name]) == 'table' then setmetatable(rawget(_G,module_name),{__index=tbl[module_name]}) end
|
if rawget(_G,module_name) and type(tbl[module_name]) == 'table' then setmetatable(rawget(_G,module_name),{__index=tbl[module_name]}) end
|
||||||
else
|
else
|
||||||
Manager.verbose('Failed load: "'..module_name..'"; path: '..path..' ('..module..')','errorCaught')
|
Manager.verbose('Failed load: "'..module_name..'"; path: '..path..' ('..module..')','errorCaught')
|
||||||
for event_name,callbacks in pairs(Manager.event) do Manager.verbose('Removed Event Handler: "'..module_name..'/'..tbl.names[event_name],'eventRegistered') callbacks[module_name] = nil end
|
for event_name,callbacks in pairs(Manager.event) do Manager.verbose('Removed Event Handler: "'..module_name..'/'..Manager.event.names[event_name],'eventRegistered') callbacks[module_name] = nil end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
-- new state for the manager to allow control of verbose
|
-- new state for the manager to allow control of verbose
|
||||||
@@ -449,7 +448,8 @@ Manager.event = setmetatable({
|
|||||||
Manager.verbose('Added Handler: "'..tbl.names[key]..'"','eventRegistered')
|
Manager.verbose('Added Handler: "'..tbl.names[key]..'"','eventRegistered')
|
||||||
-- checks that the event has a valid table to store callbacks; if its not valid it will creat it and register a real event handler
|
-- checks that the event has a valid table to store callbacks; if its not valid it will creat it and register a real event handler
|
||||||
if not rawget(rawget(tbl,'__events'),key) then
|
if not rawget(rawget(tbl,'__events'),key) then
|
||||||
if key < 0 then rawget(tbl,tbl.names[key])(function(...) tbl(key,...) end)
|
if key == -1 then -- this already has a handler
|
||||||
|
elseif key < 0 then rawget(tbl,tbl.names[key])(function(...) tbl(key,...) end)
|
||||||
else rawget(tbl,'__event')(key,function(...) tbl(key,...) end) end
|
else rawget(tbl,'__event')(key,function(...) tbl(key,...) end) end
|
||||||
rawset(rawget(tbl,'__events'),key,{}) end
|
rawset(rawget(tbl,'__events'),key,{}) end
|
||||||
-- adds callback to Manager.event.__events[event_id][module_name]
|
-- adds callback to Manager.event.__events[event_id][module_name]
|
||||||
@@ -520,6 +520,11 @@ rawset(Manager.event,'names',setmetatable({},{
|
|||||||
end
|
end
|
||||||
}))
|
}))
|
||||||
|
|
||||||
|
script.on_init(function(...)
|
||||||
|
--rawset(Manager.global,'_global',global)
|
||||||
|
--global = Manager.global
|
||||||
|
Manager.event(key,...)
|
||||||
|
end)
|
||||||
--over rides for the base values; can be called though Event
|
--over rides for the base values; can be called though Event
|
||||||
Event=setmetatable({},{__call=Manager.event,__index=function(tbl,key) return Manager.event[key] or script[key] or error('Invalid Index To Table Event') end})
|
Event=setmetatable({},{__call=Manager.event,__index=function(tbl,key) return Manager.event[key] or script[key] or error('Invalid Index To Table Event') end})
|
||||||
script.mod_name = setmetatable({},{__index=_G.module_name})
|
script.mod_name = setmetatable({},{__index=_G.module_name})
|
||||||
|
|||||||
@@ -6,7 +6,20 @@
|
|||||||
|
|
||||||
local Sync = {}
|
local Sync = {}
|
||||||
local Sync_updates = {}
|
local Sync_updates = {}
|
||||||
local global = Manager.global()
|
-- sets up the global for this module
|
||||||
|
global{
|
||||||
|
server_name='Factorio Server',
|
||||||
|
server_description='A factorio server for everyone',
|
||||||
|
reset_time='On Demand',
|
||||||
|
time='Day Mth 00 00:00:00 UTC Year',
|
||||||
|
time_set={0,'0.00M'},
|
||||||
|
last_update={0,'0.00M'},
|
||||||
|
time_period={18000,'5.00M'},
|
||||||
|
players={online={'Offline'},n_online=0,all={'Offline'},n_all=0,admins_online=0,afk_players=0,times={'Offline'}},
|
||||||
|
ranks={'Offline'},
|
||||||
|
rockets=0,
|
||||||
|
mods={'Offline'}
|
||||||
|
}
|
||||||
|
|
||||||
--- Used to standidise the tick format for any sync info
|
--- Used to standidise the tick format for any sync info
|
||||||
-- @usage Sync.tick_format(60) -- return {60,'1.00M'}
|
-- @usage Sync.tick_format(60) -- return {60,'1.00M'}
|
||||||
@@ -131,7 +144,7 @@ end
|
|||||||
function Sync.count_ranks()
|
function Sync.count_ranks()
|
||||||
if not game then return {'Offline'} end
|
if not game then return {'Offline'} end
|
||||||
local _ranks = {admin={online={},players={}},user={online={},players={}}}
|
local _ranks = {admin={online={},players={}},user={online={},players={}}}
|
||||||
for power,rank in pairs(game.players) do
|
for index,player in pairs(game.players) do
|
||||||
if player.admin then
|
if player.admin then
|
||||||
table.insert(_ranks.admin.players,player.name)
|
table.insert(_ranks.admin.players,player.name)
|
||||||
if player.connected then table.insert(_ranks.admin.online,player.name) end
|
if player.connected then table.insert(_ranks.admin.online,player.name) end
|
||||||
@@ -244,28 +257,8 @@ function Sync:on_init()
|
|||||||
info.time_set[2] = tick_to_display_format(game.tick)
|
info.time_set[2] = tick_to_display_format(game.tick)
|
||||||
return true
|
return true
|
||||||
end,function() local info = Sync.info return info.time..' (+'..(game.tick-info.time_set[1])..' Ticks)' end)
|
end,function() local info = Sync.info return info.time..' (+'..(game.tick-info.time_set[1])..' Ticks)' end)
|
||||||
-- sets up the global for this module
|
-- updates installed mods
|
||||||
global{
|
Sync.info{mods=table.keys(loaded_modules)}
|
||||||
server_name='Factorio Server',
|
|
||||||
server_description='A factorio server for everyone',
|
|
||||||
reset_time='On Demand',
|
|
||||||
time='Day Mth 00 00:00:00 UTC Year',
|
|
||||||
time_set=Sync.tick_format(0),
|
|
||||||
last_update=Sync.tick_format(0),
|
|
||||||
time_period=Sync.tick_format(18000),
|
|
||||||
players={
|
|
||||||
online=Sync.count_players(true),
|
|
||||||
n_online=game and #game.connected_players or 0,
|
|
||||||
all=Sync.count_players(),
|
|
||||||
n_all=game and #game.players or 0,
|
|
||||||
admins_online=Sync.count_admins(),
|
|
||||||
afk_players=Sync.count_afk(),
|
|
||||||
times=Sync.count_player_times()
|
|
||||||
},
|
|
||||||
ranks=Sync.count_ranks(),
|
|
||||||
rockets=game and game.forces['player'].get_item_launched('satellite') or 0,
|
|
||||||
mods=table.keys(loaded_modules)
|
|
||||||
}
|
|
||||||
-- optinal dependies
|
-- optinal dependies
|
||||||
if loaded_modules.Gui then verbose('ExpGamingCore.Gui is installed; Loading gui lib') require(module_path..'/src/gui') end
|
if loaded_modules.Gui then verbose('ExpGamingCore.Gui is installed; Loading gui lib') require(module_path..'/src/gui') end
|
||||||
if loaded_modules.Ranking then verbose('ExpGamingCore.Ranking is installed; Loading ranking lib') require(module_path..'/src/ranking') end
|
if loaded_modules.Ranking then verbose('ExpGamingCore.Ranking is installed; Loading ranking lib') require(module_path..'/src/ranking') end
|
||||||
|
|||||||
@@ -9,9 +9,9 @@ return {
|
|||||||
['Color']='/modules/FactorioStdLib/Color',
|
['Color']='/modules/FactorioStdLib/Color',
|
||||||
['table']='/modules/FactorioStdLib/Table',
|
['table']='/modules/FactorioStdLib/Table',
|
||||||
['string']='/modules/FactorioStdLib/String',
|
['string']='/modules/FactorioStdLib/String',
|
||||||
['Ranking']='/modules/ExpGamingCore/Ranking',
|
--['Ranking']='/modules/ExpGamingCore/Ranking',
|
||||||
['commands']='/modules/ExpGamingCore/Commands',
|
--['commands']='/modules/ExpGamingCore/Commands',
|
||||||
['Gui']='/modules/ExpGamingCore/Gui',
|
--['Gui']='/modules/ExpGamingCore/Gui',
|
||||||
['Server']='/modules/ExpGamingCore/Server',
|
--['Server']='/modules/ExpGamingCore/Server',
|
||||||
['Sync']='/modules/ExpGamingCore/Sync',
|
['Sync']='/modules/ExpGamingCore/Sync',
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user