EmmyLua -> LuaLS
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
---@type Events.ControlsEvents
|
||||
local ControlsEvents = Smc.requireEvents('ControlsEvents')
|
||||
local ControlsEvents = Smc.requireEvents('ControlsEvents') --[[@as Events.ControlsEvents]]
|
||||
|
||||
---@class Controls
|
||||
local Controls = {}
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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?
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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 = {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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}
|
||||
|
||||
@@ -29,6 +29,7 @@ function Peak:new(def)
|
||||
if def.groups == nil then
|
||||
_groups = {}
|
||||
else
|
||||
---@type table<string, number>
|
||||
_groups = def.groups
|
||||
end
|
||||
|
||||
|
||||
@@ -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')
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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<string,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
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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')
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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')
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
---@alias Events.Callback fun(...)
|
||||
|
||||
---@alias Events.Type
|
||||
--- 'ControlsEvents'|
|
||||
--- 'ImmersiveCraftEvents'
|
||||
---|'ControlsEvents'
|
||||
---|'ImmersiveCraftEvents'
|
||||
|
||||
---@class Events : Class
|
||||
---@field registeredEvents table<string, Events.Callback[]>
|
||||
|
||||
@@ -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<string, NodeSuperClass>
|
||||
local nodeSuperClasses = {}
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user