BaseProcessingStation: final changes
This commit is contained in:
@@ -1,11 +1,13 @@
|
||||
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()
|
||||
|
||||
---@class BaseProcessingStation : Class
|
||||
---@field name string
|
||||
---An abstract class representing nodes that implement crafting of the `processing` type.
|
||||
---@class BaseProcessingStation : Class, NodeSuperClass
|
||||
---@field craftType CraftSystem.ProcessingCraftType
|
||||
---@field handler CraftSystem.ProcessingCraftHandler
|
||||
---@field tab PlayerInventoryUI.getTabFunc
|
||||
@@ -20,24 +22,31 @@ local BaseProcessingStation = Class:extend({})
|
||||
---@field craftType CraftSystem.ProcessingCraftType
|
||||
---@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 nodesDef BaseProcessingStation.NodesDef?
|
||||
function BaseProcessingStation:new(name, def, nodesDef)
|
||||
---@param nodesDef BaseProcessingStation.NodesDefinition?
|
||||
function BaseProcessingStation:new(def, nodesDef)
|
||||
local handler = CraftSystem:getProcessingCraftHandler(def.craftType)
|
||||
|
||||
---@type BaseProcessingStation
|
||||
local instance = self:getInstance({})
|
||||
instance.name = name
|
||||
instance.craftType = def.craftType
|
||||
instance.handler = handler
|
||||
instance.tab = def.tab
|
||||
instance.craftType = def.craftType
|
||||
instance.handler = handler
|
||||
instance.tab = def.tab
|
||||
|
||||
return instance
|
||||
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`.
|
||||
---@param pos MapVector
|
||||
---@param player Player
|
||||
@@ -54,15 +63,16 @@ end
|
||||
|
||||
---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.
|
||||
---@param pos MapVector
|
||||
---@return boolean
|
||||
function BaseProcessingStation:startTimer(pos)
|
||||
local timer = core.get_node_timer(pos)
|
||||
---@static
|
||||
---@param pos MapVector
|
||||
---@param timeout number? If is `nil`, the global `TICKRATE` setting will be used.
|
||||
---@return boolean
|
||||
function BaseProcessingStation:startTimer(pos, timeout)
|
||||
local timer = coreGetTimer(pos)
|
||||
|
||||
if not timer:is_started() then
|
||||
timer:start(TICKRATE)
|
||||
timer:start(timeout or TICKRATE)
|
||||
return true
|
||||
end
|
||||
|
||||
@@ -80,9 +90,9 @@ function BaseProcessingStation:swapNode(isProcessing, pos)
|
||||
|
||||
if self.activeNodeName ~= nil then
|
||||
if isProcessing then
|
||||
core.swap_node(pos, {name = self.activeNodeName})
|
||||
coreSwapNode(pos, {name = self.activeNodeName})
|
||||
else
|
||||
core.swap_node(pos, {name = self.nodeName})
|
||||
coreSwapNode(pos, {name = self.nodeName})
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user