// // BoardView.swift // Tetris // // Created by Shadowfacts on 10/14/19. // Copyright © 2019 Shadowfacts. All rights reserved. // import SwiftUI import TetrisKit public struct BoardView: View { @Binding var board: GameBoard @Binding var currentPiece: GamePiece? @Binding var droppedPiece: GamePiece? public init(board: Binding, currentPiece: Binding, droppedPiece: Binding) { self._board = board self._currentPiece = currentPiece self._droppedPiece = droppedPiece } public var body: some View { GeometryReader { (geometry) in ZStack(alignment: .topLeading) { TilesView(board: self.$board) if self.droppedPiece != nil { GamePieceView(size: min(geometry.size.width / CGFloat(self.board.width), geometry.size.height / CGFloat(self.board.height)), piece: self.droppedPiece!, color: .gray, border: false) } if self.currentPiece != nil { GamePieceView(size: min(geometry.size.width / CGFloat(self.board.width), geometry.size.height / CGFloat(self.board.height)), piece: self.currentPiece!) } } } } } struct BoardView_Previews: PreviewProvider { @ObservedObject static var controller: GameController = { var c = GameController() c.currentPiece = GamePiece(tetromino: .t) return c }() static var previews: some View { BoardView(board: $controller.board, currentPiece: $controller.currentPiece, droppedPiece: $controller.currentPieceAtDropPoint) } }