EmmyLua -> LuaLS
This commit is contained in:
@@ -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
|
||||
Reference in New Issue
Block a user