diff options
| author | Florian Fischer <florian.fischer@muhq.space> | 2024-12-27 12:40:19 +0100 |
|---|---|---|
| committer | Florian Fischer <florian.fischer@muhq.space> | 2025-01-27 16:43:58 +0100 |
| commit | 4e2ab55d345fd5e5c5d2d5bc56948611b15564d5 (patch) | |
| tree | c6998ac54687c442ad0baa541edd0fbf917b1308 /go/ui/mapView.go | |
| parent | 5aa8e7ddbc41aed55e7918e6afaec0b5c07fa510 (diff) | |
| download | muhqs-game-4e2ab55d345fd5e5c5d2d5bc56948611b15564d5.tar.gz muhqs-game-4e2ab55d345fd5e5c5d2d5bc56948611b15564d5.zip | |
introduce game.State interface abstraction
This allows to not use the internal game state directly from client
code.
Diffstat (limited to 'go/ui/mapView.go')
| -rw-r--r-- | go/ui/mapView.go | 40 |
1 files changed, 20 insertions, 20 deletions
diff --git a/go/ui/mapView.go b/go/ui/mapView.go index 1a91703c..8bd2e341 100644 --- a/go/ui/mapView.go +++ b/go/ui/mapView.go @@ -39,14 +39,14 @@ const ( type MapView struct { hoverPermInfo - gameState *game.State + gameState game.State mapLayer *ebiten.Image permanentsLayer *ebiten.Image tileHighlights map[game.Position][]color.Color permanentsHighlights map[game.Permanent][]color.Color } -func NewMapView(g *game.State) *MapView { +func NewMapView(g game.State) *MapView { vw := &MapView{ gameState: g, tileHighlights: make(map[game.Position][]color.Color), @@ -57,12 +57,12 @@ func NewMapView(g *game.State) *MapView { } func (mv *MapView) Height() int { - return len(mv.gameState.Map.Tiles) * TILE_HEIGHT + return len(mv.gameState.Map().Tiles) * TILE_HEIGHT } func (mv *MapView) Width() int { maxWidth := 0 - for _, row := range mv.gameState.Map.Tiles { + for _, row := range mv.gameState.Map().Tiles { if n := len(row); n > maxWidth { maxWidth = n } @@ -86,12 +86,12 @@ func rotateTileImg(x, y int, radian float64, op *ebiten.DrawImageOptions) { func (vw *MapView) handleStreet(x, y int, op *ebiten.DrawImageOptions) *ebiten.Image { var img *ebiten.Image - connections, left, right, above, below := vw.gameState.Map.FindStreetConnections(x, y) + connections, left, right, above, below := vw.gameState.Map().FindStreetConnections(x, y) if connections == 0 { // This street is not connected to another street -> // check any other non neutral tiles - connections, left, right, above, below = vw.gameState.Map.FindAnyConnections(x, y) + connections, left, right, above, below = vw.gameState.Map().FindAnyConnections(x, y) } // This street is not connected to anything. Seams odd! @@ -135,12 +135,12 @@ func (vw *MapView) handleStreet(x, y int, op *ebiten.DrawImageOptions) *ebiten.I func (vw *MapView) handleWall(x, y int, op *ebiten.DrawImageOptions) *ebiten.Image { var img *ebiten.Image - connections, left, right, above, below := vw.gameState.Map.FindFortificationConnections(x, y) + connections, left, right, above, below := vw.gameState.Map().FindFortificationConnections(x, y) if connections == 0 { // This wall is not connected to another wall -> // check any other non neutral tiles - connections, left, right, above, below = vw.gameState.Map.FindAnyConnections(x, y) + connections, left, right, above, below = vw.gameState.Map().FindAnyConnections(x, y) } // This wall is not connected to anything. Seams odd! @@ -175,7 +175,7 @@ func (vw *MapView) handleWall(x, y int, op *ebiten.DrawImageOptions) *ebiten.Ima } func (vw *MapView) handleGate(x, y int, op *ebiten.DrawImageOptions) (img *ebiten.Image) { - _, left, right, above, below := vw.gameState.Map.FindFortificationConnections(x, y) + _, left, right, above, below := vw.gameState.Map().FindFortificationConnections(x, y) if left || right { img = assets.GetTile("gate_lr") @@ -189,7 +189,7 @@ func (vw *MapView) handleGate(x, y int, op *ebiten.DrawImageOptions) (img *ebite } func (vw *MapView) handleTower(x, y int, op *ebiten.DrawImageOptions) *ebiten.Image { - connections, left, right, above, _ := vw.gameState.Map.FindFortificationConnections(x, y) + connections, left, right, above, _ := vw.gameState.Map().FindFortificationConnections(x, y) if connections == 0 { return assets.GetTile("tower") } @@ -205,7 +205,7 @@ func (vw *MapView) handleTower(x, y int, op *ebiten.DrawImageOptions) *ebiten.Im selector += "u" } // corner cases where tower is placed on the edge - if selector != "" && !strings.Contains(selector, "r") && len(vw.gameState.Map.Tiles[y])-1 == x { + if selector != "" && !strings.Contains(selector, "r") && len(vw.gameState.Map().Tiles[y])-1 == x { selector += "r" } @@ -222,8 +222,8 @@ func (vw *MapView) handleTower(x, y int, op *ebiten.DrawImageOptions) *ebiten.Im func (vw *MapView) newLayerImage() *ebiten.Image { // TODO: support non symetric maps - maxWidth := len(vw.gameState.Map.Tiles[0]) * TILE_WIDTH - maxHeight := len(vw.gameState.Map.Tiles) * TILE_HEIGHT + maxWidth := len(vw.gameState.Map().Tiles[0]) * TILE_WIDTH + maxHeight := len(vw.gameState.Map().Tiles) * TILE_HEIGHT return ebiten.NewImage(maxWidth, maxHeight) } @@ -232,10 +232,10 @@ func (vw *MapView) drawMapLayer(screen *ebiten.Image) { vw.mapLayer = vw.newLayerImage() x_px, y_px := 0.0, 0.0 - for y := 0; y < len(vw.gameState.Map.Tiles); y++ { - for x := 0; x < len(vw.gameState.Map.Tiles[y]); x++ { + for y := 0; y < len(vw.gameState.Map().Tiles); y++ { + for x := 0; x < len(vw.gameState.Map().Tiles[y]); x++ { pos := game.Position{X: x, Y: y} - tile := vw.gameState.Map.TileAt(pos) + tile := vw.gameState.Map().TileAt(pos) var tileImg *ebiten.Image op := &ebiten.DrawImageOptions{} @@ -289,7 +289,7 @@ func (vw *MapView) drawPermanentsLayer(screen *ebiten.Image) { if vw.permanentsLayer == nil { vw.permanentsLayer = vw.newLayerImage() - for i, p := range vw.gameState.Permanents { + for i, p := range vw.gameState.Permanents() { t := p.Tile() // Skip permanents with no containing tiles (e.g. piled ones) if t == nil { @@ -391,7 +391,7 @@ func (vw *MapView) FindObjectAt(screenX, screenY int) interface{} { if relativeX >= xMargin && relativeX <= TILE_WIDTH-xMargin && relativeY >= yMargin && relativeY <= TILE_HEIGHT-yMargin { - for _, p := range vw.gameState.Permanents { + for _, p := range vw.gameState.Permanents() { t := p.Tile() if t == nil { continue @@ -407,8 +407,8 @@ func (vw *MapView) FindObjectAt(screenX, screenY int) interface{} { } } - if y < len(vw.gameState.Map.Tiles) && x < len(vw.gameState.Map.Tiles[y]) { - return &vw.gameState.Map.Tiles[y][x] + if y < len(vw.gameState.Map().Tiles) && x < len(vw.gameState.Map().Tiles[y]) { + return &vw.gameState.Map().Tiles[y][x] } return nil |
