MapGen: add annotations

This commit is contained in:
Van
2026-01-12 19:43:54 +03:00
parent d0eba35e8d
commit 57de1f4b42
2 changed files with 33 additions and 30 deletions

View File

@@ -132,7 +132,7 @@ end
---
---Note: layers must not overlap.
---@param name string The name that will be assigned to the layer. The name must be unique for each layer.
---@param def MapGen.LayerDef Layer description table, see details `MapGen.LayerDef`
---@param def MapGen.LayerDef Layer description table, see details `MapGen.LayerDef`.
function MapGen:registerLayer(name, def)
-- Layers with the same name cannot exist.
assert(self.layersByName[name] == nil, ('A layer named `%s` is already registered.'):format(name))
@@ -152,10 +152,11 @@ function MapGen:registerLayer(name, def)
end)
end
---@param layerName string
---@param category MapGen.Layer.Category TODO: описание
---@param color ColorString TODO: описание
---@param noiseParams NoiseParams
---Register the color and the noise parameters that correspond to it.
---@param layerName string The name of the layer for which the color will be registered.
---@param category MapGen.Layer.Category Category indicating what will be generated by noise.
---@param color ColorString Noise color. Must be unique.
---@param noiseParams NoiseParams Fractal noise parameters.
function MapGen:registerLayerNoiseColor(layerName, category, color, noiseParams)
---@type MapGen.Layer
local layer = self.layersByName[layerName]
@@ -168,8 +169,8 @@ end
---Mark the world area between two heights as a `MapGen.StaticLayer`.
---
---Note: layers must not overlap.
---@param name string The name that will be assigned to the static layer. The name must be unique for each layer.
---@param def MapGen.StaticLayerDef Static layer description table, see details `MapGen.StaticLayerDef`
---@param name string The name that will be assigned to the static layer. The name must be unique for each layer.
---@param def MapGen.StaticLayerDef Static layer description table, see details `MapGen.StaticLayerDef`.
function MapGen:registerStaticLayer(name, def)
-- Static layer with the same name cannot exist.
assert(self.staticsByName[name] == nil, ('A static layer named `%s` is already registered.'):format(name))
@@ -189,12 +190,12 @@ function MapGen:registerStaticLayer(name, def)
end)
end
---Mark a world point as `MapGen.Peak` and assign it a specific noise that will affect the generation.
---Mark a world point as `MapGen.Peak` and assign it a specific color that will affect the generation.
---
---Note: The peaks shouldn't overlap. This won't cause any errors, but it might ruin the generation.
---@param layerName string The name of the layer in which the new peak will be included.
---@param category MapGen.Layer.Category TODO: описание
---@param def MapGen.PeakDef
---@param layerName string The name of the layer in which the new peak will be included.
---@param category MapGen.Layer.Category Category indicating what will be generated by peak.
---@param def MapGen.PeakDef Peak description table, see details `MapGen.PeakDef`.
function MapGen:registerPeak(layerName, category, def)
---@type MapGen.Layer
local layer = self.layersByName[layerName]
@@ -209,13 +210,13 @@ function MapGen:registerPeak(layerName, category, def)
layer:addPeak(category, peak)
end
---Mark a world point as `MapGen.Peak` and assign it a specific noise that will affect the generation.
---Mark a world point as `MapGen.Peak` and assign it a specific color that will affect the generation.
---The Y coordinate will be forced to zero, and the `is2d` group will be added to the groups field.
---
---Note: The peaks shouldn't overlap. This won't cause any errors, but it might ruin the generation.
---@param layerName string The name of the layer in which the new peak will be included.
---@param category MapGen.Layer.Category TODO: описание
---@param def MapGen.PeakDef
---@param layerName string The name of the layer in which the new peak will be included.
---@param category MapGen.Layer.Category Category indicating what will be generated by peak.
---@param def MapGen.PeakDef Peak description table, see details `MapGen.PeakDef`.
function MapGen:register2DPeak(layerName, category, def)
def = table.copy_with_metatables(def)
@@ -234,22 +235,22 @@ end
---The Y coordinate will be forced to zero, and the `is2d` group will be added to the groups field.
---
---Note: The peaks shouldn't overlap. This won't cause any errors, but it might ruin the generation.
---@param layerName string The name of the layer in which the new peaks will be included.
---@param category MapGen.Layer.Category TODO: описание
---@param defs MapGen.PeakDef[]
---@param layerName string The name of the layer in which the new peaks will be included.
---@param category MapGen.Layer.Category Category indicating what will be generated by peaks.
---@param defs MapGen.PeakDef[] Peaks description table, see details `MapGen.PeakDef`.
function MapGen:register2DPeaks(layerName,category, defs)
for _, def in ipairs(defs) do
self:register2DPeak(layerName, category, def)
end
end
---TODO: описание
---Extract the `MapGen.Peak` from the image and assign them all a specific color that will affect the generation.
---@param layerName string The name of the layer in which the new peaks will be included.
---@param map string TODO: описание
---@param scale number TODO: описание
---@param zeroPos Position2d TODO: описание
---@param category MapGen.Layer.Category TODO: описание
---@param groups? table<string, number>
---@param map string The name of the image from which the peaks will be extracted. It should be located in the `<mod_name>/textures/maps` folder and have the following format `<image_name>.ff`
---@param scale number Multiplier of how many blocks (nodes) will be between image pixels. It is not recommended to set the value below 50 for performance reasons.
---@param zeroPos Position2d The position in pixels where the zero world coordinate will be in the image.
---@param category MapGen.Layer.Category Category indicating what will be generated by peaks.
---@param groups? table<string, number> Groups that will be added to all peaks.
function MapGen:register2DPeaksFromFile(layerName, map, scale,zeroPos, category, groups)
local modPath = core.get_modpath(core.get_current_modname())
local peaks = ff2luat(modPath .. '/textures/maps/' .. map)
@@ -315,6 +316,7 @@ function MapGen:initLayersTriangultaion()
end
end
---Initialize all layer noises. This should be called after the map object is loaded.
function MapGen:initLayersNoises()
---@param layer MapGen.Layer
for _, layer in ipairs(self.layersList) do