From acdd01909315c4a6f6dbae7064540f3a21b36008 Mon Sep 17 00:00:00 2001 From: Marc Di Luzio Date: Sun, 19 Jul 2020 11:50:19 +0100 Subject: [PATCH] Add Glyph methods to convert to a glyph --- pkg/atlas/atlas.go | 19 +++++++++++++++++++ pkg/atlas/objects.go | 19 +++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/pkg/atlas/atlas.go b/pkg/atlas/atlas.go index 73ea341..aaa7fd8 100644 --- a/pkg/atlas/atlas.go +++ b/pkg/atlas/atlas.go @@ -1,6 +1,8 @@ package atlas import ( + "log" + "github.com/mdiluz/rove/pkg/maths" ) @@ -21,6 +23,23 @@ const ( TileSand = Tile(GlyphSand) ) +// Glyph returns the glyph for this tile type +func (t Tile) Glyph() Glyph { + switch t { + case TileNone: + return GlyphNone + case TileRock: + return GlyphRock + case TileGravel: + return GlyphGravel + case TileSand: + return GlyphSand + } + + log.Fatalf("Unknown tile type: %c", t) + return GlyphNone +} + // Atlas represents a 2D world atlas of tiles and objects type Atlas interface { // SetTile sets a location on the Atlas to a type of tile diff --git a/pkg/atlas/objects.go b/pkg/atlas/objects.go index cb71229..1b9eb87 100644 --- a/pkg/atlas/objects.go +++ b/pkg/atlas/objects.go @@ -1,5 +1,7 @@ package atlas +import "log" + // ObjectType represents an object type type ObjectType byte @@ -18,6 +20,23 @@ const ( ObjectLargeRock = ObjectType(GlyphLargeRock) ) +// Glyph returns the glyph for this object type +func (o ObjectType) Glyph() Glyph { + switch o { + case ObjectNone: + return GlyphNone + case ObjectRover: + return GlyphRover + case ObjectSmallRock: + return GlyphSmallRock + case ObjectLargeRock: + return GlyphLargeRock + } + + log.Fatalf("Unknown object type: %c", o) + return GlyphNone +} + // Object represents an object in the world type Object struct { // The type of the object