Skip to content

Commit

Permalink
generate preview image if the isogen mod is available
Browse files Browse the repository at this point in the history
  • Loading branch information
BuckarooBanzay committed Oct 18, 2024
1 parent 5f603a3 commit 89b072a
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
5 changes: 4 additions & 1 deletion .luacheckrc
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ read_globals = {
"VoxelArea",

-- mods
"monitoring", "mtzip", "placeholder",
"monitoring",
"mtzip",
"placeholder",
"isogen",

-- testing
"mineunit",
Expand Down
23 changes: 22 additions & 1 deletion create_catalog.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion mod.conf
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 89b072a

Please sign in to comment.