1
0
mirror of https://github.com/ComfyFactory/ComfyFactorio.git synced 2025-01-24 03:47:58 +02:00

Merge pull request #295 from ComfyFactory/minor_tweaks

Fixes Global and Expanse
This commit is contained in:
Gerkiz 2022-08-12 00:08:34 +02:00 committed by GitHub
commit 51f12d58a0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 7 deletions

View File

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

View File

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