Bunch of updates (29.08.2025)

This commit is contained in:
2025-08-29 23:12:07 +07:00
parent 2fa17bda3f
commit 6f3a8874a7
24 changed files with 355 additions and 56 deletions

View File

@@ -0,0 +1,7 @@
local MapGen = Mod:new()
local require = MapGen.require
MapGen.Class = require('MapGen')
MapGen.Class:enable()
Api.addModToGlobalSpace(MapGen, 'Core.MapGen')

View File

@@ -0,0 +1,2 @@
name = smc__core__map_gen
depends = smc__api__system

View File

@@ -0,0 +1,40 @@
local MapGen = {}
MapGen.__index = MapGen
function MapGen:new()
local instance = setmetatable({}, self)
instance.layers = {}
return instance
end
function MapGen:RegisterLayer(layer)
Ensure.argNotNil(layer, 1, "MapGen:RegisterLayer")
Ensure.argType(layer.minHeight, "number", 1, "MapGen:RegisterLayer")
Ensure.argType(layer.maxHeight, "number", 2, "MapGen:RegisterLayer")
assert(layer.minHeight < layer.maxHeight, "minHeight must be less than maxHeight")
table.insert(self.layers, layer)
end
function MapGen:GenerateMap()
for _, layer in ipairs(self.layers) do
self:GenerateLayer(layer)
end
end
function MapGen:GenerateLayer(layer)
-- Implement layer generation logic here
-- This will include processing 2D and 3D regions
end
function MapGen:RegisterRegion2D(region)
Ensure.argNotNil(region, 1, "MapGen:RegisterRegion2D")
-- Additional validation and registration logic for 2D regions
end
function MapGen:RegisterRegion3D(region)
Ensure.argNotNil(region, 1, "MapGen:RegisterRegion3D")
-- Additional validation and registration logic for 3D regions
end
return MapGen

View File

@@ -0,0 +1,42 @@
local Layer = {}
Layer.__index = Layer
function Layer:new(minHeight, maxHeight)
Ensure.argType(minHeight, 'number', 1, 'Layer:new')
Ensure.argType(maxHeight, 'number', 2, 'Layer:new')
Ensure.argNotNil(minHeight, 1, 'Layer:new')
Ensure.argNotNil(maxHeight, 2, 'Layer:new')
assert(minHeight < maxHeight, 'minHeight must be less than maxHeight')
local layer = {
minHeight = minHeight,
maxHeight = maxHeight,
region2DList = {},
region3DList = {}
}
setmetatable(layer, self)
return layer
end
function Layer:RegisterRegion2D(region2D)
Ensure.argNotNil(region2D, 1, 'Layer:RegisterRegion2D')
assert(region2D.minHeight >= self.minHeight and region2D.maxHeight <= self.maxHeight, 'Region2D height must be within layer boundaries')
table.insert(self.region2DList, region2D)
end
function Layer:RegisterRegion3D(region3D)
Ensure.argNotNil(region3D, 1, 'Layer:RegisterRegion3D')
assert(region3D.minHeight >= self.minHeight and region3D.maxHeight <= self.maxHeight, 'Region3D height must be within layer boundaries')
table.insert(self.region3DList, region3D)
end
function Layer:GetRegions2D()
return self.region2DList
end
function Layer:GetRegions3D()
return self.region3DList
end
return Layer

View File

@@ -0,0 +1,34 @@
local Region = {}
Region.__index = Region
function Region:new(name, layer, allowedBiomes)
Ensure.stringArgNotEmpty(name, 1, "Region:new")
Ensure.argNotNil(layer, 2, "Region:new")
Ensure.argNotNil(allowedBiomes, 3, "Region:new")
local instance = setmetatable({}, self)
instance.name = name
instance.layer = layer
instance.allowedBiomes = allowedBiomes
return instance
end
function Region:GetName()
return self.name
end
function Region:GetLayer()
return self.layer
end
function Region:GetAllowedBiomes()
return self.allowedBiomes
end
function Region:IsBiomeAllowed(biome)
Ensure.stringArgNotEmpty(biome, 1, "Region:IsBiomeAllowed")
return self.allowedBiomes[biome] == true
end
return Region

