From a97d806f6be03369e106750569ec4ade56fed078 Mon Sep 17 00:00:00 2001 From: Vanic Date: Fri, 9 Jan 2026 18:44:26 +0300 Subject: [PATCH 1/4] Mapgen: add peaks register from image --- mods/API/ApiLoader/src/Api.lua | 3 +- mods/API/ApiLoader/src/Api/ff2lua.lua | 95 ++++++++++++++++++ mods/API/ApiLoader/src/Api/globalStep.lua | 2 +- mods/CORE/MapGen/src/MapGen.lua | 24 +++++ .../mapGenerator/src/mapGenerator.lua | 17 +++- .../mapGenerator/textures/maps/map.ff | Bin 0 -> 2000016 bytes 6 files changed, 138 insertions(+), 3 deletions(-) create mode 100644 mods/API/ApiLoader/src/Api/ff2lua.lua create mode 100644 mods/ENVIRONMENT/mapGenerator/textures/maps/map.ff diff --git a/mods/API/ApiLoader/src/Api.lua b/mods/API/ApiLoader/src/Api.lua index 11d3d79..21e2ad4 100644 --- a/mods/API/ApiLoader/src/Api.lua +++ b/mods/API/ApiLoader/src/Api.lua @@ -3,4 +3,5 @@ Api = {} local modInfo = Mod.getInfo('smc__api__api_loader') local require = modInfo.require -require('Api.globalStep') \ No newline at end of file +require('Api.ff2lua') +require('Api.globalStep') diff --git a/mods/API/ApiLoader/src/Api/ff2lua.lua b/mods/API/ApiLoader/src/Api/ff2lua.lua new file mode 100644 index 0000000..e3a86ee --- /dev/null +++ b/mods/API/ApiLoader/src/Api/ff2lua.lua @@ -0,0 +1,95 @@ +-- 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 + +---@param uintb string unsigned int bytes +---@return number +local function uint2num(uintb) + local num = 0 + local len = string.len(uintb) + + for i = 1,len do + local b = string.byte(uintb, i) + num = num + b*(len+1-i) + end + + return num +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 +function Api.ff2luat(filepath, backgroundColor) + if backgroundColor == nil then + backgroundColor = '#000000FF' + end + + local file = io.open(filepath, 'rb') + + if not file then + error('Can\'t open farbfeld image: ' .. dump(filepath)) + end + + if not file:read(8) == 'farbfeld' then + error('Not farbfeld image: ' .. dump(filepath)) + end + + --HACK: normalizing colorstring for future string comparison ('#000' -> '#000000FF') + backgroundColor = core.colorspec_to_colorstring(core.colorspec_to_table(backgroundColor)) + + ---@type ColoredDotsTable + local dots = { size = { w = uint2num(file:read(4)), h = uint2num(file:read(4)) } } + + for i = 1,dots.size.h do + for j = 1,dots.size.w do + local color_t = { + r = uint2num(file:read(2)), + g = uint2num(file:read(2)), + b = uint2num(file:read(2)), + a = uint2num(file:read(2)) + } + + ---@type string @ColorString + local color = core.colorspec_to_colorstring(color_t) + + if color ~= backgroundColor then + if not dots[color] then + dots[color] = {} + end + + table.insert(dots[color], { x=j, y=i }) + end + end + end + + file:close() + + return dots +end diff --git a/mods/API/ApiLoader/src/Api/globalStep.lua b/mods/API/ApiLoader/src/Api/globalStep.lua index 1554710..2378054 100644 --- a/mods/API/ApiLoader/src/Api/globalStep.lua +++ b/mods/API/ApiLoader/src/Api/globalStep.lua @@ -72,4 +72,4 @@ core.register_globalstep(function(deltaTime) end end end -end) \ No newline at end of file +end) diff --git a/mods/CORE/MapGen/src/MapGen.lua b/mods/CORE/MapGen/src/MapGen.lua index 281c97e..4ba93ca 100644 --- a/mods/CORE/MapGen/src/MapGen.lua +++ b/mods/CORE/MapGen/src/MapGen.lua @@ -232,6 +232,30 @@ function MapGen:register2DPeaks(layerName, multinoise, peakPoses, groups) end end +---TODO: описание +---@alias PeakColors table?}> + +---TODO: описание +---@param layerName string The name of the layer in which the new peaks will be included. +---@param map string TODO +---@param zeroPos Position2d +---@param peakColors PeakColors TODO +function MapGen:register2DPeaksFromFile(layerName, map, zeroPos,peakColors) + local modPath = core.get_modpath(core.get_current_modname()) + local peaks = Api.ff2luat(modPath .. '/textures/maps/' .. map) + local mapSize = peaks.size + + print(dump(peaks)) + for color, peaksPos in pairs(peaks) do + local peakParams = peakColors[color] + assert(peakParams ~= nil, ('There are no generation settings declared for the color `%s`'):format(color)) + + for _, peakPos in ipairs(peaksPos) do + self:register2DPeak(layerName, vector.new(peakPos.x - zeroPos.x, 0, peakPos.y - zeroPos.y), peakParams.noise, peakParams.groups) + end + end +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/ENVIRONMENT/mapGenerator/src/mapGenerator.lua b/mods/ENVIRONMENT/mapGenerator/src/mapGenerator.lua index 9bfdec6..763b5eb 100644 --- a/mods/ENVIRONMENT/mapGenerator/src/mapGenerator.lua +++ b/mods/ENVIRONMENT/mapGenerator/src/mapGenerator.lua @@ -101,7 +101,7 @@ local climat0 = { } local v = vector.new - +--[[ mapGenerator:register2DPeaks('midgard', { landscapeNoise = land1, @@ -132,6 +132,21 @@ mapGenerator:register2DPeaks('midgard', },{ v(200, 0, 100), v(-300, 0, -200), +})--]] + +mapGenerator:register2DPeaksFromFile('midgard', 'map.ff', {x=250, y=250}, { + ['#396fffff'] = {noise = { + landscapeNoise = land1, + tempNoise = climat2, + humidityNoise = climat2, + } + }, + ['3fff26ff'] = {noise = { + landscapeNoise = land2, + tempNoise = climat2, + humidityNoise = climat2, + } + } }) mapGenerator:registerCavern('midgard', 'cavern1', { diff --git a/mods/ENVIRONMENT/mapGenerator/textures/maps/map.ff b/mods/ENVIRONMENT/mapGenerator/textures/maps/map.ff new file mode 100644 index 0000000000000000000000000000000000000000..01cc1d90a33705406b2393c11eaedef692e0f2ec GIT binary patch literal 2000016 zcmeI*QEJ>U6a~<9F5~+V!!2DuI1YL#sLm+fCC)h z00%h00S<70103K02ROh14sd`29N+*4IKTl8aDW3G-~b0WzyS_$fCIBSkjpl%WHz5! z=i}?Lepo;F!~qU)fCC)h00%h00S<70103K02ROh14sd`29N+*4IKTl8aDW3G-~b0W zzyS_$fCC)h00%h00S<70103K02ROh14sd`29N+*4IKTl8aDW3G-~b0WzyS_$fCC)h z00%h00S<70103K02ROh14sd`29N+*4IKTl8aDW3G-~b0WzyS_$fCH;LP{(i6O5L1S zpR?y@J+q#1jsqOv00%h00S<70103K02ROh14sd`29N+*4IKTl8aDW3G-~b0WzyS_$ zfCC)h00%h00S<70103K02ROh14sd`29N+*4IKTl8aDW3G-~b0WzyS_$fCC)h00%h0 z0S<70103K02ROh14sd`29N+*4IKTl8aDW3G-~b0WzyS_$fCC)h00%h00S<70103K0 z2ROh14sd`29N+*4IKTl8aDW3G-~b0WzyS_$fCC)h00%h00S<70103K02ROh14sd`2 z9N+*4IKTl8aDW3G-~b0WzyS_$fCC)h00%h00S<70103K02ROh14sd`29N+*4IKTl8 zaDW3G-~b0WzyS_$fCC)h00%h00S<70103K02ROh14sd`29N+*4IKTl8aDW3G-~b0W zzyS_$fCC)h00%h00S<70103K02ROh14sd`29N+*4IKTl8aDW3G-~b0WzyS_$fCC)h z00%h00S<70103K02ROh14sd`29N+*4IKTl8aDW3G-~b0WzyS_$fCC)h00%h00S<70 z103K02ROh14sd`29N+*4IKTl8aDW3G-~b0WzyS_$;HnPfvb7k;RiD4-&42#uKL4q2R?k{gTLnkANarl4sd`29N+*4IKTl8aDW3G-~b0W zzyS_$fCC)h00%h00S<70103K02ROh14sd`29N+*4IKTl8aDW3G-~b0WzyS_$fCC)h z00%h00S<70103K02ROh14sd`29N+*4IKTl8aDW3G-~b0WzyS_$fCC)h00%h00S<70 z103K02ROh14sd`29N+*4IKTl8aDW3G-~b0WzyS_$fCC)h00%h00S<70103K02ROh1 z4sd`29N+*4IKTl8aDW3G-~b0WzyS_$fCC)h00%h00S<70103K02ROh14sd`29N+*4 zIKTl8aDW3G-~b0WzyS_$fCC)h00%h00S<70103K02ROh14m^_swMC?^w|c9$&(vFa zl~;MSZgGGE9N+*4IKTl8aDW3G-~b0WzyS_$fCC)h00%h00S<70103K02ROh14sd`2 z9N+*4IKTl8aDW3G-~b0WzyS_$fCC)h00%h00S<70103K02ROh14shT(9dO^L=bW3q znVWUjy2}9$aDW3G-~b0WzyS_$fCC)h00%h00S<70103K02ROh14sd`29N+*4IKTl8 zaDW3G-~b0WzyS_$fCC)h00%h00S<70103K02ROh14sd`29N+*4IKTl8aDW3G-~b0W zzyS_$fCC)h00%h00S<70103K02ROh14sd`29N+*4IKTl8aDW3G-~b0WzyS_$fCC)h z00%h00S<70103K02ROh14sd`29N+*4IKTl8aDW3G-~b0WzyS_$fCC)h00%h00S<70 z103K02ROh14sd`29N+*4IKTl8aDW3G-~b0WzyS_$fCC)h00%h00S<70103MMo(|-) zwHSw7$<>~@k|%kRC$4gU103K02ROh14sd`29N+*4IKTl8aDW3G-~b0WzyS_$fCC)h z00%h00S<70103K02ROh14sd`29N+*4IKTl8aDW3G-~b0WzyS_$fCC)h00%h00S<70 z103K02ROh14sd`29N+*4IKTl8aDW3G-~b0WzyS_$fCC)h00%h00S<70103K02ROh1 z4sd`29N+*4IKTl8aDW3G-~b0WzyS_$fCC)h00%h00S<70103K02ROh14sd`29N+*4 zIKTl8aDW3G-~b0WzyS_$fCC)h00%h00S<70103K02ROh14sd`29N+*4IKTl8aDW3G z-~b0WzyS_$fCC)h00%h00S<70103K02ROh14sd`29N+*4IKTl8aDW3G-~b0WzyS_$ zfCC)h00%h00S<70103K02ROh14sd`29N+*4IKTl8aDW3G-~b0WzyS_$fCC)h00%h0 z0S<70103K02ROh14sd`29N+*4IKTl8aDW3>aGK68Kr9N+*4IKTl8aNs!|@O!eJb8h-(Zq{Av zE(bWk0S<70103K02ROh14sd`29N+*4IKTl8aDW3G-~b0WzyS_$fCC)h00%h00S<70 z103K02ROh14sd`29N+*4IKTl8aDW3G-~b0WzyS_$fCC)h00%h00S<70103K02ROh1 z4sd`29N+*4IKTl8aDW3G-~b0WzyS_$fCC)h00%h00S<70103K02ROh14sd`29N+*4 zIKTl8aDW3G-~b0WzyS_$fCC)h00%h00S<70103K02ROh14sd`29N+*4IKTl8aDW3G z;K1Gv)E1Gt^SbwW_4#T>kKfKOEoy2ROh14sd`29N@q$2XfiQ zJDc@HPxRzgPvk>BUy9D*Y1J&o4@^#b$|mL-~b0WzyS_$fCC)h00%h00S<70103K02ROh14sd`2 z9N+*4IKTl8aDW3G-~b0WzyS_$fCC)h00%h00S<70103K02ROh14sd`29N+*4IKTl8 zaDW3G-~b0WzyS_$fCC)h00%h00S<70103K02ROh14sd`29N+*4IKTl8aDW3G-~b0W zzyS_$fCC)h00%h00S<70103K02ROh14sd`29N+*4IKTl8aDW3G-~b0WzyS_$fCC)h z00%h00S<70103K02ROh14sd`29N+*4IKTl8aDW3G-~b0WFt-D_Y%RuNPIJwvj;W+> zE^;|nF3rO{?CZG90S<70103K02ROh14sd`29N+*4IKTl8a9}+L{Jc=F^?JQtTd(z6 zul1S(9N+*4IKTl8aDW3G-~b0WzyS_$fCC)h00%h00S<70103K02ROh14sd`29N+*4 zIKTl8aDW3G-~b0WzyS_$fCC)h00%h00S<70103K02ROh14sd`29N+*4IKTl8aDW3G z-~b0WzyS_$fCC)h00%h00S<70103K02ROh14sd`29N+*4IKTl8aDW3G-~b0WzyS_$ zfCC)h00%h00S<70103K02ROh14sd`29GJm@+9FcdM}5@CGyABA@^@zb_$PnzXCK4? z4sd`29N+*4IKTl8aDW3G-~b0WzyS_$fCC)h00%h00S<70103K02ROh14sd`29N+*4 zIKTl8aA1E2ykA7G^lJZJS+Dd;uk?xo9N+*4IKTl8aDW3G-~b0WzyS_$fCC)h00%h0 z0S<70103K02ROh14sd`29N+*4IKTl8aDW3G-~b0WzyS_$fCC)h00%h00S<70103K0 z2ROh14sd`29N+*4IKTl8aDW3G-~b0WzyS_$fCC)h00%h00S<70103K02ROh14sd`2 z9N+*4IKTl8aDW3G-~b0WzyS_$fCC)h00%h00S<70103K02ROh14sd`29N+*4IKTl8 zaDW3G-~b0WzyS_$fCFnfkjvI$9Ok>`e9hHdt>1j(00%h00S<70103K02ROh14sd`2 z9N+*4IKTl8aDW3G-~b0WzyS_$fCC)h00%h00S<70103K02ROh14sd`29N+*4IKTl8 zaDW3G-~b0WzyS_$fCC)h00%h00S<70103K02ROh14sd`29N+*4IKTl8aDW3G-~b0W zzyS_$fCC)h00%h00S<70103K02ROh14sd`29N+*4IKTl8aDW3G-~b0WzyS_$fCC)h z00%h00S<70103K02ROh14sd`29N+*4IKTl8aDW3G-~b0WzyS_$fCC)h00%h00S<70 z103K02ROh14sd`29N+*4IKTl8aDW3G-~b0WzyS_$fCC)h00%h00S<70103K02ROh1 z4sd`29N+*4IKTl8aDW3G-~b0WzyS_$fCC)h00%h00S<70103K02ROh14sd`29N+*4 zIKTl8aDW3G-~b0WzyS_$UI@fcw&N zjcZ(6%{9-5Yh2?R2ROh14sd`29N+*4IKTl8aDW3G-~b0WzyS_$fCC)h00%h00S<70 z103K02ROh14sd`29N+*4IKTl8aDW3G-~b0WzyS_$fCC)h00%hm6%M#hhg^L{u6QL^ za%JDb0S<70103K02ROh14sd`29N+*4IKTl8aDW3G-~b0WzyS_$fCC)h00%h00S<70 z103K02ROh14sd`29N+*4IKTl8aDW3G-~b0WzyS_$fCC)h00%h00S<70103K02ROh1 z4sd`29N+*4IKTl8aDW3G-~b0WzyS_$fCC)h00%h00S<70103K02ROh14sd`29N+*4 zIKTl8aDW3G-~b0WzyS_$fCC)h00%h00S<70103K02ROh14sd`29N+*4IKTl8aDW3G z-~b0WzyS_$fCC)h00%h00S<70103K02ROh14sd`29N+*4IKTl8aDW3G-~b0WzyS_$ zfCC)h00%h00S<70103K02ROh14sd`29N+*4IKTl8aDW3G-~b0WzyS_$fCC)h00%h0 z0S<70103K02ROh14sd`29N+*4IKTl8aDW3G-~b0WzyS_$fCC)h00%h00S<70103K0 z2ROh14sd`29N+*4IKTl8aDW3G-~b0WzyS_$fCC)h00%h00S<70103K02ROh14sd`2 z9N+*4IKTl8aDW3G-~b0WzyS_$fCC)h00%h00S<70103K02ROh14sd`29C*xu+9Fby zBRP63M|+*WT(*%&dED!K`aE;w+8oTmewFJS-~b0WzyS_$fCC)h00%h00S<70103K0 z2ROh14sc*T2V5_qmwGv0FRhn)sh4`m0S<70103K02ROh14sd`29N+*4IKTl8aDW3G z-~b0WzyS_$fCC)h00%hmnFFr>;{+!-@tG6;ofDkk1P3_40S<70103K02ROh14sd`2 z9N+*4IKTl8aDW3G-~b0WaHIpSXOXuf^Ts!MlQ;Vu4sd`29N+*4IKTl8aDW3G-~b0W zzyS_$fCC)h00%h00S<70103K02ROh14sd`29N+*4IKTl8aDW3G-~b0WzyS_$fCC)h z00%h00S<70103K02ROh14sd`29N+*4?r|WOt;IOxM}F?fkKD+O-0+hF9N+*4IKTl8 zaDW3G-~b0WzyS_$fCC)h00%h00S<70103K02ROh14sd`29N+*4IKTl8aDW3G-~b0W zzyS_$fCC)h00%h00S<70103K02ROh14sd`29N+*4IKTl8aDW3G-~b0WzyS_$fCC)h z00%h00S<70103K02ROh14sd`29N+*4IKTl8aDW3G-~b0WzyS_$fCC)h00%h00S<70 z103K02ROh14sd`29N+*4IKTl8aDW3G;J`c%)E1HYJYNqV_`nB!-ss|k400%h0 z0S<70103K02ROh14sd`29N+*4IKTl8aDW3G-~b0WzyS_$fCC)h00%h00S<70103K0 z2RN{*19iN6B6ag!b-tdL^~?IjHx6)s103K02ROh14sd`29N+*4IB>oLUWe5~Jv_gM z) Date: Fri, 9 Jan 2026 19:14:52 +0300 Subject: [PATCH 2/4] Fixed unsigned int bytes to number conversion --- mods/API/ApiLoader/src/Api/ff2lua.lua | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/mods/API/ApiLoader/src/Api/ff2lua.lua b/mods/API/ApiLoader/src/Api/ff2lua.lua index e3a86ee..1cb7591 100644 --- a/mods/API/ApiLoader/src/Api/ff2lua.lua +++ b/mods/API/ApiLoader/src/Api/ff2lua.lua @@ -15,13 +15,12 @@ ---@param uintb string unsigned int bytes ---@return number -local function uint2num(uintb) +local function uintb2num(uintb) local num = 0 local len = string.len(uintb) for i = 1,len do - local b = string.byte(uintb, i) - num = num + b*(len+1-i) + num = num*256 + string.byte(uintb, i) end return num @@ -65,15 +64,15 @@ function Api.ff2luat(filepath, backgroundColor) backgroundColor = core.colorspec_to_colorstring(core.colorspec_to_table(backgroundColor)) ---@type ColoredDotsTable - local dots = { size = { w = uint2num(file:read(4)), h = uint2num(file:read(4)) } } + local dots = { size = { w = uintb2num(file:read(4)), h = uintb2num(file:read(4)) } } for i = 1,dots.size.h do for j = 1,dots.size.w do local color_t = { - r = uint2num(file:read(2)), - g = uint2num(file:read(2)), - b = uint2num(file:read(2)), - a = uint2num(file:read(2)) + r = uintb2num(file:read(2)), + g = uintb2num(file:read(2)), + b = uintb2num(file:read(2)), + a = uintb2num(file:read(2)) } ---@type string @ColorString -- 2.49.1 From 4c143b205590ce01db664c71aea687560a689224 Mon Sep 17 00:00:00 2001 From: ssdaniel24 Date: Fri, 9 Jan 2026 21:02:52 +0300 Subject: [PATCH 3/4] Fixed uintb2num func for normal conversion... --- mods/API/ApiLoader/src/Api/ff2lua.lua | 31 +++++++++++++-------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/mods/API/ApiLoader/src/Api/ff2lua.lua b/mods/API/ApiLoader/src/Api/ff2lua.lua index 1cb7591..570e636 100644 --- a/mods/API/ApiLoader/src/Api/ff2lua.lua +++ b/mods/API/ApiLoader/src/Api/ff2lua.lua @@ -26,6 +26,14 @@ local function uintb2num(uintb) 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: ---``` @@ -46,20 +54,11 @@ end ---@param backgroundColor string? ColorString, will be ignored while processing image. Default: `#000000FF` ---@return ColoredDotsTable function Api.ff2luat(filepath, backgroundColor) - if backgroundColor == nil then - backgroundColor = '#000000FF' - end - local file = io.open(filepath, 'rb') + if not file then error('Can\'t open farbfeld image: ' .. dump(filepath)) end + if not file:read(8) == 'farbfeld' then error('Not farbfeld image: ' .. dump(filepath)) end - if not file then - error('Can\'t open farbfeld image: ' .. dump(filepath)) - end - - if not file:read(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 = core.colorspec_to_colorstring(core.colorspec_to_table(backgroundColor)) @@ -69,10 +68,10 @@ function Api.ff2luat(filepath, backgroundColor) for i = 1,dots.size.h do for j = 1,dots.size.w do local color_t = { - r = uintb2num(file:read(2)), - g = uintb2num(file:read(2)), - b = uintb2num(file:read(2)), - a = uintb2num(file:read(2)) + r = uint16ToUint8(uintb2num(file:read(2))), + g = uint16ToUint8(uintb2num(file:read(2))), + b = uint16ToUint8(uintb2num(file:read(2))), + a = uint16ToUint8(uintb2num(file:read(2))) } ---@type string @ColorString -- 2.49.1 From 52630eb85abec28e84436585cc0f59d74c3a95da Mon Sep 17 00:00:00 2001 From: Vanic Date: Sat, 10 Jan 2026 12:04:25 +0300 Subject: [PATCH 4/4] Add test map image parsing --- mods/CORE/MapGen/src/MapGen.lua | 1 + .../mapGenerator/src/asyncInit.lua | 2 ++ .../mapGenerator/src/mapGenerator.lua | 32 ++++++++++++++---- .../mapGenerator/textures/maps/map.ff | Bin 2000016 -> 0 bytes 4 files changed, 29 insertions(+), 6 deletions(-) delete mode 100644 mods/ENVIRONMENT/mapGenerator/textures/maps/map.ff diff --git a/mods/CORE/MapGen/src/MapGen.lua b/mods/CORE/MapGen/src/MapGen.lua index 4ba93ca..ef13178 100644 --- a/mods/CORE/MapGen/src/MapGen.lua +++ b/mods/CORE/MapGen/src/MapGen.lua @@ -244,6 +244,7 @@ function MapGen:register2DPeaksFromFile(layerName, map, zeroPos,peakColors) local modPath = core.get_modpath(core.get_current_modname()) local peaks = Api.ff2luat(modPath .. '/textures/maps/' .. map) local mapSize = peaks.size + peaks.size = nil print(dump(peaks)) for color, peaksPos in pairs(peaks) do diff --git a/mods/ENVIRONMENT/mapGenerator/src/asyncInit.lua b/mods/ENVIRONMENT/mapGenerator/src/asyncInit.lua index 71f6d26..bafa56b 100644 --- a/mods/ENVIRONMENT/mapGenerator/src/asyncInit.lua +++ b/mods/ENVIRONMENT/mapGenerator/src/asyncInit.lua @@ -37,6 +37,8 @@ dofile(core.get_modpath('smc__api__table')..'/init.lua') -- TODO: пока что закоментировано, поскольку вызывает ошибку из-за global_step -- Api loader -- dofile(core.get_modpath('smc__api__api_loader')..'/init.lua') +Api = {} +dofile(core.get_modpath('smc__api__api_loader')..'/src/Api/ff2lua.lua') ---@type MapGen local mapGenerator = dofile(core.get_modpath('smc__core__map_generator')..'/src/mapGenerator.lua') diff --git a/mods/ENVIRONMENT/mapGenerator/src/mapGenerator.lua b/mods/ENVIRONMENT/mapGenerator/src/mapGenerator.lua index 763b5eb..82a9ec9 100644 --- a/mods/ENVIRONMENT/mapGenerator/src/mapGenerator.lua +++ b/mods/ENVIRONMENT/mapGenerator/src/mapGenerator.lua @@ -61,7 +61,7 @@ local land1 = { } local land2 = { - offset = 20, + offset = 10, scale = 5, spread = {x = 30, y = 30, z = 30}, seed = 47, @@ -133,22 +133,42 @@ mapGenerator:register2DPeaks('midgard', v(200, 0, 100), v(-300, 0, -200), })--]] - +--[[ mapGenerator:register2DPeaksFromFile('midgard', 'map.ff', {x=250, y=250}, { - ['#396fffff'] = {noise = { + ['#396FFFFF'] = {noise = { landscapeNoise = land1, tempNoise = climat2, humidityNoise = climat2, } }, - ['3fff26ff'] = {noise = { + ['#3FFF26FF'] = {noise = { landscapeNoise = land2, tempNoise = climat2, humidityNoise = climat2, } } -}) +})--]] +local N = 32 +for x = -10, 10 do + for z = - 10, 10 do + local land + if math.random(0,1) == 0 then + land = land1 + else + land = land2 + end + + print(x) + + mapGenerator:register2DPeak('midgard', vector.new(x*N, 0, z*N), { + landscapeNoise = land, + tempNoise = climat2, + humidityNoise = climat2, + }) + end +end +--[[ mapGenerator:registerCavern('midgard', 'cavern1', { minY = -48, maxY = 0, @@ -163,7 +183,7 @@ mapGenerator:registerCavern('midgard', 'cavern1', { persistence = 0.5, lacunarity = 2.0 }, -}) +})--]] -- --- Biomes --- diff --git a/mods/ENVIRONMENT/mapGenerator/textures/maps/map.ff b/mods/ENVIRONMENT/mapGenerator/textures/maps/map.ff deleted file mode 100644 index 01cc1d90a33705406b2393c11eaedef692e0f2ec..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2000016 zcmeI*QEJ>U6a~<9F5~+V!!2DuI1YL#sLm+fCC)h z00%h00S<70103K02ROh14sd`29N+*4IKTl8aDW3G-~b0WzyS_$fCIBSkjpl%WHz5! z=i}?Lepo;F!~qU)fCC)h00%h00S<70103K02ROh14sd`29N+*4IKTl8aDW3G-~b0W zzyS_$fCC)h00%h00S<70103K02ROh14sd`29N+*4IKTl8aDW3G-~b0WzyS_$fCC)h z00%h00S<70103K02ROh14sd`29N+*4IKTl8aDW3G-~b0WzyS_$fCH;LP{(i6O5L1S zpR?y@J+q#1jsqOv00%h00S<70103K02ROh14sd`29N+*4IKTl8aDW3G-~b0WzyS_$ zfCC)h00%h00S<70103K02ROh14sd`29N+*4IKTl8aDW3G-~b0WzyS_$fCC)h00%h0 z0S<70103K02ROh14sd`29N+*4IKTl8aDW3G-~b0WzyS_$fCC)h00%h00S<70103K0 z2ROh14sd`29N+*4IKTl8aDW3G-~b0WzyS_$fCC)h00%h00S<70103K02ROh14sd`2 z9N+*4IKTl8aDW3G-~b0WzyS_$fCC)h00%h00S<70103K02ROh14sd`29N+*4IKTl8 zaDW3G-~b0WzyS_$fCC)h00%h00S<70103K02ROh14sd`29N+*4IKTl8aDW3G-~b0W zzyS_$fCC)h00%h00S<70103K02ROh14sd`29N+*4IKTl8aDW3G-~b0WzyS_$fCC)h z00%h00S<70103K02ROh14sd`29N+*4IKTl8aDW3G-~b0WzyS_$fCC)h00%h00S<70 z103K02ROh14sd`29N+*4IKTl8aDW3G-~b0WzyS_$;HnPfvb7k;RiD4-&42#uKL4q2R?k{gTLnkANarl4sd`29N+*4IKTl8aDW3G-~b0W zzyS_$fCC)h00%h00S<70103K02ROh14sd`29N+*4IKTl8aDW3G-~b0WzyS_$fCC)h z00%h00S<70103K02ROh14sd`29N+*4IKTl8aDW3G-~b0WzyS_$fCC)h00%h00S<70 z103K02ROh14sd`29N+*4IKTl8aDW3G-~b0WzyS_$fCC)h00%h00S<70103K02ROh1 z4sd`29N+*4IKTl8aDW3G-~b0WzyS_$fCC)h00%h00S<70103K02ROh14sd`29N+*4 zIKTl8aDW3G-~b0WzyS_$fCC)h00%h00S<70103K02ROh14m^_swMC?^w|c9$&(vFa zl~;MSZgGGE9N+*4IKTl8aDW3G-~b0WzyS_$fCC)h00%h00S<70103K02ROh14sd`2 z9N+*4IKTl8aDW3G-~b0WzyS_$fCC)h00%h00S<70103K02ROh14shT(9dO^L=bW3q znVWUjy2}9$aDW3G-~b0WzyS_$fCC)h00%h00S<70103K02ROh14sd`29N+*4IKTl8 zaDW3G-~b0WzyS_$fCC)h00%h00S<70103K02ROh14sd`29N+*4IKTl8aDW3G-~b0W zzyS_$fCC)h00%h00S<70103K02ROh14sd`29N+*4IKTl8aDW3G-~b0WzyS_$fCC)h z00%h00S<70103K02ROh14sd`29N+*4IKTl8aDW3G-~b0WzyS_$fCC)h00%h00S<70 z103K02ROh14sd`29N+*4IKTl8aDW3G-~b0WzyS_$fCC)h00%h00S<70103MMo(|-) zwHSw7$<>~@k|%kRC$4gU103K02ROh14sd`29N+*4IKTl8aDW3G-~b0WzyS_$fCC)h z00%h00S<70103K02ROh14sd`29N+*4IKTl8aDW3G-~b0WzyS_$fCC)h00%h00S<70 z103K02ROh14sd`29N+*4IKTl8aDW3G-~b0WzyS_$fCC)h00%h00S<70103K02ROh1 z4sd`29N+*4IKTl8aDW3G-~b0WzyS_$fCC)h00%h00S<70103K02ROh14sd`29N+*4 zIKTl8aDW3G-~b0WzyS_$fCC)h00%h00S<70103K02ROh14sd`29N+*4IKTl8aDW3G z-~b0WzyS_$fCC)h00%h00S<70103K02ROh14sd`29N+*4IKTl8aDW3G-~b0WzyS_$ zfCC)h00%h00S<70103K02ROh14sd`29N+*4IKTl8aDW3G-~b0WzyS_$fCC)h00%h0 z0S<70103K02ROh14sd`29N+*4IKTl8aDW3>aGK68Kr9N+*4IKTl8aNs!|@O!eJb8h-(Zq{Av zE(bWk0S<70103K02ROh14sd`29N+*4IKTl8aDW3G-~b0WzyS_$fCC)h00%h00S<70 z103K02ROh14sd`29N+*4IKTl8aDW3G-~b0WzyS_$fCC)h00%h00S<70103K02ROh1 z4sd`29N+*4IKTl8aDW3G-~b0WzyS_$fCC)h00%h00S<70103K02ROh14sd`29N+*4 zIKTl8aDW3G-~b0WzyS_$fCC)h00%h00S<70103K02ROh14sd`29N+*4IKTl8aDW3G z;K1Gv)E1Gt^SbwW_4#T>kKfKOEoy2ROh14sd`29N@q$2XfiQ zJDc@HPxRzgPvk>BUy9D*Y1J&o4@^#b$|mL-~b0WzyS_$fCC)h00%h00S<70103K02ROh14sd`2 z9N+*4IKTl8aDW3G-~b0WzyS_$fCC)h00%h00S<70103K02ROh14sd`29N+*4IKTl8 zaDW3G-~b0WzyS_$fCC)h00%h00S<70103K02ROh14sd`29N+*4IKTl8aDW3G-~b0W zzyS_$fCC)h00%h00S<70103K02ROh14sd`29N+*4IKTl8aDW3G-~b0WzyS_$fCC)h z00%h00S<70103K02ROh14sd`29N+*4IKTl8aDW3G-~b0WFt-D_Y%RuNPIJwvj;W+> zE^;|nF3rO{?CZG90S<70103K02ROh14sd`29N+*4IKTl8a9}+L{Jc=F^?JQtTd(z6 zul1S(9N+*4IKTl8aDW3G-~b0WzyS_$fCC)h00%h00S<70103K02ROh14sd`29N+*4 zIKTl8aDW3G-~b0WzyS_$fCC)h00%h00S<70103K02ROh14sd`29N+*4IKTl8aDW3G z-~b0WzyS_$fCC)h00%h00S<70103K02ROh14sd`29N+*4IKTl8aDW3G-~b0WzyS_$ zfCC)h00%h00S<70103K02ROh14sd`29GJm@+9FcdM}5@CGyABA@^@zb_$PnzXCK4? z4sd`29N+*4IKTl8aDW3G-~b0WzyS_$fCC)h00%h00S<70103K02ROh14sd`29N+*4 zIKTl8aA1E2ykA7G^lJZJS+Dd;uk?xo9N+*4IKTl8aDW3G-~b0WzyS_$fCC)h00%h0 z0S<70103K02ROh14sd`29N+*4IKTl8aDW3G-~b0WzyS_$fCC)h00%h00S<70103K0 z2ROh14sd`29N+*4IKTl8aDW3G-~b0WzyS_$fCC)h00%h00S<70103K02ROh14sd`2 z9N+*4IKTl8aDW3G-~b0WzyS_$fCC)h00%h00S<70103K02ROh14sd`29N+*4IKTl8 zaDW3G-~b0WzyS_$fCFnfkjvI$9Ok>`e9hHdt>1j(00%h00S<70103K02ROh14sd`2 z9N+*4IKTl8aDW3G-~b0WzyS_$fCC)h00%h00S<70103K02ROh14sd`29N+*4IKTl8 zaDW3G-~b0WzyS_$fCC)h00%h00S<70103K02ROh14sd`29N+*4IKTl8aDW3G-~b0W zzyS_$fCC)h00%h00S<70103K02ROh14sd`29N+*4IKTl8aDW3G-~b0WzyS_$fCC)h z00%h00S<70103K02ROh14sd`29N+*4IKTl8aDW3G-~b0WzyS_$fCC)h00%h00S<70 z103K02ROh14sd`29N+*4IKTl8aDW3G-~b0WzyS_$fCC)h00%h00S<70103K02ROh1 z4sd`29N+*4IKTl8aDW3G-~b0WzyS_$fCC)h00%h00S<70103K02ROh14sd`29N+*4 zIKTl8aDW3G-~b0WzyS_$UI@fcw&N zjcZ(6%{9-5Yh2?R2ROh14sd`29N+*4IKTl8aDW3G-~b0WzyS_$fCC)h00%h00S<70 z103K02ROh14sd`29N+*4IKTl8aDW3G-~b0WzyS_$fCC)h00%hm6%M#hhg^L{u6QL^ za%JDb0S<70103K02ROh14sd`29N+*4IKTl8aDW3G-~b0WzyS_$fCC)h00%h00S<70 z103K02ROh14sd`29N+*4IKTl8aDW3G-~b0WzyS_$fCC)h00%h00S<70103K02ROh1 z4sd`29N+*4IKTl8aDW3G-~b0WzyS_$fCC)h00%h00S<70103K02ROh14sd`29N+*4 zIKTl8aDW3G-~b0WzyS_$fCC)h00%h00S<70103K02ROh14sd`29N+*4IKTl8aDW3G z-~b0WzyS_$fCC)h00%h00S<70103K02ROh14sd`29N+*4IKTl8aDW3G-~b0WzyS_$ zfCC)h00%h00S<70103K02ROh14sd`29N+*4IKTl8aDW3G-~b0WzyS_$fCC)h00%h0 z0S<70103K02ROh14sd`29N+*4IKTl8aDW3G-~b0WzyS_$fCC)h00%h00S<70103K0 z2ROh14sd`29N+*4IKTl8aDW3G-~b0WzyS_$fCC)h00%h00S<70103K02ROh14sd`2 z9N+*4IKTl8aDW3G-~b0WzyS_$fCC)h00%h00S<70103K02ROh14sd`29C*xu+9Fby zBRP63M|+*WT(*%&dED!K`aE;w+8oTmewFJS-~b0WzyS_$fCC)h00%h00S<70103K0 z2ROh14sc*T2V5_qmwGv0FRhn)sh4`m0S<70103K02ROh14sd`29N+*4IKTl8aDW3G z-~b0WzyS_$fCC)h00%hmnFFr>;{+!-@tG6;ofDkk1P3_40S<70103K02ROh14sd`2 z9N+*4IKTl8aDW3G-~b0WaHIpSXOXuf^Ts!MlQ;Vu4sd`29N+*4IKTl8aDW3G-~b0W zzyS_$fCC)h00%h00S<70103K02ROh14sd`29N+*4IKTl8aDW3G-~b0WzyS_$fCC)h z00%h00S<70103K02ROh14sd`29N+*4?r|WOt;IOxM}F?fkKD+O-0+hF9N+*4IKTl8 zaDW3G-~b0WzyS_$fCC)h00%h00S<70103K02ROh14sd`29N+*4IKTl8aDW3G-~b0W zzyS_$fCC)h00%h00S<70103K02ROh14sd`29N+*4IKTl8aDW3G-~b0WzyS_$fCC)h z00%h00S<70103K02ROh14sd`29N+*4IKTl8aDW3G-~b0WzyS_$fCC)h00%h00S<70 z103K02ROh14sd`29N+*4IKTl8aDW3G;J`c%)E1HYJYNqV_`nB!-ss|k400%h0 z0S<70103K02ROh14sd`29N+*4IKTl8aDW3G-~b0WzyS_$fCC)h00%h00S<70103K0 z2RN{*19iN6B6ag!b-tdL^~?IjHx6)s103K02ROh14sd`29N+*4IB>oLUWe5~Jv_gM z)