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