From c761aa268d89dd88bd4ace4d1fa141758608285c Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Sat, 8 Oct 2022 20:41:11 +0200 Subject: [PATCH] DevTest: Move 2 HUD commands to testhud & improve --- games/devtest/mods/testhud/init.lua | 132 ++++++++++++++++++ .../testhud/textures/testhud_waypoint.png | Bin 0 -> 111 bytes games/devtest/mods/util_commands/init.lua | 84 ----------- 3 files changed, 132 insertions(+), 84 deletions(-) create mode 100644 games/devtest/mods/testhud/textures/testhud_waypoint.png diff --git a/games/devtest/mods/testhud/init.lua b/games/devtest/mods/testhud/init.lua index 2fa12fd71..b42951a6d 100644 --- a/games/devtest/mods/testhud/init.lua +++ b/games/devtest/mods/testhud/init.lua @@ -29,6 +29,7 @@ end minetest.register_on_leaveplayer(function(player) player_huds[player:get_player_name()] = nil + player_waypoints[player:get_player_name()] = nil end) local etime = 0 @@ -79,3 +80,134 @@ minetest.register_chatcommand("hudfonts", { return true end, }) + +local player_waypoints = {} + +-- Use this to test waypoint capabilities +minetest.register_chatcommand("hudwaypoints", { + params = "[ add | add_change | remove ]", + description = "Create HUD waypoints at your position for testing (add: Add waypoints and change them after 0.5s (default). add_change: Add waypoints and change immediately. remove: Remove all waypoints)", + func = function(name, params) + local player = minetest.get_player_by_name(name) + if not player then + return false, "No player." + end + if params == "remove" then + if player_waypoints[name] then + for i=1, #player_waypoints[name] do + player:hud_remove(player_waypoints[name][i]) + end + player_waypoints[name] = {} + end + return true, "Waypoints removed." + end + if not (params == "add_change" or params == "add" or params == "") then + -- Incorrect syntax + return false + end + local regular = player:hud_add { + hud_elem_type = "waypoint", + name = "regular waypoint", + text = "m", + number = 0xFFFFFF, + world_pos = vector.add(player:get_pos(), {x = 0, y = 1.5, z = 0}) + } + local reduced_precision = player:hud_add { + hud_elem_type = "waypoint", + name = "imprecise waypoint", + text = "m (0.1 steps, precision = 10)", + precision = 10, + number = 0xFFFFFF, + world_pos = vector.add(player:get_pos(), {x = 0, y = 1, z = 0}) + } + local hidden_distance = player:hud_add { + hud_elem_type = "waypoint", + name = "waypoint with hidden distance", + text = "this text is hidden as well (precision = 0)", + precision = 0, + number = 0xFFFFFF, + world_pos = vector.add(player:get_pos(), {x = 0, y = 0.5, z = 0}) + } + local function change(chplayer) + if not (chplayer and chplayer:is_player()) then + return + end + if regular then + chplayer:hud_change(regular, "world_pos", vector.add(player:get_pos(), {x = 0, y = 3, z = 0})) + chplayer:hud_change(regular, "number", 0xFF0000) + end + if reduced_precision then + chplayer:hud_change(reduced_precision, "precision", 2) + chplayer:hud_change(reduced_precision, "text", "m (0.5 steps, precision = 2)") + chplayer:hud_change(reduced_precision, "number", 0xFFFF00) + end + if hidden_distance then + chplayer:hud_change(hidden_distance, "number", 0x0000FF) + end + minetest.chat_send_player(chplayer:get_player_name(), "Waypoints changed.") + end + if params == "add_change" then + -- change immediate + change(player) + else + minetest.after(0.5, change, player) + end + local image_waypoint = player:hud_add { + hud_elem_type = "image_waypoint", + text = "testhud_waypoint.png", + world_pos = player:get_pos(), + scale = {x = 3, y = 3}, + offset = {x = 0, y = -32} + } + if not player_waypoints[name] then + player_waypoints[name] = {} + end + if regular then + table.insert(player_waypoints[name], regular) + end + if reduced_precision then + table.insert(player_waypoints[name], reduced_precision) + end + if hidden_distance then + table.insert(player_waypoints[name], hidden_distance) + end + if image_waypoint then + table.insert(player_waypoints[name], image_waypoint) + end + regular = regular or "error" + reduced_precision = reduced_precision or "error" + hidden_distance = hidden_distance or "error" + image_waypoint = image_waypoint or "error" + return true, "Waypoints added. IDs: regular: " .. regular .. ", reduced precision: " .. reduced_precision .. + ", hidden distance: " .. hidden_distance .. ", image waypoint: " .. image_waypoint + end +}) + +minetest.register_on_leaveplayer(function(player) +end) + +minetest.register_on_joinplayer(function(player) + player:set_properties({zoom_fov = 15}) +end) + +minetest.register_chatcommand("zoomfov", { + params = "[]", + description = "Set or display your zoom_fov", + func = function(name, param) + local player = minetest.get_player_by_name(name) + if not player then + return false, "No player." + end + if param == "" then + local fov = player:get_properties().zoom_fov + return true, "zoom_fov = "..tostring(fov) + end + local fov = tonumber(param) + if not fov then + return false, "Missing or incorrect zoom_fov parameter!" + end + player:set_properties({zoom_fov = fov}) + fov = player:get_properties().zoom_fov + return true, "zoom_fov = "..tostring(fov) + end, +}) diff --git a/games/devtest/mods/testhud/textures/testhud_waypoint.png b/games/devtest/mods/testhud/textures/testhud_waypoint.png new file mode 100644 index 0000000000000000000000000000000000000000..f9f1308130f65a32d8220d3ef8dfeec45b4d4074 GIT binary patch literal 111 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!D3?x-;bCrM;TYyi9>z3%-K<2Df8t;IVil>WX zNCjguL({K%9zGuhk%%J#FIZg^+*SySR9ZTwG@fe6V!Y$eDZnnOvka)7!PC{xWt~$( F69DG%8f*Xn literal 0 HcmV?d00001 diff --git a/games/devtest/mods/util_commands/init.lua b/games/devtest/mods/util_commands/init.lua index 4f80172c6..8d12d27f0 100644 --- a/games/devtest/mods/util_commands/init.lua +++ b/games/devtest/mods/util_commands/init.lua @@ -36,32 +36,6 @@ minetest.register_chatcommand("hp", { end, }) -minetest.register_on_joinplayer(function(player) - player:set_properties({zoom_fov = 15}) -end) - -minetest.register_chatcommand("zoomfov", { - params = "[]", - description = "Set or display your zoom_fov", - func = function(name, param) - local player = minetest.get_player_by_name(name) - if not player then - return false, "No player." - end - if param == "" then - local fov = player:get_properties().zoom_fov - return true, "zoom_fov = "..tostring(fov) - end - local fov = tonumber(param) - if not fov then - return false, "Missing or incorrect zoom_fov parameter!" - end - player:set_properties({zoom_fov = fov}) - fov = player:get_properties().zoom_fov - return true, "zoom_fov = "..tostring(fov) - end, -}) - local s_infplace = minetest.settings:get("devtest_infplace") if s_infplace == "true" then infplace = true @@ -166,64 +140,6 @@ minetest.register_chatcommand("use_tool", { }) - --- Use this to test waypoint capabilities -minetest.register_chatcommand("test_waypoints", { - params = "[change_immediate]", - description = "tests waypoint capabilities", - func = function(name, params) - local player = minetest.get_player_by_name(name) - local regular = player:hud_add { - hud_elem_type = "waypoint", - name = "regular waypoint", - text = "m", - number = 0xFF0000, - world_pos = vector.add(player:get_pos(), {x = 0, y = 1.5, z = 0}) - } - local reduced_precision = player:hud_add { - hud_elem_type = "waypoint", - name = "better waypoint", - text = "m (0.5 steps, precision = 2)", - precision = 10, - number = 0xFFFF00, - world_pos = vector.add(player:get_pos(), {x = 0, y = 1, z = 0}) - } - local function change() - if regular then - player:hud_change(regular, "world_pos", vector.add(player:get_pos(), {x = 0, y = 3, z = 0})) - end - if reduced_precision then - player:hud_change(reduced_precision, "precision", 2) - end - end - if params ~= "" then - -- change immediate - change() - else - minetest.after(0.5, change) - end - regular = regular or "error" - reduced_precision = reduced_precision or "error" - local hidden_distance = player:hud_add { - hud_elem_type = "waypoint", - name = "waypoint with hidden distance", - text = "this text is hidden as well (precision = 0)", - precision = 0, - number = 0x0000FF, - world_pos = vector.add(player:get_pos(), {x = 0, y = 0.5, z = 0}) - } or "error" - local image_waypoint = player:hud_add { - hud_elem_type = "image_waypoint", - text = "wieldhand.png", - world_pos = player:get_pos(), - scale = {x = 10, y = 10}, - offset = {x = 0, y = -32} - } or "error" - minetest.chat_send_player(name, "Waypoint IDs: regular: " .. regular .. ", reduced precision: " .. reduced_precision .. - ", hidden distance: " .. hidden_distance .. ", image waypoint: " .. image_waypoint) - end -}) - -- Unlimited node placement minetest.register_on_placenode(function(pos, newnode, placer, oldnode, itemstack) if placer and placer:is_player() then