Compare commits
3 Commits
dfd8021808
...
8640e55415
| Author | SHA1 | Date | |
|---|---|---|---|
| 8640e55415 | |||
| 84295c56c4 | |||
| eaf350e9ce |
@@ -3,5 +3,4 @@ Api = {}
|
|||||||
local modInfo = Mod.getInfo('smc__api__api_loader')
|
local modInfo = Mod.getInfo('smc__api__api_loader')
|
||||||
local require = modInfo.require
|
local require = modInfo.require
|
||||||
|
|
||||||
require('Api.ff2lua')
|
|
||||||
require('Api.globalStep')
|
require('Api.globalStep')
|
||||||
|
|||||||
@@ -41,6 +41,8 @@ local Triangulation = require('MapGen.Triangulation')
|
|||||||
---@type MapGen.Cavern
|
---@type MapGen.Cavern
|
||||||
local Cavern = require('MapGen.Cavern')
|
local Cavern = require('MapGen.Cavern')
|
||||||
|
|
||||||
|
local ff2luat = require('MapGen.ff2luat')
|
||||||
|
|
||||||
---@class MapGen
|
---@class MapGen
|
||||||
---@field layersByName table<string, MapGen.Layer>
|
---@field layersByName table<string, MapGen.Layer>
|
||||||
---@field layersList MapGen.Layer[]
|
---@field layersList MapGen.Layer[]
|
||||||
@@ -250,7 +252,7 @@ end
|
|||||||
---@param groups? table<string, number>
|
---@param groups? table<string, number>
|
||||||
function MapGen:register2DPeaksFromFile(layerName, map, scale,zeroPos, category, groups)
|
function MapGen:register2DPeaksFromFile(layerName, map, scale,zeroPos, category, groups)
|
||||||
local modPath = core.get_modpath(core.get_current_modname())
|
local modPath = core.get_modpath(core.get_current_modname())
|
||||||
local peaks = Api.ff2luat(modPath .. '/textures/maps/' .. map)
|
local peaks = ff2luat(modPath .. '/textures/maps/' .. map)
|
||||||
|
|
||||||
local mapSize = peaks.size
|
local mapSize = peaks.size
|
||||||
peaks.size = nil
|
peaks.size = nil
|
||||||
@@ -901,10 +903,6 @@ function MapGen:run()
|
|||||||
self:initLayersTriangultaion()
|
self:initLayersTriangultaion()
|
||||||
|
|
||||||
MapGen.isRunning = true
|
MapGen.isRunning = true
|
||||||
|
|
||||||
for _, peak in ipairs(self.layersList[1].peaksList["landscape"]) do
|
|
||||||
print(tostring(peak))
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
return MapGen
|
return MapGen
|
||||||
|
|||||||
@@ -53,29 +53,37 @@ end
|
|||||||
---@param filepath string image in farbfeld format
|
---@param filepath string image in farbfeld format
|
||||||
---@param backgroundColor string? ColorString, will be ignored while processing image. Default: `#000000FF`
|
---@param backgroundColor string? ColorString, will be ignored while processing image. Default: `#000000FF`
|
||||||
---@return ColoredDotsTable
|
---@return ColoredDotsTable
|
||||||
function Api.ff2luat(filepath, backgroundColor)
|
local function ff2luat(filepath, backgroundColor)
|
||||||
local file = io.open(filepath, 'rb')
|
local file = io.open(filepath, 'rb')
|
||||||
if not file then error('Can\'t open 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
|
local ff = file:read('*a') -- binary!
|
||||||
|
file:close()
|
||||||
|
-- TODO: make it decompressing gzip format -> https://en.wikipedia.org/wiki/Gzip
|
||||||
|
-- I should skip 10 bytes in a beginning, read how many extra fields after it, skip them too, and skip last 8 bytes
|
||||||
|
-- (read wiki for information).
|
||||||
|
-- if filepath:sub(-3) == '.gz' then ff = core.decompress(ff, 'deflate') end
|
||||||
|
if not ff:sub(1,8) == 'farbfeld' then error('Not farbfeld image: ' .. dump(filepath)) end
|
||||||
|
|
||||||
if not backgroundColor then backgroundColor = '#000000FF' end
|
if not backgroundColor then backgroundColor = '#000000FF' end
|
||||||
--HACK: normalizing colorstring for future string comparison ('#000' -> '#000000FF')
|
--HACK: normalizing colorstring for future string comparison ('#000' -> '#000000FF')
|
||||||
backgroundColor = core.colorspec_to_colorstring(core.colorspec_to_table(backgroundColor))
|
backgroundColor = core.colorspec_to_colorstring(core.colorspec_to_table(backgroundColor))
|
||||||
|
|
||||||
---@type ColoredDotsTable
|
---@type ColoredDotsTable
|
||||||
local dots = { size = { w = uintb2num(file:read(4)), h = uintb2num(file:read(4)) } }
|
local dots = { size = { w = uintb2num(ff:sub(9,12)), h = uintb2num(ff:sub(13,16)) } }
|
||||||
|
|
||||||
|
local cursor
|
||||||
for i = 1,dots.size.h do
|
for i = 1,dots.size.h do
|
||||||
for j = 1,dots.size.w do
|
for j = 1,dots.size.w do
|
||||||
local color_t = {
|
cursor = 16 + ((i-1)*dots.size.w + j-1)*8 + 1
|
||||||
r = uint16ToUint8(uintb2num(file:read(2))),
|
local colorT = {
|
||||||
g = uint16ToUint8(uintb2num(file:read(2))),
|
r = uint16ToUint8(uintb2num(ff:sub(cursor, cursor+1))),
|
||||||
b = uint16ToUint8(uintb2num(file:read(2))),
|
g = uint16ToUint8(uintb2num(ff:sub(cursor+2,cursor+3))),
|
||||||
a = uint16ToUint8(uintb2num(file:read(2)))
|
b = uint16ToUint8(uintb2num(ff:sub(cursor+4,cursor+5))),
|
||||||
|
a = uint16ToUint8(uintb2num(ff:sub(cursor+6,cursor+7)))
|
||||||
}
|
}
|
||||||
|
|
||||||
---@type string @ColorString
|
---@type string @ColorString
|
||||||
local color = core.colorspec_to_colorstring(color_t)
|
local color = core.colorspec_to_colorstring(colorT)
|
||||||
|
|
||||||
if color ~= backgroundColor then
|
if color ~= backgroundColor then
|
||||||
if not dots[color] then
|
if not dots[color] then
|
||||||
@@ -87,7 +95,7 @@ function Api.ff2luat(filepath, backgroundColor)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
file:close()
|
|
||||||
|
|
||||||
return dots
|
return dots
|
||||||
end
|
end
|
||||||
|
|
||||||
|
return ff2luat
|
||||||
@@ -37,8 +37,6 @@ dofile(core.get_modpath('smc__api__table')..'/init.lua')
|
|||||||
-- TODO: пока что закоментировано, поскольку вызывает ошибку из-за global_step
|
-- TODO: пока что закоментировано, поскольку вызывает ошибку из-за global_step
|
||||||
-- Api loader
|
-- Api loader
|
||||||
-- dofile(core.get_modpath('smc__api__api_loader')..'/init.lua')
|
-- 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
|
---@type MapGen
|
||||||
local mapGenerator = dofile(core.get_modpath('smc__core__map_generator')..'/src/mapGenerator.lua')
|
local mapGenerator = dofile(core.get_modpath('smc__core__map_generator')..'/src/mapGenerator.lua')
|
||||||
|
|||||||
Reference in New Issue
Block a user