diff options
Diffstat (limited to 'internal/game/render_color.go')
| -rw-r--r-- | internal/game/render_color.go | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/internal/game/render_color.go b/internal/game/render_color.go index 958b671..ab3692e 100644 --- a/internal/game/render_color.go +++ b/internal/game/render_color.go @@ -107,3 +107,58 @@ func (g *Game) itemColorize(sess *net.Session, itemDef *item.ItemDef, text strin } return g.colorize(sess, "item", text) } + +// namedColorSpecs maps every color category name to its resolved ColorSpec +// for the session, letting inline tags like {command} bind to a color +// category. All player-overridable categories, server defaults, and constant +// colors are included so any color can be tagged in data content. +func (g *Game) namedColorSpecs(sess *net.Session) map[string]color.ColorSpec { + names := make(map[string]color.ColorSpec) + for name := range config.DefaultColors() { + if spec := g.resolveColor(sess, name); !spec.Empty() { + names[name] = spec + } + } + if g.ColorConfig != nil { + for name := range *g.ColorConfig { + if _, ok := names[name]; ok { + continue + } + if spec := g.resolveColor(sess, name); !spec.Empty() { + names[name] = spec + } + } + } + for name := range config.DefaultConstantColors() { + if spec := g.resolveConstant(sess, name); !spec.Empty() { + names[name] = spec + } + } + if g.ConstantColorConfig != nil { + for name := range *g.ConstantColorConfig { + if _, ok := names[name]; ok { + continue + } + if spec := g.resolveConstant(sess, name); !spec.Empty() { + names[name] = spec + } + } + } + return names +} + +// expandTags expands inline {spec}text{/} tags, including named color +// categories such as {command}, using the session's resolved colors. +func (g *Game) expandTags(sess *net.Session, text string) string { + return color.ExpandTagsNamed(g.colorMode(sess), g.namedColorSpecs(sess), text) +} + +// expandTagsDefault is expandTags with a default spec applied to untagged text. +func (g *Game) expandTagsDefault(sess *net.Session, def color.ColorSpec, text string) string { + return color.ExpandTagsDefaultNamed(g.colorMode(sess), def, g.namedColorSpecs(sess), text) +} + +// expandDialogTags expands dialog text (quoted speech) with named color tags. +func (g *Game) expandDialogTags(sess *net.Session, dialogSpec color.ColorSpec, text string) string { + return color.ExpandDialogTagsNamed(g.colorMode(sess), dialogSpec, g.namedColorSpecs(sess), text) +} |
