Notification success: do not depend on dtime

This commit is contained in:
Jean-Patrick Guerrero 2019-09-11 12:44:08 +02:00
parent 59b806c9c4
commit fb1b0cf869
2 changed files with 15 additions and 11 deletions

View File

@ -6,7 +6,7 @@
This crafting guide is a blue book named *"Crafting Guide"* or a wooden sign. This crafting guide is a blue book named *"Crafting Guide"* or a wooden sign.
This crafting guide features a **progressive mode**. This crafting guide features a **progressive mode**.
The progressive mode is a Terraria-like system that shows recipes you can craft This mode is a Terraria-like system that shows recipes you can craft
from items you ever had in your inventory. To enable it: `craftguide_progressive_mode = true` in `minetest.conf`. from items you ever had in your inventory. To enable it: `craftguide_progressive_mode = true` in `minetest.conf`.
`craftguide` is also integrated in `sfinv` (Minetest Game inventory). To enable it: `craftguide` is also integrated in `sfinv` (Minetest Game inventory). To enable it:
@ -16,5 +16,7 @@ Use the command `/craft` to show the recipe(s) of the pointed node.
For developers, `craftguide` also has a [modding API](https://github.com/minetest-mods/craftguide/blob/master/API.md). For developers, `craftguide` also has a [modding API](https://github.com/minetest-mods/craftguide/blob/master/API.md).
Love this mod? Donations are appreciated: https://www.paypal.me/jpg84240
![Preview2](https://i.imgur.com/oGSvbTW.png)
![Preview2](https://i.imgur.com/IbexMwQ.png)

View File

@ -1131,6 +1131,7 @@ end
if progressive_mode then if progressive_mode then
local PLAYERS = {} local PLAYERS = {}
local POLL_FREQ = 0.25 local POLL_FREQ = 0.25
local HUD_TIMER_MAX = 1.5
local function table_diff(t1, t2) local function table_diff(t1, t2)
local hash = {} local hash = {}
@ -1245,15 +1246,16 @@ if progressive_mode then
return inv_items return inv_items
end end
local function show_hud_success(player, data, dtime) local function show_hud_success(player, data)
-- It'd better to have an engine function `hud_move` to do not -- It'd better to have an engine function `hud_move` to only need
-- depend on the server dtime, and use the client dtime internally instead. -- 2 calls for the notification's back and forth.
local hud_info_bg = player:hud_get(data.hud.bg) local hud_info_bg = player:hud_get(data.hud.bg)
local dt = 0.016
if hud_info_bg.position.y <= 0.9 then if hud_info_bg.position.y <= 0.9 then
data.show_hud = false data.show_hud = false
data.hud_timer = (data.hud_timer or 0) + dtime data.hud_timer = (data.hud_timer or 0) + dt
end end
if data.show_hud then if data.show_hud then
@ -1262,7 +1264,7 @@ if progressive_mode then
player:hud_change(def, "position", { player:hud_change(def, "position", {
x = hud_info.position.x, x = hud_info.position.x,
y = hud_info.position.y - (dtime / 5) y = hud_info.position.y - (dt / 5)
}) })
end end
@ -1270,13 +1272,13 @@ if progressive_mode then
S("@1 new recipe(s) discovered!", data.discovered)) S("@1 new recipe(s) discovered!", data.discovered))
elseif data.show_hud == false then elseif data.show_hud == false then
if data.hud_timer > 3 then if data.hud_timer >= HUD_TIMER_MAX 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)
player:hud_change(def, "position", { player:hud_change(def, "position", {
x = hud_info.position.x, x = hud_info.position.x,
y = hud_info.position.y + (dtime / 5) y = hud_info.position.y + (dt / 5)
}) })
end end
@ -1324,14 +1326,14 @@ if progressive_mode then
poll_new_items() poll_new_items()
globalstep(function(dtime) globalstep(function()
for i = 1, #PLAYERS do for i = 1, #PLAYERS do
local player = PLAYERS[i] local player = PLAYERS[i]
local name = player:get_player_name() local name = player:get_player_name()
local data = pdata[name] local data = pdata[name]
if data.show_hud ~= nil then if data.show_hud ~= nil then
show_hud_success(player, data, dtime) show_hud_success(player, data)
end end
end end
end) end)