aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorY. Wang <y5nw@protonmail.com>2024-09-13 11:17:36 +0000
committergpcf <gpcf@gpcf.eu>2024-09-13 19:56:40 +0200
commit9ada994d5b3bd874e537b0bc9641b925058bdf51 (patch)
tree8ac018ff026cd0623c79ab43d3efb4ad36e69054
parent882108e8bf714200348bed2bd79b7f01ab6ffe7f (diff)
downloadadvtrains-9ada994d5b3bd874e537b0bc9641b925058bdf51.tar.gz
advtrains-9ada994d5b3bd874e537b0bc9641b925058bdf51.tar.bz2
advtrains-9ada994d5b3bd874e537b0bc9641b925058bdf51.zip
Avoid unnecessarily updating the driver HUD
This patch avoids sending the driver HUD if it contains the same text that was previously sent.
-rw-r--r--advtrains/trainhud.lua21
1 files changed, 14 insertions, 7 deletions
diff --git a/advtrains/trainhud.lua b/advtrains/trainhud.lua
index b2744ad..f9f4876 100644
--- a/advtrains/trainhud.lua
+++ b/advtrains/trainhud.lua
@@ -103,18 +103,20 @@ function advtrains.set_trainhud(name, text, driver)
if not player then
return
end
+ local drivertext = driver or ""
local driverhud = {
hud_elem_type = "image",
name = "ADVTRAINS_DRIVER",
position = {x=0.5, y=1},
offset = {x=0,y=-170},
- text = driver or "",
+ text = drivertext,
alignment = {x=0,y=-1},
- scale = {x=1,y=1},}
+ scale = {x=1,y=1},
+ }
if not hud then
- hud = {["driver"]={}}
+ hud = {}
advtrains.hud[name] = hud
- hud.id = player:hud_add({
+ hud.id = player:hud_add {
hud_elem_type = "text",
name = "ADVTRAINS",
number = 0xFFFFFF,
@@ -123,18 +125,23 @@ function advtrains.set_trainhud(name, text, driver)
text = text,
scale = {x=200, y=60},
alignment = {x=0, y=-1},
- })
- hud.oldText=text
+ }
hud.driver = player:hud_add(driverhud)
+ hud.oldText = text
+ hud.oldDriver = drivertext
else
if hud.oldText ~= text then
player:hud_change(hud.id, "text", text)
hud.oldText=text
end
if hud.driver then
- player:hud_change(hud.driver, "text", driver or "")
+ if hud.oldDriver ~= drivertext then
+ player:hud_change(hud.driver, "text", drivertext)
+ hud.oldDriver = drivertext
+ end
elseif driver then
hud.driver = player:hud_add(driverhud)
+ hud.oldDriver = drivertext
end
end
end