From b3f1cf255db9bc3cb2b675ff30da6fe8ec601dba Mon Sep 17 00:00:00 2001 From: Jean-Patrick Guerrero Date: Fri, 26 Nov 2021 04:58:57 +0100 Subject: [PATCH] Move stuff to HUD --- init.lua | 19 ++----------------- src/detached_inv.lua | 4 ++-- src/hud.lua | 21 +++++++++++++++++++-- 3 files changed, 23 insertions(+), 21 deletions(-) diff --git a/init.lua b/init.lua index 6f57912..b2b0974 100644 --- a/init.lua +++ b/init.lua @@ -78,13 +78,12 @@ i3.files.callbacks() local storage = core.get_mod_storage() local slz, dslz, copy = i3.get("slz", "dslz", "copy") -local str_to_pos, add_hud_waypoint = i3.get("str_to_pos", "add_hud_waypoint") local set_fs = i3.set_fs i3.data = dslz(storage:get_string"data") or {} local init_bags = i3.files.bags() -local init_inventories = i3.files.detached() +local init_detached = i3.files.detached() local fill_caches = i3.files.caches() local init_hud = i3.files.hud() @@ -175,19 +174,6 @@ local function init_data(player, info) core.after(0, set_fs, player) end -local function init_waypoints(player) - local name = player:get_player_name() - local data = i3.data[name] - data.waypoints = data.waypoints or {} - - for _, v in ipairs(data.waypoints) do - if not v.hide then - local id = add_hud_waypoint(player, v.name, str_to_pos(v.pos), v.color) - v.id = id - end - end -end - local function save_data(player_name) local _data = copy(i3.data) @@ -221,8 +207,7 @@ core.register_on_joinplayer(function(player) init_data(player, info) init_bags(player) - init_inventories(player) - init_waypoints(player) + init_detached(player) init_hud(player) end) diff --git a/src/detached_inv.lua b/src/detached_inv.lua index 24879bb..a8513bb 100644 --- a/src/detached_inv.lua +++ b/src/detached_inv.lua @@ -20,7 +20,7 @@ local trash = create_inventory("i3_trash", { trash:set_size("main", 1) -local function init_inventories(player) +local function init_detached(player) local name = player:get_player_name() local output_rcp = create_inventory(fmt("i3_output_rcp_%s", name), {}, name) @@ -30,4 +30,4 @@ local function init_inventories(player) output_usg:set_size("main", 1) end -return init_inventories +return init_detached diff --git a/src/hud.lua b/src/hud.lua index d05898d..9bb302b 100644 --- a/src/hud.lua +++ b/src/hud.lua @@ -1,4 +1,5 @@ -local get_player_by_name = i3.get("get_player_by_name") +local get_player_by_name, str_to_pos, add_hud_waypoint = + i3.get("get_player_by_name", "str_to_pos", "add_hud_waypoint") local function init_hud(player) local name = player:get_player_name() @@ -98,4 +99,20 @@ core.register_globalstep(function() end end) -return init_hud +local function init_waypoints(player) + local name = player:get_player_name() + local data = i3.data[name] + data.waypoints = data.waypoints or {} + + for _, v in ipairs(data.waypoints) do + if not v.hide then + local id = add_hud_waypoint(player, v.name, str_to_pos(v.pos), v.color) + v.id = id + end + end +end + +return function(player) + init_hud(player) + init_waypoints(player) +end