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

@@ -1,31 +1,4 @@
Events = {}
local modInfo = Mod.getInfo('smc__system__events')
local require = modInfo.require
---@alias Events.callback fun(eventName, ...)
---@type table<string, Events.callback[]>
local registeredEvents = {}
---@param eventName string
---@param callback Events.callback
function Events.subscribe(eventName, callback)
local callbacks = registeredEvents[eventName]
if callbacks == nil then
registeredEvents[eventName] = {callback}
else
table.insert(callbacks, callback)
end
end
---@param eventName string
---@param ... any
function Events.call(eventName, ...)
local callbacks = registeredEvents[eventName]
if callbacks == nil then
return
end
for _, func in ipairs(callbacks) do
func(eventName, ...)
end
end
return require('Events')

View File

@@ -1,2 +1,2 @@
name = smc__system__events
depends = smc__system__table
depends = smc__system__table, smc__system__require, smc__system__class

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