View File

@@ -0,0 +1,41 @@
local modInfo = Mod.getInfo()
local require = modInfo.require
local Ensure = require("MapGen.Utils.Ensure")
local Region2D = {}
Region2D.__index = Region2D
function Region2D:new(name, layer, allowedBiomes, heightNoise, temperatureNoise, humidityNoise, heightVariance, temperatureVariance, humidityVariance)
Ensure.stringArgNotEmpty(name, 1, "Region2D:new")
Ensure.argNotNil(layer, 2, "Region2D:new")
Ensure.argType(allowedBiomes, "table", 3, "Region2D:new")
Ensure.argType(heightNoise, "table", 4, "Region2D:new")
Ensure.argType(temperatureNoise, "table", 5, "Region2D:new")
Ensure.argType(humidityNoise, "table", 6, "Region2D:new")
Ensure.argType(heightVariance, "table", 7, "Region2D:new")
Ensure.argType(temperatureVariance, "table", 8, "Region2D:new")
Ensure.argType(humidityVariance, "table", 9, "Region2D:new")
local instance = setmetatable({}, self)
instance.name = name
instance.layer = layer
instance.allowedBiomes = allowedBiomes
instance.heightNoise = heightNoise
instance.temperatureNoise = temperatureNoise
instance.humidityNoise = humidityNoise
instance.heightVariance = heightVariance
instance.temperatureVariance = temperatureVariance
instance.humidityVariance = humidityVariance
return instance
end
function Region2D:GenerateTerrain(x, z)
-- Implement terrain generation logic based on noise and variances
end
function Region2D:CheckBounds(y)
-- Implement boundary checking logic for the layer
end
return Region2D

View File

@@ -0,0 +1,46 @@
local Ensure = require("MapGen.Utils.Ensure")
local Region3D = {}
Region3D.__index = Region3D
function Region3D:new(name, layer, allowedBiomes, caveNoise, temperatureNoise, humidityNoise, temperatureVariance, humidityVariance)
Ensure.stringArgNotEmpty(name, 1, "Region3D:new")
Ensure.argNotNil(layer, 2, "Region3D:new")
Ensure.argType(allowedBiomes, "table", 3, "Region3D:new")
Ensure.argType(caveNoise, "table", 4, "Region3D:new")
Ensure.argType(temperatureNoise, "table", 5, "Region3D:new")
Ensure.argType(humidityNoise, "table", 6, "Region3D:new")
Ensure.argType(temperatureVariance, "table", 7, "Region3D:new")
Ensure.argType(humidityVariance, "table", 8, "Region3D:new")
local instance = setmetatable({
name = name,
layer = layer,
allowedBiomes = allowedBiomes,
caveNoise = caveNoise,
temperatureNoise = temperatureNoise,
humidityNoise = humidityNoise,
temperatureVariance = temperatureVariance,
humidityVariance = humidityVariance,
}, self)
return instance
end
function Region3D:Register()
-- Logic to register the 3D region within the specified layer
end
function Region3D:ValidateBounds(minHeight, maxHeight)
-- Logic to validate that the region does not exceed the layer boundaries
end
function Region3D:GenerateCaves()
-- Logic to generate caves based on the cave noise
end
function Region3D:GenerateContents()
-- Logic to populate the region with contents based on temperature and humidity
end
return Region3D

View File

@@ -0,0 +1,31 @@
local Utils = {}
function Utils.Clamp(value, min, max)
if value < min then
return min
elseif value > max then
return max
else
return value
end
end
function Utils.Lerp(a, b, t)
return a + (b - a) * t
end
function Utils.GenerateNoise(seed, x, y, scale)
local noise = core.get_perlin(seed, scale, 1, 0)
return noise:get2d({x, y})
end
function Utils.ValidateBiome(biome, allowedBiomes)
for _, allowedBiome in ipairs(allowedBiomes) do
if biome == allowedBiome then
return true
end
end
return false
end
return Utils