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
72
73
74
75
76
77
78
79
80
|
package game
import (
"thehouseoficarus/internal/color"
"thehouseoficarus/internal/config"
"thehouseoficarus/internal/item"
"thehouseoficarus/internal/net"
"thehouseoficarus/internal/object"
)
func (g *Game) colorMode(sess *net.Session) string {
if p := sess.Player; p != nil {
return p.OptionString("color")
}
return "none"
}
func (g *Game) resolveColor(sess *net.Session, category string) color.ColorSpec {
if sess != nil && sess.Account != nil && sess.Account.Colors != nil {
if val, ok := sess.Account.Colors[category]; ok {
if val == "off" {
return color.NoColor()
}
if val != "" {
return color.Parse(val)
}
}
}
if g.ColorConfig != nil {
if val, ok := (*g.ColorConfig)[category]; ok && val != "" {
return color.Parse(val)
}
}
if val, ok := config.DefaultColors()[category]; ok && val != "" {
return color.Parse(val)
}
return color.NoColor()
}
func (g *Game) colorize(sess *net.Session, category, text string) string {
spec := g.resolveColor(sess, category)
return color.Render(g.colorMode(sess), spec, text)
}
func levelColorSpec(myLevel, theirLevel int) color.ColorSpec {
diff := theirLevel - myLevel
switch {
case diff == 0:
return color.Parse("FA")
case diff > 0 && diff < 5:
return color.Parse("B3")
case diff >= 5:
return color.Parse("A7")
case diff < 0 && diff > -5:
return color.Parse("6E")
default:
return color.Parse("41")
}
}
func (g *Game) levelColorize(sess *net.Session, myLevel, theirLevel int, text string) string {
spec := levelColorSpec(myLevel, theirLevel)
return color.Render(g.colorMode(sess), spec, text)
}
func (g *Game) objColorize(sess *net.Session, objDef *object.ObjectDef, text string) string {
if objDef != nil && objDef.Color != "" {
spec := color.Parse(objDef.Color)
return color.Render(g.colorMode(sess), spec, text)
}
return text
}
func (g *Game) itemColorize(sess *net.Session, itemDef *item.ItemDef, text string) string {
if itemDef != nil && itemDef.Color != "" {
spec := color.Parse(itemDef.Color)
return color.Render(g.colorMode(sess), spec, text)
}
return g.colorize(sess, "item", text)
}
|