diff --git a/mods/CORE/Factory/init.lua b/mods/CORE/Factory/init.lua new file mode 100644 index 0000000..41dfb64 --- /dev/null +++ b/mods/CORE/Factory/init.lua @@ -0,0 +1,5 @@ +local Factory = Mod:new() + +Factory.Class = Factory.require('Factory') + +Api.addModToGlobalSpace(Factory, 'Core.Factory') diff --git a/mods/CORE/Factory/mod.conf b/mods/CORE/Factory/mod.conf new file mode 100644 index 0000000..3362c6d --- /dev/null +++ b/mods/CORE/Factory/mod.conf @@ -0,0 +1 @@ +name = smc__core__factory diff --git a/mods/CORE/Factory/src/Factory.lua b/mods/CORE/Factory/src/Factory.lua new file mode 100644 index 0000000..b0be198 --- /dev/null +++ b/mods/CORE/Factory/src/Factory.lua @@ -0,0 +1,38 @@ +---@class Factory +---@field defaultItemDef Item.ItemDefinition | Node.NodeDefinition +---@field itemClass Item | Node +local Factory = {} + +---@param itemClass Item | Node +---@param defaultItemDef Item.ItemDefinition | Node.NodeDefinition Parameters that all nodes registered with this factory must have. +---@return Factory +function Factory:new(itemClass, defaultItemDef) + ---@type Factory + local instance = setmetatable({ + defaultItemDef = defaultItemDef, + itemClass = itemClass, + }, {__index = self}) + + return instance +end + +---The aleas `table.merge` for EmmyLua +---@type fun(...):(Item.ItemDefinition) +local defMerge = function(...) + return table.merge(..., true) +end + +---@param itemDefs Item.ItemDefinition[] | Node.NodeDefinition[] List of nodes with parameters unique to them. +function Factory:registerItems(itemDefs) + ---@param nodeDef Item.ItemDefinition | Node.NodeDefinition + for _, nodeDef in ipairs(itemDefs) do + + ---@type Item.ItemDefinition + local nodeDef = defMerge(nodeDef, self.defaultItemDef) + + self.itemClass:new(nodeDef) + + end +end + +return Factory \ No newline at end of file diff --git a/mods/CORE/NodeFactory/init.lua b/mods/CORE/NodeFactory/init.lua deleted file mode 100644 index e5f7d02..0000000 --- a/mods/CORE/NodeFactory/init.lua +++ /dev/null @@ -1,5 +0,0 @@ -local NodeFactory = Mod:new() - -NodeFactory.Class = NodeFactory.require('NodeFactory') - -Api.addModToGlobalSpace(NodeFactory, 'Core.NodeFactory') diff --git a/mods/CORE/NodeFactory/mod.conf b/mods/CORE/NodeFactory/mod.conf deleted file mode 100644 index ec7dc1c..0000000 --- a/mods/CORE/NodeFactory/mod.conf +++ /dev/null @@ -1,2 +0,0 @@ -name = smc__core__node_factory -depends = smc__core__node diff --git a/mods/CORE/NodeFactory/src/NodeFactory.lua b/mods/CORE/NodeFactory/src/NodeFactory.lua deleted file mode 100644 index 59a4126..0000000 --- a/mods/CORE/NodeFactory/src/NodeFactory.lua +++ /dev/null @@ -1,20 +0,0 @@ ----@class NodeFactory -local NodeFactory = {} - ----@param defaultNodeDef Node.NodeDefinition Parameters that all nodes registered with this factory must have. ----@param nodeDefs Node.NodeDefinition[] List of nodes with parameters unique to them. ----@return NodeFactory -function NodeFactory:new(defaultNodeDef, nodeDefs) - ---@type NodeFactory - local instance = setmetatable({}, {__index = self}) - - for _, nodeDef in ipairs(nodeDefs) do - - Core.Node:getModClassInstance(table.merge(nodeDef, defaultNodeDef)) - - end - - return instance -end - -return NodeFactory \ No newline at end of file