Skip to content

Commit

Permalink
Merge pull request #295 from ComfyFactory/minor_tweaks
Browse files Browse the repository at this point in the history
Fixes Global and Expanse
  • Loading branch information
Gerkiz authored Aug 11, 2022
2 parents c7c7812 + 5601f09 commit 51f12d5
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
15 changes: 8 additions & 7 deletions maps/expanse/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
18 changes: 18 additions & 0 deletions utils/global.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 51f12d5

Please sign in to comment.