From 8642fbfa1baf651184d992f107f8eb755e2e9336 Mon Sep 17 00:00:00 2001 From: Hugues Ross Date: Sat, 18 Apr 2020 09:15:13 -0400 Subject: [PATCH] Add detail texture support for map skin data --- map_api.lua | 13 ++++++-- map_formspec.lua | 22 +++++++++----- skin_api.lua | 30 +++++++++++++------ textures/cartographer_cliff.png | Bin 963 -> 963 bytes textures/cartographer_player_icon.png | Bin 1045 -> 1034 bytes textures/cartographer_simple_cliff.png | Bin 0 -> 961 bytes textures/cartographer_simple_player_icon.png | Bin 0 -> 1045 bytes 7 files changed, 46 insertions(+), 19 deletions(-) create mode 100644 textures/cartographer_simple_cliff.png create mode 100644 textures/cartographer_simple_player_icon.png diff --git a/map_api.lua b/map_api.lua index 26afb0c..eed8018 100644 --- a/map_api.lua +++ b/map_api.lua @@ -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 diff --git a/map_formspec.lua b/map_formspec.lua index c526829..c4ec079 100644 --- a/map_formspec.lua +++ b/map_formspec.lua @@ -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 diff --git a/skin_api.lua b/skin_api.lua index 3697b9b..2adb5b0 100644 --- a/skin_api.lua +++ b/skin_api.lua @@ -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", }; diff --git a/textures/cartographer_cliff.png b/textures/cartographer_cliff.png index d51c447239d704768957071667c5e34e1bdeacb7..281bb4d15383007bb3a31f1ae9ba75d8e3403290 100644 GIT binary patch delta 23 fcmX@iewclN4)fgf#EtsDm{|I^U%fY3mw6fhaz+X3 delta 23 fcmX@iewclN4s&OA@kae$Of2CW{AWzoWu68AYs(1Y diff --git a/textures/cartographer_player_icon.png b/textures/cartographer_player_icon.png index 81b22d989047060962a96d09aa178f282b99bff8..fbeee595b7a81dd5c9b24cbe23a5a91066e0bbfb 100644 GIT binary patch delta 125 zcmV-@0D}LO2#N@hH3PwAJ+VRG0+CP&lOO{L1cT&d=#wo2e_lyRL_t(2k-d&V4geqs z!({(|v=RfNjYr*yjTF|}OG&%8q0`qyZp?HKfbb~aev!NfimqyNt4tI_P)Wz8vbW$s fa1?J@jMa-eZ;$|qt=h@T00000NkvXXu0mjfpd&Ry delta 132 zcmV-~0DJ$62$cwsHL*e80+CP*lOO{L1j!&sN0TiBe`!=nL_t(2k+o037Qi3~QuzOW z&YC$FZ^t+lf}q(=0G}^Cz()8&)5kbO_$S1oOC|Oac!bU#Z!kTvRdY(B$|Fa0Ub*o| mSl)aIAr@UKv06;3_u~e&Pyp#jvfKOs00005OHbuu!p5~B}-iB#Efy#IfP^hV^J7%LbmNn zg5@0sy2Vulb68=Fb68=OwB)dbg-#1Oq-BvQSjZuV6#_1Fv0Ft+=?H({ONtbPZ+`Fn z-+Rpazwi6Lotm5&KK#*P0Ki~))4(B2eSR)~)4owTZ-8I~LC6WX z402yoz)*>;|MW8Yj~}jNM@sV4uGpXuDgr_7i-uq*7`@Y;5P;AivJeJ@1yMmxEy<8e zVqYX7bhV?jG8vC25{XnQmCxsk#iC_d<#O3|-Fm&=Y&P5NcBj+ncDsYYfTRwXfCIRI z2eg0?=N) zKrg^F;9P<$;H{vwhHw+T9hDSPW0YoOaMxz!GV&P(kcMP-DnJcr0Bzt2&{u{uY8j@B zG#uJhx()gp43NvgG~qaKU3eZ^ErcO@J^6Q&QJGPd^cc0t4!JFFP2@0UBI6+M!tgND z!le-9o~)NvW7?z9q}^tTUW>2Adp( zo`RKA6{(w8x6pCWlWibCnVyxs^sMcrr{i-wU;+9p=F7PD9d6yngCFtJWBjp${<9CC z|9Rr?=Myhq%)Wm0^|9$=P8T+ zUOZY_`v0QrG26CfFG+s7wX`br(Z&3Q#px>-7r!bkSeRHSUHtmvRe$=j+&VqKF!_ZX z52j8kes)H2YF2UXisIGlir?H+yme1;^?Su1epdV?RQ$cG_;k>&|8-Z+h704lb0c@= b=SDvG6*v&bflq#Wp)NxqKRLd3YEHZbxKNn} literal 0 HcmV?d00001 diff --git a/textures/cartographer_simple_player_icon.png b/textures/cartographer_simple_player_icon.png new file mode 100644 index 0000000000000000000000000000000000000000..81b22d989047060962a96d09aa178f282b99bff8 GIT binary patch literal 1045 zcmeAS@N?(olHy`uVBq!ia0vp^0zj<5!3-pI!a4piFfcO&_=LE=KD*lAKD|G;clX?t zK&eqM8UiCB1afn8SFKw0|NsA!3Lfr24>Oho`2{mLJiCzw05KxnVzu zJa8UFUbqh;AH3f+>)mW1E5y^qF+^kHR{w)y2NXDhe*CXLH_K8y|G0%{(}J764Dkf^ZVWB+kb%OGkCiCxvX