From abd612c15799f604e671e83dc7c410ed2b44185f Mon Sep 17 00:00:00 2001 From: historia <[not public]> Date: Thu, 25 Jun 2026 15:40:48 -0400 Subject: slop refactor --- internal/game/render_combat.go | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 internal/game/render_combat.go (limited to 'internal/game/render_combat.go') diff --git a/internal/game/render_combat.go b/internal/game/render_combat.go new file mode 100644 index 0000000..7285ce7 --- /dev/null +++ b/internal/game/render_combat.go @@ -0,0 +1,41 @@ +package game + +import ( + "thehouseoficarus/internal/net" + "thehouseoficarus/internal/ui" +) + +// renderBar is the shared bar renderer for both HP bars and task-progress bars. +// lowColor is the color used when the value falls below 40% (160 red for HP, +// 39 cyan for progress). +func (g *Game) renderBar(sess *net.Session, current, max, lowColor int) string { + if max <= 0 { + max = 1 + } + if current < 0 { + current = 0 + } + if current > max { + current = max + } + + pct := float64(current) / float64(max) * 100.0 + var fgColor int + switch { + case pct >= 70: + fgColor = 82 + case pct >= 40: + fgColor = 220 + default: + fgColor = lowColor + } + + unicode := sess.Player != nil && sess.Player.OptionBool("unicode") + style := &ui.BarStyle{FilledColor: fgColor, EmptyColor: 238, EmptyDim: true} + bar := ui.RenderColoredBar(current, max, 10, unicode, style, g.colorMode(sess)) + return "[" + bar + "]" +} + +func (g *Game) hpBar(sess *net.Session, current, max int) string { + return g.renderBar(sess, current, max, 160) +} -- cgit v1.2.3