From 18c293847025300c8b86c0db2027a1eec110814d Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Sun, 20 Oct 2019 19:21:04 -0400 Subject: [PATCH] Change tetromino appearance --- TetrisUI/CurrentPieceView.swift | 27 ++++++++++--------- .../TetrominoAqua.colorset/Contents.json | 4 +-- .../TetrominoAquaLight.colorset/Contents.json | 20 ++++++++++++++ .../TetrominoBlueLight.colorset/Contents.json | 20 ++++++++++++++ .../TetrominoGreen.colorset/Contents.json | 4 +-- .../Contents.json | 20 ++++++++++++++ .../TetrominoOrange.colorset/Contents.json | 6 ++--- .../Contents.json | 20 ++++++++++++++ .../Contents.json | 20 ++++++++++++++ .../TetrominoRedLight.colorset/Contents.json | 20 ++++++++++++++ .../TetrominoYellow.colorset/Contents.json | 4 +-- .../Contents.json | 20 ++++++++++++++ TetrisUI/Tetromino+Color.swift | 18 +++++++++++++ TetrisUI/TetrominoView.swift | 21 +++++++-------- TetrisUI/TilesView.swift | 5 ++-- 15 files changed, 194 insertions(+), 35 deletions(-) create mode 100644 TetrisUI/Media.xcassets/TetrominoAquaLight.colorset/Contents.json create mode 100644 TetrisUI/Media.xcassets/TetrominoBlueLight.colorset/Contents.json create mode 100644 TetrisUI/Media.xcassets/TetrominoGreenLight.colorset/Contents.json create mode 100644 TetrisUI/Media.xcassets/TetrominoOrangeLight.colorset/Contents.json create mode 100644 TetrisUI/Media.xcassets/TetrominoPurpleLight.colorset/Contents.json create mode 100644 TetrisUI/Media.xcassets/TetrominoRedLight.colorset/Contents.json create mode 100644 TetrisUI/Media.xcassets/TetrominoYellowLight.colorset/Contents.json diff --git a/TetrisUI/CurrentPieceView.swift b/TetrisUI/CurrentPieceView.swift index 4b2cc6f..404b63c 100644 --- a/TetrisUI/CurrentPieceView.swift +++ b/TetrisUI/CurrentPieceView.swift @@ -17,19 +17,20 @@ struct CurrentPieceView: View { var body: some View { GridView(rows: self.boardHeight, columns: self.boardWidth) { (col, row, size) in - Rectangle() - .foregroundColor(self.colorAt(col, row)) - .frame(width: size, height: size) - } - } - - func colorAt(_ col: Int, _ row: Int) -> Color { - if currentPieceAt(col, row) { - return self.currentPiece!.tetromino.color - } else if droppedPieceAt(col, row) { - return .gray - } else { - return .clear + if self.currentPieceAt(col, row) { + Rectangle() + .foregroundColor(self.currentPiece!.tetromino.color) + .frame(width: size, height: size) + .border(self.currentPiece!.tetromino.borderColor, width: 6) + } else if self.droppedPieceAt(col, row) { + Rectangle() + .foregroundColor(.gray) + .frame(width: size, height: size) + } else { + Rectangle() + .foregroundColor(.clear) + .frame(width: size, height: size) + } } } diff --git a/TetrisUI/Media.xcassets/TetrominoAqua.colorset/Contents.json b/TetrisUI/Media.xcassets/TetrominoAqua.colorset/Contents.json index 5358ebd..a1745c0 100644 --- a/TetrisUI/Media.xcassets/TetrominoAqua.colorset/Contents.json +++ b/TetrisUI/Media.xcassets/TetrominoAqua.colorset/Contents.json @@ -11,8 +11,8 @@ "components" : { "red" : "0", "alpha" : "1.000", - "blue" : "211", - "green" : "214" + "blue" : "202", + "green" : "205" } } } diff --git a/TetrisUI/Media.xcassets/TetrominoAquaLight.colorset/Contents.json b/TetrisUI/Media.xcassets/TetrominoAquaLight.colorset/Contents.json new file mode 100644 index 0000000..e775d66 --- /dev/null +++ b/TetrisUI/Media.xcassets/TetrominoAquaLight.colorset/Contents.json @@ -0,0 +1,20 @@ +{ + "info" : { + "version" : 1, + "author" : "xcode" + }, + "colors" : [ + { + "idiom" : "universal", + "color" : { + "color-space" : "srgb", + "components" : { + "red" : "0.320", + "alpha" : "1.000", + "blue" : "0.908", + "green" : "0.916" + } + } + } + ] +} \ No newline at end of file diff --git a/TetrisUI/Media.xcassets/TetrominoBlueLight.colorset/Contents.json b/TetrisUI/Media.xcassets/TetrominoBlueLight.colorset/Contents.json new file mode 100644 index 0000000..8a9ebf4 --- /dev/null +++ b/TetrisUI/Media.xcassets/TetrominoBlueLight.colorset/Contents.json @@ -0,0 +1,20 @@ +{ + "info" : { + "version" : 1, + "author" : "xcode" + }, + "colors" : [ + { + "idiom" : "universal", + "color" : { + "color-space" : "srgb", + "components" : { + "red" : "0.294", + "alpha" : "1.000", + "blue" : "0.839", + "green" : "0.495" + } + } + } + ] +} \ No newline at end of file diff --git a/TetrisUI/Media.xcassets/TetrominoGreen.colorset/Contents.json b/TetrisUI/Media.xcassets/TetrominoGreen.colorset/Contents.json index 8e7fb2d..0854e39 100644 --- a/TetrisUI/Media.xcassets/TetrominoGreen.colorset/Contents.json +++ b/TetrisUI/Media.xcassets/TetrominoGreen.colorset/Contents.json @@ -11,8 +11,8 @@ "components" : { "red" : "0", "alpha" : "1.000", - "blue" : "71", - "green" : "214" + "blue" : "68", + "green" : "204" } } } diff --git a/TetrisUI/Media.xcassets/TetrominoGreenLight.colorset/Contents.json b/TetrisUI/Media.xcassets/TetrominoGreenLight.colorset/Contents.json new file mode 100644 index 0000000..dd596ce --- /dev/null +++ b/TetrisUI/Media.xcassets/TetrominoGreenLight.colorset/Contents.json @@ -0,0 +1,20 @@ +{ + "info" : { + "version" : 1, + "author" : "xcode" + }, + "colors" : [ + { + "idiom" : "universal", + "color" : { + "color-space" : "srgb", + "components" : { + "red" : "0.364", + "alpha" : "1.000", + "blue" : "0.542", + "green" : "0.899" + } + } + } + ] +} \ No newline at end of file diff --git a/TetrisUI/Media.xcassets/TetrominoOrange.colorset/Contents.json b/TetrisUI/Media.xcassets/TetrominoOrange.colorset/Contents.json index 95662fa..92a079b 100644 --- a/TetrisUI/Media.xcassets/TetrominoOrange.colorset/Contents.json +++ b/TetrisUI/Media.xcassets/TetrominoOrange.colorset/Contents.json @@ -9,10 +9,10 @@ "color" : { "color-space" : "srgb", "components" : { - "red" : "255", + "red" : "1.000", "alpha" : "1.000", - "blue" : "0", - "green" : "128" + "blue" : "0.000", + "green" : "0.502" } } } diff --git a/TetrisUI/Media.xcassets/TetrominoOrangeLight.colorset/Contents.json b/TetrisUI/Media.xcassets/TetrominoOrangeLight.colorset/Contents.json new file mode 100644 index 0000000..de2607c --- /dev/null +++ b/TetrisUI/Media.xcassets/TetrominoOrangeLight.colorset/Contents.json @@ -0,0 +1,20 @@ +{ + "info" : { + "version" : 1, + "author" : "xcode" + }, + "colors" : [ + { + "idiom" : "universal", + "color" : { + "color-space" : "srgb", + "components" : { + "red" : "255", + "alpha" : "1.000", + "blue" : "89", + "green" : "172" + } + } + } + ] +} \ No newline at end of file diff --git a/TetrisUI/Media.xcassets/TetrominoPurpleLight.colorset/Contents.json b/TetrisUI/Media.xcassets/TetrominoPurpleLight.colorset/Contents.json new file mode 100644 index 0000000..c592b40 --- /dev/null +++ b/TetrisUI/Media.xcassets/TetrominoPurpleLight.colorset/Contents.json @@ -0,0 +1,20 @@ +{ + "info" : { + "version" : 1, + "author" : "xcode" + }, + "colors" : [ + { + "idiom" : "universal", + "color" : { + "color-space" : "srgb", + "components" : { + "red" : "0.722", + "alpha" : "1.000", + "blue" : "0.839", + "green" : "0.294" + } + } + } + ] +} \ No newline at end of file diff --git a/TetrisUI/Media.xcassets/TetrominoRedLight.colorset/Contents.json b/TetrisUI/Media.xcassets/TetrominoRedLight.colorset/Contents.json new file mode 100644 index 0000000..6e9b879 --- /dev/null +++ b/TetrisUI/Media.xcassets/TetrominoRedLight.colorset/Contents.json @@ -0,0 +1,20 @@ +{ + "info" : { + "version" : 1, + "author" : "xcode" + }, + "colors" : [ + { + "idiom" : "universal", + "color" : { + "color-space" : "srgb", + "components" : { + "red" : "0.839", + "alpha" : "1.000", + "blue" : "0.449", + "green" : "0.294" + } + } + } + ] +} \ No newline at end of file diff --git a/TetrisUI/Media.xcassets/TetrominoYellow.colorset/Contents.json b/TetrisUI/Media.xcassets/TetrominoYellow.colorset/Contents.json index 4ac8cd1..60b5519 100644 --- a/TetrisUI/Media.xcassets/TetrominoYellow.colorset/Contents.json +++ b/TetrisUI/Media.xcassets/TetrominoYellow.colorset/Contents.json @@ -11,8 +11,8 @@ "components" : { "red" : "255", "alpha" : "1.000", - "blue" : "71", - "green" : "229" + "blue" : "0", + "green" : "206" } } } diff --git a/TetrisUI/Media.xcassets/TetrominoYellowLight.colorset/Contents.json b/TetrisUI/Media.xcassets/TetrominoYellowLight.colorset/Contents.json new file mode 100644 index 0000000..c3c15ef --- /dev/null +++ b/TetrisUI/Media.xcassets/TetrominoYellowLight.colorset/Contents.json @@ -0,0 +1,20 @@ +{ + "info" : { + "version" : 1, + "author" : "xcode" + }, + "colors" : [ + { + "idiom" : "universal", + "color" : { + "color-space" : "srgb", + "components" : { + "red" : "1.000", + "alpha" : "1.000", + "blue" : "0.431", + "green" : "0.920" + } + } + } + ] +} \ No newline at end of file diff --git a/TetrisUI/Tetromino+Color.swift b/TetrisUI/Tetromino+Color.swift index 41b77a0..8e745d9 100644 --- a/TetrisUI/Tetromino+Color.swift +++ b/TetrisUI/Tetromino+Color.swift @@ -28,4 +28,22 @@ extension Tetromino { return Color("TetrominoGreen", bundle: .tetrisUI) } } + var borderColor: Color { + switch self { + case .i: + return Color("TetrominoAquaLight", bundle: .tetrisUI) + case .o: + return Color("TetrominoYellowLight", bundle: .tetrisUI) + case .t: + return Color("TetrominoPurpleLight", bundle: .tetrisUI) + case .j: + return Color("TetrominoOrangeLight", bundle: .tetrisUI) + case .l: + return Color("TetrominoBlueLight", bundle: .tetrisUI) + case .s: + return Color("TetrominoRedLight", bundle: .tetrisUI) + case .z: + return Color("TetrominoGreenLight", bundle: .tetrisUI) + } + } } diff --git a/TetrisUI/TetrominoView.swift b/TetrisUI/TetrominoView.swift index d63add2..6750e25 100644 --- a/TetrisUI/TetrominoView.swift +++ b/TetrisUI/TetrominoView.swift @@ -18,9 +18,16 @@ public struct TetrominoView: View { public var body: some View { GridView(rows: self.rows, columns: self.columns) { (col, row, size) in - Rectangle() - .foregroundColor(self.colorAt(col, row)) - .frame(width: size, height: size) + if row < self.tetromino.shape.count && col < self.tetromino.shape[row].count && self.tetromino.shape[row][col] { + Rectangle() + .foregroundColor(self.tetromino.color) + .frame(width: size, height: size) + .border(self.tetromino.borderColor, width: 6) + } else { + Rectangle() + .foregroundColor(.clear) + .frame(width: size, height: size) + } } } @@ -39,14 +46,6 @@ public struct TetrominoView: View { }) ?? row.count - 1) + 1 }.max() ?? self.tetromino.shape.first!.count } - - func colorAt(_ col: Int, _ row: Int) -> Color { - if row < tetromino.shape.count && col < tetromino.shape[row].count && tetromino.shape[row][col] { - return tetromino.color - } else { - return .clear - } - } } struct TetrominoView_Previews: PreviewProvider { diff --git a/TetrisUI/TilesView.swift b/TetrisUI/TilesView.swift index 34f850f..8daf60f 100644 --- a/TetrisUI/TilesView.swift +++ b/TetrisUI/TilesView.swift @@ -17,12 +17,13 @@ struct TilesView: View { if self.board[col, row] { Rectangle() .frame(width: size, height: size) - .foregroundColor(self.board[col, row]?.color ?? Color("Background", bundle: .tetrisUI)) + .foregroundColor(self.board[col, row]!.color) + .border(self.board[col, row]!.borderColor, width: 6) } else { Rectangle() .frame(width: size, height: size) .foregroundColor(Color("Background", bundle: .tetrisUI)) - .border(Color("TileBorder"), width: 1) + .border(Color("TileBorder", bundle: .tetrisUI), width: 2) } } }