diff options
| author | historia <[not public]> | 2026-07-18 04:44:50 -0400 |
|---|---|---|
| committer | historia <[not public]> | 2026-07-18 04:44:50 -0400 |
| commit | 2b5d8f595f96a2864899f4c7e28bc06fa52d2603 (patch) | |
| tree | f1539db865d9968414e59d9b250861c1b356d627 /internal/game/render_combat.go | |
| parent | db8ca1fe26a36b78074a424ae657b2cbb9b3af19 (diff) | |
| download | thehouseoficarus-2b5d8f595f96a2864899f4c7e28bc06fa52d2603.tar.gz | |
feat: expose all colors in config.yaml for easier theming
Diffstat (limited to 'internal/game/render_combat.go')
| -rw-r--r-- | internal/game/render_combat.go | 44 |
1 files changed, 34 insertions, 10 deletions
diff --git a/internal/game/render_combat.go b/internal/game/render_combat.go index e4a0d55..4055b4d 100644 --- a/internal/game/render_combat.go +++ b/internal/game/render_combat.go @@ -3,6 +3,7 @@ package game import ( "fmt" + "thehouseoficarus/internal/color" "thehouseoficarus/internal/net" "thehouseoficarus/internal/ui" ) @@ -14,7 +15,10 @@ func (g *Game) dmgDisplay(sess *net.Session, dmg int) string { return fmt.Sprintf("> %d <", dmg) } -func (g *Game) renderBar(sess *net.Session, current, max, lowColor int) string { +// renderBarGeneric renders a high/med/low tiered bar at width 10 using the +// named constant-color family (prefix: "hp_bar" or "task_bar"). The empty +// cells are painted with hp_bar_empty. +func (g *Game) renderBarGeneric(sess *net.Session, current, max int, prefix string) string { if max <= 0 { max = 1 } @@ -25,23 +29,43 @@ func (g *Game) renderBar(sess *net.Session, current, max, lowColor int) string { current = max } - pct := float64(current) / float64(max) * 100.0 - var fgColor int + pct := float64(current) / float64(max) + var spec color.ColorSpec switch { - case pct >= 70: - fgColor = 108 - case pct >= 40: - fgColor = 179 + case pct >= 0.7: + spec = g.resolveConstant(sess, prefix+"_high") + case pct >= 0.4: + spec = g.resolveConstant(sess, prefix+"_med") default: - fgColor = lowColor + spec = g.resolveConstant(sess, prefix+"_low") } + empty := g.resolveConstant(sess, "hp_bar_empty") unicode := sess.Player != nil && sess.Player.OptionBool("unicode") - style := &ui.BarStyle{FilledColor: fgColor, EmptyColor: 237, EmptyDim: true} + style := &ui.BarStyle{FilledColor: spec.Fg, EmptyColor: empty.Fg, EmptyDim: empty.Dim} bar := ui.RenderColoredBar(current, max, 10, unicode, style, g.colorMode(sess)) return "[" + bar + "]" } +// hpBarStyle returns the per-tier fill/empty color spec for an HP bar at the +// given ratio (high>=70%, med>=40%, low<40%). Colors come from the +// constant_colors map (hp_bar_high/med/low/empty). +func (g *Game) hpBarStyle(sess *net.Session, current, max int) *ui.BarStyle { + if max <= 0 { + max = 1 + } + pct := float64(current) / float64(max) + spec := g.resolveConstant(sess, "hp_bar_low") + switch { + case pct >= 0.7: + spec = g.resolveConstant(sess, "hp_bar_high") + case pct >= 0.4: + spec = g.resolveConstant(sess, "hp_bar_med") + } + empty := g.resolveConstant(sess, "hp_bar_empty") + return &ui.BarStyle{FilledColor: spec.Fg, EmptyColor: empty.Fg, EmptyDim: empty.Dim} +} + func (g *Game) hpBar(sess *net.Session, current, max int) string { - return g.renderBar(sess, current, max, 167) + return g.renderBarGeneric(sess, current, max, "hp_bar") } |
