Rename Factory => itemFactory
This commit is contained in:
@@ -1,5 +0,0 @@
|
|||||||
local Factory = Mod:new()
|
|
||||||
|
|
||||||
Factory.Class = Factory.require('Factory')
|
|
||||||
|
|
||||||
Api.addModToGlobalSpace(Factory, 'Core.Factory')
|
|
||||||
@@ -1,2 +1,2 @@
|
|||||||
name = smc__core__item
|
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
|
||||||
|
|||||||
@@ -105,15 +105,15 @@ function Item:getExtended(defaultDef)
|
|||||||
return ChildClass
|
return ChildClass
|
||||||
end
|
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
|
---@param defaultDef? Item.ItemDefinition
|
||||||
---@return Factory
|
---@return ItemFactory
|
||||||
function Item:getFactory(defaultDef)
|
function Item:getFactory(defaultDef)
|
||||||
if defaultDef == nil then
|
if defaultDef == nil then
|
||||||
defaultDef = self.defaultDef
|
defaultDef = self.defaultDef
|
||||||
end
|
end
|
||||||
|
|
||||||
local instance = Core.Factory():new(self, defaultDef)
|
local instance = Core.ItemFactory():new(self, defaultDef)
|
||||||
|
|
||||||
return instance
|
return instance
|
||||||
end
|
end
|
||||||
|
|||||||
5
mods/CORE/ItemFactory/init.lua
Normal file
5
mods/CORE/ItemFactory/init.lua
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
local ItemFactory = Mod:new()
|
||||||
|
|
||||||
|
ItemFactory.Class = ItemFactory.require('ItemFactory')
|
||||||
|
|
||||||
|
Api.addModToGlobalSpace(ItemFactory, 'Core.ItemFactory')
|
||||||
@@ -1,2 +1,2 @@
|
|||||||
name = smc__core__factory
|
name = smc__core__item_factory
|
||||||
depends = smc__api__api_loader
|
depends = smc__api__api_loader
|
||||||
@@ -1,13 +1,13 @@
|
|||||||
---@class Factory
|
---@class ItemFactory
|
||||||
---@field defaultDef Item.ItemDefinition | Node.NodeDefinition
|
---@field defaultDef Item.ItemDefinition | Node.NodeDefinition
|
||||||
---@field itemClass Item | Node
|
---@field itemClass Item | Node
|
||||||
local Factory = {}
|
local ItemFactory = {}
|
||||||
|
|
||||||
---@param itemClass Item | Node
|
---@param itemClass Item | Node
|
||||||
---@param defaultDef Item.ItemDefinition | Node.NodeDefinition Parameters that all nodes registered with this factory must have.
|
---@param defaultDef Item.ItemDefinition | Node.NodeDefinition Parameters that all nodes registered with this ItemFactory must have.
|
||||||
---@return Factory
|
---@return ItemFactory
|
||||||
function Factory:new(itemClass, defaultDef)
|
function ItemFactory:new(itemClass, defaultDef)
|
||||||
---@type Factory
|
---@type ItemFactory
|
||||||
local instance = setmetatable({
|
local instance = setmetatable({
|
||||||
defaultDef = defaultDef,
|
defaultDef = defaultDef,
|
||||||
itemClass = itemClass,
|
itemClass = itemClass,
|
||||||
@@ -24,7 +24,7 @@ end
|
|||||||
|
|
||||||
---@param itemDefs Item.ItemDefinition[] | Node.NodeDefinition[] List of nodes with parameters unique to them.
|
---@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`
|
---@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
|
if addModName == nil then
|
||||||
addModName = true
|
addModName = true
|
||||||
end
|
end
|
||||||
@@ -44,9 +44,16 @@ function Factory:registerItems(itemDefs, addModName)
|
|||||||
end
|
end
|
||||||
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 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`
|
---@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
|
if addModName == nil then
|
||||||
addModName = true
|
addModName = true
|
||||||
end
|
end
|
||||||
@@ -74,4 +81,4 @@ function Factory:registerNodesByShortDef(shortNodeDefs, addModName)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
return Factory
|
return ItemFactory
|
||||||
@@ -1,2 +1,2 @@
|
|||||||
name = smc__core__node
|
name = smc__core__node
|
||||||
depends = smc__core__item, smc__core__factory
|
depends = smc__core__item, smc__core__item_factory
|
||||||
|
|||||||
@@ -30,16 +30,16 @@ function Node:getExtended(defaultDef)
|
|||||||
return ChildClass
|
return ChildClass
|
||||||
end
|
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
|
---@param defaultDef? Node.NodeDefinition
|
||||||
---@return Factory
|
---@return ItemFactory
|
||||||
function Node:getFactory(defaultDef)
|
function Node:getFactory(defaultDef)
|
||||||
if defaultDef == nil then
|
if defaultDef == nil then
|
||||||
defaultDef = self.defaultDef
|
defaultDef = self.defaultDef
|
||||||
end
|
end
|
||||||
|
|
||||||
---@type Factory
|
---@type ItemFactory
|
||||||
local instance = Core.Factory:getModClassInstance(self, defaultDef)
|
local instance = Core.ItemFactory:getModClassInstance(self, defaultDef)
|
||||||
|
|
||||||
return instance
|
return instance
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user