diff --git a/control.lua b/control.lua
index 542acec0..cf9409bd 100644
--- a/control.lua
+++ b/control.lua
@@ -14,9 +14,9 @@ Discord: https://discord.gg/r6dC2uK
Manager = require("FactorioSoftmodManager")
Manager.setVerbose{
selfInit=true, -- called while the manager is being set up
- moduleLoad=true, -- when a module is required by the manager
- moduleInit=true, -- when and within the initation of a module
- modulePost=true, -- when and within the post of a module
+ moduleLoad=false, -- when a module is required by the manager
+ moduleInit=false, -- when and within the initation of a module
+ modulePost=false, -- when and within the post of a module
moduleEnv=true, -- during module runtime, this is a global option set within each module for fine control
eventRegistered=false, -- when a module registers its event handlers
errorCaught=true, -- when an error is caught during runtime
diff --git a/doc/modules/ExpGamingCore.Ranking.html b/doc/modules/ExpGamingCore.Ranking.html
index 9844fe66..4c716bbe 100644
--- a/doc/modules/ExpGamingCore.Ranking.html
+++ b/doc/modules/ExpGamingCore.Ranking.html
@@ -134,7 +134,7 @@
@@ -554,8 +554,8 @@
-
-
- rank_change
+
+ on_rank_change
-
Called when there is a rank change for a user
diff --git a/modules/ExpGamingCore/Gui/control.lua b/modules/ExpGamingCore/Gui/control.lua
index cb801e78..0b637c5a 100644
--- a/modules/ExpGamingCore/Gui/control.lua
+++ b/modules/ExpGamingCore/Gui/control.lua
@@ -7,10 +7,6 @@
local Gui = {}
local Gui_data = {}
---- Stores all the on_player_joined_game event handlers for the guis
--- @table events
-Gui.events = {join={},rank={}}
-
--- 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
@@ -28,19 +24,11 @@ Gui.data = setmetatable({},{
end
})
--- loaded the different gui parts, each is its own module for ldoc reasons
-local join, rank
-Gui.center, join, rank = require(module_path..'/src/center')
-table.insert(Gui.events.join,event) table.insert(Gui.events.rank,rank)
-Gui.inputs, event = require(module_path..'/src/inputs')
-table.insert(Gui.events.join,event) table.insert(Gui.events.rank,rank)
-Gui.left, event = require(module_path..'/src/left')
-table.insert(Gui.events.join,event) table.insert(Gui.events.rank,rank)
-Gui.popup, event = require(module_path..'/src/popup')
-table.insert(Gui.events.join,event) table.insert(Gui.events.rank,rank)
-Gui.toolbar, event = require(module_path..'/src/toolbar')
-table.insert(Gui.events.join,event) table.insert(Gui.events.rank,rank)
-join, rank = nil, nil
+Gui.center = require(module_path..'/src/center')
+Gui.inputs = require(module_path..'/src/inputs')
+Gui.left = require(module_path..'/src/left')
+Gui.popup = require(module_path..'/src/popup')
+Gui.toolbar = require(module_path..'/src/toolbar')
--- Add a white bar to any gui frame
-- @usage Gui.bar(frame,100)
@@ -74,20 +62,6 @@ function Gui.set_dropdown_index(dropdown,_item)
return dropdown
end
-function Gui:on_init()
- if loaded_modules.Server then verbose('ExpGamingCore.Server is installed; Loading server src') require(module_path..'/src/server') end
- if loaded_modules.Ranking then
- verbose('ExpGamingCore.Ranking is installed; Loading ranking src')
- script.on_event('on_player_joined_game',function(event)
- for _,callback in pairs(Gui.events.rank) do callback(event) end
- end)
- end
-end
-
-function Gui:on_post()
- Gui.test = require(module_path..'/src/test')
-end
-
--- Prams for Gui.cam_link
-- @table ParametersForCamLink
-- @field entity this is the entity that the camera will follow
@@ -152,7 +126,9 @@ function Gui.cam_link(data)
end
script.on_event('on_player_joined_game',function(event)
- for _,callback in pairs(Gui.events.join) do callback(event) end
+ Gui.toolbar.on_player_joined_game(event)
+ Gui.popup.on_player_joined_game(event)
+ Gui.left.on_player_joined_game(event)
end)
script.on_event('on_tick', function(event)
@@ -183,4 +159,21 @@ script.on_event('on_player_respawned',function(event)
end
end)
+function Gui:on_init()
+ if loaded_modules.Server then verbose('ExpGamingCore.Server is installed; Loading server src') require(module_path..'/src/server') end
+ if loaded_modules.Ranking then
+ verbose('ExpGamingCore.Ranking is installed; Loading ranking src')
+ script.on_event('on_rank_change',function(event)
+ Gui.toolbar.on_rank_change(event)
+ Gui.center.on_rank_change(event)
+ end)
+ end
+end
+
+function Gui:on_post()
+ Gui.test = require(module_path..'/src/test')
+ Gui.popup.load() Gui.popup.load = nil
+end
+
+
return Gui
\ No newline at end of file
diff --git a/modules/ExpGamingCore/Gui/src/center.lua b/modules/ExpGamingCore/Gui/src/center.lua
index 92fb8dd0..8fd0e6e1 100644
--- a/modules/ExpGamingCore/Gui/src/center.lua
+++ b/modules/ExpGamingCore/Gui/src/center.lua
@@ -201,6 +201,5 @@ script.on_event('on_gui_closed',function(event)
if event.element and event.element.valid then event.element.destroy() end
end)
--- when the player rank is changed it closses the center guis
--- second return is join event and third is rank change event
-return center, nil, center.clear
\ No newline at end of file
+center.on_rank_change = center.clear
+return center
\ No newline at end of file
diff --git a/modules/ExpGamingCore/Gui/src/inputs.lua b/modules/ExpGamingCore/Gui/src/inputs.lua
index b387a87b..e3d1df69 100644
--- a/modules/ExpGamingCore/Gui/src/inputs.lua
+++ b/modules/ExpGamingCore/Gui/src/inputs.lua
@@ -371,6 +371,6 @@ function inputs.add_drop_down(name,items,index,callback)
end
-- second return is join event and third is rank change event
-return inputs, nil, nil
+return inputs
-- to see examples look at GuiParts/test.lua
diff --git a/modules/ExpGamingCore/Gui/src/left.lua b/modules/ExpGamingCore/Gui/src/left.lua
index d99d8a84..4de283e0 100644
--- a/modules/ExpGamingCore/Gui/src/left.lua
+++ b/modules/ExpGamingCore/Gui/src/left.lua
@@ -144,13 +144,13 @@ function left._left.toggle(event)
if not success then error(err)
elseif err == true then open = true
elseif global().over_ride_left_can_open then
- if is_type(Ranking,'table') and Ranking._presets and Ranking._presets().meta.rank_count > 0 then
+ if is_type(Ranking,'table') and Ranking.meta.rank_count > 0 then
if Ranking.get_rank(player):allowed(_left.name) then open = true
else open = {gui.unauthorized} end
end
else open = err end
else
- if is_type(Ranking,'table') and Ranking._presets and Ranking._presets().meta.rank_count > 0 then
+ if is_type(Ranking,'table') and Ranking.meta.rank_count > 0 then
if Ranking.get_rank(player):allowed(_left.name) then open = true
else open = {gui.unauthorized} end
end
@@ -164,8 +164,7 @@ function left._left.toggle(event)
elseif open ~= true then player_return({'gui.cant-open',open},defines.textcolor.crit,player) player.play_sound{path='utility/cannot_build'} end
end
--- second return is join event and third is rank change event
-return left, function(event)
+left.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 {}
@@ -173,4 +172,6 @@ return left, function(event)
local fake_event = {player_index=player.index,element={name=name}}
left.open(fake_event)
end
-end, nil
\ No newline at end of file
+end
+
+return left
\ No newline at end of file
diff --git a/modules/ExpGamingCore/Gui/src/popup.lua b/modules/ExpGamingCore/Gui/src/popup.lua
index 256abdb9..3a21d9d7 100644
--- a/modules/ExpGamingCore/Gui/src/popup.lua
+++ b/modules/ExpGamingCore/Gui/src/popup.lua
@@ -10,7 +10,7 @@
local popup = {}
popup._popup = {}
-function popup._load()
+function popup.load()
popup._popup.close = Gui.inputs.add{
type='button',
name='popup-close',
@@ -107,5 +107,6 @@ function popup._popup:add_left(obj)
self.left = Gui.left.add(obj)
end
--- second return is join event and third is rank change event
-return popup, popup.flow, nil
\ No newline at end of file
+popup.on_player_joined_game = popup.flow
+
+return popup
\ No newline at end of file
diff --git a/modules/ExpGamingCore/Gui/src/toolbar.lua b/modules/ExpGamingCore/Gui/src/toolbar.lua
index ca2e903f..ef8fa300 100644
--- a/modules/ExpGamingCore/Gui/src/toolbar.lua
+++ b/modules/ExpGamingCore/Gui/src/toolbar.lua
@@ -34,7 +34,7 @@ function toolbar.draw(player)
toolbar_frame.clear()
if not Gui.data.toolbar then return end
for name,button in pairs(Gui.data.toolbar) do
- if is_type(Ranking,'table') and Ranking._presets and Ranking._presets().meta.rank_count > 0 then
+ if is_type(Ranking,'table') and Ranking.meta.rank_count > 0 then
local rank = Ranking.get_rank(player)
if rank:allowed(name) then
button:draw(toolbar_frame)
@@ -43,5 +43,6 @@ function toolbar.draw(player)
end
end
--- second return is join event and third is rank change event
-return toolbar, toolbar.draw, toolbar.draw
\ No newline at end of file
+toolbar.on_rank_change = toolbar.draw
+toolbar.on_player_joined_game = toolbar.draw
+return toolbar
\ No newline at end of file
diff --git a/modules/ExpGamingCore/Ranking/control.lua b/modules/ExpGamingCore/Ranking/control.lua
index 17717ebd..afe26af1 100644
--- a/modules/ExpGamingCore/Ranking/control.lua
+++ b/modules/ExpGamingCore/Ranking/control.lua
@@ -14,14 +14,14 @@ local module_verbose = false --true|false
local global = global{old={},preset={},last_change=nil}
--- Called when there is a rank change for a user
--- @event rank_change
+-- @event on_rank_change
-- @field name the rank id
-- @field tick the tick which the event was raised on
-- @field player_index the player whos rank was changed
-- @field by_player_index the player who changed the rank, 0 means server
-- @field new_rank the name of the rank that was given
-- @field old_rank the name of the rank the player had
-script.generate_event_name('rank_change')
+script.generate_event_name('on_rank_change')
--- Outputs as a string all the ranks and the loaded order
-- @usage Ranking.output_ranks(player) -- prints to player
@@ -208,8 +208,8 @@ function Ranking.give_rank(player,rank,by_player,tick)
player.admin = rank.is_admin or false
player.spectator = rank.is_spectator or false
local by_player_index = by_player_name == 'server' and 0 or Game.get_player(by_player_name).index
- script.raise_event(defines.events.rank_change,{
- name=defines.events.rank_change,
+ script.raise_event(defines.events.on_rank_change,{
+ name=defines.events.on_rank_change,
tick=tick,
player_index=player.index,
by_player_index=by_player_index,
diff --git a/modules/ExpGamingCore/Server/control.lua b/modules/ExpGamingCore/Server/control.lua
index 7f48c562..b4d2f837 100644
--- a/modules/ExpGamingCore/Server/control.lua
+++ b/modules/ExpGamingCore/Server/control.lua
@@ -167,7 +167,6 @@ function Server._thread_handler(event)
end
end)
end
-script.on_event(defines.events,Server._thread_handler)
--[[ cant be used V
--- Adds a event handler to tell threads about events
@@ -370,7 +369,7 @@ function Server._thread:resolve(...)
local _return = false
-- checks if the resolve haddler is still present
if is_type(self._resolve,'function') then
- local sandbox, success, err = Manager.sandbox(self._resolve,thread._env,self,...)
+ local sandbox, success, err = Manager.sandbox(self._resolve,self._env,self,...)
if success then
-- if it was successful then it will attemp to call the success handler
if is_type(self._success,'function') then
@@ -462,6 +461,7 @@ script.on_event(-2,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
if loaded_modules.commands then verbose('ExpGamingCore.Commands is installed; Loading commands src') require(module_path..'/src/commands') end
end
diff --git a/modules/ExpGamingCore/Sync/src/ranking.lua b/modules/ExpGamingCore/Sync/src/ranking.lua
index 062d0f3d..74b49294 100644
--- a/modules/ExpGamingCore/Sync/src/ranking.lua
+++ b/modules/ExpGamingCore/Sync/src/ranking.lua
@@ -37,7 +37,7 @@ if Sync.add_to_gui then
end
-- adds a discord emit for rank chaning
-script.on_event('rank_change',function(event)
+script.on_event('on_rank_change',function(event)
local rank = Ranking.get_rank(event.new_rank)
local player = Game.get_player(event)
local by_player_name = Game.get_player(event.by_player_index) or ''