From b7a5f69dc079fc3d2ebc3b3e5fa7bcd65f63bb71 Mon Sep 17 00:00:00 2001 From: Nils Dagsson Moskopp Date: Fri, 20 May 2022 20:53:41 +0200 Subject: [PATCH] =?UTF-8?q?Change=20name=20from=20=E2=80=9Cmaps=E2=80=9D?= =?UTF-8?q?=20to=20=E2=80=9Cxmaps=E2=80=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 10 +- generate_textures.lua | 8 +- init.lua | 174 +++++++++--------- mod.conf | 2 +- textures/{maps_arrow.tga => xmaps_arrow.tga} | Bin ..._diagonal.tga => xmaps_arrow_diagonal.tga} | Bin ...maps_dot_large.tga => xmaps_dot_large.tga} | Bin ...maps_dot_small.tga => xmaps_dot_small.tga} | Bin textures/{maps_map.tga => xmaps_map.tga} | Bin textures/{maps_x.tga => xmaps_x.tga} | Bin 10 files changed, 97 insertions(+), 97 deletions(-) rename textures/{maps_arrow.tga => xmaps_arrow.tga} (100%) rename textures/{maps_arrow_diagonal.tga => xmaps_arrow_diagonal.tga} (100%) rename textures/{maps_dot_large.tga => xmaps_dot_large.tga} (100%) rename textures/{maps_dot_small.tga => xmaps_dot_small.tga} (100%) rename textures/{maps_map.tga => xmaps_map.tga} (100%) rename textures/{maps_x.tga => xmaps_x.tga} (100%) diff --git a/README.md b/README.md index ddf3ac5..494139b 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Maps +# X Maps This mod adds map items that show terrain in HUD. @@ -14,17 +14,17 @@ If you target a node, its position shows as a red X on a map. With the X players can share coordinates or have treasure hunts. -## Maps API +## X Maps API -You can use `maps.create_map_item()` to create a treasure map: +You can use `xmaps.create_map_item()` to create a treasure map: ``` -local itemstack = maps.create_map_item(pos, { draw_x = true }) +local itemstack = xmaps.create_map_item(pos, { draw_x = true }) ``` ## Notes -`maps` is similar to `mcl_maps`, which is part of MineClone2. +`xmaps` is similar to `mcl_maps`, which is part of MineClone2. All map items have a colormapped TGA file in their item meta. diff --git a/generate_textures.lua b/generate_textures.lua index e201d0d..4007428 100644 --- a/generate_textures.lua +++ b/generate_textures.lua @@ -13,7 +13,7 @@ local pixels = { { _, _, K, W, K, _, _ }, { _, _, _, K, _, _, _ }, } -tga_encoder.image(pixels):save("textures/maps_arrow.tga") +tga_encoder.image(pixels):save("textures/xmaps_arrow.tga") local pixels = { { _, _, _, _, K, _, _ }, @@ -24,7 +24,7 @@ local pixels = { { K, W, W, W, W, K, _ }, { K, K, K, K, K, K, _ }, } -tga_encoder.image(pixels):save("textures/maps_arrow_diagonal.tga") +tga_encoder.image(pixels):save("textures/xmaps_arrow_diagonal.tga") local pixels = { { _, _, K, K, K, _, _ }, @@ -35,7 +35,7 @@ local pixels = { { _, K, W, W, W, K, _ }, { _, _, K, K, K, _, _ }, } -tga_encoder.image(pixels):save("textures/maps_dot_large.tga") +tga_encoder.image(pixels):save("textures/xmaps_dot_large.tga") local pixels = { { _, _, _, _, _, _, _ }, @@ -46,4 +46,4 @@ local pixels = { { _, _, K, K, K, _, _ }, { _, _, _, _, _, _, _ }, } -tga_encoder.image(pixels):save("textures/maps_dot_small.tga") +tga_encoder.image(pixels):save("textures/xmaps_dot_small.tga") diff --git a/init.lua b/init.lua index a3e8bca..a6b9df1 100644 --- a/init.lua +++ b/init.lua @@ -1,6 +1,6 @@ --[[ -maps – Minetest mod that adds map items that show terrain in HUD +xmaps – Minetest mod that adds map items that show terrain in HUD Copyright © 2022 Nils Dagsson Moskopp (erlehmann) This program is free software: you can redistribute it and/or modify @@ -46,51 +46,51 @@ function tga_encoder.image:blit_icon(icon, pos, stop_colors) end end -maps = {} +xmaps = {} -maps.dark = {} -- key: player name; value: is it dark? -maps.huds = {} -- key: player name; value: player huds -maps.maps = {} -- key: player name; value: map texture -maps.mark = {} -- key: player name; value: marker texture -maps.marx = {} -- key: player name; value: marker x offset -maps.mary = {} -- key: player name; value: marker y offset +xmaps.dark = {} -- key: player name; value: is it dark? +xmaps.huds = {} -- key: player name; value: player huds +xmaps.maps = {} -- key: player name; value: map texture +xmaps.mark = {} -- key: player name; value: marker texture +xmaps.marx = {} -- key: player name; value: marker x offset +xmaps.mary = {} -- key: player name; value: marker y offset -maps.load = {} -- maps loaded by players -maps.sent = {} -- maps sent to players -maps.work = {} -- maps being created +xmaps.load = {} -- maps loaded by players +xmaps.sent = {} -- maps sent to players +xmaps.work = {} -- maps being created local size = 80 local worldpath = minetest.get_worldpath() -local textures_dir = worldpath .. "/maps/" +local textures_dir = worldpath .. "/xmaps/" minetest.mkdir(textures_dir) -maps.get_map_filename = function(map_id) - return "maps_map_texture_" .. map_id .. ".tga" +xmaps.get_map_filename = function(map_id) + return "xmaps_map_texture_" .. map_id .. ".tga" end -maps.create_map_item = function(pos, properties) +xmaps.create_map_item = function(pos, properties) properties = properties or {} - local itemstack = ItemStack("maps:map") + local itemstack = ItemStack("xmaps:map") local meta = itemstack:get_meta() local map_id = tostring(os.time() + math.random()) - meta:set_string("maps:id", map_id) + meta:set_string("xmaps:id", map_id) local minp = vector.multiply(vector.floor(vector.divide(pos, size)), size) - meta:set_string("maps:minp", minetest.pos_to_string(minp)) + meta:set_string("xmaps:minp", minetest.pos_to_string(minp)) local maxp = vector.add(minp, vector.new(size - 1, size - 1, size - 1)) - meta:set_string("maps:maxp", minetest.pos_to_string(maxp)) + meta:set_string("xmaps:maxp", minetest.pos_to_string(maxp)) if properties.draw_x then local xpos = vector.round(pos) - meta:set_string("maps:xpos", minetest.pos_to_string(xpos)) + meta:set_string("xmaps:xpos", minetest.pos_to_string(xpos)) end - local filename = maps.get_map_filename(map_id) - maps.work[map_id] = true + local filename = xmaps.get_map_filename(map_id) + xmaps.work[map_id] = true local emerge_callback = function( blockpos, @@ -372,7 +372,7 @@ maps.create_map_item = function(pos, properties) filepath, { colormap=colormap } ) - maps.work[map_id] = false + xmaps.work[map_id] = false end minetest.emerge_area( @@ -383,18 +383,18 @@ maps.create_map_item = function(pos, properties) return itemstack end -maps.load_map = function(map_id) +xmaps.load_map = function(map_id) assert( nil ~= map_id ) if ( "" == map_id or - maps.work[map_id] + xmaps.work[map_id] ) then return end - local filename = maps.get_map_filename(map_id) + local filename = xmaps.get_map_filename(map_id) - if not maps.sent[map_id] then + if not xmaps.sent[map_id] then if not minetest.features.dynamic_add_media_table then -- minetest.dynamic_add_media() blocks in -- Minetest 5.3 and 5.4 until media loads @@ -402,26 +402,26 @@ maps.load_map = function(map_id) textures_dir .. filename, function() end ) - maps.load[map_id] = true + xmaps.load[map_id] = true else -- minetest.dynamic_add_media() never blocks -- in Minetest 5.5, callback runs after load minetest.dynamic_add_media( textures_dir .. filename, function() - maps.load[map_id] = true + xmaps.load[map_id] = true end ) end - maps.sent[map_id] = true + xmaps.sent[map_id] = true end - if maps.load[map_id] then + if xmaps.load[map_id] then return filename end end -maps.encode_map_item_meta = function(input) +xmaps.encode_map_item_meta = function(input) return minetest.encode_base64( minetest.compress( input, @@ -431,7 +431,7 @@ maps.encode_map_item_meta = function(input) ) end -maps.decode_map_item_meta = function(input) +xmaps.decode_map_item_meta = function(input) return minetest.decompress( minetest.decode_base64(input), "deflate", @@ -440,27 +440,27 @@ maps.decode_map_item_meta = function(input) end result_original = "foo\0\01\02\x03\n\rbar" -result_roundtrip = maps.decode_map_item_meta( - maps.encode_map_item_meta(result_original) +result_roundtrip = xmaps.decode_map_item_meta( + xmaps.encode_map_item_meta(result_original) ) assert( result_original == result_roundtrip, - "maps: mismatch between maps.encode_map_item_meta() and maps.decode_map_item_meta()" + "xmaps: mismatch between xmaps.encode_map_item_meta() and xmaps.decode_map_item_meta()" ) -maps.load_map_item = function(itemstack) +xmaps.load_map_item = function(itemstack) local meta = itemstack:get_meta() - local map_id = meta:get_string("maps:id") + local map_id = meta:get_string("xmaps:id") if ( not map_id or "" == map_id or - maps.work[map_id] + xmaps.work[map_id] ) then return end - local texture_file_name = maps.get_map_filename(map_id) + local texture_file_name = xmaps.get_map_filename(map_id) local texture_file_path = textures_dir .. texture_file_name -- does the texture file exist? @@ -478,7 +478,7 @@ maps.load_map_item = function(itemstack) end -- does the texture item meta exist? - local tga_deflate_base64 = meta:get_string("maps:tga_deflate_base64") + local tga_deflate_base64 = meta:get_string("xmaps:tga_deflate_base64") local texture_item_meta_exists = true if "" == tga_deflate_base64 then texture_item_meta_exists = false @@ -488,14 +488,14 @@ maps.load_map_item = function(itemstack) if texture_item_meta_exists then -- sanity check: do we have the same textures? -- if server-side texture has changed, take it - if maps.decode_map_item_meta(tga_deflate_base64) ~= texture_data_from_file then + if xmaps.decode_map_item_meta(tga_deflate_base64) ~= texture_data_from_file then minetest.log( "action", - "maps: update item meta from file content for map " .. map_id + "xmaps: update item meta from file content for map " .. map_id ) meta:set_string( - "maps:tga_deflate_base64", - maps.encode_map_item_meta(texture_data_from_file) + "xmaps:tga_deflate_base64", + xmaps.encode_map_item_meta(texture_data_from_file) ) end else @@ -503,11 +503,11 @@ maps.load_map_item = function(itemstack) -- we now write the file contents to item meta minetest.log( "action", - "maps: create item meta from file content for map " .. map_id + "xmaps: create item meta from file content for map " .. map_id ) meta:set_string( - "maps:tga_deflate_base64", - maps.encode_map_item_meta(texture_data_from_file) + "xmaps:tga_deflate_base64", + xmaps.encode_map_item_meta(texture_data_from_file) ) end else @@ -517,12 +517,12 @@ maps.load_map_item = function(itemstack) if texture_item_meta_exists then minetest.log( "action", - "maps: create file content from item meta for map " .. map_id + "xmaps: create file content from item meta for map " .. map_id ) assert( minetest.safe_file_write( texture_file_path, - maps.decode_map_item_meta(tga_deflate_base64) + xmaps.decode_map_item_meta(tga_deflate_base64) ) ) else @@ -534,7 +534,7 @@ maps.load_map_item = function(itemstack) end end - local texture = maps.load_map(map_id) + local texture = xmaps.load_map(map_id) return texture, itemstack end @@ -550,39 +550,39 @@ minetest.register_on_joinplayer( scale = { x = 4, y = 4 } } local pos_def = table.copy(map_def) - maps.huds[player_name] = { + xmaps.huds[player_name] = { map = player:hud_add(map_def), pos = player:hud_add(pos_def), } end ) -maps.show_map_hud = function(player) +xmaps.show_map_hud = function(player) local wield_item = player:get_wielded_item() - local texture, updated_wield_item = maps.load_map_item(wield_item) + local texture, updated_wield_item = xmaps.load_map_item(wield_item) local player_pos = player:get_pos() local player_name = player:get_player_name() if not player_pos or not texture then - if maps.maps[player_name] then + if xmaps.maps[player_name] then player:hud_change( - maps.huds[player_name].map, + xmaps.huds[player_name].map, "text", "blank.png" ) player:hud_change( - maps.huds[player_name].pos, + xmaps.huds[player_name].pos, "text", "blank.png" ) - maps.maps[player_name] = nil - maps.mark[player_name] = nil + xmaps.maps[player_name] = nil + xmaps.mark[player_name] = nil end return end if ( - texture ~= maps.maps[player_name] and + texture ~= xmaps.maps[player_name] and updated_wield_item ) then player:set_wielded_item(updated_wield_item) @@ -591,22 +591,22 @@ maps.show_map_hud = function(player) local pos = vector.round(player_pos) local meta = wield_item:get_meta() - local meta_minp = meta:get_string("maps:minp") + local meta_minp = meta:get_string("xmaps:minp") assert( "" ~= meta_minp ) local minp = minetest.string_to_pos(meta_minp) - local meta_maxp = meta:get_string("maps:maxp") + local meta_maxp = meta:get_string("xmaps:maxp") assert( "" ~= meta_maxp ) local maxp = minetest.string_to_pos(meta_maxp) - local meta_xpos = meta:get_string("maps:xpos") + local meta_xpos = meta:get_string("xmaps:xpos") if "" ~= meta_xpos then local xpos = minetest.string_to_pos(meta_xpos) local x_x = xpos.x - minp.x - 4 local x_z = maxp.z - xpos.z - 4 local x_overlay = "^[combine:" .. size .. "x" .. size .. ":" .. - x_x .. "," .. x_z .. "=maps_x.tga" + x_x .. "," .. x_z .. "=xmaps_x.tga" texture = texture .. x_overlay end @@ -614,20 +614,20 @@ maps.show_map_hud = function(player) local darkness = 255 - (light_level * 17) local light_level_overlay = "^[colorize:black:" .. darkness if ( - texture ~= maps.maps[player_name] or - darkness ~= maps.dark[player_name] + texture ~= xmaps.maps[player_name] or + darkness ~= xmaps.dark[player_name] ) then player:hud_change( - maps.huds[player_name].map, + xmaps.huds[player_name].map, "text", texture .. light_level_overlay ) - maps.maps[player_name] = texture + xmaps.maps[player_name] = texture end local marker - local dot_large = "maps_dot_large.tga" .. "^[makealpha:1,1,1" - local dot_small = "maps_dot_small.tga" .. "^[makealpha:1,1,1" + local dot_large = "xmaps_dot_large.tga" .. "^[makealpha:1,1,1" + local dot_small = "xmaps_dot_small.tga" .. "^[makealpha:1,1,1" if pos.x < minp.x then if minp.x - pos.x < size then @@ -676,7 +676,7 @@ maps.show_map_hud = function(player) yaw == 180 or yaw == 270 ) then - marker = "maps_arrow.tga" .. + marker = "xmaps_arrow.tga" .. "^[makealpha:1,1,1" .. "^[transformR" .. yaw @@ -686,7 +686,7 @@ maps.show_map_hud = function(player) yaw == 225 or yaw == 315 ) then - marker = "maps_arrow_diagonal.tga" .. + marker = "xmaps_arrow_diagonal.tga" .. "^[makealpha:1,1,1" .. "^[transformR" .. (yaw - 45) @@ -694,36 +694,36 @@ maps.show_map_hud = function(player) end if marker and ( - marker ~= maps.mark[player_name] or - darkness ~= maps.dark[player_name] + marker ~= xmaps.mark[player_name] or + darkness ~= xmaps.dark[player_name] ) then player:hud_change( - maps.huds[player_name].pos, + xmaps.huds[player_name].pos, "text", marker .. light_level_overlay ) - maps.mark[player_name] = marker + xmaps.mark[player_name] = marker end local marker_x = (pos.x - minp.x - (size/2)) * 4 local marker_y = (maxp.z - pos.z - size + 3) * 4 if ( - marker_x ~= maps.marx[player_name] or - marker_y ~= maps.mary[player_name] + marker_x ~= xmaps.marx[player_name] or + marker_y ~= xmaps.mary[player_name] ) then player:hud_change( - maps.huds[player_name].pos, + xmaps.huds[player_name].pos, "offset", { x = marker_x, y = marker_y, } ) - maps.marx[player_name] = marker_x - maps.mary[player_name] = marker_y + xmaps.marx[player_name] = marker_x + xmaps.mary[player_name] = marker_y end - maps.dark[player_name] = darkness + xmaps.dark[player_name] = darkness end local time_elapsed = 0 @@ -736,16 +736,16 @@ minetest.register_globalstep( end local players = minetest.get_connected_players() for _, player in pairs(players) do - maps.show_map_hud(player) + xmaps.show_map_hud(player) end end ) minetest.register_craftitem( - "maps:map", + "xmaps:map", { description = "Map", - inventory_image = "maps_map.tga", + inventory_image = "xmaps_map.tga", groups = { not_in_creative_inventory = 1 }, } ) @@ -757,7 +757,7 @@ if minetest.registered_items["map:mapping_kit"] then on_place = function(itemstack, player, pointed_thing) local pos = pointed_thing.under if pos then - local map = maps.create_map_item( + local map = xmaps.create_map_item( pos, { draw_x = true } ) @@ -767,7 +767,7 @@ if minetest.registered_items["map:mapping_kit"] then on_secondary_use = function(itemstack, player, pointed_thing) local pos = player:get_pos() if pos then - local map = maps.create_map_item(pos) + local map = xmaps.create_map_item(pos) return map end end, diff --git a/mod.conf b/mod.conf index 777e7aa..c1b6178 100644 --- a/mod.conf +++ b/mod.conf @@ -1,4 +1,4 @@ depends = tga_encoder optional_depends = map description = Adds map items that show terrain in HUD -name = maps +name = xmaps diff --git a/textures/maps_arrow.tga b/textures/xmaps_arrow.tga similarity index 100% rename from textures/maps_arrow.tga rename to textures/xmaps_arrow.tga diff --git a/textures/maps_arrow_diagonal.tga b/textures/xmaps_arrow_diagonal.tga similarity index 100% rename from textures/maps_arrow_diagonal.tga rename to textures/xmaps_arrow_diagonal.tga diff --git a/textures/maps_dot_large.tga b/textures/xmaps_dot_large.tga similarity index 100% rename from textures/maps_dot_large.tga rename to textures/xmaps_dot_large.tga diff --git a/textures/maps_dot_small.tga b/textures/xmaps_dot_small.tga similarity index 100% rename from textures/maps_dot_small.tga rename to textures/xmaps_dot_small.tga diff --git a/textures/maps_map.tga b/textures/xmaps_map.tga similarity index 100% rename from textures/maps_map.tga rename to textures/xmaps_map.tga diff --git a/textures/maps_x.tga b/textures/xmaps_x.tga similarity index 100% rename from textures/maps_x.tga rename to textures/xmaps_x.tga