BaseProcessingStation: final changes

This commit is contained in:
Van
2026-06-06 19:54:16 +03:00
parent 592bbf9c58
commit c0cbf86c8b

View File

@@ -1,11 +1,13 @@
local TICKRATE = 1 local TICKRATE = 1
local CraftSystem = Smc.requireCraftSystem() local assert = assert
local coreGetMeta, coreGetTimer, coreSwapNode = core.get_meta, core.get_node_timer, core.swap_node
local CraftSystem = Smc.requireCraftSystem()
local PlayerInventoryUI = Smc.requirePlayerInventoryUI() local PlayerInventoryUI = Smc.requirePlayerInventoryUI()
---@class BaseProcessingStation : Class ---An abstract class representing nodes that implement crafting of the `processing` type.
---@field name string ---@class BaseProcessingStation : Class, NodeSuperClass
---@field craftType CraftSystem.ProcessingCraftType ---@field craftType CraftSystem.ProcessingCraftType
---@field handler CraftSystem.ProcessingCraftHandler ---@field handler CraftSystem.ProcessingCraftHandler
---@field tab PlayerInventoryUI.getTabFunc ---@field tab PlayerInventoryUI.getTabFunc
@@ -20,24 +22,31 @@ local BaseProcessingStation = Class:extend({})
---@field craftType CraftSystem.ProcessingCraftType ---@field craftType CraftSystem.ProcessingCraftType
---@field tab PlayerInventoryUI.getTabFunc ---@field tab PlayerInventoryUI.getTabFunc
---@alias BaseProcessingStation.NodesDef {settings:Node.Settings, activeSettings?:Node.Settings, callbacks:Node.Callbacks?} ---@alias BaseProcessingStation.NodesDefinition {settings:Node.Settings, activeSettings:Node.Settings?, callbacks:Node.Callbacks?}
---@param name string
---@param def BaseProcessingStationDef ---@param def BaseProcessingStationDef
---@param nodesDef BaseProcessingStation.NodesDef? ---@param nodesDef BaseProcessingStation.NodesDefinition?
function BaseProcessingStation:new(name, def, nodesDef) function BaseProcessingStation:new(def, nodesDef)
local handler = CraftSystem:getProcessingCraftHandler(def.craftType) local handler = CraftSystem:getProcessingCraftHandler(def.craftType)
---@type BaseProcessingStation ---@type BaseProcessingStation
local instance = self:getInstance({}) local instance = self:getInstance({})
instance.name = name instance.craftType = def.craftType
instance.craftType = def.craftType instance.handler = handler
instance.handler = handler instance.tab = def.tab
instance.tab = def.tab
return instance return instance
end end
---A wrapper around `core.get_meta()` for convenience
---and returning the correct `MetaDataRef` type.
---@static
---@param pos MapVector
---@return MetaDataRef
function BaseProcessingStation:getMeta(pos)
return coreGetMeta(pos)
end
---Opens the player's inventory, adding the node tab described in `self.tab`. ---Opens the player's inventory, adding the node tab described in `self.tab`.
---@param pos MapVector ---@param pos MapVector
---@param player Player ---@param player Player
@@ -54,15 +63,16 @@ end
---Starts the station timer only if it is not running. ---Starts the station timer only if it is not running.
--- ---
---The timer timeout is set to the timeout specified `self.timeout`.
---
---Returns `true` if the timer has been started. ---Returns `true` if the timer has been started.
---@param pos MapVector ---@static
---@return boolean ---@param pos MapVector
function BaseProcessingStation:startTimer(pos) ---@param timeout number? If is `nil`, the global `TICKRATE` setting will be used.
local timer = core.get_node_timer(pos) ---@return boolean
function BaseProcessingStation:startTimer(pos, timeout)
local timer = coreGetTimer(pos)
if not timer:is_started() then if not timer:is_started() then
timer:start(TICKRATE) timer:start(timeout or TICKRATE)
return true return true
end end
@@ -80,9 +90,9 @@ function BaseProcessingStation:swapNode(isProcessing, pos)
if self.activeNodeName ~= nil then if self.activeNodeName ~= nil then
if isProcessing then if isProcessing then
core.swap_node(pos, {name = self.activeNodeName}) coreSwapNode(pos, {name = self.activeNodeName})
else else
core.swap_node(pos, {name = self.nodeName}) coreSwapNode(pos, {name = self.nodeName})
end end
end end
end end