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