LastMUD/internal/game/commands.go

36 lines
715 B
Go
Raw Normal View History

2025-06-22 22:27:56 +03:00
package game
2025-06-22 22:59:46 +03:00
import (
"strings"
"code.haedhutner.dev/mvv/LastMUD/internal/game/command"
)
2025-06-22 22:27:56 +03:00
type CommandType = string
const (
SayCommand CommandType = "say"
)
func (game *LastMUDGame) CreateGameCommandRegistry() *command.CommandRegistry {
return command.CreateCommandRegistry(
command.CreateCommandDefinition(
SayCommand,
func(tokens []command.Token) bool {
return len(tokens) > 1 && tokens[0].Lexeme() == "say"
},
func(tokens []command.Token) []command.Parameter {
2025-06-22 22:59:46 +03:00
lexemes := []string{}
2025-06-22 22:27:56 +03:00
for _, t := range tokens[1:] {
2025-06-22 22:59:46 +03:00
lexemes = append(lexemes, t.Lexeme())
2025-06-22 22:27:56 +03:00
}
return []command.Parameter{
2025-06-22 22:59:46 +03:00
command.CreateParameter(strings.Join(lexemes, " ")),
2025-06-22 22:27:56 +03:00
}
},
),
)
}