Add fallback texture support in case of scanned-but-unknown biomes

This commit is contained in:
Hugues Ross 2022-03-16 08:06:29 -04:00
parent 8bc95500ee
commit e379b3ea66
8 changed files with 82 additions and 62 deletions

View File

@ -1,8 +1,14 @@
-- Arguments
-- util: API for uncategorized utility methods
local util = ...;
local util,skin = ...
local biome_lookup = {};
local biome_lookup = {}
local fallback_biome_lookup = {}
local function match_biome_metrics (biome, height)
return (not biome.min_height or height >= biome.min_height)
and (not biome.max_height or height <= biome.max_height)
end
-- Contains functions for registering and getting biome-related mapping information
return {
@ -20,7 +26,22 @@ return {
textures = textures,
min_height = min_height,
max_height = max_height,
};
}
end,
-- Register fallback biome textures to use when a biome hasn't been registered
--
-- textures: A table of texture names.
-- These should correspond with detail levels,
-- any detail level past the length of the table will return the last texture
-- (Optional) min_height: The minimum Y position where these textures should be used
-- (Optional) max_height: The maximum Y position where these textures should be used
add_fallback = function (textures, min_height, max_height)
table.insert(fallback_biome_lookup, {
textures = textures,
min_height = min_height,
max_height = max_height,
})
end,
-- Get the texture name (minus index/extension) for the given biome, height, and detail level.
@ -29,16 +50,22 @@ return {
-- height: A number representing the Y position of the biome
-- detail: The detail level
--
-- Returns a string with a texture name, or nil if no matching biome entry was found.
-- Always returns a string with a texture name, if the biome is unregistered it will fallback to other options
get_texture = function (name, height, detail)
for _,biome in ipairs(biome_lookup) do
local matches_height = (not biome.min_height or height >= biome.min_height)
and (not biome.max_height or height <= biome.max_height);
if biome.name == name and matches_height then
return util.get_clamped(biome.textures, detail);
if biome.name == name and match_biome_metrics (biome, height) then
return util.get_clamped(biome.textures, detail)
end
end
return nil;
-- Fallback on matching default biomes
for _,biome in ipairs(fallback_biome_lookup) do
if match_biome_metrics (biome, height) then
return util.get_clamped(biome.textures, detail)
end
end
-- If we don't have any registered defaults, fallback to a texture
return util.get_clamped(skin.default_biome_textures, detail)
end,
};
}

View File

@ -16,7 +16,7 @@ local gui = loadfile(modpath .. "/formspec.lua") ();
local skin = loadfile(modpath .. "/skin_api.lua") ();
local util = loadfile(modpath .. "/util.lua") ();
local audio = loadfile(modpath .. "/audio.lua") ();
local biomes = loadfile(modpath .. "/biome_api.lua") (util);
local biomes = loadfile(modpath .. "/biome_api.lua") (util, skin);
local markers = loadfile(modpath .. "/marker_api.lua") ();
local scanner = loadfile(modpath .. "/scanner.lua") (map_data, chunk, settings);
local maps = loadfile(modpath .. "/map_api.lua") (map_data, chunk);

View File

@ -86,74 +86,62 @@ local function generate_map(x, y, w, h, player_x, player_y, detail, map_scale, h
local height = column[world_j].height;
local biome = biomes.get_texture(name, math.floor(height + 0.5), detail);
if biome then
local depth = math.min(math.max(math.floor(height / 8), -8), 0) * -1
height = math.max(math.min(math.floor(height / (math.max(map_scale * 0.5, 1) + 4)), 8), 0)
local depth = math.min(math.max(math.floor(height / 8), -8), 0) * -1
height = math.max(math.min(math.floor(height / (math.max(map_scale * 0.5, 1) + 4)), 8), 0)
local mod = "";
if height > 0 then
mod = "^[colorize:white:"..tostring(height * 10)
height = height * 0.05;
local mod = "";
if height > 0 then
mod = "^[colorize:white:"..tostring(height * 10)
height = height * 0.05;
if height_mode then
str = str .. gui.image {
x = fx,
y = fy - height + TILE_OFFSET,
w = TILE_SIZE,
h = height + 0.01,
if height_mode then
str = str .. gui.image {
x = fx,
y = fy - height + TILE_OFFSET,
w = TILE_SIZE,
h = height + 0.01,
image = util.get_clamped(skin.cliff_textures, detail) .. ".png",
};
else
height = 0;
end
elseif depth > 0 then
mod = "^[colorize:#1f1f34:"..tostring(depth * 10)
image = util.get_clamped(skin.cliff_textures, detail) .. ".png",
};
else
height = 0;
end
elseif depth > 0 then
mod = "^[colorize:#1f1f34:"..tostring(depth * 10)
end
str = str .. gui.image {
x = fx,
y = fy - height,
w = TILE_SIZE,
h = TILE_SIZE,
str = str .. gui.image {
x = fx,
y = fy - height,
w = TILE_SIZE,
h = TILE_SIZE,
image = get_variant(biome, i, j, noise) .. mod,
};
image = get_variant(biome, i, j, noise) .. mod,
};
if get_marker then
local marker = markers.get_texture(get_marker(..., i, j), detail);
if marker then
str = str .. gui.image {
x = fx,
y = fy - height,
w = TILE_SIZE,
h = TILE_SIZE,
image = marker .. ".png",
};
end
end
if i == player_x and j == player_y then
local player_icon = util.get_clamped(skin.player_icons, detail);
str = str .. gui.animated_image {
if get_marker then
local marker = markers.get_texture(get_marker(..., i, j), detail);
if marker then
str = str .. gui.image {
x = fx,
y = fy - height,
w = TILE_SIZE,
h = TILE_SIZE,
animation = player_icon,
image = marker .. ".png",
};
end
else
local unknown_tex = util.get_clamped(skin.unknown_biome_textures, detail);
str = str .. gui.image {
end
if i == player_x and j == player_y then
local player_icon = util.get_clamped(skin.player_icons, detail);
str = str .. gui.animated_image {
x = fx,
y = fy,
y = fy - height,
w = TILE_SIZE,
h = TILE_SIZE,
image = get_variant(unknown_tex, i, j, noise),
animation = player_icon,
};
end
end

View File

@ -6,11 +6,16 @@ return {
"cartographer_cliff",
};
-- The textures to use in maps for uncovered/unknown tiles
-- The textures to use in maps for undiscovered tiles
unknown_biome_textures = {
"cartographer_unknown_biome",
};
-- The textures to use in maps for tiles with no associated biome
default_biome_textures = {
"cartographer_default_biome",
};
-- The animated texture data to use for the player icon
player_icons = {
{

Binary file not shown.

After

Width:  |  Height:  |  Size: 963 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 963 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 963 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 963 B