From a86b0efe4cc45d82079d5998b056e21958a11c68 Mon Sep 17 00:00:00 2001 From: Vanic Date: Fri, 26 Sep 2025 20:03:07 +0300 Subject: [PATCH] Rename Factory => itemFactory --- mods/CORE/Factory/init.lua | 5 ---- mods/CORE/Item/mod.conf | 2 +- mods/CORE/Item/src/Item.lua | 6 ++--- mods/CORE/ItemFactory/init.lua | 5 ++++ mods/CORE/{Factory => ItemFactory}/mod.conf | 2 +- .../src/ItemFactory.lua} | 25 ++++++++++++------- mods/CORE/Node/mod.conf | 2 +- mods/CORE/Node/src/Node.lua | 8 +++--- 8 files changed, 31 insertions(+), 24 deletions(-) delete mode 100644 mods/CORE/Factory/init.lua create mode 100644 mods/CORE/ItemFactory/init.lua rename mods/CORE/{Factory => ItemFactory}/mod.conf (50%) rename mods/CORE/{Factory/src/Factory.lua => ItemFactory/src/ItemFactory.lua} (78%) diff --git a/mods/CORE/Factory/init.lua b/mods/CORE/Factory/init.lua deleted file mode 100644 index 41dfb64..0000000 --- a/mods/CORE/Factory/init.lua +++ /dev/null @@ -1,5 +0,0 @@ -local Factory = Mod:new() - -Factory.Class = Factory.require('Factory') - -Api.addModToGlobalSpace(Factory, 'Core.Factory') diff --git a/mods/CORE/Item/mod.conf b/mods/CORE/Item/mod.conf index ca47080..d238ca3 100644 --- a/mods/CORE/Item/mod.conf +++ b/mods/CORE/Item/mod.conf @@ -1,2 +1,2 @@ name = smc__core__item -depends = smc__api__api_loader, smc__core__enum, smc__core__factory +depends = smc__api__api_loader, smc__core__enum, smc__core__item_factory diff --git a/mods/CORE/Item/src/Item.lua b/mods/CORE/Item/src/Item.lua index 0a610db..2c703d0 100644 --- a/mods/CORE/Item/src/Item.lua +++ b/mods/CORE/Item/src/Item.lua @@ -105,15 +105,15 @@ function Item:getExtended(defaultDef) return ChildClass end ----Returns an instance of the `Factory` class that can be used to mass-register identical items. +---Returns an instance of the `ItemFactory` class that can be used to mass-register identical items. ---@param defaultDef? Item.ItemDefinition ----@return Factory +---@return ItemFactory function Item:getFactory(defaultDef) if defaultDef == nil then defaultDef = self.defaultDef end - local instance = Core.Factory():new(self, defaultDef) + local instance = Core.ItemFactory():new(self, defaultDef) return instance end diff --git a/mods/CORE/ItemFactory/init.lua b/mods/CORE/ItemFactory/init.lua new file mode 100644 index 0000000..a5c12ea --- /dev/null +++ b/mods/CORE/ItemFactory/init.lua @@ -0,0 +1,5 @@ +local ItemFactory = Mod:new() + +ItemFactory.Class = ItemFactory.require('ItemFactory') + +Api.addModToGlobalSpace(ItemFactory, 'Core.ItemFactory') diff --git a/mods/CORE/Factory/mod.conf b/mods/CORE/ItemFactory/mod.conf similarity index 50% rename from mods/CORE/Factory/mod.conf rename to mods/CORE/ItemFactory/mod.conf index dc6daad..81a0c8d 100644 --- a/mods/CORE/Factory/mod.conf +++ b/mods/CORE/ItemFactory/mod.conf @@ -1,2 +1,2 @@ -name = smc__core__factory +name = smc__core__item_factory depends = smc__api__api_loader diff --git a/mods/CORE/Factory/src/Factory.lua b/mods/CORE/ItemFactory/src/ItemFactory.lua similarity index 78% rename from mods/CORE/Factory/src/Factory.lua rename to mods/CORE/ItemFactory/src/ItemFactory.lua index 46b984a..6c7d7c8 100644 --- a/mods/CORE/Factory/src/Factory.lua +++ b/mods/CORE/ItemFactory/src/ItemFactory.lua @@ -1,13 +1,13 @@ ----@class Factory +---@class ItemFactory ---@field defaultDef Item.ItemDefinition | Node.NodeDefinition ---@field itemClass Item | Node -local Factory = {} +local ItemFactory = {} ---@param itemClass Item | Node ----@param defaultDef Item.ItemDefinition | Node.NodeDefinition Parameters that all nodes registered with this factory must have. ----@return Factory -function Factory:new(itemClass, defaultDef) - ---@type Factory +---@param defaultDef Item.ItemDefinition | Node.NodeDefinition Parameters that all nodes registered with this ItemFactory must have. +---@return ItemFactory +function ItemFactory:new(itemClass, defaultDef) + ---@type ItemFactory local instance = setmetatable({ defaultDef = defaultDef, itemClass = itemClass, @@ -24,7 +24,7 @@ end ---@param itemDefs Item.ItemDefinition[] | Node.NodeDefinition[] List of nodes with parameters unique to them. ---@param addModName boolean Whether to add the mod name to the settings.name. Default: `true` -function Factory:registerItems(itemDefs, addModName) +function ItemFactory:registerItems(itemDefs, addModName) if addModName == nil then addModName = true end @@ -44,9 +44,16 @@ function Factory:registerItems(itemDefs, addModName) end end +---The alias `table.merge` for EmmyLua +---@type fun(...):(Node.NodeDefinition) +local defMerge = function(...) + return table.merge(...) +end + + ---@param shortNodeDefs table Table of the form `{ {name, title, description, tiles}, {name, title, description, tiles}, ...}` ---@param addModName boolean? Whether to add the mod name to the settings.name. Default: `true` -function Factory:registerNodesByShortDef(shortNodeDefs, addModName) +function ItemFactory:registerNodesByShortDef(shortNodeDefs, addModName) if addModName == nil then addModName = true end @@ -74,4 +81,4 @@ function Factory:registerNodesByShortDef(shortNodeDefs, addModName) end end -return Factory \ No newline at end of file +return ItemFactory \ No newline at end of file diff --git a/mods/CORE/Node/mod.conf b/mods/CORE/Node/mod.conf index e0a682f..a91930d 100644 --- a/mods/CORE/Node/mod.conf +++ b/mods/CORE/Node/mod.conf @@ -1,2 +1,2 @@ name = smc__core__node -depends = smc__core__item, smc__core__factory +depends = smc__core__item, smc__core__item_factory diff --git a/mods/CORE/Node/src/Node.lua b/mods/CORE/Node/src/Node.lua index 10495dc..738c7cd 100644 --- a/mods/CORE/Node/src/Node.lua +++ b/mods/CORE/Node/src/Node.lua @@ -30,16 +30,16 @@ function Node:getExtended(defaultDef) return ChildClass end ----Returns an instance of the `Factory` class that can be used to mass-register identical items. +---Returns an instance of the `ItemFactory` class that can be used to mass-register identical items. ---@param defaultDef? Node.NodeDefinition ----@return Factory +---@return ItemFactory function Node:getFactory(defaultDef) if defaultDef == nil then defaultDef = self.defaultDef end - ---@type Factory - local instance = Core.Factory:getModClassInstance(self, defaultDef) + ---@type ItemFactory + local instance = Core.ItemFactory:getModClassInstance(self, defaultDef) return instance end