blob: 56de7e88b1bd2deeb76b3a38b25052c3b69d1b8d (
plain)
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
|
package game
import (
"math"
"strings"
"thehouseoficarus/internal/color"
"thehouseoficarus/internal/net"
)
func (g *Game) hpBar(sess *net.Session, current, max int) string {
if max <= 0 {
max = 1
}
if current < 0 {
current = 0
}
if current > max {
current = max
}
pct := float64(current) / float64(max) * 100.0
filled := int(math.Round(pct / 10.0))
if filled < 0 {
filled = 0
}
if filled > 10 {
filled = 10
}
mode := g.colorMode(sess)
var fgColor int
switch {
case pct >= 70:
fgColor = 82
case pct >= 40:
fgColor = 220
default:
fgColor = 160
}
fillSpec := color.ColorSpec{Fg: fgColor}
emptySpec := color.ColorSpec{Fg: 238, Dim: true}
fillChar := "█"
emptyChar := "░"
if sess.Player != nil && !sess.Player.OptionBool("unicode") {
fillChar = "#"
emptyChar = "."
}
var sb strings.Builder
sb.WriteString("[")
sb.WriteString(color.Render(mode, fillSpec, strings.Repeat(fillChar, filled)))
sb.WriteString(color.Render(mode, emptySpec, strings.Repeat(emptyChar, 10-filled)))
sb.WriteString("]")
return sb.String()
}
|