diff --git a/control.lua b/control.lua index 4bbad60..368a922 100644 --- a/control.lua +++ b/control.lua @@ -1,12 +1,17 @@ require "lib" +---@class (partial) PyPostProcessingStorage +---@field nth_tick_order table +---@field on_tick table> +storage = {} + -- on_nth_tick functions ---@class NthTickOrder ---@field func string ----@field delay int +---@field delay uint ---@class NthTickFunc ----@field tick int +---@field tick uint ---@field mod string ---@type table @@ -27,7 +32,6 @@ local register_on_nth_tick = function(func_list) end local function init_nth_tick(mod) - ---@type table storage.nth_tick_order = storage.nth_tick_order or {} local added_funcs = {} for _, tick_funcs in pairs(storage.nth_tick_order) do @@ -97,9 +101,6 @@ remote.add_interface("on_nth_tick", { }) -- delayed functions ----@type table> -storage.on_tick = storage.on_tick or {} - py.on_event(defines.events.on_tick, function(event) local tick = event.tick storage.on_tick = storage.on_tick or {} diff --git a/lib/control-stage.lua b/lib/control-stage.lua index d55a6e4..dfbb664 100644 --- a/lib/control-stage.lua +++ b/lib/control-stage.lua @@ -53,6 +53,9 @@ py.randomize_position = function(position, factor) return {x = x + factor * (random() - 0.5), y = y + factor * (random() - 0.5)} end +---@class (partial) PyPostProcessingStorage +---@field _last_cancel_creation_message uint + ---Intended to be called inside a build event. Cancels creation of the entity. ---Returns its item_to_place back to the player or spills it on the ground. ---@param entity LuaEntity @@ -115,7 +118,7 @@ py.cancel_creation = function(entity, player_index, message, color) create_at_cursor = player.index == player_index } end - storage._last_cancel_creation_message = game.tick + storage._last_cancel_creation_message = tick end end diff --git a/lib/events.lua b/lib/events.lua index 3e3711b..313b9b9 100644 --- a/lib/events.lua +++ b/lib/events.lua @@ -72,6 +72,9 @@ py.events = { end } +---@class (partial) PyPostProcessingStorage +---@field ignored_players {[uint]: uint} player_index -> game tick + ---Conditionally runs the given event based on if the player is not present within ignored_players ---@param event EventData.on_gui_click ---@param f function event handler