From d287d33e055037029e0b36ab18f8d7959402d8e1 Mon Sep 17 00:00:00 2001 From: Cooldude2606 Date: Fri, 26 Oct 2018 13:19:50 +0100 Subject: [PATCH] Work Around For Desync --- modules/DeconControl/control.lua | 7 +++++++ modules/ExpGamingBot/autoMessage/control.lua | 7 +++++++ modules/ExpGamingCore/Gui/src/popup.lua | 5 ++++- modules/ExpGamingCore/Gui/src/server.lua | 3 +++ modules/ExpGamingPlayer/afkKick/src/server.lua | 6 ++++++ modules/GameSettingsGui/control.lua | 2 +- 6 files changed, 28 insertions(+), 2 deletions(-) diff --git a/modules/DeconControl/control.lua b/modules/DeconControl/control.lua index 0046ba33..f4161aef 100644 --- a/modules/DeconControl/control.lua +++ b/modules/DeconControl/control.lua @@ -8,12 +8,14 @@ local Game = require('FactorioStdLib.Game@^0.8.0') local Server = require('ExpGamingCore.Server@^4.0.0') local Role -- ExpGamingCore.Role@^4.0.0 +local Admin -- ExpGamingAdmin.AdminLib@^4.0.0 -- Module Define local module_verbose = false local ThisModule = { on_init=function() if loaded_modules['ExpGamingCore.Role@^4.0.0'] then Role = require('ExpGamingCore.Role@^4.0.0') end + if loaded_modules['ExpGamingAdmin.AdminLib@^4.0.0'] then Admin = require('ExpGamingAdmin.AdminLib@^4.0.0') end end } @@ -31,6 +33,11 @@ Event.register(-1,function(event) if tree and tree.valid then tree.destroy() end end end):on_event(defines.events.on_marked_for_deconstruction,function(self,event) + -- the _env should be auto loaded but it does not for some reason + local _ENV = _ENV or setmetatable({},{__index=_G}) + _ENV.Game = self._env.Game + _ENV.Role = self._env.Role + _ENV.Admin = self._env.Admin local chache = self.data.chache[event.player_index] if not chache then local player = Game.get_player(event) diff --git a/modules/ExpGamingBot/autoMessage/control.lua b/modules/ExpGamingBot/autoMessage/control.lua index 00906d71..d5cfa4ac 100644 --- a/modules/ExpGamingBot/autoMessage/control.lua +++ b/modules/ExpGamingBot/autoMessage/control.lua @@ -49,6 +49,10 @@ script.on_init(function(event) game.print{'ExpGamingBot-autoMessage.message',{'ExpGamingBot-autoMessage.map-time',tick_to_display_format(game.tick)}} self.reopen = true end):on_event(defines.events.on_player_joined_game,function(self,event) + -- the _env should be auto loaded but it does not for some reason + local _ENV = _ENV or setmetatable({},{__index=_G}) + _ENV.Game = self._env.Game + _ENV.Role = self._env.Role local player = Game.get_player(event) if not player then return end local data = self.data @@ -60,6 +64,9 @@ script.on_init(function(event) player_return({'ExpGamingBot-autoMessage.message',message},nil,player) end end):on_event('error',function(self,err) + -- the _env should be auto loaded but it does not for some reason + local _ENV = _ENV or setmetatable({},{__index=_G}) + _ENV.Sync = self._env.Sync if Sync then Sync.emit_embeded{ title='Auto Message Error', color=Color.to_hex(defines.textcolor.bg), diff --git a/modules/ExpGamingCore/Gui/src/popup.lua b/modules/ExpGamingCore/Gui/src/popup.lua index eadd2cfb..6033c41a 100644 --- a/modules/ExpGamingCore/Gui/src/popup.lua +++ b/modules/ExpGamingCore/Gui/src/popup.lua @@ -88,9 +88,12 @@ function popup.open(style,data,players) Server.new_thread{ data={players=players,popup=_popup,data=data} }:on_event('tick',function(thread) + -- the _env should be auto loaded but it does not for some reason + local _ENV = _ENV or setmetatable({},{__index=_G}) + _ENV.popup = self._env.popup if #thread.data.players == 0 then thread:close() return end local player = table.remove(thread.data.players,1) - if _popup.left then _popup.left:close(player) end + if thread.data.popup.left then thread.data.popup.left:close(player) end local flow = popup.flow(player) flow.style.visible=true local _frame = flow.add{ diff --git a/modules/ExpGamingCore/Gui/src/server.lua b/modules/ExpGamingCore/Gui/src/server.lua index 11e944dc..5173a346 100644 --- a/modules/ExpGamingCore/Gui/src/server.lua +++ b/modules/ExpGamingCore/Gui/src/server.lua @@ -28,6 +28,9 @@ return function(event) -- posible error handling if needed error(err) end):on_event(defines.events.on_player_respawned,function(self,event) + -- the _env should be auto loaded but it does not for some reason + local _ENV = _ENV or setmetatable({},{__index=_G}) + _ENV.Game = self._env.Game if self.data.players[event.player_index] then local remove = {} local player = Game.get_player(event) diff --git a/modules/ExpGamingPlayer/afkKick/src/server.lua b/modules/ExpGamingPlayer/afkKick/src/server.lua index 0e761c48..9bb9d3cb 100644 --- a/modules/ExpGamingPlayer/afkKick/src/server.lua +++ b/modules/ExpGamingPlayer/afkKick/src/server.lua @@ -6,6 +6,9 @@ script.on_init(function(event) Server.new_thread{ name='afk-kick', }:on_event('tick',function(self) + -- the _env should be auto loaded but it does not for some reason + local _ENV = _ENV or setmetatable({},{__index=_G}) + _ENV.get_allowed_afk_time = self._env.get_allowed_afk_time if (game.tick%3600) ~= 0 then return end for _,player in pairs(game.connected_players) do local afk = #game.connected_players < 3 and 10 or get_allowed_afk_time(player) @@ -14,6 +17,9 @@ script.on_init(function(event) end end end):on_event('error',function(self,err) + -- the _env should be auto loaded but it does not for some reason + local _ENV = _ENV or setmetatable({},{__index=_G}) + _ENV.Sync = self._env.Sync if Sync then Sync.emit_embeded{ title='Auto Kick Error', diff --git a/modules/GameSettingsGui/control.lua b/modules/GameSettingsGui/control.lua index 98778bfe..61bbb758 100644 --- a/modules/GameSettingsGui/control.lua +++ b/modules/GameSettingsGui/control.lua @@ -95,7 +95,7 @@ for name,group in pairs(_root_list) do data=element }:on_event('timeout',function(self) if self.data and self.data.valid then - element.parent.parent['game-settings-are-you-sure'].state = false + self.data.parent.parent['game-settings-are-you-sure'].state = false self.data.parent.style.visible = false self.data.state = false end