MapGen: Zoning support 4/7. #17
This commit is contained in:
@@ -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<string, number> 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.
|
||||
|
||||
Reference in New Issue
Block a user