From 4202980019335df034bd1e9f323091c825405fdc Mon Sep 17 00:00:00 2001 From: Jaidyn Ann <10477760+JadedCtrl@users.noreply.github.com> Date: Tue, 9 Jan 2024 23:57:05 -0600 Subject: [PATCH] =?UTF-8?q?Compatibility=20with=20minetest=5Fgame=E2=80=99?= =?UTF-8?q?s=20sethome?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If sethome is present, we use its API for getting/setting homes, otherwise we use i3’s own. --- src/fields.lua | 20 +++++++++++++++----- src/gui.lua | 24 ++++++++++++++++-------- 2 files changed, 31 insertions(+), 13 deletions(-) diff --git a/src/fields.lua b/src/fields.lua index e3cb2f1..e696b6d 100644 --- a/src/fields.lua +++ b/src/fields.lua @@ -132,18 +132,28 @@ local function inv_fields(player, data, fields) elseif fields.sort then sort_inventory(player, data) + elseif (fields.home or fields.set_home) and not check_privs(name, {home = true}) then + return msg(name, "'home' privilege missing") + elseif fields.home then - if not data.home then + if sethome then + if not sethome.go(name) then + return msg(name, "No home set") + end + elseif not data.home then return msg(name, "No home set") - elseif not check_privs(name, {home = true}) then - return msg(name, "'home' privilege missing") + else + safe_teleport(player, str_to_pos(data.home)) end - safe_teleport(player, str_to_pos(data.home)) msg(name, S"Welcome back home!") elseif fields.set_home then - data.home = pos_to_str(player:get_pos(), 1) + if sethome then + sethome.set(name, player:get_pos()) + else + data.home = pos_to_str(player:get_pos(), 1) + end elseif fields.bag_rename then data.bag_rename = true diff --git a/src/gui.lua b/src/gui.lua index 3e70dad..5bf7468 100644 --- a/src/gui.lua +++ b/src/gui.lua @@ -569,7 +569,7 @@ local function get_container(fs, data, player, yoffset, ctn_len, award_list, awa end end -local function show_settings(fs, data) +local function show_settings(fs, data, player) if data.confirm_trash then image(2.8, 10.65, 4.6, 0.7, PNG.bg_goto) label(3.02, 11, "Confirm trash?") @@ -608,8 +608,16 @@ local function show_settings(fs, data) if show_home then local coords, c, str = {"X", "Y", "Z"}, 0, ES"No home set" - if data.home then - str = data.home:gsub(",", " "):sub(2,-2):gsub("%.%d", ""):gsub( + local home = data.home + if sethome then + -- i3 stores home coordinates with one decimal of precision, as the blow fmt() statement + -- assumes. So we need to trim sethome’s coordinates to one decimal, likewise. + local home_pos = sethome.get(player:get_player_name()) + home = string.format("(%.1f,%.1f,%.1f)", home_pos.x, home_pos.y, home_pos.z) + end + + if home then + str = home:gsub(",", " "):sub(2,-2):gsub("%.%d", ""):gsub( "(%-?%d+)", function(a) c++ return fmt("%s: ", @@ -682,7 +690,7 @@ local function show_settings(fs, data) end end -local function get_footer(fs, data) +local function get_footer(fs, data, player) local btn = { {"trash", ES"Clear inventory"}, {"sort", ES"Sort inventory"}, @@ -698,10 +706,10 @@ local function get_footer(fs, data) fs("tooltip[%s;%s;#32333899;#fff]", btn_name, tooltip) end - show_settings(fs, data) + show_settings(fs, data, player) end -local function get_slots(fs, data) +local function get_slots(fs, data, player) local legacy_inventory = data.legacy_inventory local hotbar_len = data.hotbar_len local inv_x = legacy_inventory and 0.23 or 0.22 @@ -725,7 +733,7 @@ local function get_slots(fs, data) fs"listring[current_player;craft]listring[current_player;main]" - get_footer(fs, data) + get_footer(fs, data, player) end local function get_inventory_fs(player, data, fs) @@ -1777,7 +1785,7 @@ local function make_fs(player, data) end if tab.slots then - get_slots(fs, data) + get_slots(fs, data, player) end end