Rename Factory => itemFactory

This commit is contained in:
Van
2025-09-26 20:03:07 +03:00
parent 2b96db73b2
commit a86b0efe4c
8 changed files with 31 additions and 24 deletions

View File

@@ -1,5 +0,0 @@
local Factory = Mod:new()
Factory.Class = Factory.require('Factory')
Api.addModToGlobalSpace(Factory, 'Core.Factory')

View File

@@ -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

View File

@@ -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

View File

@@ -0,0 +1,5 @@
local ItemFactory = Mod:new()
ItemFactory.Class = ItemFactory.require('ItemFactory')
Api.addModToGlobalSpace(ItemFactory, 'Core.ItemFactory')

View File

@@ -1,2 +1,2 @@
name = smc__core__factory
name = smc__core__item_factory
depends = smc__api__api_loader

View File

@@ -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
return ItemFactory

View File

@@ -1,2 +1,2 @@
name = smc__core__node
depends = smc__core__item, smc__core__factory
depends = smc__core__item, smc__core__item_factory

View File

@@ -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