From 426e7be2bfa1d9ec4fdd79ea8b790f684625f734 Mon Sep 17 00:00:00 2001 From: Gerkiz Date: Fri, 12 Aug 2022 00:05:26 +0200 Subject: [PATCH 1/2] Global This fixes if a file calls `Global.register` multiple times from the same file. --- utils/global.lua | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/utils/global.lua b/utils/global.lua index 91b598d8d..e9aff3e7a 100644 --- a/utils/global.lua +++ b/utils/global.lua @@ -9,12 +9,30 @@ global.tokens = {} local concat = table.concat +--- Validates if a global table exists +--- Returns a new table index if original table exists. +---@param filepath string +---@return string +local function validate_entry(filepath) + if global.tokens[filepath] then + if not global.tokens[filepath].token_index then + global.tokens[filepath].token_index = 1 + else + global.tokens[filepath].token_index = global.tokens[filepath].token_index + 1 + end + local index = global.tokens[filepath].token_index + filepath = filepath .. '_' .. index + end + return filepath +end + --- Sets a new global ---@param tbl any ---@return integer ---@return string function Global.set_global(tbl) local filepath = debug.getinfo(3, 'S').source:match('^.+/currently%-playing/(.+)$'):sub(1, -5):gsub('/', '_') + filepath = validate_entry(filepath) Global.index = Global.index + 1 Global.filepath[filepath] = Global.index From 5601f092a76be778fbe0c1c9df2791a98e8c37b0 Mon Sep 17 00:00:00 2001 From: Gerkiz Date: Fri, 12 Aug 2022 00:06:15 +0200 Subject: [PATCH 2/2] Expanse - fixes events being misaligned --- maps/expanse/main.lua | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/maps/expanse/main.lua b/maps/expanse/main.lua index 361c4e4f6..0f3bbbff1 100644 --- a/maps/expanse/main.lua +++ b/maps/expanse/main.lua @@ -17,19 +17,20 @@ local format_number = require 'util'.format_number local Random = require 'maps.chronosphere.random' local Autostash = require 'modules.autostash' -local expanse = {} +local expanse = { + events = { + gui_update = Event.generate_event_name('expanse_gui_update'), + invasion_warn = Event.generate_event_name('invasion_warn'), + invasion_detonate = Event.generate_event_name('invasion_detonate'), + invasion_trigger = Event.generate_event_name('invasion_trigger') + } +} Global.register( expanse, function(tbl) expanse = tbl end ) -expanse.events = { - gui_update = Event.generate_event_name('expanse_gui_update'), - invasion_warn = Event.generate_event_name('invasion_warn'), - invasion_detonate = Event.generate_event_name('invasion_detonate'), - invasion_trigger = Event.generate_event_name('invasion_trigger'), -} local main_button_name = Gui.uid_name() local main_frame_name = Gui.uid_name()