Item & Node: inheritance from a Class
This commit is contained in:
@@ -1,5 +1,3 @@
|
|||||||
local getInstance, extend = Class.getInstance, Class.extend
|
|
||||||
|
|
||||||
local tableCopy, tableMerge, colorize = table.copy, table.merge, core.colorize
|
local tableCopy, tableMerge, colorize = table.copy, table.merge, core.colorize
|
||||||
|
|
||||||
local ItemFactory = Smc.requireItemFactory()
|
local ItemFactory = Smc.requireItemFactory()
|
||||||
@@ -39,12 +37,12 @@ local RARITY_INDEX = {
|
|||||||
['unique'] = 0
|
['unique'] = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
---@class Item
|
---@class Item : Class
|
||||||
---@field itemDef Item.ItemDefinition
|
---@field itemDef Item.ItemDefinition
|
||||||
---@field luantiDef ItemDefinition
|
---@field luantiDef ItemDefinition
|
||||||
---@field getType fun():string
|
---@field getType fun():string
|
||||||
---@field defaultDef Item.ItemDefinition
|
---@field defaultDef Item.ItemDefinition
|
||||||
local Item = {
|
local Item = Class:extend({
|
||||||
defaultDef = {
|
defaultDef = {
|
||||||
settings = {
|
settings = {
|
||||||
name = '',
|
name = '',
|
||||||
@@ -58,7 +56,7 @@ local Item = {
|
|||||||
},
|
},
|
||||||
callbacks = {}
|
callbacks = {}
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
|
|
||||||
---Adds an item's rarity tag to the description.
|
---Adds an item's rarity tag to the description.
|
||||||
---@param rarity Item.Rarity
|
---@param rarity Item.Rarity
|
||||||
@@ -180,7 +178,7 @@ function Item:new(itemDef)
|
|||||||
end
|
end
|
||||||
|
|
||||||
---@type Item
|
---@type Item
|
||||||
local instance = getInstance(self, {})
|
local instance = self:getInstance({})
|
||||||
|
|
||||||
local luantiDef = itemDefToLuantiDef(itemDef)
|
local luantiDef = itemDefToLuantiDef(itemDef)
|
||||||
local type = itemDef.settings._type
|
local type = itemDef.settings._type
|
||||||
@@ -221,7 +219,7 @@ function Item:getExtended(defaultDef)
|
|||||||
defaultDef = tableMerge(defaultDef, self.defaultDef, true)
|
defaultDef = tableMerge(defaultDef, self.defaultDef, true)
|
||||||
|
|
||||||
---@type Item
|
---@type Item
|
||||||
local ChildClass = extend(self, {
|
local ChildClass = self:extend({
|
||||||
defaultDef = defaultDef,
|
defaultDef = defaultDef,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ local Item, ItemFactory = Smc.requireItem(), Smc.requireItemFactory()
|
|||||||
|
|
||||||
---@class Node : Item
|
---@class Node : Item
|
||||||
---@field defaultDef Node.NodeDefinition
|
---@field defaultDef Node.NodeDefinition
|
||||||
local Node = Class.extend(Item, {})
|
local Node = Item:extend({})
|
||||||
|
|
||||||
---@param nodeDef Node.NodeDefinition
|
---@param nodeDef Node.NodeDefinition
|
||||||
local function registerSlab(nodeDef)
|
local function registerSlab(nodeDef)
|
||||||
@@ -102,7 +102,7 @@ function Node:getExtended(defaultDef)
|
|||||||
defaultDef = tableMerge(defaultDef, self.defaultDef, true)
|
defaultDef = tableMerge(defaultDef, self.defaultDef, true)
|
||||||
|
|
||||||
---@type Node
|
---@type Node
|
||||||
local ChildClass = Class.extend(self, {
|
local ChildClass = self:extend({
|
||||||
defaultDef = defaultDef,
|
defaultDef = defaultDef,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user