From cb2852e88f5e8fa4f6e0873eace2a26db66e4f66 Mon Sep 17 00:00:00 2001 From: kay27 Date: Wed, 2 Mar 2022 02:47:38 +0400 Subject: [PATCH] #233 Add /debug chat command --- mods/HUD/mcl_info/init.lua | 43 +++++++++++++++++++++++-- mods/HUD/mcl_info/locale/mcl_info.ru.tr | 4 +++ mods/HUD/mcl_info/locale/template.txt | 4 +++ 3 files changed, 48 insertions(+), 3 deletions(-) create mode 100644 mods/HUD/mcl_info/locale/mcl_info.ru.tr create mode 100644 mods/HUD/mcl_info/locale/template.txt diff --git a/mods/HUD/mcl_info/init.lua b/mods/HUD/mcl_info/init.lua index ae0fdc526c..02af53fbcc 100644 --- a/mods/HUD/mcl_info/init.lua +++ b/mods/HUD/mcl_info/init.lua @@ -1,5 +1,6 @@ local refresh_interval = .63 local huds = {} +local default_debug = 3 local after = minetest.after local get_connected_players = minetest.get_connected_players local get_biome_name = minetest.get_biome_name @@ -9,7 +10,15 @@ local format = string.format local min1, min2, min3 = mcl_mapgen.overworld.min, mcl_mapgen.end_.min, mcl_mapgen.nether.min local max1, max2, max3 = mcl_mapgen.overworld.max, mcl_mapgen.end_.max, mcl_mapgen.nether.max + 128 -local function get_text(pos) +local modname = minetest.get_current_modname() +local modpath = minetest.get_modpath(modname) +local S = minetest.get_translator(modname) +local storage = minetest.get_mod_storage() +local player_dbg = minetest.deserialize(storage:get_string("player_dbg") or "return {}") or {} + +local function get_text(pos, bits) + local bits = bits + if bits == 0 then return "" end local y = pos.y if y >= min1 then y = y - min1 @@ -20,7 +29,14 @@ local function get_text(pos) end local biome_data = get_biome_data(pos) local biome_name = biome_data and get_biome_name(biome_data.biome) or "No biome" - local text = format("%s x:%.1f y:%.1f z:%.1f", biome_name, pos.x, y, pos.z) + local text + if bits == 1 then + text = biome_name + elseif bits == 2 then + text = format("x:%.1f y:%.1f z:%.1f", pos.x, y, pos.z) + elseif bits == 3 then + text = format("%s x:%.1f y:%.1f z:%.1f", biome_name, pos.x, y, pos.z) + end return text end @@ -28,7 +44,7 @@ local function info() for _, player in pairs(get_connected_players()) do local name = player:get_player_name() local pos = player:get_pos() - local text = get_text(pos) + local text = get_text(pos, player_dbg[name] or default_debug) local hud = huds[name] if not hud then local def = { @@ -65,4 +81,25 @@ minetest.register_on_authplayer(function(name, ip, is_success) end end) +minetest.register_chatcommand("debug",{ + description = S("Set debug bit mask: 0 = disable, 1 = biome name, 2 = coordinates, 3 = all"), + func = function(name, params) + local dbg = math.floor(tonumber(params) or default_debug) + if dbg < 0 or dbg > 3 then + minetest.chat_send_player(name, S("Error! Possible values are integer numbers from @1 to @2", 0, 3)) + return + end + if dbg == default_dbg then + player_dbg[name] = nil + else + player_dbg[name] = dbg + end + minetest.chat_send_player(name, S("Debug bit mask set to @1", dbg)) + end +}) + +minetest.register_on_shutdown(function() + storage:set_string("player_dbg", minetest.serialize(player_dbg)) +end) + info() diff --git a/mods/HUD/mcl_info/locale/mcl_info.ru.tr b/mods/HUD/mcl_info/locale/mcl_info.ru.tr new file mode 100644 index 0000000000..7f5b79fe1b --- /dev/null +++ b/mods/HUD/mcl_info/locale/mcl_info.ru.tr @@ -0,0 +1,4 @@ +# textdomain: mcl_info +Set debug bit mask: 0 @= disable, 1 @= biome name, 2 @= coordinates, 3 @= all=Установка отладочной битовой маски: 0 @= отключить, 1 @= биом, 2 @= координаты, 3 @= всё +Error! Possible values are integer numbers from @1 to @2=Ошибка! Допустимые значения - целые числа от @1 до @2 +Debug bit mask set to @1=Отладочной битовой маске присвоено значение @1 diff --git a/mods/HUD/mcl_info/locale/template.txt b/mods/HUD/mcl_info/locale/template.txt new file mode 100644 index 0000000000..1a0b70ebc9 --- /dev/null +++ b/mods/HUD/mcl_info/locale/template.txt @@ -0,0 +1,4 @@ +# textdomain: mcl_info +Set debug bit mask: 0 @= disable, 1 @= biome name, 2 @= coordinates, 3 @= all= +Error! Possible values are integer numbers from @1 to @2= +Debug bit mask set to @1=