Compare commits
3 Commits
0a20ac8987
...
cb6e046b81
| Author | SHA1 | Date | |
|---|---|---|---|
| cb6e046b81 | |||
| 21e0b8ec22 | |||
| 99b8c1d0b6 |
@@ -1,5 +1,3 @@
|
||||
local getInstance, extend = Class.getInstance, Class.extend
|
||||
|
||||
local tableCopy, tableMerge, colorize = table.copy, table.merge, core.colorize
|
||||
|
||||
local ItemFactory = Smc.requireItemFactory()
|
||||
@@ -39,12 +37,12 @@ local RARITY_INDEX = {
|
||||
['unique'] = 0
|
||||
}
|
||||
|
||||
---@class Item
|
||||
---@class Item : Class
|
||||
---@field itemDef Item.ItemDefinition
|
||||
---@field luantiDef ItemDefinition
|
||||
---@field getType fun():string
|
||||
---@field defaultDef Item.ItemDefinition
|
||||
local Item = {
|
||||
local Item = Class:extend({
|
||||
defaultDef = {
|
||||
settings = {
|
||||
name = '',
|
||||
@@ -58,7 +56,7 @@ local Item = {
|
||||
},
|
||||
callbacks = {}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
---Adds an item's rarity tag to the description.
|
||||
---@param rarity Item.Rarity
|
||||
@@ -180,7 +178,7 @@ function Item:new(itemDef)
|
||||
end
|
||||
|
||||
---@type Item
|
||||
local instance = getInstance(self, {})
|
||||
local instance = self:getInstance({})
|
||||
|
||||
local luantiDef = itemDefToLuantiDef(itemDef)
|
||||
local type = itemDef.settings._type
|
||||
@@ -221,7 +219,7 @@ function Item:getExtended(defaultDef)
|
||||
defaultDef = tableMerge(defaultDef, self.defaultDef, true)
|
||||
|
||||
---@type Item
|
||||
local ChildClass = extend(self, {
|
||||
local ChildClass = self:extend({
|
||||
defaultDef = defaultDef,
|
||||
})
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ local Item, ItemFactory = Smc.requireItem(), Smc.requireItemFactory()
|
||||
|
||||
---@class Node : Item
|
||||
---@field defaultDef Node.NodeDefinition
|
||||
local Node = Class.extend(Item, {})
|
||||
local Node = Item:extend({})
|
||||
|
||||
---@param nodeDef Node.NodeDefinition
|
||||
local function registerSlab(nodeDef)
|
||||
@@ -102,7 +102,7 @@ function Node:getExtended(defaultDef)
|
||||
defaultDef = tableMerge(defaultDef, self.defaultDef, true)
|
||||
|
||||
---@type Node
|
||||
local ChildClass = Class.extend(self, {
|
||||
local ChildClass = self:extend({
|
||||
defaultDef = defaultDef,
|
||||
})
|
||||
|
||||
|
||||
@@ -103,7 +103,7 @@ Callbacks.can_dig = nil
|
||||
---* `node`: node being hit
|
||||
---* `puncher`: ObjectRef of punch
|
||||
---* `pointed_thing`: Vector of the direction of the gaze of the person who placed the block
|
||||
---@type fun(pos:MapVector, node:NodeTable, puncher:Player|ObjectRef|nil, pointed_thing:pointed_thing)?
|
||||
---@type fun(pos:MapVector, node:NodeTable, puncher:Player|ObjectRef, pointed_thing:pointed_thing)?
|
||||
Callbacks.on_punch = nil
|
||||
|
||||
---Called when clicker (an ObjectRef) used the 'place/build' key
|
||||
|
||||
@@ -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