feat: add chat emote system (/hi, /gg, /go, /wait, /help)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-03-25 14:05:04 +09:00
parent 083a895be2
commit fc0c5edc38
3 changed files with 53 additions and 1 deletions

17
game/emote.go Normal file
View File

@@ -0,0 +1,17 @@
package game
var emotes = map[string]string{
"/hi": "👋 waves hello!",
"/gg": "🎉 says GG!",
"/go": "⚔️ says Let's go!",
"/wait": "✋ says Wait!",
"/help": "🆘 calls for help!",
}
func ParseEmote(input string) (string, bool) {
if input == "" {
return "", false
}
text, ok := emotes[input]
return text, ok
}

31
game/emote_test.go Normal file
View File

@@ -0,0 +1,31 @@
package game
import "testing"
func TestParseEmote(t *testing.T) {
tests := []struct {
input string
isEmote bool
expected string
}{
{"/hi", true, "👋 waves hello!"},
{"/gg", true, "🎉 says GG!"},
{"/go", true, "⚔️ says Let's go!"},
{"/wait", true, "✋ says Wait!"},
{"/help", true, "🆘 calls for help!"},
{"/unknown", false, ""},
{"hello", false, ""},
{"", false, ""},
}
for _, tt := range tests {
t.Run(tt.input, func(t *testing.T) {
result, ok := ParseEmote(tt.input)
if ok != tt.isEmote {
t.Errorf("ParseEmote(%q) isEmote = %v, want %v", tt.input, ok, tt.isEmote)
}
if ok && result != tt.expected {
t.Errorf("ParseEmote(%q) = %q, want %q", tt.input, result, tt.expected)
}
})
}
}

View File

@@ -361,7 +361,11 @@ func (s *GameSession) BuyItem(playerID string, itemIdx int) bool {
func (s *GameSession) SendChat(playerName, message string) {
s.mu.Lock()
defer s.mu.Unlock()
s.addLog(fmt.Sprintf("[%s] %s", playerName, message))
if emoteText, ok := ParseEmote(message); ok {
s.addLog(fmt.Sprintf("✨ %s %s", playerName, emoteText))
} else {
s.addLog(fmt.Sprintf("[%s] %s", playerName, message))
}
}
// LeaveShop exits the shop phase