fix broken help command

master
Jordan Orelli 6 years ago
parent a330d87b4c
commit b0aaa046ad

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

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

@ -35,6 +35,12 @@ func (c Command) Commands() []Command {
type CommandSet []Command
func (c CommandSet) GetCommand(name string) *Command {
switch name {
case "help":
return &helpCommand
case "commands":
return &commandsCommand
}
for _, cmd := range c {
if cmd.name == name {
return &cmd
@ -44,7 +50,7 @@ func (c CommandSet) GetCommand(name string) *Command {
}
func (c CommandSet) Commands() []Command {
return []Command(c)
return append([]Command(c), helpCommand, commandsCommand)
}
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
are farther away take longer to communicate with.
`
if len(args) == 0 {
msg = strings.TrimSpace(msg)
fmt.Fprintln(conn, msg)
if len(args) == 0 {
fmt.Fprint(conn, "\n")
conn.Line()
fmt.Fprint(conn, "\n")
@ -85,8 +90,8 @@ are farther away take longer to communicate with.
return
}
for _, cmdName := range args {
cmd, ok := commandRegistry[cmdName]
if !ok {
cmd := conn.GetCommand(cmdName)
if cmd == nil {
conn.Printf("no such command: %v\n", cmdName)
continue
}

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

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

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

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

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

Loading…
Cancel
Save