diff --git a/biome_api.lua b/biome_api.lua index ef2697f..739f877 100644 --- a/biome_api.lua +++ b/biome_api.lua @@ -1,3 +1,5 @@ +local util = ...; + local biome_lookup = {}; return { @@ -27,7 +29,7 @@ return { 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 cartographer.detail_texture(biome.textures, detail); + return util.get_clamped(biome.textures, detail); end end diff --git a/init.lua b/init.lua index c532b55..76a0b48 100644 --- a/init.lua +++ b/init.lua @@ -49,13 +49,14 @@ local marker_lookup = {}; local skin = loadfile(modpath .. "/skin_api.lua") (); local gui = loadfile(modpath .. "/formspec.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 maps = loadfile(modpath .. "/map_api.lua") (map_data, chunk, scanner); 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); loadfile(modpath .. "/commands.lua") (chunk, audio, map_formspec); loadfile(modpath .. "/table.lua") (gui, skin, audio, maps, map_item); diff --git a/map_api.lua b/map_api.lua index 59401a1..b45f69f 100644 --- a/map_api.lua +++ b/map_api.lua @@ -144,13 +144,4 @@ local function fill_loop() end 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; diff --git a/map_formspec.lua b/map_formspec.lua index c4c2053..b8b2ccf 100644 --- a/map_formspec.lua +++ b/map_formspec.lua @@ -1,6 +1,6 @@ -- Arguments -- map_data: The cartographer map data table -local map_data, gui, skin, biomes, markers = ...; +local map_data, gui, skin, util, biomes, markers = ...; -- Constants 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 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 - 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 { x = fx, 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, h = height + 0.01, - image = cartographer.detail_texture(skin.cliff_textures, detail) .. ".png", + image = util.get_clamped(skin.cliff_textures, detail) .. ".png", }; else height = 0; @@ -126,7 +126,7 @@ local function generate_map(x, y, w, h, player_x, player_y, detail, map_scale, h end 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 { x = fx, y = fy - height, @@ -137,7 +137,7 @@ local function generate_map(x, y, w, h, player_x, player_y, detail, map_scale, h }; end 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 { x = fx, y = fy, diff --git a/util.lua b/util.lua new file mode 100644 index 0000000..c760a07 --- /dev/null +++ b/util.lua @@ -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 +};