Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions control.lua
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
require "lib"

---@class (partial) PyPostProcessingStorage
---@field nth_tick_order table<uint, NthTickOrder[]>
---@field on_tick table<uint, table<uint, {name: string, params: any[]?}>>
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<string, NthTickFunc>
Expand All @@ -27,7 +32,6 @@ local register_on_nth_tick = function(func_list)
end

local function init_nth_tick(mod)
---@type table<int, NthTickOrder[]>
storage.nth_tick_order = storage.nth_tick_order or {}
local added_funcs = {}
for _, tick_funcs in pairs(storage.nth_tick_order) do
Expand Down Expand Up @@ -97,9 +101,6 @@ remote.add_interface("on_nth_tick", {
})

-- delayed functions
---@type table<integer, table<int, {name: string, params: any[]?}>>
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 {}
Expand Down
5 changes: 4 additions & 1 deletion lib/control-stage.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
3 changes: 3 additions & 0 deletions lib/events.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading