aboutsummaryrefslogtreecommitdiff
path: root/internal/game/ui_color.go
diff options
context:
space:
mode:
authorworkhorse <workhorse@localhost.localdomain>2026-06-19 20:24:52 -0400
committerworkhorse <workhorse@localhost.localdomain>2026-06-19 20:24:52 -0400
commit8ee8982b8759bcae116647cc993867f4c8b0a6ce (patch)
treeee01f7b1d745cbc94d9981108a1209527487b3e5 /internal/game/ui_color.go
parent2bec24859af8f03c80a0a58e3240519942450167 (diff)
downloadthehouseoficarus-8ee8982b8759bcae116647cc993867f4c8b0a6ce.tar.gz
reorganized items, objects, and rooms in directories. oranized module names. added startup checks.
Diffstat (limited to 'internal/game/ui_color.go')
-rw-r--r--internal/game/ui_color.go79
1 files changed, 79 insertions, 0 deletions
diff --git a/internal/game/ui_color.go b/internal/game/ui_color.go
new file mode 100644
index 0000000..962728a
--- /dev/null
+++ b/internal/game/ui_color.go
@@ -0,0 +1,79 @@
+package game
+
+import (
+ "thehouseoficarus/internal/color"
+ "thehouseoficarus/internal/config"
+ "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.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("231")
+ case diff > 0 && diff < 5:
+ return color.Parse("208")
+ case diff >= 5:
+ return color.Parse("196")
+ case diff < 0 && diff > -5:
+ return color.Parse("190")
+ default:
+ return color.Parse("34")
+ }
+}
+
+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 *object.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)
+}