Lazy commit: processing stations
This commit is contained in:
@@ -1,14 +1,15 @@
|
||||
local TICKRATE = 1
|
||||
|
||||
local CraftSystem = Smc.requireCraftSystem()
|
||||
|
||||
local PlayerInventoryUI = Smc.requirePlayerInventoryUI()
|
||||
|
||||
---@class BaseProcessingStation : Class
|
||||
---@field name string
|
||||
---@field timeout number
|
||||
---@field craftType CraftSystem.ProcessingCraftType
|
||||
---@field handler CraftSystem.ProcessingCraftHandler
|
||||
---@field tab PlayerInventoryUI.getTabFunc
|
||||
---@field nodeName string
|
||||
---@field nodeName string?
|
||||
---@field activeNodeName string?
|
||||
local BaseProcessingStation = Class:extend({})
|
||||
|
||||
@@ -16,7 +17,6 @@ local BaseProcessingStation = Class:extend({})
|
||||
---
|
||||
---**Only for EmmyLua.**
|
||||
---@class BaseProcessingStationDef
|
||||
---@field timeout number?
|
||||
---@field craftType CraftSystem.ProcessingCraftType
|
||||
---@field tab PlayerInventoryUI.getTabFunc
|
||||
|
||||
@@ -24,14 +24,13 @@ local BaseProcessingStation = Class:extend({})
|
||||
|
||||
---@param name string
|
||||
---@param def BaseProcessingStationDef
|
||||
---@param nodesDef BaseProcessingStation.NodesDef
|
||||
---@param nodesDef BaseProcessingStation.NodesDef?
|
||||
function BaseProcessingStation:new(name, def, nodesDef)
|
||||
local handler = CraftSystem:getProcessingCraftHandler(def.craftType)
|
||||
|
||||
---@type BaseProcessingStation
|
||||
local instance = self:getInstance({})
|
||||
instance.name = name
|
||||
instance.timeout = def.timeout or 1
|
||||
instance.craftType = def.craftType
|
||||
instance.handler = handler
|
||||
instance.tab = def.tab
|
||||
@@ -40,7 +39,7 @@ function BaseProcessingStation:new(name, def, nodesDef)
|
||||
end
|
||||
|
||||
---Opens the player's inventory, adding the node tab described in `self.tab`.
|
||||
---@param pos MapPosition
|
||||
---@param pos MapVector
|
||||
---@param player Player
|
||||
function BaseProcessingStation:showForm(pos, player)
|
||||
local playerName = player:get_player_name()
|
||||
@@ -58,12 +57,12 @@ end
|
||||
---The timer timeout is set to the timeout specified `self.timeout`.
|
||||
---
|
||||
---Returns `true` if the timer has been started.
|
||||
---@param pos MapPosition
|
||||
---@param pos MapVector
|
||||
---@return boolean
|
||||
function BaseProcessingStation:startTimer(pos)
|
||||
local timer = core.get_node_timer(pos)
|
||||
if not timer:is_started() then
|
||||
timer:start(self.timeout)
|
||||
timer:start(TICKRATE)
|
||||
return true
|
||||
end
|
||||
|
||||
@@ -75,8 +74,10 @@ end
|
||||
---If an active node is not specified for a station,
|
||||
---then no replacement will occur regardless of the status of the process.
|
||||
---@param isProcessing boolean The stations process status. If `true`, the process is running.
|
||||
---@param pos MapPosition
|
||||
---@param pos MapVector
|
||||
function BaseProcessingStation:swapNode(isProcessing, pos)
|
||||
assert(self.nodeName ~= nil)
|
||||
|
||||
if self.activeNodeName ~= nil then
|
||||
if isProcessing then
|
||||
core.swap_node(pos, {name = self.activeNodeName})
|
||||
|
||||
Reference in New Issue
Block a user