diff --git a/mods/CORE/MapGen/src/MapGen.lua b/mods/CORE/MapGen/src/MapGen.lua index 0e38fa6..e9e81c1 100644 --- a/mods/CORE/MapGen/src/MapGen.lua +++ b/mods/CORE/MapGen/src/MapGen.lua @@ -114,6 +114,29 @@ function MapGen:getStaticByHeight(yPos) end end +---Returns the `MapGen.Peak` at the coordinates. If there is no peak at these coordinates, it returns nil. +---@param layer string|MapGen.Layer The layer or name of the layer in which the peak is located. +---@param category MapGen.Layer.Category The category in which the peak is located. +---@param pos Position Coordinate of the desired peak. +---@return MapGen.Peak? +function MapGen:getPeakByPos(layer, category, pos) + if type(layer) == 'string' then + local layerName = layer + layer = self.layersByName[layerName] + + assert(layer ~= nil, ('There is no layer named `%s` registered.'):format(layerName)) + end + + pos = vector.new(pos) + + ---@param peak MapGen.Peak + for _, peak in ipairs(layer.peaksList[category]) do + if peak:getPeakPos() == pos then + return peak + end + end +end + -- --- REGISTRATION METHODS --- @@ -182,7 +205,7 @@ end ---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. +---Note: The peaks shouldn't overlap. ---@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`. @@ -192,7 +215,9 @@ function MapGen:registerPeak(layerName, category, def) assert(layer ~= nil, ('There is no layer named `%s` registered.'):format(layerName)) - --TODO: добавить проверку, что координата пиков не совпадают + assert(self:getPeakByPos(layer, category, def.pos) == nil, + ('In the `%s` layer in the `%s` category there is already a peak with coordinates: %s, %s, %s.'):format + (layerName, category, def.pos.x, def.pos.y, def.pos.z)) ---@type MapGen.Peak local peak = Peak:new(def) @@ -203,7 +228,7 @@ end ---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. +---Note: The peaks shouldn't overlap. ---@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`. @@ -224,7 +249,7 @@ end ---Mark the world points as `MapGen.Peak` and assign them all a specific noise that will affect 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. +---Note: The peaks shouldn't overlap. ---@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`. @@ -262,6 +287,25 @@ function MapGen:register2DPeaksFromFile(layerName, map, scale,zeroPos, category, end end +---Adds groups to the already registered groups in the peak by coordinate. +---If the peak does not exist, an error will be raised. +---@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 pos Position The position of the peak to which the group should be added. +---@param groups table Groups to be added. +function MapGen:addGroupsToPeakByPos(layerName, category, pos, groups) + ---@type MapGen.Layer + local layer = self.layersByName[layerName] + + assert(layer ~= nil, ('There is no layer named `%s` registered.'):format(layerName)) + + local peak = self:getPeakByPos(layer, category, pos) + assert( peak ~= nil, ('In the `%s` layer in the `%s` category there is no peak with coordinates: %s, %s, %s.'):format + (layerName, category, pos.x, pos.y, pos.z)) + + peak:addGroups(groups) +end + ---Mark a point on the biomes diagram and constrain the world area by height to mark it as `MapGen.Biome`. ---@param layerName string The name of the layer in which the new biome will be included. ---@param biomeName string The name to be assigned to the biome. The name must be unique for each biome. diff --git a/mods/CORE/MapGen/src/MapGen/Peak.lua b/mods/CORE/MapGen/src/MapGen/Peak.lua index 6b95a9a..3ad4294 100644 --- a/mods/CORE/MapGen/src/MapGen/Peak.lua +++ b/mods/CORE/MapGen/src/MapGen/Peak.lua @@ -1,8 +1,9 @@ ---@class MapGen.Peak ----@field id number ----@field getPeakPos fun(self):vector ----@field getColor fun(self):ColorString ----@field getGroups fun(self):table +---@field id number +---@field getPeakPos fun(self):vector +---@field getColor fun(self):ColorString +---@field getGroups fun(self):table +---@field addGroups fun(self, groups:table) local Peak = { id = 0, } @@ -50,6 +51,14 @@ function Peak:new(def) return table.copy_with_metatables(_groups) end + function instance:addGroups(groups) + -- Groups that cannot be overwritten + groups.is2d = nil + groups.is3d = nil + + _groups = table.merge(_groups, groups, true) + end + return instance end