fix broken help command

master
Jordan Orelli 5 years ago
parent a330d87b4c
commit b0aaa046ad

@ -56,7 +56,6 @@ func MakeBomb(s *System) ConnectionState {
m.CommandSuite = CommandSet{ m.CommandSuite = CommandSet{
balCommand, balCommand,
BroadcastCommand(s), BroadcastCommand(s),
helpCommand,
NearbyCommand(s), NearbyCommand(s),
playersCommand, playersCommand,
} }

@ -17,7 +17,6 @@ func MakeColony(c *Connection, sys *System) {
CommandSuite: CommandSet{ CommandSuite: CommandSet{
balCommand, balCommand,
BroadcastCommand(sys), BroadcastCommand(sys),
helpCommand,
NearbyCommand(sys), NearbyCommand(sys),
playersCommand, playersCommand,
}, },

@ -35,6 +35,12 @@ func (c Command) Commands() []Command {
type CommandSet []Command type CommandSet []Command
func (c CommandSet) GetCommand(name string) *Command { func (c CommandSet) GetCommand(name string) *Command {
switch name {
case "help":
return &helpCommand
case "commands":
return &commandsCommand
}
for _, cmd := range c { for _, cmd := range c {
if cmd.name == name { if cmd.name == name {
return &cmd return &cmd
@ -44,7 +50,7 @@ func (c CommandSet) GetCommand(name string) *Command {
} }
func (c CommandSet) Commands() []Command { func (c CommandSet) Commands() []Command {
return []Command(c) return append([]Command(c), helpCommand, commandsCommand)
} }
var helpCommand = Command{ var helpCommand = Command{
@ -73,10 +79,9 @@ attempting to communicate from one star system to another, it takes time for
the light of your message to reach the other star systems. Star systems that the light of your message to reach the other star systems. Star systems that
are farther away take longer to communicate with. are farther away take longer to communicate with.
` `
if len(args) == 0 {
msg = strings.TrimSpace(msg) msg = strings.TrimSpace(msg)
fmt.Fprintln(conn, msg) fmt.Fprintln(conn, msg)
if len(args) == 0 {
fmt.Fprint(conn, "\n") fmt.Fprint(conn, "\n")
conn.Line() conn.Line()
fmt.Fprint(conn, "\n") fmt.Fprint(conn, "\n")
@ -85,8 +90,8 @@ are farther away take longer to communicate with.
return return
} }
for _, cmdName := range args { for _, cmdName := range args {
cmd, ok := commandRegistry[cmdName] cmd := conn.GetCommand(cmdName)
if !ok { if cmd == nil {
conn.Printf("no such command: %v\n", cmdName) conn.Printf("no such command: %v\n", cmdName)
continue continue
} }

@ -15,7 +15,6 @@ func Idle(sys *System) ConnectionState {
i := &IdleState{System: sys} i := &IdleState{System: sys}
i.CommandSuite = CommandSet{ i.CommandSuite = CommandSet{
balCommand, balCommand,
helpCommand,
playersCommand, playersCommand,
BroadcastCommand(sys), BroadcastCommand(sys),
NearbyCommand(sys), NearbyCommand(sys),

@ -44,8 +44,6 @@ type LobbyState struct {
func EnterLobby() ConnectionState { func EnterLobby() ConnectionState {
return &LobbyState{ return &LobbyState{
CommandSuite: CommandSet{ CommandSuite: CommandSet{
commandsCommand,
helpCommand,
newGameCommand, newGameCommand,
joinGameCommand, joinGameCommand,
}, },

@ -14,7 +14,6 @@ func Mine(sys *System) ConnectionState {
m := &MiningState{System: sys} m := &MiningState{System: sys}
m.CommandSuite = CommandSet{ m.CommandSuite = CommandSet{
balCommand, balCommand,
helpCommand,
playersCommand, playersCommand,
BroadcastCommand(sys), BroadcastCommand(sys),
NearbyCommand(sys), NearbyCommand(sys),

@ -10,7 +10,6 @@ func MakeShield(c *Connection, s *System) {
CommandSuite: CommandSet{ CommandSuite: CommandSet{
balCommand, balCommand,
BroadcastCommand(s), BroadcastCommand(s),
helpCommand,
NearbyCommand(s), NearbyCommand(s),
playersCommand, playersCommand,
}, },

@ -20,7 +20,6 @@ func NewTravel(c *Connection, start, dest *System) ConnectionState {
dist: start.DistanceTo(dest), dist: start.DistanceTo(dest),
} }
t.CommandSuite = CommandSet{ t.CommandSuite = CommandSet{
helpCommand,
playersCommand, playersCommand,
balCommand, balCommand,
Command{ Command{

Loading…
Cancel
Save