diff --git a/.emmyrc.json b/.emmyrc.json deleted file mode 100644 index c4cd027..0000000 --- a/.emmyrc.json +++ /dev/null @@ -1,99 +0,0 @@ -{ - "codeAction": { - "insertSpace": false - }, - "codeLens": { - "enable": true - }, - "completion": { - "autoRequire": false, - "autoRequireFunction": "require", - "autoRequireNamingConvention": "keep", - "autoRequireSeparator": ".", - "callSnippet": false, - "enable": true, - "postfix": "@" - }, - "diagnostics": { - "diagnosticInterval": 1, - "disable": [ - "unnecessary-if", - "redefined-local" - ], - "enable": true, - "enables": [], - "globals": [ - "core", - "Smc", - "table", - "Events", - "VoxelArea", - "VoxelManip", - "vector", - "Ensure", - "string", - "string_utf8", - "Profiler" - ], - "globalsRegex": [] - }, - "documentColor": { - "enable": true - }, - "hint": { - "enable": true, - "indexHint": true, - "localHint": true, - "overrideHint": true, - "paramHint": true - }, - "hover": { - "enable": true - }, - "references": { - "enable": true, - "fuzzySearch": true, - "shortStringSearch": false - }, - "resource": { - "paths": [] - }, - "runtime": { - "classDefaultCall": { - "forceNonColon": false, - "forceReturnSelf": false, - "functionName": "" - }, - "extensions": [], - "frameworkVersions": [], - "requireLikeFunction": [], - "requirePattern": [], - "version": "LuaJIT" - }, - "semanticTokens": { - "enable": true - }, - "signature": { - "detailSignatureHelper": true - }, - "strict": { - "arrayIndex": true, - "docBaseConstMatchBaseType": true, - "metaOverrideFileDefine": true, - "requirePath": false, - "typeCall": false - }, - "workspace": { - "enableReindex": false, - "encoding": "utf-8", - "ignoreDir": [], - "ignoreGlobs": [], - "library": [ - "util/ide-helper" - ], - "moduleMap": [], - "preloadFileSize": 0, - "reindexDuration": 5000, - "workspaceRoots": [] - } - } diff --git a/.luarc.json b/.luarc.json new file mode 100644 index 0000000..0ba4f44 --- /dev/null +++ b/.luarc.json @@ -0,0 +1,36 @@ +{ + "$schema": "https://raw.githubusercontent.com/LuaLS/vscode-lua/master/setting/schema.json", + "runtime.version": "LuaJIT", + "workspace.library": ["${workspaceFolder}/"], + "diagnostics.libraryFiles": "Enable", + "workspace.preloadFileSize": 500000, + "workspace.maxPreload": 500000, + "diagnostics.workspaceDelay": 2, + "hint.enable": true, + "diagnostics.enable": true, + "diagnostics.groupFileStatus": { + "ambiguity": "Any", + "duplicate": "Any", + "global": "Any", + "redefined": "Any", + "strict": "Any", + "type-check": "Any", + "unbalanced": "Any" + }, + "diagnostics.disable": [ + "inject-field" + ], + "diagnostics.globals": [ + "core", + "Smc", + "table", + "Events", + "VoxelArea", + "VoxelManip", + "vector", + "Ensure", + "string", + "string_utf8", + "Profiler" + ] +} diff --git a/mods/CORE/Controls/src/Controls.lua b/mods/CORE/Controls/src/Controls.lua index d1b9e9a..58027f7 100644 --- a/mods/CORE/Controls/src/Controls.lua +++ b/mods/CORE/Controls/src/Controls.lua @@ -1,5 +1,4 @@ ----@type Events.ControlsEvents -local ControlsEvents = Smc.requireEvents('ControlsEvents') +local ControlsEvents = Smc.requireEvents('ControlsEvents') --[[@as Events.ControlsEvents]] ---@class Controls local Controls = {} diff --git a/mods/CORE/CraftSystem/src/CraftSystem/BaseCraft.lua b/mods/CORE/CraftSystem/src/CraftSystem/BaseCraft.lua index d282f1d..e83ddc7 100644 --- a/mods/CORE/CraftSystem/src/CraftSystem/BaseCraft.lua +++ b/mods/CORE/CraftSystem/src/CraftSystem/BaseCraft.lua @@ -126,7 +126,7 @@ function BaseCraft:recipeToString(recipeIndex, mainList) local recipeItem = ItemStack(itemName) recipeDesc = recipeDesc..('%s %s x%s\n'):format( getCheckMaterialItem(recipeItem, recipeItem:get_count(), mainList), - core.strip_colors(recipeItem:get_definition()._title), + core.strip_colors(Smc.getItemDefinition(recipeItem).settings._title), recipeItem:get_count()) else recipeDesc = recipeDesc..('%s any item from the group %s x%s\n'):format( diff --git a/mods/CORE/CraftSystem/src/CraftSystem/ImmersiveCraft.lua b/mods/CORE/CraftSystem/src/CraftSystem/ImmersiveCraft.lua index bff661d..06fe318 100644 --- a/mods/CORE/CraftSystem/src/CraftSystem/ImmersiveCraft.lua +++ b/mods/CORE/CraftSystem/src/CraftSystem/ImmersiveCraft.lua @@ -4,8 +4,7 @@ local coreChatSendPlayer, coreItemDrop = core.chat_send_player, core.item_drop local require = Mod.getInfo('smc__core__craft_system').require ----@type Events.ImmersiveCraftEvents -local ImmersiveCraftEvents = Smc.requireEvents('ImmersiveCraftEvents') +local ImmersiveCraftEvents = Smc.requireEvents('ImmersiveCraftEvents') --[[@as Events.ImmersiveCraftEvents]] ---@type CraftSystem.BaseCraft local BaseCraft = require('CraftSystem.BaseCraft') @@ -43,6 +42,8 @@ function ImmersiveCraft:new(name, def) local StageClass = stageTypes[stageDef.type] stageDef.craftName = name + + ---@cast stageDef CraftSystem.ImmersiveCraftStage.TappingStageDef local stage = StageClass:new(stageDef) stagesByName[stageDef.name] = stage @@ -60,8 +61,7 @@ function ImmersiveCraft:new(name, def) if nextStageName == nil then instance:endCraft(pos, player) else - ---@type ImmersiveWorkStation? - local workStation = Smc.getNodeSuperclassByPos(pos) + local workStation = Smc.getNodeSuperclassByPos(pos) --[[@as ImmersiveWorkStation?]] assert(workStation ~= nil) local nextStage = instance.stagesByName[nextStageName] @@ -83,8 +83,7 @@ end ---@param amount integer ---@return boolean function ImmersiveCraft:startCraft(pos, player, amount) - ---@type ImmersiveWorkStation? - local workStation = Smc.getNodeSuperclassByPos(pos) + local workStation = Smc.getNodeSuperclassByPos(pos) --[[@as ImmersiveWorkStation?]] assert(workStation ~= nil) local meta = workStation:getMeta(pos) @@ -118,8 +117,7 @@ end ---@param pos MapVector ---@param player Player function ImmersiveCraft:endCraft(pos, player) - ---@type ImmersiveWorkStation? - local workStation = Smc.getNodeSuperclassByPos(pos) + local workStation = Smc.getNodeSuperclassByPos(pos) --[[@as ImmersiveWorkStation?]] assert(workStation ~= nil) local meta = workStation:getMeta(pos) @@ -147,8 +145,7 @@ end ---Stop the crafting process and free up the workbench. ---@param pos MapVector function ImmersiveCraft:abortCraft(pos) - ---@type ImmersiveWorkStation? - local workStation = Smc.getNodeSuperclassByPos(pos) + local workStation = Smc.getNodeSuperclassByPos(pos) --[[@as ImmersiveWorkStation?]] assert(workStation ~= nil) local meta = workStation:getMeta(pos) @@ -171,7 +168,9 @@ function ImmersiveCraft:abortCraft(pos) end ---Returns a human-readable description of the crafting process. ----@return string +---@param recipeIndex integer? +---@param mainList ItemStack[]? +---@return string function ImmersiveCraft:recipeToString(recipeIndex, mainList) local recipeDesc = '' ---@type string? diff --git a/mods/CORE/CraftSystem/src/CraftSystem/ImmersiveCraftHandler.lua b/mods/CORE/CraftSystem/src/CraftSystem/ImmersiveCraftHandler.lua index ea4ca58..a0af300 100644 --- a/mods/CORE/CraftSystem/src/CraftSystem/ImmersiveCraftHandler.lua +++ b/mods/CORE/CraftSystem/src/CraftSystem/ImmersiveCraftHandler.lua @@ -53,6 +53,8 @@ core.register_on_mods_loaded(function() tableSort(crafts, function(a, b) if a.output < b.output then return true + else + return false end end) @@ -69,6 +71,8 @@ core.register_on_mods_loaded(function() if outputA < outputB then return true + else + return false end end) end) diff --git a/mods/CORE/CraftSystem/src/CraftSystem/ImmersiveCraftNode/tappingNode.lua b/mods/CORE/CraftSystem/src/CraftSystem/ImmersiveCraftNode/tappingNode.lua index 7384b2f..f2393ad 100644 --- a/mods/CORE/CraftSystem/src/CraftSystem/ImmersiveCraftNode/tappingNode.lua +++ b/mods/CORE/CraftSystem/src/CraftSystem/ImmersiveCraftNode/tappingNode.lua @@ -1,7 +1,6 @@ local require = Mod.getInfo('smc__core__craft_system').require ----@type Events.ImmersiveCraftEvents -local ImmersiveCraftEvents = Smc.requireEvents('ImmersiveCraftEvents') +local ImmersiveCraftEvents = Smc.requireEvents('ImmersiveCraftEvents') --[[@as Events.ImmersiveCraftEvents]] ---@type CraftSystem.ImmersiveCraftNode local ImmersiveCraftNode = require('CraftSystem.ImmersiveCraftNode') @@ -68,7 +67,7 @@ local tappingNode = ImmersiveCraftNode:new({ ---@param luaEntity CraftSystem.ImmersiveCraftNode.LuaTappingNode get_staticdata = function(luaEntity) - ---@type CraftSystem.ImmersiveCraftStage.TappingNode.InitParams? + ---@type CraftSystem.ImmersiveCraftStage.TappingNode.InitParams local params = { targetItem = luaEntity._item_name, craftName = luaEntity._craft_name, diff --git a/mods/CORE/CraftSystem/src/CraftSystem/ImmersiveCraftStage/TappingStage.lua b/mods/CORE/CraftSystem/src/CraftSystem/ImmersiveCraftStage/TappingStage.lua index 3e25e99..fe0c280 100644 --- a/mods/CORE/CraftSystem/src/CraftSystem/ImmersiveCraftStage/TappingStage.lua +++ b/mods/CORE/CraftSystem/src/CraftSystem/ImmersiveCraftStage/TappingStage.lua @@ -5,8 +5,7 @@ local coreItemDrop = core.item_drop local require = Mod.getInfo('smc__core__craft_system').require ----@type Events.ImmersiveCraftEvents -local ImmersiveCraftEvents = Smc.requireEvents('ImmersiveCraftEvents') +local ImmersiveCraftEvents = Smc.requireEvents('ImmersiveCraftEvents') --[[@as Events.ImmersiveCraftEvents]] ---@type CraftSystem.ImmersiveCraftStage local ImmersiveCraftStage = require('CraftSystem.ImmersiveCraftStage') @@ -41,8 +40,7 @@ local TappingStage = extend(ImmersiveCraftStage, {}) ---@param def CraftSystem.ImmersiveCraftStage.TappingStageDef function TappingStage:new(def) - ---@type CraftSystem.ImmersiveCraftStage.TappingStage - local instance = ImmersiveCraftStage:new(def) + local instance = ImmersiveCraftStage:new(def) --[[@as CraftSystem.ImmersiveCraftStage.TappingStage]] instance.targetItem = def.targetItem instance.clicksNeed = def.clicksNeed instance.toolGroup = def.toolGroup @@ -71,8 +69,7 @@ function TappingStage:new(def) entityGUID = obj:get_guid() } - ---@type ImmersiveWorkStation? - local workStation = Smc.getNodeSuperclassByPos(pos) + local workStation = Smc.getNodeSuperclassByPos(pos) --[[@as ImmersiveWorkStation?]] assert(workStation ~= nil) local meta = workStation:getMeta(pos) @@ -82,8 +79,7 @@ function TappingStage:new(def) -- Registering the crafting stage process handler. -- Called when a player clicks on a crafting node (entity). instance.processHandler = function(tappingStage, pos, player) - ---@type ImmersiveWorkStation? - local workStation = Smc.getNodeSuperclassByPos(pos) + local workStation = Smc.getNodeSuperclassByPos(pos) --[[@as ImmersiveWorkStation?]] assert(workStation ~= nil) local meta = workStation:getMeta(pos) @@ -104,8 +100,7 @@ function TappingStage:new(def) -- Registering the crafting stage end handler. instance.endHandler = function(tappingStage, pos, player) - ---@type ImmersiveWorkStation? - local workStation = Smc.getNodeSuperclassByPos(pos) + local workStation = Smc.getNodeSuperclassByPos(pos) --[[@as ImmersiveWorkStation?]] assert(workStation ~= nil) local meta = workStation:getMeta(pos) @@ -113,7 +108,7 @@ function TappingStage:new(def) local stageData = core.deserialize(meta:get_string('stage_data')) assert(stageData ~= nil) - local entity = Smc.getObjectByGUID(stageData.entityGUID) + local entity = Smc.getObjectByGUID(stageData.entityGUID) --[[@as Entity?]] assert(entity ~= nil, 'The entity for immersive crafting is nil.') entity:remove() @@ -123,9 +118,9 @@ function TappingStage:new(def) -- Registering the aborting the crafting process handler. ---@param tappingStage CraftSystem.ImmersiveCraftStage.TappingStage + ---@param pos MapVector instance.abortHandler = function(tappingStage, pos) - ---@type ImmersiveWorkStation? - local workStation = Smc.getNodeSuperclassByPos(pos) + local workStation = Smc.getNodeSuperclassByPos(pos) --[[@as ImmersiveWorkStation?]] assert(workStation ~= nil) local meta = workStation:getMeta(pos) @@ -140,7 +135,8 @@ function TappingStage:new(def) local stageData = stageData assert(stageData ~= nil, 'Immersive stage data is empty.') - local entity = Smc.getObjectByGUID(stageData.entityGUID) + ---@type Entity? + local entity = Smc.getObjectByGUID(stageData.entityGUID) --[[@as Entity?]] assert(entity ~= nil, 'The entity for immersive crafting is nil.') entity:remove() diff --git a/mods/CORE/CraftSystem/src/CraftSystem/PrimitiveCraftHandler.lua b/mods/CORE/CraftSystem/src/CraftSystem/PrimitiveCraftHandler.lua index f366506..e614b24 100644 --- a/mods/CORE/CraftSystem/src/CraftSystem/PrimitiveCraftHandler.lua +++ b/mods/CORE/CraftSystem/src/CraftSystem/PrimitiveCraftHandler.lua @@ -69,6 +69,8 @@ core.register_on_mods_loaded(function() tableSort(crafts, function(a, b) if a.output < b.output then return true + else + return false end end) @@ -85,6 +87,8 @@ core.register_on_mods_loaded(function() if outputA < outputB then return true + else + return false end end) end) diff --git a/mods/CORE/Creature/src/Creature.lua b/mods/CORE/Creature/src/Creature.lua index 1b2cd5a..e0176fa 100644 --- a/mods/CORE/Creature/src/Creature.lua +++ b/mods/CORE/Creature/src/Creature.lua @@ -24,8 +24,7 @@ local function entityDefToLuantiDef(entityDef) local s = entityDef.settings local c = entityDef.callbacks or {} - ---@type EntityDefinition - local luantiDef = tableMerge(s, c) + local luantiDef = tableMerge(s, c) --[[@as EntityDefinition]] return luantiDef end @@ -45,6 +44,7 @@ function Creature:new(entityDef) local s = entityDef.settings local c = entityDef.callbacks + assert(c ~= nil) -- Add the short mod name prefix to the entity name. if s._add_mod_name then @@ -66,8 +66,7 @@ function Creature:new(entityDef) initCustomFields.name = nil initCustomFields.object = nil - ---@type LuaEntity - self = tableMerge(self, initCustomFields) + self = tableMerge(self, initCustomFields) --[[@as LuaEntity]] -- If an initialization callback was specified for the entity, then we call it. if c.on_activate ~= nil then diff --git a/mods/CORE/ImmersiveWorkStation/src/ImmersiveWorkStation.lua b/mods/CORE/ImmersiveWorkStation/src/ImmersiveWorkStation.lua index e5d0704..1734267 100644 --- a/mods/CORE/ImmersiveWorkStation/src/ImmersiveWorkStation.lua +++ b/mods/CORE/ImmersiveWorkStation/src/ImmersiveWorkStation.lua @@ -102,7 +102,7 @@ end ---@param pos MapVector ---@return ImmersiveWorkStation.MetaData function ImmersiveWorkStation:getMeta(pos) - return coreGetMeta(pos) + return coreGetMeta(pos) --[[@as ImmersiveWorkStation.MetaData]] end function ImmersiveWorkStation:showForm(pos, player) diff --git a/mods/CORE/Item/src/Item.lua b/mods/CORE/Item/src/Item.lua index 5331229..11b5b5a 100644 --- a/mods/CORE/Item/src/Item.lua +++ b/mods/CORE/Item/src/Item.lua @@ -40,7 +40,7 @@ local RARITY_INDEX = { ---@class Item : Class ---@field itemDef Item.ItemDefinition ---@field luantiDef ItemDefinition ----@field getType fun():string +---@field getType fun(self:Item):string ---@field defaultDef Item.ItemDefinition local Item = Class:extend({ defaultDef = { diff --git a/mods/CORE/ItemFactory/src/ItemFactory.lua b/mods/CORE/ItemFactory/src/ItemFactory.lua index 57f082a..63ec062 100644 --- a/mods/CORE/ItemFactory/src/ItemFactory.lua +++ b/mods/CORE/ItemFactory/src/ItemFactory.lua @@ -26,7 +26,7 @@ end ---@param itemDefs Item.ItemDefinition[]|Node.NodeDefinition[] List of nodes with parameters unique to them. function ItemFactory:registerItems(itemDefs) - ---@param nodeDef Item.ItemDefinition | Node.NodeDefinition + ---@param itemDef Item.ItemDefinition | Node.NodeDefinition for _, itemDef in ipairs(itemDefs) do itemDef = defMerge(itemDef, self.defaultDef, true) @@ -41,7 +41,7 @@ local defMerge = function(...) return table.merge(...) end ----@param shortNodeDefs [string, (string[]|TileDefinition[])?][] Format list {{name, tiles}, {name, tiles}, ...} +---@param shortNodeDefs [string, (string[]|TileDefinition[]|nil)][] Format list {{name, tiles}, {name, tiles}, ...} function ItemFactory:registerNodesByShortDef(shortNodeDefs) for _, shortNodeDef in ipairs(shortNodeDefs) do ---@type Node.NodeDefinition diff --git a/mods/CORE/MapGen/src/MapGen.lua b/mods/CORE/MapGen/src/MapGen.lua index f7c401f..8cd1972 100644 --- a/mods/CORE/MapGen/src/MapGen.lua +++ b/mods/CORE/MapGen/src/MapGen.lua @@ -181,7 +181,7 @@ end function MapGen:isCavern(layer, x, y, z) for _, cavern in ipairs(layer.cavernsList) do if cavern.isRegional then - local inRegion, distance = self:pointInRegion2D(layer, cavern.name, v(x, y, z)) + local inRegion, distance = self:pointInRegion2D(layer, cavern.name, v(x, y, z) --[[@as MapVector]]) if inRegion and distance ~= nil then if cavern:isCavern(x, y, z, distance) then @@ -394,7 +394,7 @@ function MapGen:findTriangle(layer, x, z, triangle) return nil end - isFound, triangle = self:isPointInTriangle(triangle, v(x, 0, z)) + isFound, triangle = self:isPointInTriangle(triangle, v(x, 0, z) --[[@as MapVector]]) end return triangle @@ -567,7 +567,6 @@ function MapGen:initCavernsNoise() ---@param layer MapGen.Layer for _, layer in ipairs(self.layersList) do - ---@param peak MapGen.Peak for _, cavern in ipairs(layer.cavernsList) do cavern:initNoise() end @@ -819,7 +818,7 @@ function MapGen:getFactors(layer, x, y, z) end -- TODO: это сильно тормозит обычные чанки, но ускоряет те, что находятся за границей - if not self:pointInRegion2D(layer, 'triangles_boundary', v(x, y, z)) then + if not self:pointInRegion2D(layer, 'triangles_boundary', v(x, y, z) --[[@as MapVector]]) then return end @@ -833,7 +832,7 @@ function MapGen:getFactors(layer, x, y, z) ---@param triangle MapGen.Triangle for _, triangle in ipairs(triangles) do - if self:isPointInTriangle(triangle, v(x, 0, z)) then + if self:isPointInTriangle(triangle, v(x, 0, z) --[[@as MapVector]]) then local height = calcNoise2dValue('landscape', layer, triangle, x, y, z) local temp = calcNoise2dValue('temp', layer, triangle, x, y, z) local humidity = calcNoise2dValue('humidity', layer, triangle, x, y, z) diff --git a/mods/CORE/MapGen/src/MapGen/Cavern.lua b/mods/CORE/MapGen/src/MapGen/Cavern.lua index 094b92c..df2563f 100644 --- a/mods/CORE/MapGen/src/MapGen/Cavern.lua +++ b/mods/CORE/MapGen/src/MapGen/Cavern.lua @@ -19,8 +19,8 @@ local getInstance = Class.getInstance ---@field step integer? ---@field warpStrength number --- ----@field getNoise fun():MapGen.Cavern.ValueNoise ----@field initNoise fun() +---@field getNoise fun(self:MapGen.Cavern):MapGen.Cavern.ValueNoise +---@field initNoise fun(self:MapGen.Cavern) local Cavern = {} ---@alias MapGen.Cavern.NoiseParams {baseNoise:NoiseParams, xNoise?:NoiseParams, yNoise?:NoiseParams, zNoise?:NoiseParams} diff --git a/mods/CORE/MapGen/src/MapGen/Peak.lua b/mods/CORE/MapGen/src/MapGen/Peak.lua index 0332370..5a7a6f9 100644 --- a/mods/CORE/MapGen/src/MapGen/Peak.lua +++ b/mods/CORE/MapGen/src/MapGen/Peak.lua @@ -29,6 +29,7 @@ function Peak:new(def) if def.groups == nil then _groups = {} else + ---@type table _groups = def.groups end diff --git a/mods/CORE/MapGen/src/MapGen/Tree.lua b/mods/CORE/MapGen/src/MapGen/Tree.lua index cb6afa7..073ef60 100644 --- a/mods/CORE/MapGen/src/MapGen/Tree.lua +++ b/mods/CORE/MapGen/src/MapGen/Tree.lua @@ -107,10 +107,9 @@ local function isAreaGenerated(pos1, pos2) return true end ----@param pos MapPosition +---@param pos MapVector function Tree:place(pos) - ---@type MapVector, MapVector - local pos1, pos2 = pos - v(16, 0, 16), pos + v(16, 80, 16) + local pos1, pos2 = pos - v(16, 0, 16), pos + v(16, 80, 16) --[[@as MapVector]] if isAreaGenerated(pos1, pos2) then corePlaceSchematic(pos, self.path, getRotation(pos), nil, nil, 'place_center_x, place_center_z') @@ -119,8 +118,8 @@ function Tree:place(pos) end end ----@param voxelManip VoxelManip ----@param pos MapPosition +---@param voxelManip VoxelManip +---@param pos MapVector function Tree:placeOnVM(voxelManip, pos) local result = corePlaceSchematicOnVM(voxelManip, pos, self.path, getRotation(pos), nil, nil, 'place_center_x, place_center_z') diff --git a/mods/CORE/MapGen/src/MapGen/Triangle.lua b/mods/CORE/MapGen/src/MapGen/Triangle.lua index d55ca32..201cfcf 100644 --- a/mods/CORE/MapGen/src/MapGen/Triangle.lua +++ b/mods/CORE/MapGen/src/MapGen/Triangle.lua @@ -181,7 +181,7 @@ function Triangle:getHeight(p1, p2, p3) -- When * the dot product. local t = w:dot(v) / v:dot(v) - local posP = pos2 + v * t + local posP = pos2 + v * t --[[@as IntegerVector]] return Edge:new(p1, FakePeak:new(posP)) end @@ -211,7 +211,7 @@ function Triangle:getHeight2D(p1, p2, p3) -- When * the dot product. local t = w:dot(v) / v:dot(v) - local posP = pos2 + v * t + local posP = pos2 + v * t --[[@as IntegerVector]] return Edge:new(p1, FakePeak:new(posP)) end diff --git a/mods/CORE/MapGen/src/MapGen/ff2luat.lua b/mods/CORE/MapGen/src/MapGen/ff2luat.lua deleted file mode 100644 index 4e63b13..0000000 --- a/mods/CORE/MapGen/src/MapGen/ff2luat.lua +++ /dev/null @@ -1,101 +0,0 @@ --- A method for converting an image with colored dots (pixels) into a Lua table grouped by color. --- Author: @ssdaniel24 (github) - ----Table with color as key and value is table with coordinates of dots. Note: coords begin from 1,1 (not 0,0). ----Example of table: ----```lua ----{ ---- 'size': { h=256, w=256 }, ---- '#fff': { {x=1,y=1}, {x=2,y=2}, ... }, ---- '#ff0': { {x=3,y=3}, {x=4,y=4}, ... }, ---- ... ----} ----``` ----@alias ColoredDotsTable table - ----@param uintb string unsigned int bytes ----@return number -local function uintb2num(uintb) - local num = 0 - local len = string.len(uintb) - - for i = 1,len do - num = num*256 + string.byte(uintb, i) - end - - return num -end - ----Converts (scaling) 16-bit unsigned integer to 8-bit unsigned integer. ----Why? Because hex codes of colors are 8-bit: #ffffff -> ff = 256 (8 bit). Not 65536 (16 bit). ----@param num number 16-bit number ----@return number 8-bit number -local function uint16ToUint8(num) - return math.floor(num / 256) -end - ----Converts given farbfeld image to ColoredDotsTable. ----Farbfeld format: ----``` ----╔════════╤═════════════════════════════════════════════════════════╗ ----║ Bytes │ Description ║ ----╠════════╪═════════════════════════════════════════════════════════╣ ----║ 8 │ 'farbfeld' magic value ║ ----╟────────┼─────────────────────────────────────────────────────────╢ ----║ 4 │ 32-Bit BE unsigned integer (width) ║ ----╟────────┼─────────────────────────────────────────────────────────╢ ----║ 4 │ 32-Bit BE unsigned integer (height) ║ ----╟────────┼─────────────────────────────────────────────────────────╢ ----║ [2222] │ 4x16-Bit BE unsigned integers [RGBA] / pixel, row-major ║ ----╚════════╧═════════════════════════════════════════════════════════╝ ----``` ----[tools/farbfeld | suckless.org software that sucks less](https://tools.suckless.org/farbfeld/) ----@param filepath string image in farbfeld format ----@param backgroundColor string? ColorString, will be ignored while processing image. Default: `#000000FF` ----@return ColoredDotsTable -local function ff2luat(filepath, backgroundColor) - local file = io.open(filepath, 'rb') - if not file then error('Can\'t open farbfeld image: ' .. dump(filepath)) end - local ff = file:read('*a') -- binary! - file:close() - -- TODO: make it decompressing gzip format -> https://en.wikipedia.org/wiki/Gzip - -- I should skip 10 bytes in a beginning, read how many extra fields after it, skip them too, and skip last 8 bytes - -- (read wiki for information). - -- if filepath:sub(-3) == '.gz' then ff = core.decompress(ff, 'deflate') end - if not ff:sub(1,8) == 'farbfeld' then error('Not farbfeld image: ' .. dump(filepath)) end - - if not backgroundColor then backgroundColor = '#000000FF' end - --HACK: normalizing colorstring for future string comparison ('#000' -> '#000000FF') - backgroundColor = Smc.fixColorString(backgroundColor) - - ---@type ColoredDotsTable - local dots = { size = { w = uintb2num(ff:sub(9,12)), h = uintb2num(ff:sub(13,16)) } } - - local cursor - for i = 1,dots.size.h do - for j = 1,dots.size.w do - cursor = 16 + ((i-1)*dots.size.w + j-1)*8 + 1 - local colorT = { - r = uint16ToUint8(uintb2num(ff:sub(cursor, cursor+1))), - g = uint16ToUint8(uintb2num(ff:sub(cursor+2,cursor+3))), - b = uint16ToUint8(uintb2num(ff:sub(cursor+4,cursor+5))), - a = uint16ToUint8(uintb2num(ff:sub(cursor+6,cursor+7))) - } - - ---@type string @ColorString - local color = core.colorspec_to_colorstring(colorT) or '' - - if color ~= backgroundColor then - if not dots[color] then - dots[color] = {} - end - - table.insert(dots[color], { x=j, y=i }) - end - end - end - - return dots -end - -return ff2luat diff --git a/mods/CORE/Node/src/Node.lua b/mods/CORE/Node/src/Node.lua index c817fa9..88a2624 100644 --- a/mods/CORE/Node/src/Node.lua +++ b/mods/CORE/Node/src/Node.lua @@ -88,8 +88,8 @@ function Node:new(nodeDef) registerStair(nodeDef) end - ---@type Node - local instance = Item:new(nodeDef) + local instance = Item:new(nodeDef) --[[@as Node]] + return instance end diff --git a/mods/CORE/Node/src/Node/Callbacks.lua b/mods/CORE/Node/src/Node/Callbacks.lua index d200a46..d430fcb 100644 --- a/mods/CORE/Node/src/Node/Callbacks.lua +++ b/mods/CORE/Node/src/Node/Callbacks.lua @@ -166,25 +166,25 @@ Callbacks.allow_metadata_inventory_take = nil ---Called after the actual action has happened, according to what was allowed. --- ---No return value. ----@type (fun(pos:MapVector, from_list:string, from_index:number, to_list:string, to_index:number, count:number, player:Player): void)? +---@type (fun(pos:MapVector, from_list:string, from_index:number, to_list:string, to_index:number, count:number, player:Player): any)? Callbacks.on_metadata_inventory_move = nil ---Called after the actual action has happened, according to what was allowed. --- ---No return value. ----@type (fun(pos:MapVector, listname:string, index:number, stack:ItemStack, player:Player): void)? +---@type (fun(pos:MapVector, listname:string, index:number, stack:ItemStack, player:Player): any)? Callbacks.on_metadata_inventory_put = nil ---Called after the actual action has happened, according to what was allowed. --- ---No return value. ----@type (fun(pos:MapVector, listname:string, index:number, stack:ItemStack, player:Player): void)? +---@type (fun(pos:MapVector, listname:string, index:number, stack:ItemStack, player:Player): any)? Callbacks.on_metadata_inventory_take = nil ---If defined, called when an explosion touches the node, instead of ---removing the node. ---* `intensity`: 1.0 = mid range of regular TNT. ----@type (fun(pos:MapVector, intensity:number): void)? +---@type (fun(pos:MapVector, intensity:number): any)? Callbacks.on_blast = nil return Callbacks diff --git a/mods/CORE/ProcessingContainerStation/src/ProcessingContainerStation.lua b/mods/CORE/ProcessingContainerStation/src/ProcessingContainerStation.lua index 5a4e6a9..4be6e0f 100644 --- a/mods/CORE/ProcessingContainerStation/src/ProcessingContainerStation.lua +++ b/mods/CORE/ProcessingContainerStation/src/ProcessingContainerStation.lua @@ -76,7 +76,7 @@ function ProcessingContainerStation:new(def, nodesDef) callbacks.on_rightclick = function(pos, node, clicker, itemstack, pointed_thing) oldCallback(pos, node, clicker, itemstack, pointed_thing) - instance:showForm(pos, clicker) + instance:showForm(pos, clicker --[[@as Player]]) end oldCallback = callbacks.on_metadata_inventory_move or function(...) end @@ -249,8 +249,7 @@ function ProcessingContainerStation:pushFuelStation( meta, pos) return end - ---@type ProcessingFuelStation? - local fuelStation = Smc.getNodeSuperclassByPos(fuelPos) + local fuelStation = Smc.getNodeSuperclassByPos(fuelPos) --[[@as ProcessingFuelStation?]] assert(fuelStation ~= nil) if fuelStation.fuelGroup ~= self.fuelGroup then @@ -307,10 +306,8 @@ local tab = function(self, playerName, tabType) local pos = self:getContex(playerName, 'node_tab_pos') local inventoryLocation = ('nodemeta:%s,%s,%s'):format(pos.x, pos.y, pos.z) - ---@type ProcessingContainerStation.MetaData - local meta = core.get_meta(pos) - ---@type ProcessingFuelStation.MetaData - local fuelMeta = core.get_meta(pos - vector.new(0, 1, 0)) + local meta = core.get_meta(pos) --[[@as ProcessingContainerStation.MetaData]] + local fuelMeta = core.get_meta(pos - vector.new(0, 1, 0)) --[[@as ProcessingFuelStation.MetaData]] form :image(0, 0, 11, 9, 'player_inventory_tab_background.png') diff --git a/mods/CORE/ProcessingFuelStation/src/ProcessingFuelStation.lua b/mods/CORE/ProcessingFuelStation/src/ProcessingFuelStation.lua index fcd2338..2057e69 100644 --- a/mods/CORE/ProcessingFuelStation/src/ProcessingFuelStation.lua +++ b/mods/CORE/ProcessingFuelStation/src/ProcessingFuelStation.lua @@ -96,7 +96,7 @@ function ProcessingFuelStation:new(def, nodesDef) callbacks.on_rightclick = function(pos, node, clicker, itemstack, pointed_thing) oldCallback(pos, node, clicker, itemstack, pointed_thing) - instance:showForm(pos, clicker) + instance:showForm(pos, clicker --[[@as Player]]) end oldCallback = callbacks.on_metadata_inventory_move or function(...) end @@ -312,8 +312,7 @@ function ProcessingFuelStation:pushContainerStation(meta, pos) return end - ---@type ProcessingContainerStation? - local containerStation = Smc.getNodeSuperclassByPos(containerPos) + local containerStation = Smc.getNodeSuperclassByPos(containerPos) --[[@as ProcessingContainerStation?]] assert(containerStation ~= nil) if containerStation.fuelGroup ~= self.fuelGroup then @@ -326,7 +325,6 @@ end ---@param pos MapVector ---@param elapsed number ---@param node NodeTable ----@param elapsed number ---@return boolean? function ProcessingFuelStation:onTimer(pos, elapsed, node, timeout) local meta = self:getMeta(pos) @@ -369,8 +367,7 @@ local tab = function(self, playerName, tabType) local pos = self:getContex(playerName, 'node_tab_pos') local inventoryLocation = ('nodemeta:%s,%s,%s'):format(pos.x, pos.y, pos.z) - ---@type ProcessingFuelStation.MetaData - local meta = core.get_meta(pos) + local meta = core.get_meta(pos) --[[@as ProcessingFuelStation.MetaData]] form :image(0, 0, 11, 9, 'player_inventory_tab_background.png') @@ -404,8 +401,7 @@ core.register_abm({ nodenames = {'processing_fuel_station:test_processing_node'}, ---@param pos MapVector action = function(pos, node, active_object_count, active_object_count_wider) - ---@type ProcessingFuelStation.MetaData - local meta = core.get_meta(pos) + local meta = core.get_meta(pos) --[[@as ProcessingFuelStation.MetaData]] if meta:get_float("remaining_fuel") > 0 then core.add_particlespawner({ amount = 10, diff --git a/mods/CORE/ProcessingStation/src/ProcessingStation.lua b/mods/CORE/ProcessingStation/src/ProcessingStation.lua index 62f4bff..655dc4d 100644 --- a/mods/CORE/ProcessingStation/src/ProcessingStation.lua +++ b/mods/CORE/ProcessingStation/src/ProcessingStation.lua @@ -62,7 +62,7 @@ function ProcessingStation:new(def, nodesDef) callbacks.on_rightclick = function(pos, node, clicker, itemstack, pointed_thing) oldCallback(pos, node, clicker, itemstack, pointed_thing) - instance:showForm(pos, clicker) + instance:showForm(pos, clicker --[[@as Player]]) end oldCallback = callbacks.on_metadata_inventory_move or function(...) end @@ -170,8 +170,7 @@ local tab = function(self, playerName, tabType) local pos = self:getContex(playerName, 'node_tab_pos') local inventoryLocation = ('nodemeta:%s,%s,%s'):format(pos.x, pos.y, pos.z) - ---@type ProcessingStation.MetaData - local meta = core.get_meta(pos) + local meta = core.get_meta(pos) --[[@as ProcessingStation.MetaData]] form :image(0, 0, 11, 9, 'player_inventory_tab_background.png') diff --git a/mods/CORE/Tool/src/Tool.lua b/mods/CORE/Tool/src/Tool.lua index 5f8250b..c2ae032 100644 --- a/mods/CORE/Tool/src/Tool.lua +++ b/mods/CORE/Tool/src/Tool.lua @@ -14,8 +14,8 @@ function Tool:new(ToolDef) ToolDef.settings._type = 'tool' - ---@type Tool - local instance = Item:new(ToolDef) + local instance = Item:new(ToolDef) --[[@as Tool]] + return instance end diff --git a/mods/ENVIRONMENT/mapGenerator/src/mapGenerator.lua b/mods/ENVIRONMENT/mapGenerator/src/mapGenerator.lua index 247b3e9..ae213c6 100644 --- a/mods/ENVIRONMENT/mapGenerator/src/mapGenerator.lua +++ b/mods/ENVIRONMENT/mapGenerator/src/mapGenerator.lua @@ -752,8 +752,7 @@ mapGenerator:registerBiome('midgard', 'green_meadow', { if value > 8 then if x % 10 == 0 and z % 10 == 0 then - ---@type MapVector - local pos = v(x, y+1, z) + local pos = v(x, y+1, z) --[[@as MapVector]] mapGenerator:getTree('test_tree'):placeOnVM(voxelManip, pos) end end diff --git a/mods/GAME/adminCommands/init.lua b/mods/GAME/adminCommands/init.lua index dd01ce3..eb105d6 100644 --- a/mods/GAME/adminCommands/init.lua +++ b/mods/GAME/adminCommands/init.lua @@ -89,7 +89,7 @@ core.register_chatcommand('get_missing_locale', { privs = {server = true}, description = '{short_mod_name:string?, lang_codes:string[]?}', func = function(name, paramsStr) - local params = core.deserialize('return '..paramsStr or '{}') + local params = core.deserialize(('return '..paramsStr) or '{}') if params == nil then return false diff --git a/mods/SYSTEM/Events/src/Events.lua b/mods/SYSTEM/Events/src/Events.lua index 412364a..9de8e6d 100644 --- a/mods/SYSTEM/Events/src/Events.lua +++ b/mods/SYSTEM/Events/src/Events.lua @@ -1,8 +1,8 @@ ---@alias Events.Callback fun(...) ---@alias Events.Type ---- 'ControlsEvents'| ---- 'ImmersiveCraftEvents' +---|'ControlsEvents' +---|'ImmersiveCraftEvents' ---@class Events : Class ---@field registeredEvents table diff --git a/mods/SYSTEM/HelperLib/src/Lib/nodeSuperClasses.lua b/mods/SYSTEM/HelperLib/src/Lib/nodeSuperClasses.lua index 95bbe8b..e5e508b 100644 --- a/mods/SYSTEM/HelperLib/src/Lib/nodeSuperClasses.lua +++ b/mods/SYSTEM/HelperLib/src/Lib/nodeSuperClasses.lua @@ -2,7 +2,7 @@ ---Each instance of such a class registers one or more nodes and implements their logic. --- ---**Note**: An instance is static for all nodes it registers. ----@interface NodeSuperClass +---@class NodeSuperClass ---@type table local nodeSuperClasses = {} diff --git a/mods/SYSTEM/HelperLib/src/Lib/registeredItems.lua b/mods/SYSTEM/HelperLib/src/Lib/registeredItems.lua index bdd9932..dd262e9 100644 --- a/mods/SYSTEM/HelperLib/src/Lib/registeredItems.lua +++ b/mods/SYSTEM/HelperLib/src/Lib/registeredItems.lua @@ -40,7 +40,7 @@ end ---@param itemName ItemStack|ItemStackString ---@return Item.ItemDefinition|Node.NodeDefinition function Smc.getItemDefinition(itemName) - if type(itemName) == 'table' or type(itemName) == 'userdata' then + if type(itemName) ~= 'string' then itemName = itemName:get_name() end diff --git a/mods/SYSTEM/Math/init.lua b/mods/SYSTEM/Math/init.lua index e02742a..81728ad 100644 --- a/mods/SYSTEM/Math/init.lua +++ b/mods/SYSTEM/Math/init.lua @@ -1,11 +1,9 @@ -local math = math - ---Limiting the value by minimum and maximum value. ---@param value number The value to be limited. ---@param min number Minimum limit. ---@param max number Maximum limit. ---@return number -math.clamp = function(value, min, max) +function math.clamp(value, min, max) return math.min(math.max(value, min), max) end diff --git a/mods/SYSTEM/Table/init.lua b/mods/SYSTEM/Table/init.lua index 2449ca7..3ebe1ea 100644 --- a/mods/SYSTEM/Table/init.lua +++ b/mods/SYSTEM/Table/init.lua @@ -58,7 +58,6 @@ end function table.contains(t, value) ensureArgType(t, 'table', 1, 'table.contains') - ---@diagnostic disable-next-line: param-type-not-match return tableKeyOf(t, value) ~= nil end @@ -415,7 +414,7 @@ end ---@generic value any ---@param list value[] ---@param value value ----@param value[] +---@return value[] function table.remove_value(list, value) local index = table.indexof(list, value) while index ~= -1 do diff --git a/mods/UI/AdminListUI/src/AdminListUI.lua b/mods/UI/AdminListUI/src/AdminListUI.lua index 7ed5288..e3b2c88 100644 --- a/mods/UI/AdminListUI/src/AdminListUI.lua +++ b/mods/UI/AdminListUI/src/AdminListUI.lua @@ -48,16 +48,16 @@ local function getFormSpecString(self, playerName, isSelect) if isSelect then ---@type ItemStackString local item = self:getContex(playerName, 'select_item') - local itemDef = core.registered_items[item] + local itemSettings = Smc.getItemDefinition(item).settings listForm :itemImage(11, 0.5, 2, 2, item) :areaLabel(11, 4.5, 4, 1, 'Add to inventory:') :button(11, 5, 3, 1, 'admin_commands:list_add_item', '1') - :button(14, 5,3, 1, 'admin_commands:list_add_item', ''..tostring(itemDef.stack_max)) + :button(14, 5,3, 1, 'admin_commands:list_add_item', ''..tostring(itemSettings.stack_max)) :areaLabel(14.5, 0.5, 6, 4, item..'\n\n'.. - (itemDef._title or itemDef.description)..'\n'.. - (itemDef._description or '')) + (itemSettings._title or itemSettings.description)..'\n'.. + (itemSettings._description or '')) end return listForm:toString() diff --git a/mods/UI/PlayerInventoryUI/src/PlayerInventoryUI.lua b/mods/UI/PlayerInventoryUI/src/PlayerInventoryUI.lua index be7cb2c..9aaed12 100644 --- a/mods/UI/PlayerInventoryUI/src/PlayerInventoryUI.lua +++ b/mods/UI/PlayerInventoryUI/src/PlayerInventoryUI.lua @@ -240,17 +240,17 @@ end ---Context keys for the `PlayerInventoryUI` class. ---@alias PlayerInventoryUI.ContexKey ---- 'compact_mode'| ---- 'node_tab_pos'| ---- 'node_tab'| +---|'compact_mode' +---|'node_tab_pos' +---|'node_tab' --- ---- 'left_tab_name'| ---- 'right_tab_name'| +---|'left_tab_name'| +---|'right_tab_name'| --- ---- 'left_craft_tab_craft_data'| ---- 'right_craft_tab_craft_data'| ---- 'left_node_tab_craft_data'| ---- 'right_node_tab_craft_data' +---|'left_craft_tab_craft_data'| +---|'right_craft_tab_craft_data'| +---|'left_node_tab_craft_data'| +---|'right_node_tab_craft_data' ---@class PlayerInventoryUI : BaseUI @@ -265,7 +265,6 @@ local PlayerInventoryUI = BaseUI:new('', getFormSpecString, false) ---@param tabName 'craft_tab'|'node_tab' ---@return PlayerInventoryUI.CraftTabData function PlayerInventoryUI:getTabCraftData(playerName, tabType, tabName) - ---@diagnostic disable-next-line: param-type-not-match ---@type PlayerInventoryUI.CraftTabData local craftTabData = self:getContex(playerName, tabType..'_'..tabName..'_craft_data') @@ -277,7 +276,6 @@ end ---@param tabName 'craft_tab'|'node_tab' ---@param data PlayerInventoryUI.CraftTabData function PlayerInventoryUI:setTabCraftData(playerName, tabType, tabName, data) - ---@diagnostic disable-next-line: param-type-not-match self:setContex(playerName, tabType..'_'..tabName..'_craft_data', data) end @@ -716,7 +714,7 @@ core.register_allow_player_inventory_action(function(player, action, inventory, -- Equipment items will automatically place themselves in their slots -- when you hold down the shift key. if inventoryInfo.to_list == 'listring_equip' then - return equipListring(player, inventory, inventoryInfo.from_list, inventoryInfo.from_index) + return equipListring(player --[[@as Player]], inventory, inventoryInfo.from_list, inventoryInfo.from_index) end -- Checking if a slot is an equipment slot. diff --git a/mods/UI/PlayerInventoryUI/src/PlayerInventoryUI/getBagTab.lua b/mods/UI/PlayerInventoryUI/src/PlayerInventoryUI/getBagTab.lua index 9d524bb..ee7490a 100644 --- a/mods/UI/PlayerInventoryUI/src/PlayerInventoryUI/getBagTab.lua +++ b/mods/UI/PlayerInventoryUI/src/PlayerInventoryUI/getBagTab.lua @@ -26,7 +26,7 @@ local function getBagTab(self, playerName, tabType) BagLists :image(0.5, 0, 9.875, (lines)*1.25+1, background) :itemImage(0.5625, 0.0625, 1, 1, bag:get_name()) - :label(1.7625, 0.5, bag:get_definition()._title or '') + :label(1.7625, 0.5, Smc.getItemDefinition(bag).settings._title or '') :list('current_player', 'inventory_back', 0.5625, 1.25, 8, 4) containerHeight = containerHeight + lines * 1.25 + 1 @@ -43,7 +43,7 @@ local function getBagTab(self, playerName, tabType) BagLists :image(0.5, containerHeight, 9.875, (lines)*1.25+1, background) :itemImage(0.5625, containerHeight + 0.0625, 1, 1, bag:get_name()) - :label(1.7625, containerHeight + 0.5, bag:get_definition()._title or '') + :label(1.7625, containerHeight + 0.5, Smc.getItemDefinition(bag).settings._title or '') :list('current_player', 'inventory_left_thigh', 0.5625, containerHeight + 1.25, 8, 4) containerHeight = containerHeight + lines * 1.25 + 1 @@ -60,7 +60,7 @@ local function getBagTab(self, playerName, tabType) BagLists :image(0.5, containerHeight, 9.875, (lines)*1.25+1, background) :itemImage(0.5625, containerHeight + 0.0625, 1, 1, bag:get_name()) - :label(1.7625, containerHeight + 0.5, bag:get_definition()._title or '') + :label(1.7625, containerHeight + 0.5, Smc.getItemDefinition(bag).settings._title or '') :list('current_player', 'inventory_right_thigh', 0.5625, containerHeight + 1.25, 8, 4) containerHeight = containerHeight + lines * 1.25 + 1 diff --git a/mods/UI/WorkStationUI/src/WorkStationUI.lua b/mods/UI/WorkStationUI/src/WorkStationUI.lua index f3663cc..f50e487 100644 --- a/mods/UI/WorkStationUI/src/WorkStationUI.lua +++ b/mods/UI/WorkStationUI/src/WorkStationUI.lua @@ -34,15 +34,15 @@ local function getFormSpecString(self, playerName, isSelect) if isSelect then local stage = craft.stagesByName[craft.startStageName] - local outputDef = core.registered_nodes[craft.output] + local outputSettings = Smc.getItemDefinition(craft.output).settings listForm :itemImage(9, 0.5, 2, 2, craft.output) :areaLabel(9, 6, 2, 1, 'Start crafting:') :button(9, 6.5, 3, 1, 'work_station:start_craft', 'x1') :button(12, 6.5,3, 1, 'work_station:start_craft', 'x10') :areaLabel(11.5, 0.5, 4, 4, - outputDef._title..'\n'.. - outputDef._description) + outputSettings._title..'\n'.. + outputSettings._description) :areaLabel(9, 2.5, 6, 4, 'Craft description:'..'\n'..craft:toString()) end diff --git a/util/ide-helper b/util/ide-helper index 2ea8f09..24531f8 160000 --- a/util/ide-helper +++ b/util/ide-helper @@ -1 +1 @@ -Subproject commit 2ea8f09092cb3d18162c0e68d4561cb465cb9556 +Subproject commit 24531f8af65ba8ec4564d2eee6584a01d6f00869