ProcessingStation: final changes
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
local coreNodePunch = core.node_punch
|
||||
|
||||
local BaseProcessingStation = Smc.requireBaseProcessingStation()
|
||||
local ProcessingContainerStation, ProcessingFuelStation = Smc.requireProcessingContainerStation(), Smc.requireProcessingFuelStation()
|
||||
|
||||
local PlayerInventoryUI = Smc.requirePlayerInventoryUI()
|
||||
|
||||
local Node = Smc.requireNode()
|
||||
|
||||
local ProcessingStationNode = Node:getExtended({
|
||||
@@ -17,6 +17,8 @@ local ProcessingStationNode = Node:getExtended({
|
||||
---@class ProcessingStation : BaseProcessingStation
|
||||
---@field containerStation ProcessingContainerStation
|
||||
---@field fuelStation ProcessingFuelStation
|
||||
---
|
||||
---@field getMeta fun(self:ProcessingStation, pos:MapVector):ProcessingStation.MetaData
|
||||
local ProcessingStation = BaseProcessingStation:extend({})
|
||||
|
||||
---Definition table for the `ProcessingStation`.
|
||||
@@ -24,14 +26,13 @@ local ProcessingStation = BaseProcessingStation:extend({})
|
||||
---**Only for EmmyLua.**
|
||||
---@class ProcessingStationDef : ProcessingContainerStationDef, ProcessingFuelStationDef
|
||||
|
||||
---@param name string
|
||||
---@param def ProcessingStationDef
|
||||
---@param nodesDef BaseProcessingStation.NodesDef
|
||||
function ProcessingStation:new(name, def, nodesDef)
|
||||
---@param nodesDef BaseProcessingStation.NodesDefinition
|
||||
function ProcessingStation:new(def, nodesDef)
|
||||
---@type ProcessingStation
|
||||
local instance = self:getInstance(BaseProcessingStation:new(name, def))
|
||||
instance.containerStation = ProcessingContainerStation:new(name, def)
|
||||
instance.fuelStation = ProcessingFuelStation:new(name, def)
|
||||
local instance = self:getInstance(BaseProcessingStation:new(def))
|
||||
instance.containerStation = ProcessingContainerStation:new(def)
|
||||
instance.fuelStation = ProcessingFuelStation:new(def)
|
||||
|
||||
local settings = nodesDef.settings
|
||||
local activeSettings = nodesDef.activeSettings
|
||||
@@ -47,6 +48,14 @@ function ProcessingStation:new(name, def, nodesDef)
|
||||
instance.fuelStation:init(pos)
|
||||
end
|
||||
|
||||
oldCallback = callbacks.on_punch or function(...) end
|
||||
callbacks.on_punch = function(pos, node, puncher, pointed_thing)
|
||||
oldCallback(pos, node, puncher, pointed_thing)
|
||||
|
||||
instance.fuelStation:onPunch(pos, node, puncher, pointed_thing)
|
||||
coreNodePunch(pos, node, puncher, pointed_thing)
|
||||
end
|
||||
|
||||
oldCallback = callbacks.on_rightclick or function(...) end
|
||||
-- Right-clicking on a station opens the player's inventory, adding context to the station tab.
|
||||
-- Note: we do not use formspec via node metadata.
|
||||
@@ -94,8 +103,12 @@ function ProcessingStation:new(name, def, nodesDef)
|
||||
if activeSettings ~= nil then
|
||||
local activeNode = ProcessingStationNode:new({ settings = activeSettings, callbacks = callbacks })
|
||||
instance.activeNodeName = activeNode.itemDef.settings.name
|
||||
|
||||
Smc.addNodeSuperclass(instance.activeNodeName, instance)
|
||||
end
|
||||
|
||||
Smc.addNodeSuperclass(instance.nodeName, instance)
|
||||
|
||||
return instance
|
||||
end
|
||||
|
||||
@@ -105,15 +118,22 @@ end
|
||||
---@param timeout number
|
||||
---@return boolean?
|
||||
function ProcessingStation:onTimer(pos, elapsed, node, timeout)
|
||||
local meta = core.get_meta(pos)
|
||||
local meta = self:getMeta(pos)
|
||||
|
||||
local isProcessing, craft = self.containerStation:getCraft(true, meta)
|
||||
isProcessing = self.fuelStation:burnFuel(isProcessing, meta, elapsed)
|
||||
if craft ~= nil then
|
||||
isProcessing = self.fuelStation:takeFuel(isProcessing, meta, elapsed)
|
||||
|
||||
if self.containerStation.enableFuelPush then
|
||||
self.fuelStation:setMetaIsEnable(meta, meta:get_string('craft_name') ~= '')
|
||||
end
|
||||
|
||||
isProcessing = self.fuelStation:burnFuel(isProcessing, meta, elapsed)
|
||||
isProcessing = self.fuelStation:takeFuel(isProcessing, meta, elapsed)
|
||||
isProcessing = self.containerStation:processing(isProcessing, meta, elapsed, craft)
|
||||
|
||||
if self.containerStation.enableFuelPush then
|
||||
self.fuelStation:setMetaIsEnable(meta, meta:get_string('craft_name') ~= '')
|
||||
end
|
||||
|
||||
self:swapNode(isProcessing, pos)
|
||||
|
||||
PlayerInventoryUI:updateNodeForm(pos)
|
||||
@@ -135,6 +155,12 @@ handler:registerCraft('test_pro_craft', {
|
||||
time = 5,
|
||||
})
|
||||
|
||||
handler:registerCraft('test_craft', {
|
||||
output = 'wood:allwhere_log',
|
||||
recipe = {'wood:dallalia_stick', 'rocks:sylite'},
|
||||
time = 2.5,
|
||||
})
|
||||
|
||||
---@param self PlayerInventoryUI
|
||||
---@param playerName string
|
||||
---@param tabType PlayerInventoryUI.TabType
|
||||
@@ -158,14 +184,15 @@ local tab = function(self, playerName, tabType)
|
||||
return form
|
||||
end
|
||||
|
||||
ProcessingStation:new('test_processing_node', {
|
||||
ProcessingStation:new({
|
||||
craftType = 'test',
|
||||
tab = tab,
|
||||
inputSlots = 2,
|
||||
fuelGroup = 'wood',
|
||||
alwaysEnable = false,
|
||||
enableFuelPush = true,
|
||||
enableIdling = true,
|
||||
enableContainerProcessing = true,
|
||||
--enableRegression = true,
|
||||
enableRegression = true,
|
||||
},
|
||||
{
|
||||
settings = {
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
---@alias ProcessingStation.MetaData.FloatKey ProcessingContainerStation.MetaData.FloatKey|ProcessingFuelStation.MetaData.FloatKey
|
||||
---@alias ProcessingStation.MetaData.StringKey ProcessingContainerStation.MetaData.StringKey
|
||||
|
||||
---@alias ProcessingStation.MetaData.StringKey ProcessingContainerStation.MetaData.StringKey|ProcessingFuelStation.MetaData.StringKey
|
||||
|
||||
---**Only for EmmyLua.**
|
||||
---@class ProcessingStation.MetaData : NodeMetaRef
|
||||
---@class ProcessingStation.MetaData : ProcessingContainerStation.MetaData, ProcessingFuelStation.MetaData
|
||||
---@field get_float fun(self, key:ProcessingStation.MetaData.FloatKey):number
|
||||
---@field set_float fun(self, key:ProcessingStation.MetaData.FloatKey, value:number)
|
||||
---@field get_string fun(self, key:ProcessingStation.MetaData.StringKey):string
|
||||
|
||||
Reference in New Issue
Block a user