Add fallback texture support in case of scanned-but-unknown biomes
This commit is contained in:
parent
8bc95500ee
commit
e379b3ea66
@ -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,
|
||||
};
|
||||
}
|
||||
|
2
init.lua
2
init.lua
@ -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);
|
||||
|
@ -86,7 +86,6 @@ 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)
|
||||
|
||||
@ -145,17 +144,6 @@ local function generate_map(x, y, w, h, player_x, player_y, detail, map_scale, h
|
||||
animation = player_icon,
|
||||
};
|
||||
end
|
||||
else
|
||||
local unknown_tex = util.get_clamped(skin.unknown_biome_textures, detail);
|
||||
str = str .. gui.image {
|
||||
x = fx,
|
||||
y = fy,
|
||||
w = TILE_SIZE,
|
||||
h = TILE_SIZE,
|
||||
|
||||
image = get_variant(unknown_tex, i, j, noise),
|
||||
};
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -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 = {
|
||||
{
|
||||
|
BIN
textures/cartographer_default_biome.1.png
Normal file
BIN
textures/cartographer_default_biome.1.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 963 B |
BIN
textures/cartographer_default_biome.2.png
Normal file
BIN
textures/cartographer_default_biome.2.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 963 B |
BIN
textures/cartographer_default_biome.3.png
Normal file
BIN
textures/cartographer_default_biome.3.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 963 B |
BIN
textures/cartographer_default_biome.4.png
Normal file
BIN
textures/cartographer_default_biome.4.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 963 B |
Loading…
x
Reference in New Issue
Block a user