aboutsummaryrefslogtreecommitdiff
path: root/internal/game/color.go
diff options
context:
space:
mode:
authorhistoria <[not public]>2026-06-16 01:59:27 -0400
committerhistoria <[not public]>2026-06-16 01:59:27 -0400
commit43f21aabae8924f35c12c8485e690aeefe0089fb (patch)
treeb5fbadb89df3cf4ffec86503bb8e2d7e52b27454 /internal/game/color.go
parent4cc1ddcd185509080b4b3e15d1646567edd51c9d (diff)
downloadthehouseoficarus-43f21aabae8924f35c12c8485e690aeefe0089fb.tar.gz
feat: overhauled ansi color, added prompt options
Diffstat (limited to 'internal/game/color.go')
-rw-r--r--internal/game/color.go66
1 files changed, 62 insertions, 4 deletions
diff --git a/internal/game/color.go b/internal/game/color.go
index 45df212..f93f097 100644
--- a/internal/game/color.go
+++ b/internal/game/color.go
@@ -2,7 +2,9 @@ package game
import (
"thirdcollapse/internal/color"
+ "thirdcollapse/internal/config"
"thirdcollapse/internal/net"
+ "thirdcollapse/internal/object"
"thirdcollapse/internal/player"
)
@@ -13,10 +15,66 @@ func (g *Game) colorMode(sess *net.Session) string {
return "none"
}
-func (g *Game) colorize(sess *net.Session, name, text string) string {
- return color.Wrap(g.colorMode(sess), name, text)
+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.ColorSpec{}
+ }
+ 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.ColorSpec{}
+}
+
+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("fg=white")
+ case diff > 0 && diff < 5:
+ return color.Parse("fg=bright_yellow")
+ case diff >= 5:
+ return color.Parse("fg=bright_red")
+ case diff < 0 && diff > -5:
+ return color.Parse("fg=yellow")
+ default:
+ return color.Parse("fg=green")
+ }
+}
+
+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) colorTag(sess *net.Session, text string) string {
- return color.Tag(g.colorMode(sess), 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)
}