Item: Corrections to the design, added the last empty lines
This commit is contained in:
@@ -33,10 +33,10 @@ local RARITY_INDEX = {
|
||||
}
|
||||
|
||||
---@class Item
|
||||
---@field itemDef Item.ItemDefinition
|
||||
---@field luantiDef table
|
||||
---@field getVisual fun(): string
|
||||
---@field defaultDef Item.ItemDefinition
|
||||
---@field itemDef Item.ItemDefinition
|
||||
---@field luantiDef ItemDefinition
|
||||
---@field getVisual fun(): string
|
||||
---@field defaultDef Item.ItemDefinition
|
||||
local Item = {
|
||||
defaultDef = {
|
||||
settings = {
|
||||
@@ -122,19 +122,19 @@ local function itemDefToLuantiDef(itemDef)
|
||||
return luantiDef
|
||||
end
|
||||
|
||||
---@param luantiDef NodeDefinition|ItemDefinition
|
||||
---@param luantiDef NodeDefinition
|
||||
local function register3dItem(luantiDef)
|
||||
local ld = luantiDef
|
||||
local name = ld.name
|
||||
ld.name = nil
|
||||
local name = luantiDef.name
|
||||
luantiDef.name = nil
|
||||
|
||||
core.register_node(':'..name, luantiDef)
|
||||
end
|
||||
|
||||
---@param luantiDef ItemDefinition
|
||||
local function registerFlatItem(luantiDef)
|
||||
local ld = luantiDef
|
||||
local name = ld.name
|
||||
ld.name = nil
|
||||
local name = luantiDef.name
|
||||
luantiDef.name = nil
|
||||
|
||||
core.register_craftitem(':'..name, luantiDef)
|
||||
end
|
||||
|
||||
@@ -144,23 +144,23 @@ local defMerge = function(...)
|
||||
return table.merge(...)
|
||||
end
|
||||
|
||||
---@param itemDef Item.ItemDefinition|Node.NodeDefinition
|
||||
---@return Item
|
||||
function Item:new(itemDef)
|
||||
---@param def Item.ItemDefinition|Node.NodeDefinition
|
||||
---@return Item
|
||||
function Item:new(def)
|
||||
---Adding default parameters
|
||||
itemDef = defMerge(itemDef, self.defaultDef, true)
|
||||
def = defMerge(def, self.defaultDef, true)
|
||||
|
||||
---@type Item
|
||||
local instance = getInstance(self, {})
|
||||
|
||||
local luantiDef = itemDefToLuantiDef(itemDef)
|
||||
local visual = itemDef.settings.visual
|
||||
local luantiDef = itemDefToLuantiDef(def)
|
||||
local visual = def.settings.visual
|
||||
|
||||
if visual == nil then
|
||||
visual = 'item_2d'
|
||||
end
|
||||
|
||||
itemDef.settings.visual = nil
|
||||
def.settings.visual = nil
|
||||
|
||||
if visual == 'item_3d' then
|
||||
register3dItem(luantiDef)
|
||||
@@ -173,7 +173,7 @@ function Item:new(itemDef)
|
||||
return visual
|
||||
end
|
||||
|
||||
instance.itemDef = itemDef
|
||||
instance.itemDef = def
|
||||
instance.luantiDef = luantiDef
|
||||
|
||||
return instance
|
||||
|
||||
@@ -64,4 +64,4 @@ Callbacks.on_use = nil
|
||||
---@type fun(itemstack:ItemStack, user:Player|ObjectRef|nil, node, digparams)?
|
||||
Callbacks.after_use = nil
|
||||
|
||||
return Callbacks
|
||||
return Callbacks
|
||||
|
||||
@@ -5,4 +5,4 @@
|
||||
--- * `eminent`
|
||||
--- * `prime`
|
||||
--- * `unique`
|
||||
---@alias Item.Rarity 'common'|'uncommon'|'distinguished'|'eminent'|'prime'|'unique'
|
||||
---@alias Item.Rarity 'common'|'uncommon'|'distinguished'|'eminent'|'prime'|'unique'
|
||||
|
||||
@@ -186,4 +186,4 @@ Settings.touch_interaction = nil
|
||||
Settings.sound = nil
|
||||
|
||||
|
||||
return Settings
|
||||
return Settings
|
||||
|
||||
Reference in New Issue
Block a user