From 1e9d3e90896dbfdb35fed6a3cbe85ae0d2010fc3 Mon Sep 17 00:00:00 2001 From: Sander Schobers Date: Wed, 15 Jan 2020 19:51:57 +0100 Subject: [PATCH] Renamed Tile to TileType. --- cmd/krampus19/playlevel.go | 6 +++--- cmd/krampus19/playlevelstate.go | 24 ++++++++++++------------ soko/level.go | 2 +- soko/levelparser.go | 6 +++--- soko/tile.go | 21 --------------------- soko/tiletype.go | 21 +++++++++++++++++++++ 6 files changed, 40 insertions(+), 40 deletions(-) delete mode 100644 soko/tile.go create mode 100644 soko/tiletype.go diff --git a/cmd/krampus19/playlevel.go b/cmd/krampus19/playlevel.go index 5b183bc..6bb5552 100644 --- a/cmd/krampus19/playlevel.go +++ b/cmd/krampus19/playlevel.go @@ -125,7 +125,7 @@ func (l *playLevel) Layout(ctx *alui.Context, bounds geom.RectangleF32) { var contentCenter = l.posToScreenF32(geom.PtF32(.5*float32(level.Width), .5*float32(level.Height)), 0) var content = geom.RectF32(contentCenter.X, contentCenter.Y, contentCenter.X, contentCenter.Y) for idx, tile := range l.state.Level().Tiles { - if tile == soko.TileNothing || tile == soko.TileInvalid { + if tile == soko.TileTypeNothing || tile == soko.TileTypeInvalid { continue } pos := level.IdxToPos(idx).ToF32() @@ -196,13 +196,13 @@ func (l *playLevel) Render(ctx *alui.Context, bounds geom.RectangleF32) { pos := geom.Pt(i%level.Width, i/level.Width) scr := entityLoc{pos.ToF32(), 0} switch t { - case soko.TileBasic: + case soko.TileTypeBasic: if l.state.IsNextToMagma(pos) { l.drawSprite("lava_brick", "magma", scr) } else { l.drawSprite("lava_brick", "lava_brick", scr) } - case soko.TileMagma: + case soko.TileTypeMagma: l.drawSprite("magma", "magma", scr) brick := l.state.FindSunkenBrick(pos) if brick != nil { diff --git a/cmd/krampus19/playlevelstate.go b/cmd/krampus19/playlevelstate.go index 722e367..b391abb 100644 --- a/cmd/krampus19/playlevelstate.go +++ b/cmd/krampus19/playlevelstate.go @@ -177,11 +177,11 @@ func (s *playLevelState) canMove(from, dir geom.Point) bool { return true } -func (s *playLevelState) checkTile(pos geom.Point, check func(pos geom.Point, idx int, t soko.Tile) bool) bool { +func (s *playLevelState) checkTile(pos geom.Point, check func(pos geom.Point, idx int, t soko.TileType) bool) bool { return s.checkTileNotFound(pos, check, false) } -func (s *playLevelState) checkTileNotFound(pos geom.Point, check func(pos geom.Point, idx int, t soko.Tile) bool, notFound bool) bool { +func (s *playLevelState) checkTileNotFound(pos geom.Point, check func(pos geom.Point, idx int, t soko.TileType) bool, notFound bool) bool { idx := s.level.PosToIdx(pos) if idx == -1 { return notFound @@ -200,33 +200,33 @@ func (s *playLevelState) findEntityAt(pos geom.Point) *entity { return s.sunken.FindEntity(pos) } -func (s *playLevelState) isObstructed(pos geom.Point, idx int, t soko.Tile) bool { +func (s *playLevelState) isObstructed(pos geom.Point, idx int, t soko.TileType) bool { if s.bricks.FindEntity(pos) != nil { return true // brick } switch s.level.Tiles[idx] { - case soko.TileMagma: + case soko.TileTypeMagma: return false - case soko.TileBasic: + case soko.TileTypeBasic: return false } return true } -func (s *playLevelState) isMagma(pos geom.Point, idx int, t soko.Tile) bool { - return t == soko.TileMagma +func (s *playLevelState) isMagma(pos geom.Point, idx int, t soko.TileType) bool { + return t == soko.TileTypeMagma } -func (s *playLevelState) isSolidTile(pos geom.Point, idx int, t soko.Tile) bool { +func (s *playLevelState) isSolidTile(pos geom.Point, idx int, t soko.TileType) bool { switch t { - case soko.TileBasic: + case soko.TileTypeBasic: return true - case soko.TileMagma: + case soko.TileTypeMagma: return s.sunken.FindEntity(pos) != nil } return false } -func (s *playLevelState) wouldBrickSink(pos geom.Point, idx int, t soko.Tile) bool { - return t == soko.TileMagma && s.sunken.FindEntity(pos) == nil +func (s *playLevelState) wouldBrickSink(pos geom.Point, idx int, t soko.TileType) bool { + return t == soko.TileTypeMagma && s.sunken.FindEntity(pos) == nil } diff --git a/soko/level.go b/soko/level.go index a681746..46ec4bf 100644 --- a/soko/level.go +++ b/soko/level.go @@ -7,7 +7,7 @@ import ( type Level struct { Width int Height int - Tiles []Tile + Tiles []TileType Entities []EntityType } diff --git a/soko/levelparser.go b/soko/levelparser.go index 03ba97f..566e403 100644 --- a/soko/levelparser.go +++ b/soko/levelparser.go @@ -59,16 +59,16 @@ func (c *levelContext) parseRow(p *gut.LineParser) gut.ParseLineFn { } func (c *levelContext) addRow(p *gut.LineParser, line string) gut.ParseLineFn { - var tiles []Tile + var tiles []TileType var entities []EntityType for i := 0; i < len(line); i += 2 { - tiles = append(tiles, Tile(line[i])) + tiles = append(tiles, TileType(line[i])) entities = append(entities, EntityType(line[i+1])) } for i, t := range tiles { if !t.IsValid() { - return p.EmitErr(fmt.Errorf("level contains invalid Tile at (%d, %d)", i, c.level.Height)) + return p.EmitErr(fmt.Errorf("level contains invalid TileType at (%d, %d)", i, c.level.Height)) } } for i, e := range entities { diff --git a/soko/tile.go b/soko/tile.go deleted file mode 100644 index af92fc8..0000000 --- a/soko/tile.go +++ /dev/null @@ -1,21 +0,0 @@ -package soko - -type Tile byte - -const ( - TileInvalid Tile = Tile(0) - TileNothing = '.' - TileBasic = '#' - TileMagma = '~' -) - -func (t Tile) IsValid() bool { - switch t { - case TileNothing: - case TileBasic: - case TileMagma: - default: - return false - } - return true -} diff --git a/soko/tiletype.go b/soko/tiletype.go new file mode 100644 index 0000000..0b8282b --- /dev/null +++ b/soko/tiletype.go @@ -0,0 +1,21 @@ +package soko + +type TileType byte + +const ( + TileTypeInvalid TileType = TileType(0) + TileTypeNothing = '.' + TileTypeBasic = '#' + TileTypeMagma = '~' +) + +func (t TileType) IsValid() bool { + switch t { + case TileTypeNothing: + case TileTypeBasic: + case TileTypeMagma: + default: + return false + } + return true +}