From b68916b7d83e9441bc4efc273ea72792c5760c38 Mon Sep 17 00:00:00 2001 From: Benjamin Kindle Date: Sun, 20 Dec 2020 10:57:15 -0500 Subject: [PATCH] format --- Wonky Blocks/UI/GameViewController.swift | 3 ++- Wonky Blocks/UI/MainMenuView.swift | 11 ++++---- Wonky Blocks/UI/PiecePreviewView.swift | 5 +++- Wonky Blocks/UI/RootView.swift | 26 +++++++++---------- Wonky Blocks/UI/SKNodes/WonkyGameBoard.swift | 5 +++- Wonky Blocks/UI/SKNodes/WonkyRow.swift | 10 ++++--- .../UI/SKNodes/WonkyRowIndicator.swift | 5 ++-- .../UI/SKNodes/WonkyTetronimo+movements.swift | 2 +- Wonky Blocks/UI/ScoreboardView.swift | 20 +++++++------- 9 files changed, 50 insertions(+), 37 deletions(-) diff --git a/Wonky Blocks/UI/GameViewController.swift b/Wonky Blocks/UI/GameViewController.swift index 09fb787..7fd358d 100644 --- a/Wonky Blocks/UI/GameViewController.swift +++ b/Wonky Blocks/UI/GameViewController.swift @@ -127,7 +127,8 @@ class WonkyGameViewController: UIViewController { } allCans.append(contactCan) let activeTetCan = self.gameState.$activeTet.sink { (newActive) in - let newPieceXPosition = (CGFloat(WonkyGameBoard.width) / 2) + WonkyRowIndicator.indicatorWidth - newActive.center.x + let newPieceXPosition = + (CGFloat(WonkyGameBoard.width) / 2) + WonkyRowIndicator.indicatorWidth - newActive.center.x newActive.position = CGPoint(x: newPieceXPosition, y: CGFloat(WonkyGameBoard.height)) newActive.removeFromParent() // removes from preview scene self.spriteKitView.scene?.addChild(newActive) diff --git a/Wonky Blocks/UI/MainMenuView.swift b/Wonky Blocks/UI/MainMenuView.swift index 032b0a7..5adef40 100644 --- a/Wonky Blocks/UI/MainMenuView.swift +++ b/Wonky Blocks/UI/MainMenuView.swift @@ -33,17 +33,18 @@ struct MainMenuView: View { .padding() } Text("High Score: \(gameState.highScore)") - Button("Reset High Score") { - gameState.resetHighScore() - } - .wonkyButton() + Button("Reset High Score") { + gameState.resetHighScore() + } + .wonkyButton() } } } struct WonkyButton: ViewModifier { func body(content: Content) -> some View { - return content + return + content .foregroundColor(.primary) .font(.headline) .padding(5) diff --git a/Wonky Blocks/UI/PiecePreviewView.swift b/Wonky Blocks/UI/PiecePreviewView.swift index eb6d006..cdb0d8a 100644 --- a/Wonky Blocks/UI/PiecePreviewView.swift +++ b/Wonky Blocks/UI/PiecePreviewView.swift @@ -40,7 +40,10 @@ struct PiecePreviewView: UIViewRepresentable { scene.isPaused = false piece.removeFromParent() scene.addChild(piece) - piece.position = CGPoint(x: Self.previewSize / 2 - piece.center.x, y: Self.previewSize / 2 - piece.center.y) + piece.position = CGPoint( + x: Self.previewSize / 2 - piece.center.x, + y: Self.previewSize / 2 - piece.center.y + ) scene.isPaused = true } } diff --git a/Wonky Blocks/UI/RootView.swift b/Wonky Blocks/UI/RootView.swift index c2e2d84..536ecf3 100644 --- a/Wonky Blocks/UI/RootView.swift +++ b/Wonky Blocks/UI/RootView.swift @@ -22,9 +22,9 @@ struct RootView: View { if gameState.gameStarted && size.size.width <= size.size.height && !gameState.gameOver { HStack { #if targetEnvironment(macCatalyst) - if gameState.gameStarted && showInstructions { - InstructionsView(layoutDirection: .horizontal) - } + if gameState.gameStarted && showInstructions { + InstructionsView(layoutDirection: .horizontal) + } #endif Spacer() ScoreBoardView() @@ -51,9 +51,9 @@ struct RootView: View { Spacer() Group { #if targetEnvironment(macCatalyst) - if showInstructions { - InstructionsView(layoutDirection: .vertical) - } + if showInstructions { + InstructionsView(layoutDirection: .vertical) + } #endif } } @@ -62,15 +62,15 @@ struct RootView: View { } // we don't want this to get in the way of button presses #if !targetEnvironment(macCatalyst) - if gameState.gameStarted, !gameState.gameOver { - VStack { - Spacer(minLength: size.size.height / 2) // cause joysticks to only be on bottom half so buttons can be pressed - HStack(spacing: 0) { - Joystick(state: self.$joyState, radius: 50) - Joystick(state: self.$rotateState, radius: 50) + if gameState.gameStarted, !gameState.gameOver { + VStack { + Spacer(minLength: size.size.height / 2) // cause joysticks to only be on bottom half so buttons can be pressed + HStack(spacing: 0) { + Joystick(state: self.$joyState, radius: 50) + Joystick(state: self.$rotateState, radius: 50) + } } } - } #endif } .onAppear { diff --git a/Wonky Blocks/UI/SKNodes/WonkyGameBoard.swift b/Wonky Blocks/UI/SKNodes/WonkyGameBoard.swift index b292085..7d4968d 100644 --- a/Wonky Blocks/UI/SKNodes/WonkyGameBoard.swift +++ b/Wonky Blocks/UI/SKNodes/WonkyGameBoard.swift @@ -28,7 +28,10 @@ class WonkyGameBoard: SKNode { let ground = SKShapeNode(rect: CGRect(x: 0, y: 0, width: Self.width, height: 0)) ground.name = "ground" - ground.physicsBody = SKPhysicsBody(edgeFrom: CGPoint(x: 0, y: -2), to: CGPoint(x: Self.width, y: -2)) + ground.physicsBody = SKPhysicsBody( + edgeFrom: CGPoint(x: 0, y: -2), + to: CGPoint(x: Self.width, y: -2) + ) ground.physicsBody?.categoryBitMask = groundCategory self.addChild(leftWall) diff --git a/Wonky Blocks/UI/SKNodes/WonkyRow.swift b/Wonky Blocks/UI/SKNodes/WonkyRow.swift index fde6d24..8027fd0 100644 --- a/Wonky Blocks/UI/SKNodes/WonkyRow.swift +++ b/Wonky Blocks/UI/SKNodes/WonkyRow.swift @@ -16,10 +16,14 @@ class WonkyRow: SKShapeNode { init(rowNumber: Int = 0) { super.init() let rowSize = CGSize(width: Self.rowWidth, height: Self.rowHeight) - let rowCenter = CGPoint(x: rowSize.width / 2, y: rowSize.height / 2 + (CGFloat(Self.rowHeight * rowNumber))) + let rowCenter = CGPoint( + x: rowSize.width / 2, y: rowSize.height / 2 + (CGFloat(Self.rowHeight * rowNumber))) self.path = CGPath( - rect: CGRect(x: 0, y: Self.rowHeight * rowNumber, width: Self.rowWidth, height: Self.rowHeight), - transform: nil) + rect: CGRect( + x: 0, y: Self.rowHeight * rowNumber, width: Self.rowWidth, height: Self.rowHeight + ), + transform: nil + ) physicsBody = SKPhysicsBody( rectangleOf: rowSize, center: CGPoint(x: rowCenter.x, y: rowCenter.y)) physicsBody?.affectedByGravity = true diff --git a/Wonky Blocks/UI/SKNodes/WonkyRowIndicator.swift b/Wonky Blocks/UI/SKNodes/WonkyRowIndicator.swift index a8ace7c..a50f8a2 100644 --- a/Wonky Blocks/UI/SKNodes/WonkyRowIndicator.swift +++ b/Wonky Blocks/UI/SKNodes/WonkyRowIndicator.swift @@ -10,7 +10,7 @@ import SpriteKit /// The bars on the left side of the board that indicate how full the row is. class WonkyRowIndicator: SKShapeNode { - static let indicatorWidth = CGFloat(WonkyRow.rowHeight) // square, based on the row height + static let indicatorWidth = CGFloat(WonkyRow.rowHeight) // square, based on the row height static let indicatorHeight = CGFloat(WonkyRow.rowHeight) override init() { @@ -23,8 +23,9 @@ class WonkyRowIndicator: SKShapeNode { } func updateRowStatus(fillPercentage: CGFloat) { + let rowStatusWidth = Self.indicatorWidth * fillPercentage self.path = CGPath( - rect: CGRect(x: 0, y: 0, width: Self.indicatorWidth * fillPercentage, height: Self.indicatorHeight), + rect: CGRect(x: 0, y: 0, width: rowStatusWidth, height: Self.indicatorHeight), transform: nil ) if fillPercentage > 1 { diff --git a/Wonky Blocks/UI/SKNodes/WonkyTetronimo+movements.swift b/Wonky Blocks/UI/SKNodes/WonkyTetronimo+movements.swift index 32fef94..5fd2f55 100644 --- a/Wonky Blocks/UI/SKNodes/WonkyTetronimo+movements.swift +++ b/Wonky Blocks/UI/SKNodes/WonkyTetronimo+movements.swift @@ -6,8 +6,8 @@ // Copyright © 2020 Benjamin Kindle. All rights reserved. // -import Foundation import CoreGraphics +import Foundation extension WonkyTetronimo { func moveLeft() { diff --git a/Wonky Blocks/UI/ScoreboardView.swift b/Wonky Blocks/UI/ScoreboardView.swift index 128099e..10b75ba 100644 --- a/Wonky Blocks/UI/ScoreboardView.swift +++ b/Wonky Blocks/UI/ScoreboardView.swift @@ -25,17 +25,17 @@ struct ScoreBoardView: View { Text("High Score: \(highScore)") } if gameState.gameStarted && !gameState.gameOver { - VStack(alignment: .center) { - Button("Main Menu") { - gameState.gameStarted = false - } - .wonkyButton() - - Button(gameState.paused ? "Resume" : "Pause") { - gameState.paused.toggle() - } - .wonkyButton() + VStack(alignment: .center) { + Button("Main Menu") { + gameState.gameStarted = false } + .wonkyButton() + + Button(gameState.paused ? "Resume" : "Pause") { + gameState.paused.toggle() + } + .wonkyButton() + } } } }