MOve glyph code into client

This commit is contained in:
Marc Di Luzio 2020-07-19 12:36:48 +01:00
parent 4a89cb9d6e
commit da91d31649
3 changed files with 4 additions and 20 deletions

60
cmd/rove/glyph.go Normal file
View file

@ -0,0 +1,60 @@
package main
import (
"log"
"github.com/mdiluz/rove/proto/roveapi"
)
// Glyph represents the text representation of something in the game
type Glyph byte
const (
// GlyphGroundRock is solid rock ground
GlyphGroundRock = Glyph('-')
// GlyphGroundGravel is loose rocks
GlyphGroundGravel = Glyph(':')
// GlyphGroundSand is sand
GlyphGroundSand = Glyph('~')
// GlyphRoverLive represents a live rover
GlyphRoverLive = Glyph('R')
// GlyphRockSmall is a small stashable rock
GlyphRockSmall = Glyph('o')
// GlyphRockLarge is a large blocking rock
GlyphRockLarge = Glyph('O')
)
// TileGlyph returns the glyph for this tile type
func TileGlyph(t roveapi.Tile) Glyph {
switch t {
case roveapi.Tile_Rock:
return GlyphGroundRock
case roveapi.Tile_Gravel:
return GlyphGroundGravel
case roveapi.Tile_Sand:
return GlyphGroundSand
}
log.Fatalf("Unknown tile type: %c", t)
return 0
}
// ObjectGlyph returns the glyph for this object type
func ObjectGlyph(o roveapi.Object) Glyph {
switch o {
case roveapi.Object_RoverLive:
return GlyphRoverLive
case roveapi.Object_RockSmall:
return GlyphRockSmall
case roveapi.Object_RockLarge:
return GlyphRockLarge
}
log.Fatalf("Unknown object type: %c", o)
return 0
}

View file

@ -10,7 +10,6 @@ import (
"path/filepath"
"time"
"github.com/mdiluz/rove/pkg/atlas"
"github.com/mdiluz/rove/pkg/maths"
"github.com/mdiluz/rove/pkg/version"
"github.com/mdiluz/rove/proto/roveapi"
@ -288,9 +287,9 @@ func InnerMain(command string, args ...string) error {
t := response.Tiles[i+num*j]
o := response.Objects[i+num*j]
if o != roveapi.Object_ObjectUnknown {
fmt.Printf("%c", atlas.ObjectGlyph(o))
fmt.Printf("%c", ObjectGlyph(o))
} else {
fmt.Printf("%c", atlas.TileGlyph(t))
fmt.Printf("%c", TileGlyph(t))
}
}