From 89b072a70059fa18b43ac4befeec6cc4b3a1ed19 Mon Sep 17 00:00:00 2001 From: BuckarooBanzay Date: Fri, 18 Oct 2024 09:24:58 +0200 Subject: [PATCH] generate preview image if the `isogen` mod is available --- .luacheckrc | 5 ++++- create_catalog.lua | 23 ++++++++++++++++++++++- mod.conf | 2 +- 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/.luacheckrc b/.luacheckrc index 91b97d7..66ef39c 100644 --- a/.luacheckrc +++ b/.luacheckrc @@ -16,7 +16,10 @@ read_globals = { "VoxelArea", -- mods - "monitoring", "mtzip", "placeholder", + "monitoring", + "mtzip", + "placeholder", + "isogen", -- testing "mineunit", diff --git a/create_catalog.lua b/create_catalog.lua index 8267068..0a3c872 100644 --- a/create_catalog.lua +++ b/create_catalog.lua @@ -2,6 +2,8 @@ -- Create catalog function local global_env = ... +local has_isogen = minetest.get_modpath("isogen") + ------ -- Serialize options -- @number delay for async mode: delay between serialization-calls @@ -28,6 +30,7 @@ function mapblock_lib.create_catalog(filename, pos1, pos2, options) options.delay = options.delay or 0.1 options.callback = options.callback or function() end options.progress_callback = options.progress_callback or function() end + options.iso_cube_len = 8 pos1, pos2 = mapblock_lib.sort_pos(pos1, pos2) local start = minetest.get_us_time() @@ -49,7 +52,25 @@ function mapblock_lib.create_catalog(filename, pos1, pos2, options) options.progress_callback(count / total_count) minetest.after(options.delay, worker) else - -- done, write global manifest + -- done, generate preview and write global manifest + + if has_isogen then + -- isogen in modpath, generate isometric preview and metadata + local min = mapblock_lib.get_mapblock_bounds_from_mapblock(pos1) + local _, max = mapblock_lib.get_mapblock_bounds_from_mapblock(pos2) + + local png = isogen.draw(min, max, { cube_len = options.iso_cube_len }) + z:add("preview.png", png) + + local size = vector.add(vector.subtract(max, min), 1) + local width, height = isogen.calculate_image_size(size, options.iso_cube_len) + local preview_metadata = { + width = width, + height = height + } + z:add("preview.json", minetest.write_json(preview_metadata)) + end + local manifest = { range = vector.subtract(pos2, pos1), version = mapblock_lib.version diff --git a/mod.conf b/mod.conf index e802c30..d35d11f 100644 --- a/mod.conf +++ b/mod.conf @@ -1,5 +1,5 @@ name = mapblock_lib description = mapblock serialization functions -optional_depends = worldedit, monitoring, mtt, placeholder +optional_depends = worldedit, monitoring, mtt, placeholder, isogen depends = mtzip min_protocol = 37