travel progress indicator

master
Jordan Orelli 6 years ago
parent 8cdd7bdaa6
commit aa6bd1ca9e

@ -104,6 +104,7 @@ are farther away take longer to communicate with.
}
type status struct {
GameCode string
State string
Balance int
Bombs int
@ -113,7 +114,8 @@ type status struct {
}
var statusTemplate = template.Must(template.New("status").Parse(`
********************************************************************************
--------------------------------------------------------------------------------
Current Game: {{.GameCode}}
Current State: {{.State}}
Balance: {{.Balance}}
Bombs: {{.Bombs}}
@ -121,7 +123,7 @@ Kills: {{.Kills}}
Location: {{.Location}}
{{.Description}}
********************************************************************************
`))
var statusCommand = Command{

@ -59,18 +59,7 @@ func (c *Connection) RunCommand(name string, args ...string) {
}()
switch name {
case "commands":
c.Line()
commands := c.Commands()
names := make([]string, len(commands))
for i := range commands {
names[i] = commands[i].name
}
sort.Strings(names)
for _, name := range names {
cmd := c.GetCommand(name)
c.Printf("%-20s%s\n", name, cmd.help)
}
c.Line()
c.ListCommands()
return
}
@ -82,6 +71,24 @@ func (c *Connection) RunCommand(name string, args ...string) {
cmd.handler(c, args...)
}
func (c *Connection) ListCommands() {
c.Printf("\n")
c.Line()
c.Printf("- Available Commands\n")
c.Line()
commands := c.Commands()
names := make([]string, len(commands))
for i := range commands {
names[i] = commands[i].name
}
sort.Strings(names)
for _, name := range names {
cmd := c.GetCommand(name)
c.Printf("%-20s%s\n", name, cmd.help)
}
c.Printf("\n")
}
func (c *Connection) SetState(s ConnectionState) {
if c.ConnectionState == s {
return
@ -92,8 +99,8 @@ func (c *Connection) SetState(s ConnectionState) {
c.ConnectionState.Exit(c)
}
log_info("enter state: %v", s)
s.Enter(c)
c.ConnectionState = s
s.Enter(c)
}
func (c *Connection) ReadLines(out chan []string) {

@ -32,6 +32,7 @@ var banner = `
O * ' .
A game of dark cunning in the vast unknown of space by Jordan Orelli.
##############################################################################################
`
@ -87,7 +88,7 @@ func (st *LobbyState) Enter(c *Connection) {
}
break
}
c.ListCommands()
}
func (st *LobbyState) Tick(c *Connection, frame int64) ConnectionState { return st }

@ -1,6 +1,7 @@
package main
import (
"bytes"
"fmt"
"text/template"
"time"
@ -45,8 +46,6 @@ 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) {
@ -54,20 +53,45 @@ func (t *TravelState) Enter(c *Connection) {
Departing *System
Destination *System
Duration time.Duration
Time time.Time
ETA time.Time
}{
t.start,
t.dest,
t.tripTime(),
time.Now(),
t.eta(),
})
t.start.Leave(c)
}
func (t *TravelState) Tick(c *Connection, frame int64) ConnectionState {
t.travelled += options.playerSpeed * options.lightSpeed
dt := options.playerSpeed * options.lightSpeed
segmentLength := t.dist / 18
x := t.travelled
for x > segmentLength {
x -= segmentLength
}
if x < dt {
c.Printf("%v", t.start.name)
var buf bytes.Buffer
segment := int(t.travelled / t.dist * 18)
buf.WriteRune('|')
for i := 0; i < 18; i++ {
switch {
case i == segment:
buf.WriteRune('>')
case i == segment-1:
buf.WriteRune('=')
case i < segment:
buf.WriteRune('-')
default:
buf.WriteRune(' ')
}
}
buf.WriteRune('|')
c.Write(buf.Bytes())
c.Printf("at %v in %v\n", t.dest.name, t.remaining())
}
t.travelled += dt
if t.travelled >= t.dist {
return Idle(t.dest)
}
@ -86,6 +110,7 @@ func (t *TravelState) String() string {
func (t *TravelState) PrintStatus(c *Connection) {
desc := fmt.Sprintf("Traveling from %v to %v", t.start, t.dest)
statusTemplate.Execute(c, status{
GameCode: c.game.id,
State: "In Transit",
Balance: c.money,
Bombs: c.bombs,

Loading…
Cancel
Save