1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
package game
import (
"fmt"
"thehouseoficarus/internal/color"
"thehouseoficarus/internal/net"
"thehouseoficarus/internal/ui"
)
func (g *Game) dmgDisplay(sess *net.Session, dmg int) string {
if sess.Player != nil && sess.Player.OptionBool("unicode") {
return fmt.Sprintf("\U0001FB38 %d \U0001FB34", dmg)
}
return fmt.Sprintf("> %d <", dmg)
}
// 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
}
if current < 0 {
current = 0
}
if current > max {
current = max
}
pct := float64(current) / float64(max)
var spec color.ColorSpec
switch {
case pct >= 0.7:
spec = g.resolveConstant(sess, prefix+"_high")
case pct >= 0.4:
spec = g.resolveConstant(sess, prefix+"_med")
default:
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: 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.renderBarGeneric(sess, current, max, "hp_bar")
}
|