Item: Corrections to the design, added the last empty lines
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
local modInfo = Mod.getInfo('smc__core__item')
|
local modInfo = Mod.getInfo('smc__core__item')
|
||||||
local require = modInfo.require
|
local require = modInfo.require
|
||||||
|
|
||||||
return require('Item')
|
return require('Item')
|
||||||
|
|||||||
@@ -6,4 +6,4 @@ uncommon=необычный
|
|||||||
distinguished=выдающийся
|
distinguished=выдающийся
|
||||||
eminent=исключительный
|
eminent=исключительный
|
||||||
prime=Превосходный
|
prime=Превосходный
|
||||||
unique=Уникальный
|
unique=Уникальный
|
||||||
|
|||||||
@@ -33,10 +33,10 @@ local RARITY_INDEX = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
---@class Item
|
---@class Item
|
||||||
---@field itemDef Item.ItemDefinition
|
---@field itemDef Item.ItemDefinition
|
||||||
---@field luantiDef table
|
---@field luantiDef ItemDefinition
|
||||||
---@field getVisual fun(): string
|
---@field getVisual fun(): string
|
||||||
---@field defaultDef Item.ItemDefinition
|
---@field defaultDef Item.ItemDefinition
|
||||||
local Item = {
|
local Item = {
|
||||||
defaultDef = {
|
defaultDef = {
|
||||||
settings = {
|
settings = {
|
||||||
@@ -122,19 +122,19 @@ local function itemDefToLuantiDef(itemDef)
|
|||||||
return luantiDef
|
return luantiDef
|
||||||
end
|
end
|
||||||
|
|
||||||
---@param luantiDef NodeDefinition|ItemDefinition
|
---@param luantiDef NodeDefinition
|
||||||
local function register3dItem(luantiDef)
|
local function register3dItem(luantiDef)
|
||||||
local ld = luantiDef
|
local name = luantiDef.name
|
||||||
local name = ld.name
|
luantiDef.name = nil
|
||||||
ld.name = nil
|
|
||||||
core.register_node(':'..name, luantiDef)
|
core.register_node(':'..name, luantiDef)
|
||||||
end
|
end
|
||||||
|
|
||||||
---@param luantiDef ItemDefinition
|
---@param luantiDef ItemDefinition
|
||||||
local function registerFlatItem(luantiDef)
|
local function registerFlatItem(luantiDef)
|
||||||
local ld = luantiDef
|
local name = luantiDef.name
|
||||||
local name = ld.name
|
luantiDef.name = nil
|
||||||
ld.name = nil
|
|
||||||
core.register_craftitem(':'..name, luantiDef)
|
core.register_craftitem(':'..name, luantiDef)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -144,23 +144,23 @@ local defMerge = function(...)
|
|||||||
return table.merge(...)
|
return table.merge(...)
|
||||||
end
|
end
|
||||||
|
|
||||||
---@param itemDef Item.ItemDefinition|Node.NodeDefinition
|
---@param def Item.ItemDefinition|Node.NodeDefinition
|
||||||
---@return Item
|
---@return Item
|
||||||
function Item:new(itemDef)
|
function Item:new(def)
|
||||||
---Adding default parameters
|
---Adding default parameters
|
||||||
itemDef = defMerge(itemDef, self.defaultDef, true)
|
def = defMerge(def, self.defaultDef, true)
|
||||||
|
|
||||||
---@type Item
|
---@type Item
|
||||||
local instance = getInstance(self, {})
|
local instance = getInstance(self, {})
|
||||||
|
|
||||||
local luantiDef = itemDefToLuantiDef(itemDef)
|
local luantiDef = itemDefToLuantiDef(def)
|
||||||
local visual = itemDef.settings.visual
|
local visual = def.settings.visual
|
||||||
|
|
||||||
if visual == nil then
|
if visual == nil then
|
||||||
visual = 'item_2d'
|
visual = 'item_2d'
|
||||||
end
|
end
|
||||||
|
|
||||||
itemDef.settings.visual = nil
|
def.settings.visual = nil
|
||||||
|
|
||||||
if visual == 'item_3d' then
|
if visual == 'item_3d' then
|
||||||
register3dItem(luantiDef)
|
register3dItem(luantiDef)
|
||||||
@@ -173,7 +173,7 @@ function Item:new(itemDef)
|
|||||||
return visual
|
return visual
|
||||||
end
|
end
|
||||||
|
|
||||||
instance.itemDef = itemDef
|
instance.itemDef = def
|
||||||
instance.luantiDef = luantiDef
|
instance.luantiDef = luantiDef
|
||||||
|
|
||||||
return instance
|
return instance
|
||||||
|
|||||||
@@ -64,4 +64,4 @@ Callbacks.on_use = nil
|
|||||||
---@type fun(itemstack:ItemStack, user:Player|ObjectRef|nil, node, digparams)?
|
---@type fun(itemstack:ItemStack, user:Player|ObjectRef|nil, node, digparams)?
|
||||||
Callbacks.after_use = nil
|
Callbacks.after_use = nil
|
||||||
|
|
||||||
return Callbacks
|
return Callbacks
|
||||||
|
|||||||
@@ -5,4 +5,4 @@
|
|||||||
--- * `eminent`
|
--- * `eminent`
|
||||||
--- * `prime`
|
--- * `prime`
|
||||||
--- * `unique`
|
--- * `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
|
Settings.sound = nil
|
||||||
|
|
||||||
|
|
||||||
return Settings
|
return Settings
|
||||||
|
|||||||
Reference in New Issue
Block a user