mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2025-12-29 20:16:38 +09:00
Covnerted Event and Global
This commit is contained in:
@@ -171,7 +171,7 @@ end
|
||||
-- Event Handlers Define
|
||||
|
||||
-- creates all permission groups and links them
|
||||
script.on_event('on_init',function()
|
||||
Event.add('on_init',function()
|
||||
for name,group in pairs(Group.groups) do
|
||||
local _group = game.permissions.create_group(name)
|
||||
verbose('Created Permission Group: '..name)
|
||||
|
||||
@@ -208,14 +208,14 @@ function center._prototype:add_tab(name,caption,tooltip,callback)
|
||||
end
|
||||
|
||||
-- used so that when gui close key is pressed this will close the gui
|
||||
script.on_event(defines.events.on_gui_closed,function(event)
|
||||
Event.add(defines.events.on_gui_closed,function(event)
|
||||
if event.element and event.element.valid then event.element.destroy() end
|
||||
end)
|
||||
|
||||
script.on_event(defines.events.on_player_respawned,center.clear)
|
||||
Event.add(defines.events.on_player_respawned,center.clear)
|
||||
|
||||
function center.on_init()
|
||||
if loaded_modules['ExpGamingCore.Role'] then script.on_event(defines.events.on_role_change,center.clear) end
|
||||
if loaded_modules['ExpGamingCore.Role'] then Event.add(defines.events.on_role_change,center.clear) end
|
||||
end
|
||||
-- calling will attempt to add a new gui
|
||||
return setmetatable(center,{__call=function(self,...) return self.add(...) end})
|
||||
@@ -9,7 +9,8 @@ local Color = require('FactorioStdLib.Color')
|
||||
local Server -- ExpGamingCore.Server@?^4.0.0
|
||||
|
||||
local Gui = {}
|
||||
local global = global()
|
||||
local global = {}
|
||||
Global.register(global,function(tbl) global = tbl end)
|
||||
--- Used to set and get data about different guis
|
||||
-- @usage Gui.data[location] -- returns the gui data for that gui location ex center
|
||||
-- @usage Gui.data(location,gui_name,gui_data) -- adds gui data for a gui at a location
|
||||
@@ -140,7 +141,7 @@ function Gui.cam_link(data)
|
||||
return data.cam
|
||||
end
|
||||
|
||||
script.on_event('on_tick', function(event)
|
||||
Event.add('on_tick', function(event)
|
||||
if loaded_modules['ExpGamingCore.Server'] then return end
|
||||
if global.cams and is_type(global.cams,'table') and #global.cams > 0 then
|
||||
local update = 4
|
||||
@@ -158,7 +159,7 @@ script.on_event('on_tick', function(event)
|
||||
end
|
||||
end)
|
||||
|
||||
script.on_event('on_player_respawned',function(event)
|
||||
Event.add('on_player_respawned',function(event)
|
||||
if loaded_modules['ExpGamingCore.Server'] then return end
|
||||
if global.players and is_type(global.players,'table') and #global.players > 0 and global.players[event.player_index] then
|
||||
local remove = {}
|
||||
|
||||
@@ -136,7 +136,7 @@ function inputs._event_handler(event)
|
||||
end
|
||||
end
|
||||
|
||||
script.on_event(inputs.events,inputs._event_handler)
|
||||
Event.add(inputs.events,inputs._event_handler)
|
||||
inputs.events.error = {}
|
||||
|
||||
-- the following functions are just to make inputs easier but if what you want is not include use inputs.add(obj)
|
||||
|
||||
@@ -27,7 +27,8 @@ left.hide = Gui.inputs{
|
||||
end
|
||||
end)
|
||||
|
||||
local global = global()
|
||||
local global = {}
|
||||
Global.register(global,function(tbl) global = tbl end)
|
||||
|
||||
-- used for debugging
|
||||
function left.override_open(state)
|
||||
@@ -212,7 +213,7 @@ function left._prototype:toggle(player)
|
||||
return left_frame.style.visible
|
||||
end
|
||||
|
||||
script.on_event(defines.events.on_player_joined_game,function(event)
|
||||
Event.add(defines.events.on_player_joined_game,function(event)
|
||||
-- draws the left guis when a player first joins, fake_event is just because i am lazy
|
||||
local player = Game.get_player(event)
|
||||
local frames = Gui.data.left or {}
|
||||
@@ -231,7 +232,7 @@ script.on_event(defines.events.on_player_joined_game,function(event)
|
||||
end
|
||||
end)
|
||||
|
||||
script.on_event(defines.events.on_tick,function(event)
|
||||
Event.add(defines.events.on_tick,function(event)
|
||||
if ((event.tick+10)/(3600*game.speed)) % 15 == 0 then
|
||||
left.update()
|
||||
end
|
||||
|
||||
@@ -124,7 +124,7 @@ function popup.on_post()
|
||||
end)
|
||||
end
|
||||
|
||||
script.on_event(defines.events.on_player_joined_game,popup.flow)
|
||||
Event.add(defines.events.on_player_joined_game,popup.flow)
|
||||
|
||||
-- calling will attempt to add a new popup style
|
||||
return setmetatable(popup,{__call=function(self,...) return self.add(...) end})
|
||||
@@ -85,6 +85,6 @@ function toolbar.on_init()
|
||||
if loaded_modules['ExpGamingCore.Role'] then Role = require('ExpGamingCore.Role') end
|
||||
end
|
||||
|
||||
script.on_event({defines.events.on_role_change,defines.events.on_player_joined_game},toolbar.draw)
|
||||
Event.add({defines.events.on_role_change,defines.events.on_player_joined_game},toolbar.draw)
|
||||
-- calling with only a player will draw the toolbar for that player, more params will attempt to add a button
|
||||
return setmetatable(toolbar,{__call=function(self,player,extra,...) if extra then return self.add(player,extra,...) else self.draw(player) end end})
|
||||
@@ -61,7 +61,7 @@ local Role = {
|
||||
_RoleSelfReference=Role
|
||||
|
||||
-- Global Define
|
||||
local global = global{
|
||||
local global = {
|
||||
change_cache_length=15,
|
||||
changes={},
|
||||
latest_change={},
|
||||
@@ -69,7 +69,8 @@ local global = global{
|
||||
players={},
|
||||
roles={}
|
||||
}
|
||||
RoleGlobal = global
|
||||
Global.register(global,function(tbl) RoleGlobal = tbl end)
|
||||
|
||||
-- Function Define
|
||||
|
||||
--- Used to set default roles for players who join
|
||||
@@ -459,7 +460,7 @@ function Role._prototype:remove_player(player,by_player,batch)
|
||||
end
|
||||
|
||||
-- Event Handlers Define
|
||||
script.on_event(role_change_event_id,function(event)
|
||||
Event.add(role_change_event_id,function(event)
|
||||
-- variable init
|
||||
local player = Game.get_player(event)
|
||||
local by_player = Game.get_player(event.by_player_index) or SERVER
|
||||
@@ -505,7 +506,7 @@ script.on_event(role_change_event_id,function(event)
|
||||
end
|
||||
end)
|
||||
|
||||
script.on_event(defines.events.on_player_created,function(event)
|
||||
Event.add(defines.events.on_player_created,function(event)
|
||||
local player = Game.get_player(event)
|
||||
local highest = Role.get_highest(player) or Role.meta.default
|
||||
Group.assign(player,highest.group)
|
||||
@@ -514,7 +515,7 @@ script.on_event(defines.events.on_player_created,function(event)
|
||||
if Role.preassign[player.name:lower()] then Role.assign(player,Role.preassign[player.name:lower()]) end
|
||||
end)
|
||||
|
||||
script.on_event(defines.events.on_tick,function(event)
|
||||
Event.add(defines.events.on_tick,function(event)
|
||||
if game.tick%(3600*5) ~= 0 then return end -- every 5 minutes
|
||||
for _,player in pairs(game.connected_players) do
|
||||
if not Role.has_flag(player,'block_auto_promote') then
|
||||
|
||||
@@ -65,7 +65,7 @@ if Sync.add_to_gui then
|
||||
end
|
||||
|
||||
-- adds a discord emit for rank changing
|
||||
script.on_event('on_role_change',function(event)
|
||||
Event.add('on_role_change',function(event)
|
||||
local role = Role.get(event.role_name)
|
||||
local player = Game.get_player(event)
|
||||
local by_player = Game.get_player(event.by_player_index) or SERVER
|
||||
|
||||
@@ -22,7 +22,7 @@ local module_verbose = false --true|false
|
||||
-- @field print_to contains players that event details will be printed to
|
||||
-- @field uuid contains the random number generator for the uuid system
|
||||
local pre_load_uuid = 0
|
||||
local global = global{
|
||||
local global = {
|
||||
all={_n=0},
|
||||
queue={},
|
||||
tick={},
|
||||
@@ -33,6 +33,7 @@ local global = global{
|
||||
print_to={},
|
||||
uuid=0
|
||||
}
|
||||
Global.register(global,function(tbl) global = tbl end)
|
||||
|
||||
--- Used to generate a new uuid for the thread system
|
||||
-- @usage local uuid = tostring(Server.uuid) -- calling tostring locks the value
|
||||
@@ -155,9 +156,9 @@ function Server._thread_debuger(player,event,state)
|
||||
else print_to[player.index][event] = true end
|
||||
end
|
||||
|
||||
--- Calls all threads on a certain game event (used with script.on_event)
|
||||
--- Calls all threads on a certain game event (used with Event.add)
|
||||
-- @local Server._thread_handler
|
||||
-- @usage script.on_event(defines.events,Server._thread_handler) -- adds this handler
|
||||
-- @usage Event.add(defines.events,Server._thread_handler) -- adds this handler
|
||||
-- @tparam table event the event that is called
|
||||
function Server._thread_handler(event)
|
||||
-- returns to players who have set _thread_debuger to true
|
||||
@@ -195,7 +196,7 @@ function Server.add_thread_handler(event)
|
||||
local threads = global
|
||||
if not threads.events[event] then
|
||||
threads.events[event] = {}
|
||||
script.on_event(event,Server._thread_handler)
|
||||
Event.add(event,Server._thread_handler)
|
||||
return true
|
||||
end
|
||||
return false
|
||||
@@ -485,7 +486,7 @@ function Server._thread:on_event(event,callback)
|
||||
return self
|
||||
end
|
||||
|
||||
script.on_event(defines.events.on_tick,function(event)
|
||||
Event.add(defines.events.on_tick,function(event)
|
||||
-- uses its own on_tick event so that other actions can be tested for
|
||||
if event.tick < 10 then return end
|
||||
if #global.tick > 0 then Server.run_tick_threads() end -- on tick events
|
||||
@@ -505,7 +506,7 @@ script.on_load(function(event)
|
||||
end)
|
||||
|
||||
function Server:on_init()
|
||||
for name,id in pairs(defines.events) do if not script.get_event_handler(id) then script.on_event(id,Server._thread_handler) end end
|
||||
for name,id in pairs(defines.events) do if not script.get_event_handler(id) then Event.add(id,Server._thread_handler) end end
|
||||
if loaded_modules['ExpGamingCore.Command'] then verbose('ExpGamingCore.Command is installed; Loading commands src') require(module_path..'/src/commands',{Server=Server}) end
|
||||
end
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ local module_verbose = false --true|false
|
||||
-- @field ranks a list of player ranks
|
||||
-- @field rockets the number of rockets launched
|
||||
-- @field mods the mods which are loaded
|
||||
local global = global{
|
||||
local global = {
|
||||
server_name='Factorio Server',
|
||||
server_description='A factorio server for everyone',
|
||||
reset_time='On Demand',
|
||||
@@ -47,6 +47,7 @@ local global = global{
|
||||
rockets=0,
|
||||
mods={'Offline'}
|
||||
}
|
||||
Global.register(global,function(tbl) global = tbl end)
|
||||
|
||||
--- Player sub-table
|
||||
-- @table global.players
|
||||
@@ -316,14 +317,14 @@ Sync.time=add_metatable({},function(full,date)
|
||||
end,function() local info = Sync.info return info.time..' (+'..(game.tick-info.time_set[1])..' Ticks)' end)
|
||||
|
||||
-- will auto replace the file every 5 min by default
|
||||
script.on_event('on_tick',function(event)
|
||||
Event.add('on_tick',function(event)
|
||||
local time = Sync.info.time_period[1]
|
||||
if (event.tick%time)==0 then Sync.emit_update() end
|
||||
end)
|
||||
|
||||
script.on_event('on_player_joined_game',Sync.emit_update)
|
||||
script.on_event('on_pre_player_left_game',Sync.emit_update)
|
||||
script.on_event('on_rocket_launched',Sync.emit_update)
|
||||
Event.add('on_player_joined_game',Sync.emit_update)
|
||||
Event.add('on_pre_player_left_game',Sync.emit_update)
|
||||
Event.add('on_rocket_launched',Sync.emit_update)
|
||||
|
||||
function Sync:on_init()
|
||||
if loaded_modules['ExpGamingCore.Gui'] then verbose('ExpGamingCore.Gui is installed; Loading gui src') require(module_path..'/src/gui',{Sync=Sync,module_path=module_path}) end
|
||||
|
||||
@@ -96,11 +96,11 @@ Sync.info_gui = Gui.center{
|
||||
}.style.font='default-small'
|
||||
end}
|
||||
|
||||
script.on_event(defines.events.on_gui_click,function(event)
|
||||
Event.add(defines.events.on_gui_click,function(event)
|
||||
local element = event.element
|
||||
if element and element.valid and element.caption and element.caption == 'Press Ecs or E to close; this is only visible once!' then
|
||||
Gui.center.clear(event)
|
||||
end
|
||||
end)
|
||||
|
||||
script.on_event(defines.events.on_player_joined_game,function(event) Sync.info_gui(event) end)
|
||||
Event.add(defines.events.on_player_joined_game,function(event) Sync.info_gui(event) end)
|
||||
Reference in New Issue
Block a user