~gpcf/advtrains-devel

Avoid unnecessarily updating the driver HUD v1 APPLIED

Y. Wang: 1
 Avoid unnecessarily updating the driver HUD

 1 files changed, 14 insertions(+), 7 deletions(-)
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~gpcf/advtrains-devel/patches/55027/mbox | git am -3
Learn more about email & git

[PATCH] Avoid unnecessarily updating the driver HUD Export this patch

This patch avoids sending the driver HUD if it contains the same text
that was previously sent.

---
 advtrains/trainhud.lua | 21 ++++++++++++++-------
 1 file 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
-- 
2.46.0