cleaning up enter travel text

master
Jordan Orelli 6 years ago
parent 2914275282
commit 8cdd7bdaa6

@ -3,6 +3,7 @@ package main
import ( import (
"fmt" "fmt"
"strings" "strings"
"text/template"
) )
var commandRegistry map[string]*Command var commandRegistry map[string]*Command
@ -102,6 +103,27 @@ are farther away take longer to communicate with.
}, },
} }
type status struct {
State string
Balance int
Bombs int
Kills int
Location string
Description string
}
var statusTemplate = template.Must(template.New("status").Parse(`
********************************************************************************
Current State: {{.State}}
Balance: {{.Balance}}
Bombs: {{.Bombs}}
Kills: {{.Kills}}
Location: {{.Location}}
{{.Description}}
********************************************************************************
`))
var statusCommand = Command{ var statusCommand = Command{
name: "status", name: "status",
help: "display your current status", help: "display your current status",

@ -2,6 +2,7 @@ package main
import ( import (
"fmt" "fmt"
"text/template"
"time" "time"
) )
@ -33,20 +34,35 @@ func NewTravel(c *Connection, start, dest *System) ConnectionState {
help: "displays estimated time of arrival", help: "displays estimated time of arrival",
arity: 0, arity: 0,
handler: func(c *Connection, args ...string) { handler: func(c *Connection, args ...string) {
c.Printf("Remaining: %v\n", t.remaining()) c.Printf("%v\n", t.remaining())
c.Printf("Current time: %v\n", time.Now())
c.Printf("ETA: %v\n", t.eta())
}, },
}, },
} }
return t return t
} }
var enterTravelTemplate = template.Must(template.New("enter-travel").Parse(`
Departing: {{.Departing}}
Destination: {{.Destination}}
Total Trip Time: {{.Duration}}
Current Time: {{.Time}}
ETA: {{.ETA}}
`))
func (t *TravelState) Enter(c *Connection) { func (t *TravelState) Enter(c *Connection) {
c.Printf("Leaving %v, bound for %v.\n", t.start, t.dest) enterTravelTemplate.Execute(c, struct {
c.Printf("Trip duration: %v\n", t.tripTime()) Departing *System
c.Printf("Current time: %v\n", time.Now()) Destination *System
c.Printf("ETA: %v\n", t.eta()) Duration time.Duration
Time time.Time
ETA time.Time
}{
t.start,
t.dest,
t.tripTime(),
time.Now(),
t.eta(),
})
t.start.Leave(c) t.start.Leave(c)
} }
@ -68,7 +84,15 @@ func (t *TravelState) String() string {
} }
func (t *TravelState) PrintStatus(c *Connection) { func (t *TravelState) PrintStatus(c *Connection) {
panic("not done") desc := fmt.Sprintf("Traveling from %v to %v", t.start, t.dest)
statusTemplate.Execute(c, status{
State: "In Transit",
Balance: c.money,
Bombs: c.bombs,
Kills: c.kills,
Location: fmt.Sprintf("%s -> %s", t.start, t.dest),
Description: desc,
})
} }
func (t *TravelState) progress(c *Connection, args ...string) { func (t *TravelState) progress(c *Connection, args ...string) {

Loading…
Cancel
Save