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;
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.
-- name: A string containing the biome name
-- 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.
function cartographer.get_biome_texture(name, height, detail)
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
return biome.textures[math.min(detail, #biome.textures)];
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 cartographer.detail_texture(biome.textures, detail);
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
-- x: The x position of the tile
-- y: The y position of the tile
-- detail: The detail level
-- variant: The tile variant
--
-- Returns a formspec string
local function unknown_biome_tile(x, y, variant)
return tile:format(x, y, TILE_SIZE, TILE_SIZE, cartographer.skin.unknown_biome_texture .. "." .. tostring(variant) .. ".png");
local function unknown_biome_tile(x, y, detail, variant)
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
-- 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
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
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
local name = minetest.get_biome_name(column[j * map_scale].biome);
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)
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
mod = "^[colorize:#1f1f34:"..tostring(depth * 10)
end
@ -100,14 +105,15 @@ local function generate_map(data, x, y, w, h, player_x, player_y, detail, map_sc
end
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,
TILE_SIZE, TILE_SIZE,
cartographer.skin.player_icon.texture .. ".png",
cartographer.skin.player_icon.frame_count,
cartographer.skin.player_icon.frame_duration);
player_icon.texture .. ".png",
player_icon.frame_count,
player_icon.frame_duration);
end
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

View File

@ -1,13 +1,28 @@
-- Table used for skinning cartographer's look and feel
cartographer.skin = {
-- The texture to use in maps for the sides of tiles
cliff_texture = "cartographer_cliff",
-- The textures to use in maps for the sides of tiles
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
player_icon = {
frame_count = 2,
frame_duration = 500,
texture = "cartographer_player_icon",
player_icons = {
{
frame_count = 2,
frame_duration = 500,
texture = "cartographer_simple_player_icon",
},
{
frame_count = 2,
frame_duration = 500,
texture = "cartographer_player_icon",
},
},
-- The skinning data for the cartographer's tables
@ -147,7 +162,4 @@ cartographer.skin = {
pressed_texture = "cartographer_simple_table_button_pressed",
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