Add detail texture support for map skin data

This commit is contained in:
Hugues Ross 2020-04-18 09:15:13 -04:00
parent 62ace2394b
commit 8642fbfa1b
7 changed files with 46 additions and 19 deletions

View File

@ -215,6 +215,15 @@ function cartographer.is_filled(map, x, z)
return map.fill[(x - map.x) + ((z - map.z) * map.w)] ~= nil; return map.fill[(x - map.x) + ((z - map.z) * map.w)] ~= nil;
end end
-- Get an entry from a list for a given detail level
-- textures: An array of textures
-- detail: The detail level
--
-- Returns the entry at detail, or the last entry if detail is out-of-bounds
function cartographer.detail_texture(textures, detail)
return textures[math.min(detail, #textures)];
end
-- Get the texture name (minus index/extension) for the given biome, height, and detail level. -- Get the texture name (minus index/extension) for the given biome, height, and detail level.
-- name: A string containing the biome name -- name: A string containing the biome name
-- height: A number representing the Y position of the biome -- height: A number representing the Y position of the biome
@ -222,8 +231,8 @@ end
-- Returns a string with a texture name, or nil if no matching biome entry was found. -- Returns a string with a texture name, or nil if no matching biome entry was found.
function cartographer.get_biome_texture(name, height, detail) function cartographer.get_biome_texture(name, height, detail)
for _,biome in ipairs(_cartographer.biome_lookup) do for _,biome in ipairs(_cartographer.biome_lookup) do
if biome.name == name and (biome.min_height == nil or height >= biome.min_height) and (biome.max_height == nil or height <= biome.max_height) then if biome.name == name and (not biome.min_height or height >= biome.min_height) and (not biome.max_height or height <= biome.max_height) then
return biome.textures[math.min(detail, #biome.textures)]; return cartographer.detail_texture(biome.textures, detail);
end end
end end

View File

@ -36,11 +36,16 @@ local marker = "animated_image[%f,%f;%f,%f;;%s;%d;%d]";
-- Generate formspec markup for an unknown biome tile -- Generate formspec markup for an unknown biome tile
-- x: The x position of the tile -- x: The x position of the tile
-- y: The y position of the tile -- y: The y position of the tile
-- detail: The detail level
-- variant: The tile variant -- variant: The tile variant
-- --
-- Returns a formspec string -- Returns a formspec string
local function unknown_biome_tile(x, y, variant) local function unknown_biome_tile(x, y, detail, variant)
return tile:format(x, y, TILE_SIZE, TILE_SIZE, cartographer.skin.unknown_biome_texture .. "." .. tostring(variant) .. ".png"); return string.format("image[%f,%f;%f,%f;%s.%s.png]",
x, y,
TILE_SIZE, TILE_SIZE,
cartographer.detail_texture(cartographer.skin.unknown_biome_textures, detail),
variant);
end end
-- Generate formspec markup for a given map -- Generate formspec markup for a given map
@ -70,7 +75,7 @@ local function generate_map(data, x, y, w, h, player_x, player_y, detail, map_sc
for j = y + h,y,-1 do for j = y + h,y,-1 do
local fy = (y + h - j) * TILE_OFFSET; local fy = (y + h - j) * TILE_OFFSET;
if column == nil or column[j * map_scale] == nil or (is_visible and not is_visible(user, i, j)) then if column == nil or column[j * map_scale] == nil or (is_visible and not is_visible(user, i, j)) then
str = str .. unknown_biome_tile(fx, fy, get_variant(i - x, j - y, noise)); str = str .. unknown_biome_tile(fx, fy, detail, get_variant(i - x, j - y, noise));
else else
local name = minetest.get_biome_name(column[j * map_scale].biome); local name = minetest.get_biome_name(column[j * map_scale].biome);
local height = column[j * map_scale].height; local height = column[j * map_scale].height;
@ -85,7 +90,7 @@ local function generate_map(data, x, y, w, h, player_x, player_y, detail, map_sc
mod = "^[colorize:white:"..tostring(height * 10) mod = "^[colorize:white:"..tostring(height * 10)
height = height * 0.05; height = height * 0.05;
str = str..tile:format(fx, fy - height + TILE_OFFSET, TILE_SIZE, height + 0.01, cartographer.skin.cliff_texture .. ".png"); str = str .. tile:format(fx, fy - height + TILE_OFFSET, TILE_SIZE, height + 0.01, cartographer.detail_texture(cartographer.skin.cliff_textures, detail) .. ".png");
elseif depth > 0 then elseif depth > 0 then
mod = "^[colorize:#1f1f34:"..tostring(depth * 10) mod = "^[colorize:#1f1f34:"..tostring(depth * 10)
end end
@ -100,14 +105,15 @@ local function generate_map(data, x, y, w, h, player_x, player_y, detail, map_sc
end end
if i == player_x and j == player_y then if i == player_x and j == player_y then
local player_icon = cartographer.detail_texture(cartographer.skin.player_icons, detail);
str = str..marker:format(fx, fy - height, str = str..marker:format(fx, fy - height,
TILE_SIZE, TILE_SIZE, TILE_SIZE, TILE_SIZE,
cartographer.skin.player_icon.texture .. ".png", player_icon.texture .. ".png",
cartographer.skin.player_icon.frame_count, player_icon.frame_count,
cartographer.skin.player_icon.frame_duration); player_icon.frame_duration);
end end
else else
str = str .. unknown_biome_tile(fx, fy, get_variant(i - x, j - y, noise)); str = str .. unknown_biome_tile(fx, fy, detail, get_variant(i - x, j - y, noise));
end end
end end
end end

View File

@ -1,14 +1,29 @@
-- Table used for skinning cartographer's look and feel -- Table used for skinning cartographer's look and feel
cartographer.skin = { cartographer.skin = {
-- The texture to use in maps for the sides of tiles -- The textures to use in maps for the sides of tiles
cliff_texture = "cartographer_cliff", cliff_textures = {
"cartographer_simple_cliff",
"cartographer_cliff",
};
-- The textures to use in maps for uncovered/unknown tiles
unknown_biome_textures = {
"cartographer_unknown_biome",
};
-- The animated texture data to use for the player icon -- The animated texture data to use for the player icon
player_icon = { player_icons = {
{
frame_count = 2,
frame_duration = 500,
texture = "cartographer_simple_player_icon",
},
{
frame_count = 2, frame_count = 2,
frame_duration = 500, frame_duration = 500,
texture = "cartographer_player_icon", texture = "cartographer_player_icon",
}, },
},
-- The skinning data for the cartographer's tables -- The skinning data for the cartographer's tables
table_skins = { table_skins = {
@ -147,7 +162,4 @@ cartographer.skin = {
pressed_texture = "cartographer_simple_table_button_pressed", pressed_texture = "cartographer_simple_table_button_pressed",
radius = 8, radius = 8,
}, },
-- The texture to use in maps when biome data is missing or empty
unknown_biome_texture = "cartographer_unknown_biome",
}; };

Binary file not shown.

Before

Width:  |  Height:  |  Size: 963 B

After

Width:  |  Height:  |  Size: 963 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.0 KiB

After

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 961 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB