Move detail_texture into internal utility api

This commit is contained in:
Hugues Ross 2020-06-10 19:54:28 -04:00
parent ad9c5e77b0
commit 3d6ebe66c1
5 changed files with 21 additions and 17 deletions

View File

@ -1,3 +1,5 @@
local util = ...;
local biome_lookup = {}; local biome_lookup = {};
return { return {
@ -27,7 +29,7 @@ return {
local matches_height = (not biome.min_height or height >= biome.min_height) local matches_height = (not biome.min_height or height >= biome.min_height)
and (not biome.max_height or height <= biome.max_height); and (not biome.max_height or height <= biome.max_height);
if biome.name == name and matches_height then if biome.name == name and matches_height then
return cartographer.detail_texture(biome.textures, detail); return util.get_clamped(biome.textures, detail);
end end
end end

View File

@ -49,13 +49,14 @@ local marker_lookup = {};
local skin = loadfile(modpath .. "/skin_api.lua") (); local skin = loadfile(modpath .. "/skin_api.lua") ();
local gui = loadfile(modpath .. "/formspec.lua") (); local gui = loadfile(modpath .. "/formspec.lua") ();
local audio = loadfile(modpath .. "/audio.lua") (); local audio = loadfile(modpath .. "/audio.lua") ();
local util = loadfile(modpath .. "/util.lua") ();
local biomes = loadfile(modpath .. "/biome_api.lua") (); local biomes = loadfile(modpath .. "/biome_api.lua") (util);
local scanner = loadfile(modpath .. "/scanner.lua") (map_data, chunk); local scanner = loadfile(modpath .. "/scanner.lua") (map_data, chunk);
local maps = loadfile(modpath .. "/map_api.lua") (map_data, chunk, scanner); local maps = loadfile(modpath .. "/map_api.lua") (map_data, chunk, scanner);
local markers = loadfile(modpath .. "/marker_api.lua") (marker_lookup); local markers = loadfile(modpath .. "/marker_api.lua") (marker_lookup);
local map_formspec = loadfile(modpath .. "/map_formspec.lua") (map_data, gui, skin, biomes, markers); local map_formspec = loadfile(modpath .. "/map_formspec.lua") (map_data, gui, skin, util, biomes, markers);
local map_item = loadfile(modpath .. "/items.lua") (chunk, marker_lookup, gui, skin, audio, maps, map_formspec); local map_item = loadfile(modpath .. "/items.lua") (chunk, marker_lookup, gui, skin, audio, maps, map_formspec);
loadfile(modpath .. "/commands.lua") (chunk, audio, map_formspec); loadfile(modpath .. "/commands.lua") (chunk, audio, map_formspec);
loadfile(modpath .. "/table.lua") (gui, skin, audio, maps, map_item); loadfile(modpath .. "/table.lua") (gui, skin, audio, maps, map_item);

View File

@ -144,13 +144,4 @@ local function fill_loop()
end end
minetest.after(5, fill_loop); minetest.after(5, fill_loop);
-- 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
return maps; return maps;

View File

@ -1,6 +1,6 @@
-- Arguments -- Arguments
-- map_data: The cartographer map data table -- map_data: The cartographer map data table
local map_data, gui, skin, biomes, markers = ...; local map_data, gui, skin, util, biomes, markers = ...;
-- Constants -- Constants
local TILE_SIZE = 0.25; local TILE_SIZE = 0.25;
@ -63,7 +63,7 @@ local function generate_map(x, y, w, h, player_x, player_y, detail, map_scale, h
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(..., i, j)) then if column == nil or column[j * map_scale] == nil or (is_visible and not is_visible(..., i, j)) then
local unknown_tex = cartographer.detail_texture(skin.unknown_biome_textures, detail); local unknown_tex = util.get_clamped(skin.unknown_biome_textures, detail);
str = str .. gui.image { str = str .. gui.image {
x = fx, x = fx,
y = fy, y = fy,
@ -93,7 +93,7 @@ local function generate_map(x, y, w, h, player_x, player_y, detail, map_scale, h
w = TILE_SIZE, w = TILE_SIZE,
h = height + 0.01, h = height + 0.01,
image = cartographer.detail_texture(skin.cliff_textures, detail) .. ".png", image = util.get_clamped(skin.cliff_textures, detail) .. ".png",
}; };
else else
height = 0; height = 0;
@ -126,7 +126,7 @@ local function generate_map(x, y, w, h, player_x, player_y, detail, map_scale, h
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(skin.player_icons, detail); local player_icon = util.get_clamped(skin.player_icons, detail);
str = str .. gui.animated_image { str = str .. gui.animated_image {
x = fx, x = fx,
y = fy - height, y = fy - height,
@ -137,7 +137,7 @@ local function generate_map(x, y, w, h, player_x, player_y, detail, map_scale, h
}; };
end end
else else
local unknown_tex = cartographer.detail_texture(skin.unknown_biome_textures, detail); local unknown_tex = util.get_clamped(skin.unknown_biome_textures, detail);
str = str .. gui.image { str = str .. gui.image {
x = fx, x = fx,
y = fy, y = fy,

10
util.lua Normal file
View File

@ -0,0 +1,10 @@
return {
-- 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
get_clamped = function(textures, detail)
return textures[math.min(detail, #textures)];
end
};