CRASHFIX: fix potential crashes with player-ball switches when spectating (closes #108)

This commit is contained in:
marco_a 2024-01-04 12:32:38 +01:00
parent b1dee8efa1
commit 377b88b158
4 changed files with 34 additions and 29 deletions

View File

@ -1,18 +1,18 @@
function block_league.HUD_skill_create(p_name)
function block_league.HUD_skill_create(p_name, is_spectator)
local skill, x_offset
if arena_lib.is_player_spectating(p_name) then
skill = block_league.get_player_skill(arena_lib.get_player_spectated(p_name))
if is_spectator then
skill = ""
x_offset = 168
else
skill = block_league.get_player_skill(p_name)
skill = "bl_skill_" .. block_league.get_player_skill(p_name):sub(14, -1) .. ".png"
x_offset = 145
end
Panel:new("bl_skill", {
player = p_name,
bg = "bl_skill_" .. skill:sub(14, -1) .. ".png",
bg = skill,
position = { x = 0.5, y = 1 },
alignment = { x = 0, y = 0 },
offset = { x = x_offset, y = -30 },

View File

@ -1,18 +1,24 @@
local S = minetest.get_translator("block_league")
local function get_bullet_count() end
function block_league.HUD_weapons_create(p_name)
local inv = ""
function block_league.HUD_weapons_create(p_name, is_spectator)
local inv = "" -- TODO: cementato. Quando potran cambiare equip con nuove armi, cambiare
local sub_img_elems = {}
local sub_txt_elems = {}
local offset_x = -90
local offset_y = ""
local offset_y
if arena_lib.is_player_spectating(p_name) then
inv = minetest.get_player_by_name(arena_lib.get_player_spectated(p_name)):get_inventory()
if is_spectator then
local arena = arena_lib.get_arena_by_player(p_name)
local random_p
for pl_name, _ in pairs(arena.players) do
random_p = minetest.get_player_by_name(pl_name)
break
end
inv = random_p:get_inventory()
offset_y = -160
else
inv = minetest.get_player_by_name(p_name):get_inventory()
@ -29,6 +35,13 @@ function block_league.HUD_weapons_create(p_name)
})
-- armi
-- TODO: in futuro, con nuove armi non + possibile usare w_name perché ogni gioc
-- avrà suo equip. Due possibili approcci:
-- 1. trovare modo x usare ID caselle al posto di w_name (ma dovrò fare
-- get_stack(ID):get_name() == w_name ogni volta?)
-- 2. ricreare HUD ogni volta che si cambia gioc seguitə, e mantenere w_name. Non
-- dovrebbe dar problemi con async perché armi non sparano su globalstep, non so
-- però se potrebbe creare casini con gli after invocati dalle armi
for i = 1, 3 do
local w_name = inv:get_stack("main", i):get_name() ~= "" and inv:get_stack("main", i):get_name() or ("NIL" .. i)
local weapon = minetest.registered_nodes[w_name]
@ -97,9 +110,9 @@ function block_league.HUD_weapons_update(arena, p_name, w_name, is_reloading)
)
for sp_name, _ in pairs(arena_lib.get_player_spectators(p_name)) do
local panel = panel_lib.get_panel(sp_name, "bl_weapons")
local panel_sp = panel_lib.get_panel(sp_name, "bl_weapons")
panel:update(nil,
panel_sp:update(nil,
{[w_name .. "_magazine_txt"] = { text = current_magazine }},
{[w_name .. "_bg"] = { text = bg_pic }}
)

View File

@ -8,20 +8,12 @@ arena_lib.on_change_spectated_target("block_league", function(arena, sp_name, t_
sp_data.was_following_ball = false
end
-- ritardo di 0.1 perché on_join non è ancora stato chiamato, quindi non hanno ancora la HUD
minetest.after(0.1, function()
-- il 2° controllo è nel caso si stesse seguendo la palla, che viene presa
-- da Tiziə, che viene seccatə all'istante: l'inquadratura torna sulla palla
-- ancora prima dell'after
if not minetest.get_player_by_name(t_name) or not arena_lib.get_player_spectated(sp_name) then return end
for _, weap_name in pairs(block_league.get_player_weapons(t_name)) do
block_league.HUD_weapons_update(arena, t_name, weap_name)
end
for _, weap_name in pairs(block_league.get_player_weapons(t_name)) do
block_league.HUD_weapons_update(arena, t_name, weap_name)
end
block_league.HUD_skill_update(sp_name)
block_league.HUD_stamina_update(arena, t_name)
end)
block_league.HUD_skill_update(sp_name)
block_league.HUD_stamina_update(arena, t_name)
elseif t_type == "entity" then
-- se al seguire la palla questa è in testa a qualcunə, segui quel qualcunə

View File

@ -152,8 +152,8 @@ function create_and_show_HUD(arena, p_name, is_spectator, was_spectator)
end
block_league.HUD_critical_create(p_name) -- TODO: abbastanza sicuro che questo non debba essere generato ogni volta
block_league.HUD_weapons_create(p_name)
block_league.HUD_skill_create(p_name)
block_league.HUD_weapons_create(p_name, is_spectator)
block_league.HUD_skill_create(p_name, is_spectator)
if is_spectator then
block_league.HUD_spectate_create(arena, p_name)