diff options
Diffstat (limited to 'internal/game/cmd_symbol.go')
| -rw-r--r-- | internal/game/cmd_symbol.go | 91 |
1 files changed, 91 insertions, 0 deletions
diff --git a/internal/game/cmd_symbol.go b/internal/game/cmd_symbol.go new file mode 100644 index 0000000..ec8d68b --- /dev/null +++ b/internal/game/cmd_symbol.go @@ -0,0 +1,91 @@ +package game + +import ( + "fmt" + "strings" + "unicode/utf8" + + "thehouseoficarus/internal/color" + "thehouseoficarus/internal/net" + "thehouseoficarus/internal/player" +) + +func (g *Game) executeSymbol(sess *net.Session, args []string, rawInput string) { + p := sess.Player + if len(args) == 0 { + data, ok := p.MapSymbols[p.RoomID] + if !ok { + sess.WriteLine("No custom symbol set for this room.") + return + } + msg := fmt.Sprintf("Custom symbol: %s", data.Char) + if data.Color != "" { + spec := color.Parse(data.Color) + colored := color.Render(g.colorMode(sess), spec, data.Char) + msg = fmt.Sprintf("Custom symbol: %s (%s)", colored, data.Color) + } + sess.WriteLine(msg) + return + } + + // ponytail: extract symbol char from rawInput to preserve case, since + // handleGameCommand lowercases args before dispatch (same pattern as say). + char := args[0] + if idx := strings.Index(strings.ToLower(rawInput), "symbol"); idx >= 0 { + rest := strings.TrimSpace(rawInput[idx+6:]) + if space := strings.Index(rest, " "); space >= 0 { + char = rest[:space] + } else { + char = rest + } + } + + cleared := false + if strings.EqualFold(char, "clear") || strings.EqualFold(char, "remove") { + delete(p.MapSymbols, p.RoomID) + if err := g.AccountStore.SaveCharacter(p); err != nil { + sess.WriteLine("Error saving: " + err.Error()) + return + } + sess.WriteLine("Custom symbol cleared for this room.") + cleared = true + } + + if !cleared { + r, size := utf8.DecodeRuneInString(char) + if size == 0 || size != len(char) || r == utf8.RuneError { + sess.WriteLine("Usage: symbol <single character> [color...]") + return + } + + colorSpec := "" + if len(args) > 1 { + colorSpec = strings.Join(args[1:], " ") + if colorSpec != "" { + spec := color.Parse(colorSpec) + if spec.Empty() { + sess.WriteLine("Invalid color spec. Use a color number like 232 and/or bold/dim/underline.") + return + } + } + } + + p.MapSymbols[p.RoomID] = player.MapSymbolData{ + Char: char, + Color: colorSpec, + } + + if err := g.AccountStore.SaveCharacter(p); err != nil { + sess.WriteLine("Error saving: " + err.Error()) + return + } + + msg := fmt.Sprintf("Map symbol set to: %s", char) + if colorSpec != "" { + spec := color.Parse(colorSpec) + colored := color.Render(g.colorMode(sess), spec, char) + msg = fmt.Sprintf("Map symbol set to: %s", colored) + } + sess.WriteLine(msg) + } +} |
