Covnerted Event and Global

This commit is contained in:
Cooldude2606
2019-02-24 21:28:33 +00:00
parent fc279c42f8
commit 1cb2a3c3a0
35 changed files with 97 additions and 78 deletions

View File

@@ -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})

View File

@@ -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 = {}

View File

@@ -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)

View File

@@ -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

View File

@@ -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})

View File

@@ -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})