Bunch of updates (29.08.2025)
This commit is contained in:
@@ -1,41 +1,52 @@
|
||||
local Item = {}
|
||||
|
||||
--- @class ItemDefinition
|
||||
--- @field settings table
|
||||
local ItemDefinition = {
|
||||
settings = {
|
||||
name = '',
|
||||
title = '',
|
||||
description = '',
|
||||
visual = '', -- '3d' | 'flat'
|
||||
},
|
||||
callbacks = {
|
||||
...
|
||||
},
|
||||
}
|
||||
|
||||
--- @param itemDef ItemDefinition
|
||||
local function itemDefToLuantiDef(itemDef)
|
||||
itemDef = table.copy(itemDef)
|
||||
local s = itemDef.settings
|
||||
local c = itemDef.callbacks
|
||||
local luantiDef = table.copy(c)
|
||||
local description = s.title .. "\n" .. s.description
|
||||
s.title, s.description = nil, description
|
||||
|
||||
local luantiDef = table.merge(s, c)
|
||||
|
||||
return luantiDef
|
||||
end
|
||||
|
||||
local function register3dItem(luantiDef)
|
||||
local ld = luantiDef
|
||||
core.register_node(ld.name, {
|
||||
description = ld.description
|
||||
})
|
||||
local name = ld.name
|
||||
ld.name = nil
|
||||
core.register_node(':'..name, luantiDef)
|
||||
end
|
||||
|
||||
local function registerFlatItem(luantiDef)
|
||||
|
||||
local ld = luantiDef
|
||||
local name = ld.name
|
||||
ld.name = nil
|
||||
core.register_craftitem(':'..name, luantiDef)
|
||||
end
|
||||
|
||||
function Item:new(itemDef)
|
||||
local item = {}
|
||||
local instance = {}
|
||||
local luantiDef = itemDefToLuantiDef(itemDef)
|
||||
local visual = itemDef.settings.visual
|
||||
itemDef.settings.visual = nil
|
||||
|
||||
|
||||
if visual == '3d' then
|
||||
register3dItem(luantiDef)
|
||||
else
|
||||
visual = 'flat'
|
||||
registerFlatItem(luantiDef)
|
||||
end
|
||||
|
||||
function instance:getVisual()
|
||||
return visual
|
||||
end
|
||||
|
||||
instance.itemDef = itemDef
|
||||
instance.luantiDef = luantiDef
|
||||
return instance
|
||||
end
|
||||
|
||||
return Item
|
||||
|
||||
15
mods/CORE/Item/src/ItemDefinition.lua
Normal file
15
mods/CORE/Item/src/ItemDefinition.lua
Normal file
@@ -0,0 +1,15 @@
|
||||
--- @class ItemDefinition
|
||||
--- @field settings table
|
||||
local ItemDefinition = {
|
||||
settings = {
|
||||
name = '',
|
||||
title = '', -- 1st line of item description
|
||||
description = '', -- the rest of item description
|
||||
visual = '', -- '3d' | 'flat'
|
||||
...
|
||||
},
|
||||
callbacks = {
|
||||
},
|
||||
}
|
||||
|
||||
return ItemDefinition
|
||||
Reference in New Issue
Block a user