diff --git a/mods/CORE/Entity/src/Entity/EntityDefinition.lua b/mods/CORE/Entity/src/Entity/EntityDefinition.lua index 7731941..2bbd6ed 100644 --- a/mods/CORE/Entity/src/Entity/EntityDefinition.lua +++ b/mods/CORE/Entity/src/Entity/EntityDefinition.lua @@ -1,4 +1,6 @@ ---@class Entity.EntityDefinition +---@field settings Item.Settings +---@field callbacks Item.Callbacks? local EntityDefinition = {} -return EntityDefinition \ No newline at end of file +return EntityDefinition diff --git a/mods/CORE/Item/src/Item.lua b/mods/CORE/Item/src/Item.lua index 95611dd..6f87d14 100644 --- a/mods/CORE/Item/src/Item.lua +++ b/mods/CORE/Item/src/Item.lua @@ -1,4 +1,6 @@ -local getInstance = Class.getInstance +local getInstance, extend = Class.getInstance, Class.extend + +local tableCopy, tableMerge, colorize = table.copy, table.merge, core.colorize local modInfo = Mod.getInfo('smc__core__item') local require = modInfo.require @@ -40,13 +42,13 @@ local RARITY_INDEX = { local Item = { defaultDef = { settings = { - name = '', - title = '', - description = '', - titleColor = '#FFFFFF', - descriptionColor = '#C0C0C0', - rarity = 'common', - addModName = true, + name = '', + _title = '', + _description = '', + _title_color = '#FFFFFF', + _description_color = '#C0C0C0', + _rarity = 'common', + _add_mod_name = true, }, callbacks = {} } @@ -70,13 +72,13 @@ local function addRarityToDesc(rarity, desc) rarityString = rarityString..' ['..RARITY_INDEX[rarity]..']' end - return desc..'\n'..core.colorize(color, rarityString) + return desc..'\n'..colorize(color, rarityString) end ---The alias `table.merge` for EmmyLua ---@type fun(...):(NodeDefinition|ItemDefinition) local defMerge = function(...) - return table.merge(...) + return tableMerge(...) end ---@param itemDef Item.ItemDefinition @@ -85,16 +87,16 @@ local function itemDefToLuantiDef(itemDef) local modName = Mod.getInfo().shortName local S = core.get_translator(modName) - itemDef = table.copy(itemDef) + itemDef = tableCopy(itemDef) local s = itemDef.settings local c = itemDef.callbacks - if s.addModName then + if s._add_mod_name then s.name = modName .. ':' .. s.name end - local title = s.title - local description = s.description + local title = s._title + local description = s._description if title == nil or title == '' then title = string.match(s.name, '%S:(%S+)')..'-title' @@ -104,18 +106,18 @@ local function itemDefToLuantiDef(itemDef) description = string.match(s.name, '%S:(%S+)')..'-desc' end - if s.titleColor ~= nil and s.descriptionColor ~= nil then - description = core.colorize(s.titleColor ,S(title))..'\n'.. - core.colorize(s.descriptionColor, S(description)) + if s._title_color ~= nil and s._description_color ~= nil then + description = colorize(s._title_color ,S(title))..'\n'.. + colorize(s._description_color, S(description)) else error('Item description color parameters cannot be empty.') end - assert(s.rarity ~= nil, 'The rarity of an item cannot be empty.') + assert(s._rarity ~= nil, 'The rarity of an item cannot be empty.') - description = addRarityToDesc(s.rarity, description) + description = addRarityToDesc(s._rarity, description) - s.title, s.description = nil, description..core.get_background_escape_sequence('#110F13') + s.description = description..core.get_background_escape_sequence('#110F13') local luantiDef = defMerge(s, c) @@ -141,12 +143,17 @@ end ---The alias `table.merge` for EmmyLua ---@type fun(...):(Item.ItemDefinition) local defMerge = function(...) - return table.merge(...) + return tableMerge(...) end ---@param def Item.ItemDefinition|Node.NodeDefinition ---@return Item function Item:new(def) + assert(def.settings.description == nil, + 'The item description was specified using `description`, not `_description`. '.. + 'Please note that the `description` field should not be used when registering an item. '.. + 'Use `_title` and `_description` instead.') + ---Adding default parameters def = defMerge(def, self.defaultDef, true) @@ -154,13 +161,13 @@ function Item:new(def) local instance = getInstance(self, {}) local luantiDef = itemDefToLuantiDef(def) - local visual = def.settings.visual + local visual = def.settings._visual if visual == nil then visual = 'item_2d' end - def.settings.visual = nil + def.settings._visual = nil if visual == 'item_3d' then register3dItem(luantiDef) @@ -186,7 +193,7 @@ end ---@return Item function Item:getExtended(defaultDef) ---@type Item - local ChildClass = Class.extend(self, { + local ChildClass = extend(self, { defaultDef = defaultDef, }) diff --git a/mods/CORE/Item/src/Item/Settings.lua b/mods/CORE/Item/src/Item/Settings.lua index 584cfc8..3942219 100644 --- a/mods/CORE/Item/src/Item/Settings.lua +++ b/mods/CORE/Item/src/Item/Settings.lua @@ -5,41 +5,40 @@ local Settings = {} ---@type string Settings.name = '' +---@type string? +Settings.description = nil + ---Whether to add the mod name to the settings.name. Default: `true` ---@type boolean? -Settings.addModName = nil +Settings._add_mod_name = nil ---Item description. 1st line of item description. ---@type string? -Settings.title = nil +Settings._title = nil ---Item description. The rest of item description. ---@type string? -Settings.description = nil +Settings._description = nil ---Item title color in description. --- ---Default: `#FFFFFF` ---@type ColorString? -Settings.titleColor = nil +Settings._title_color = nil ---Item description color in description. --- ---Default: `#C0C0C0` ---@type ColorString? -Settings.descriptionColor = nil - ----@alias Item.Visual ----'item_2d'| ----'item_3d' +Settings._description_color = nil ---Visual node type. ---@type Item.Visual? -Settings.visual = nil +Settings._visual = nil ---Formal (lore) rarity of an item. Default `common`. ---@type Item.Rarity? -Settings.rarity = nil +Settings._rarity = nil ---Table of groups-characteristics of Item. diff --git a/mods/CORE/Item/src/Item/Visual.lua b/mods/CORE/Item/src/Item/Visual.lua new file mode 100644 index 0000000..5715984 --- /dev/null +++ b/mods/CORE/Item/src/Item/Visual.lua @@ -0,0 +1 @@ +---@alias Item.Visual 'item_2d'|'item_3d' \ No newline at end of file diff --git a/mods/CORE/Node/src/Node.lua b/mods/CORE/Node/src/Node.lua index 7fb1323..d6ac38d 100644 --- a/mods/CORE/Node/src/Node.lua +++ b/mods/CORE/Node/src/Node.lua @@ -22,7 +22,7 @@ function Node:new(nodeDef) ---Adding default parameters nodeDef = defMerge(nodeDef, self.defaultDef, true) - nodeDef.settings.visual = 'item_3d' + nodeDef.settings._visual = 'item_3d' ---@type Node local instance = Item:new(nodeDef) diff --git a/mods/GAME/ITEMS/liquids/init.lua b/mods/GAME/ITEMS/liquids/init.lua index 8457ee1..ba657c0 100644 --- a/mods/GAME/ITEMS/liquids/init.lua +++ b/mods/GAME/ITEMS/liquids/init.lua @@ -5,7 +5,7 @@ local Node = Mod.getInfo('smc__core__node').require('Node') local defaultLiquidDef = { settings = { name = '', - addModName = false, + _add_mod_name = false, tiles = {}, waving = 3, use_texture_alpha = "blend", diff --git a/mods/GAME/ITEMS/plants/init.lua b/mods/GAME/ITEMS/plants/init.lua index 8d3fbd6..d02473a 100644 --- a/mods/GAME/ITEMS/plants/init.lua +++ b/mods/GAME/ITEMS/plants/init.lua @@ -21,7 +21,7 @@ for i=0, 3 do Plant:new({ settings = { name = 'plant'..tostring(i), - title = 'Plant', + _title = 'Plant', tiles = { ts:t(i,0) }, place_param2 = 3, }, diff --git a/mods/GAME/ITEMS/rocks/init.lua b/mods/GAME/ITEMS/rocks/init.lua index b100341..87be972 100644 --- a/mods/GAME/ITEMS/rocks/init.lua +++ b/mods/GAME/ITEMS/rocks/init.lua @@ -8,7 +8,7 @@ local Node = Mod.getInfo('smc__core__node').require('Node') local defaultRockDef = { settings = { name = "", - description = "A rocks", + _description = "A rocks", tiles = {}, groups = { dig_immediate = 2, diff --git a/mods/GAME/ITEMS/soils/init.lua b/mods/GAME/ITEMS/soils/init.lua index 5afee81..ffa2f6f 100644 --- a/mods/GAME/ITEMS/soils/init.lua +++ b/mods/GAME/ITEMS/soils/init.lua @@ -8,7 +8,7 @@ local Node = Mod.getInfo('smc__core__node').require('Node') local defaultSoilDef = { settings = { name = "", - description = "A soil", + _description = "A soil", tiles = {}, groups = { dig_immediate = 2, @@ -47,7 +47,7 @@ soilFactory:registerItems({ { settings = { name = "clay_soil_baren", - title = "Barren Clay Soil", + _title = "Barren Clay Soil", --description = "", tiles = clayTiles, }, @@ -56,7 +56,7 @@ soilFactory:registerItems({ { settings = { name = "clay_soil_poor", - title = "Poor Clay Soil", + _title = "Poor Clay Soil", --description = "", tiles = clayTiles, }, @@ -65,7 +65,7 @@ soilFactory:registerItems({ { settings = { name = "clay_soil_moderate", - title = "Moderate Clay Soil", + _title = "Moderate Clay Soil", --description = "", tiles = clayTiles, }, @@ -74,7 +74,7 @@ soilFactory:registerItems({ { settings = { name = "clay_soil_fertile", - title = "Fertile Clay Soil", + _title = "Fertile Clay Soil", --description = "", tiles = clayTiles, }, @@ -83,7 +83,7 @@ soilFactory:registerItems({ { settings = { name = "clay_soil_rich", - title = "Rich Clay Soil", + _title = "Rich Clay Soil", --description = "", tiles = clayTiles, }, @@ -96,7 +96,7 @@ soilFactory:registerItems({ { settings = { name = "sandy_soil_baren", - title = "Barren Sandy Soil", + _title = "Barren Sandy Soil", --description = "", tiles = sandyTiles, }, @@ -105,7 +105,7 @@ soilFactory:registerItems({ { settings = { name = "sandy_soil_poor", - title = "Poor Sandy Soil", + _title = "Poor Sandy Soil", --description = "", tiles = sandyTiles, }, @@ -114,7 +114,7 @@ soilFactory:registerItems({ { settings = { name = "sandy_soil_moderate", - title = "Moderate Sandy Soil", + _title = "Moderate Sandy Soil", --description = "", tiles = sandyTiles, }, @@ -123,7 +123,7 @@ soilFactory:registerItems({ { settings = { name = "sandy_soil_fertile", - title = "Fertile Sandy Soil", + _title = "Fertile Sandy Soil", --description = "", tiles = sandyTiles, }, @@ -132,7 +132,7 @@ soilFactory:registerItems({ { settings = { name = "sandy_soil_rich", - title = "Rich Sandy Soil", + _title = "Rich Sandy Soil", --description = "", tiles = sandyTiles, }, @@ -145,7 +145,7 @@ soilFactory:registerItems({ { settings = { name = "mixed_soil_baren", - title = "Barren Mixed Soil", + _title = "Barren Mixed Soil", --description = "", tiles = mixedTiles, }, @@ -154,7 +154,7 @@ soilFactory:registerItems({ { settings = { name = "mixed_soil_poor", - title = "Poor Mixed Soil", + _title = "Poor Mixed Soil", --description = "", tiles = mixedTiles, }, @@ -163,7 +163,7 @@ soilFactory:registerItems({ { settings = { name = "mixed_soil_moderate", - title = "Moderate Mixed Soil", + _title = "Moderate Mixed Soil", --description = "", tiles = mixedTiles, }, @@ -172,7 +172,7 @@ soilFactory:registerItems({ { settings = { name = "mixed_soil_fertile", - title = "Fertile Mixed Soil", + _title = "Fertile Mixed Soil", --description = "", tiles = mixedTiles, }, @@ -181,7 +181,7 @@ soilFactory:registerItems({ { settings = { name = "mixed_soil_rich", - title = "Rich Mixed Soil", + _title = "Rich Mixed Soil", --description = "", tiles = mixedTiles, }, @@ -194,7 +194,7 @@ soilFactory:registerItems({ { settings = { name = "rocky_soil_baren", - title = "Barren Rocky Soil", + _title = "Barren Rocky Soil", --description = "", tiles = rockyTiles, rarity = 'uncommon' @@ -204,7 +204,7 @@ soilFactory:registerItems({ { settings = { name = "rocky_soil_poor", - title = "Poor Rocky Soil", + _title = "Poor Rocky Soil", --description = "", tiles = rockyTiles, rarity = 'distinguished' @@ -214,7 +214,7 @@ soilFactory:registerItems({ { settings = { name = "rocky_soil_moderate", - title = "Moderate Rocky Soil", + _title = "Moderate Rocky Soil", --description = "", tiles = rockyTiles, rarity = 'eminent' @@ -224,7 +224,7 @@ soilFactory:registerItems({ { settings = { name = "rocky_soil_fertile", - title = "Fertile Rocky Soil", + _title = "Fertile Rocky Soil", --description = "", tiles = rockyTiles, rarity = 'prime' @@ -234,7 +234,7 @@ soilFactory:registerItems({ { settings = { name = "rocky_soil_rich", - title = "Rich Rocky Soil", + _title = "Rich Rocky Soil", --description = "", tiles = rockyTiles, }, @@ -253,6 +253,6 @@ Node:new({ dig_immediate = 2, soil_fertiliry = 100, -- Soil fertility for agriculture }, - rarity = 'unique' + _rarity = 'unique' } }) \ No newline at end of file diff --git a/mods/GAME/ITEMS/wood/init.lua b/mods/GAME/ITEMS/wood/init.lua index 986afcd..c72c92e 100644 --- a/mods/GAME/ITEMS/wood/init.lua +++ b/mods/GAME/ITEMS/wood/init.lua @@ -8,7 +8,7 @@ local TileSheet = Mod.getInfo('smc__core__tilesheet').require('TileSheet') local defaultRockDef = { settings = { name = "", - description = "A log", + _description = "A log", tiles = {}, groups = { dig_immediate = 2, @@ -21,7 +21,7 @@ local defaultRockDef = { local defaultPlanksDef = { settings = { name = "", - description = "A planks", + _description = "A planks", tiles = {}, groups = { dig_immediate = 2, @@ -54,7 +54,7 @@ logFactory:registerItems({ { settings = { name = "marentine_log", - title = "Marentine Log", + _title = "Marentine Log", --description = "", tiles = t(0, 1), }, @@ -63,7 +63,7 @@ logFactory:registerItems({ { settings = { name = "allwhere_log", - title = "Allwhere Log", + _title = "Allwhere Log", --description = "", tiles = t(2, 1), }, @@ -72,7 +72,7 @@ logFactory:registerItems({ { settings = { name = "fis_log", - title = "Fis Log", + _title = "Fis Log", --description = "", tiles = t(4, 1), }, @@ -81,7 +81,7 @@ logFactory:registerItems({ { settings = { name = "tammoy_log", - title = "Tammoy Log", + _title = "Tammoy Log", --description = "", tiles = t(6, 1), }, @@ -90,7 +90,7 @@ logFactory:registerItems({ { settings = { name = "dallalia_log", - title = "Dallalia Log", + _title = "Dallalia Log", --description = "", tiles = t(8, 1), }, @@ -99,7 +99,7 @@ logFactory:registerItems({ { settings = { name = "zuph_log", - title = "Zuph Log", + _title = "Zuph Log", --description = "", tiles = t(10, 1), }, @@ -111,7 +111,7 @@ planksFactory:registerItems({ { settings = { name = "marentine_planks", - title = "Marentine Planks", + _title = "Marentine Planks", --description = "", tiles = { logTileSheet:t(0, 4) }, }, @@ -120,7 +120,7 @@ planksFactory:registerItems({ { settings = { name = "allwhere_planks", - title = "Allwhere Planks", + _title = "Allwhere Planks", --description = "", tiles = { logTileSheet:t(2, 4) }, }, @@ -129,7 +129,7 @@ planksFactory:registerItems({ { settings = { name = "fis_planks", - title = "Fis Planks", + _title = "Fis Planks", --description = "", tiles = { logTileSheet:t(4, 4) }, }, @@ -138,7 +138,7 @@ planksFactory:registerItems({ { settings = { name = "tammoy_planks", - title = "Tammoy Planks", + _title = "Tammoy Planks", --description = "", tiles = { logTileSheet:t(6, 4) }, }, @@ -147,7 +147,7 @@ planksFactory:registerItems({ { settings = { name = "dallalia_planks", - title = "Dallalia Planks", + _title = "Dallalia Planks", --description = "", tiles = { logTileSheet:t(8, 4) }, }, @@ -156,7 +156,7 @@ planksFactory:registerItems({ { settings = { name = "zuph_planks", - title = "Zuph Planks", + _title = "Zuph Planks", --description = "", tiles = { logTileSheet:t(10, 4) }, }, @@ -183,7 +183,7 @@ planksFactory:registerItems({ { settings = { name = "case_closed", - title = "Case", + _title = "Case", --description = "", tiles = t(0,0) }, @@ -192,7 +192,7 @@ planksFactory:registerItems({ { settings = { name = "case_open", - title = "Case", + _title = "Case", --description = "", tiles = t(1,0); drawtype = 'nodebox';