Lazy commit: processing stations

This commit is contained in:
Van
2026-06-03 21:46:40 +03:00
parent 3854410041
commit 592bbf9c58
16 changed files with 266 additions and 185 deletions

View File

@@ -0,0 +1,37 @@
---@alias Events.Callback fun(eventName:string, ...)
---@alias Events.Types
--- 'ProcessingStationEvents'
---@class Events : Class
---@field registeredEvents table<string, Events.Callback[]>
Events = Class:extend({
registeredEvents = {}
})
---@param eventName string
---@param callback Events.Callback
function Events:subscribe(eventName, callback)
local callbacks = self.registeredEvents[eventName]
if callbacks == nil then
self.registeredEvents[eventName] = {callback}
else
table.insert(callbacks, callback)
end
end
---@param eventName string
---@param ... any
function Events:call(eventName, ...)
local callbacks = self.registeredEvents[eventName]
if callbacks == nil then
return
end
for _, func in ipairs(callbacks) do
func(eventName, ...)
end
end
return Events

View File

@@ -0,0 +1,21 @@
---@alias Events.ProcessingStationEvents.EventName 'on_push_container'
---@alias Events.ProcessingStationEvents.Callback fun(eventName:Events.ProcessingStationEvents.EventName, ...)
---@class Events.ProcessingStationEvents : Events
---@field subscribe fun(self:Events.ProcessingStationEvents,eventName:Events.ProcessingStationEvents.EventName, callback:Events.ProcessingStationEvents.Callback)
---@field call fun(self:Events.ProcessingStationEvents,eventName:Events.ProcessingStationEvents.EventName, ...)
local ProcessingStationEvents = Events:extend()
---@param callback fun(eventName:Events.ProcessingStationEvents.EventName, pos:MapVector, energy:number)
function ProcessingStationEvents:subscribeOnPushContainer(callback)
self:subscribe('on_push_container', callback)
end
---@param pos MapVector
---@param energy number
function ProcessingStationEvents:callOnPushContainer(pos, energy)
self:call('on_push_container', pos, energy)
end
return ProcessingStationEvents