forked from Apancore.Studio/simple-makes-complex
Node: add getFactory & getExtended methods, add support defaultItemDef
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
local VisualEnum = Core.Item.require('Item.VisualEnum')
|
||||
|
||||
---@class Node : Item
|
||||
---@field defaultDef Node.NodeDefinition
|
||||
local Node = Core.Item:getModClassExtended({})
|
||||
|
||||
---@param nodeDef Node.NodeDefinition
|
||||
@@ -15,4 +16,31 @@ function Node:new(nodeDef)
|
||||
return instance
|
||||
end
|
||||
|
||||
---Allows you to create a child class of an node by specifying
|
||||
---default parameters that will be added to the node's parameters
|
||||
---when an instance is received.
|
||||
---@param defaultDef Node.NodeDefinition
|
||||
---@return Node
|
||||
function Node:getExtended(defaultDef)
|
||||
---@type Node
|
||||
local ChildClass = Mod:getClassExtended(self, {
|
||||
defaultNodeDef = defaultDef,
|
||||
})
|
||||
|
||||
return ChildClass
|
||||
end
|
||||
|
||||
---Returns an instance of the `Factory` class that can be used to mass-register identical items.
|
||||
---@param defaultDef Node.NodeDefinition
|
||||
---@return Factory
|
||||
function Node:getFactory(defaultDef)
|
||||
if defaultDef == nil then
|
||||
defaultDef = self.defaultDef
|
||||
end
|
||||
|
||||
local instance = Core.Factory():new(self, defaultDef)
|
||||
|
||||
return instance
|
||||
end
|
||||
|
||||
return Node
|
||||
Reference in New Issue
Block a user