Progressive Mode: more cleaning
This commit is contained in:
parent
02e66f368a
commit
b0326dab43
|
@ -161,6 +161,11 @@ local function show_hud_success(player, data)
|
||||||
data.hud_timer = (data.hud_timer or 0) + dt
|
data.hud_timer = (data.hud_timer or 0) + dt
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local discovered = data.tot_discovered or data.discovered
|
||||||
|
|
||||||
|
player:hud_change(data.hud.text, "text",
|
||||||
|
fmt("%u new recipe%s unlocked!", discovered, discovered > 1 and "s" or ""))
|
||||||
|
|
||||||
if data.show_hud then
|
if data.show_hud then
|
||||||
for _, def in pairs(data.hud) do
|
for _, def in pairs(data.hud) do
|
||||||
local hud_info = player:hud_get(def)
|
local hud_info = player:hud_get(def)
|
||||||
|
@ -171,9 +176,6 @@ local function show_hud_success(player, data)
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
player:hud_change(data.hud.text, "text",
|
|
||||||
fmt("%u new recipe%s unlocked!", data.discovered, data.discovered > 1 and "s" or ""))
|
|
||||||
|
|
||||||
elseif data.show_hud == false then
|
elseif data.show_hud == false then
|
||||||
if data.hud_timer >= HUD_TIMER_MAX then
|
if data.hud_timer >= HUD_TIMER_MAX then
|
||||||
for _, def in pairs(data.hud) do
|
for _, def in pairs(data.hud) do
|
||||||
|
@ -188,6 +190,7 @@ local function show_hud_success(player, data)
|
||||||
if hud_info_bg.position.y >= 1 then
|
if hud_info_bg.position.y >= 1 then
|
||||||
data.show_hud = nil
|
data.show_hud = nil
|
||||||
data.hud_timer = nil
|
data.hud_timer = nil
|
||||||
|
data.tot_discovered = nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -195,42 +198,34 @@ end
|
||||||
|
|
||||||
-- Workaround. Need an engine call to detect when the contents of
|
-- Workaround. Need an engine call to detect when the contents of
|
||||||
-- the player inventory changed, instead.
|
-- the player inventory changed, instead.
|
||||||
local function poll_new_items()
|
local function poll_new_items(player, data, join)
|
||||||
local players = core.get_connected_players()
|
local inv_items = get_inv_items(player)
|
||||||
|
local diff = array_diff(inv_items, data.inv_items)
|
||||||
|
|
||||||
for i = 1, #players do
|
if join or #diff > 0 then
|
||||||
local player = players[i]
|
data.inv_items = table_merge(diff, data.inv_items)
|
||||||
local name = player:get_player_name()
|
local oldknown = data.known_recipes or 0
|
||||||
local data = i3.data[name]
|
local items = get_filtered_items(player, data)
|
||||||
|
data.discovered = data.known_recipes - oldknown
|
||||||
|
|
||||||
if data then
|
if data.discovered > 0 then
|
||||||
local inv_items = get_inv_items(player)
|
data.tot_discovered = (data.tot_discovered or 0) + data.discovered
|
||||||
local diff = array_diff(inv_items, data.inv_items)
|
|
||||||
|
|
||||||
if #diff > 0 then
|
if data.show_hud == nil then
|
||||||
data.inv_items = table_merge(diff, data.inv_items)
|
data.show_hud = true
|
||||||
local oldknown = data.known_recipes or 0
|
|
||||||
local items = get_filtered_items(player, data)
|
|
||||||
data.discovered = data.known_recipes - oldknown
|
|
||||||
|
|
||||||
if data.show_hud == nil and data.discovered > 0 then
|
|
||||||
data.show_hud = true
|
|
||||||
end
|
|
||||||
|
|
||||||
data.items_raw = items
|
|
||||||
data.itab = 1
|
|
||||||
|
|
||||||
search(data)
|
|
||||||
set_fs(player)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
data.items_raw = items
|
||||||
|
data.itab = 1
|
||||||
|
|
||||||
|
search(data)
|
||||||
|
set_fs(player)
|
||||||
end
|
end
|
||||||
|
|
||||||
core.after(POLL_FREQ, poll_new_items)
|
core.after(POLL_FREQ, poll_new_items, player, data)
|
||||||
end
|
end
|
||||||
|
|
||||||
poll_new_items()
|
|
||||||
|
|
||||||
if singleplayer then
|
if singleplayer then
|
||||||
core.register_globalstep(function()
|
core.register_globalstep(function()
|
||||||
local name = "singleplayer"
|
local name = "singleplayer"
|
||||||
|
@ -252,19 +247,11 @@ core.register_on_joinplayer(function(player)
|
||||||
|
|
||||||
data.inv_items = data.inv_items or {}
|
data.inv_items = data.inv_items or {}
|
||||||
data.known_recipes = data.known_recipes or 0
|
data.known_recipes = data.known_recipes or 0
|
||||||
|
data.discovered = data.discovered or 0
|
||||||
|
|
||||||
local oldknown = data.known_recipes
|
poll_new_items(player, data, true)
|
||||||
local items = get_filtered_items(player, data)
|
|
||||||
data.discovered = data.known_recipes - oldknown
|
|
||||||
|
|
||||||
data.items_raw = items
|
|
||||||
search(data)
|
|
||||||
|
|
||||||
if singleplayer then
|
if singleplayer then
|
||||||
init_hud(player, data)
|
init_hud(player, data)
|
||||||
|
|
||||||
if data.show_hud == nil and data.discovered > 0 then
|
|
||||||
data.show_hud = true
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
Ŝarĝante…
Reference in New Issue