Move colors to TetrisUI asset catalog

This commit is contained in:
Shadowfacts 2019-10-17 12:06:26 -04:00
parent 68fab068d9
commit 758de0c1f3
Signed by: shadowfacts
GPG Key ID: 94A5AB95422746E5
13 changed files with 185 additions and 26 deletions

View File

@ -0,0 +1,16 @@
//
// BundleHelper.swift
// Tetris
//
// Created by Shadowfacts on 10/17/19.
// Copyright © 2019 Shadowfacts. All rights reserved.
//
import Foundation
fileprivate class BundleHelper {}
extension Bundle {
static var tetrisUI: Bundle {
Bundle(for: BundleHelper.self)
}
}

View File

@ -0,0 +1,6 @@
{
"info" : {
"version" : 1,
"author" : "xcode"
}
}

View File

@ -0,0 +1,20 @@
{
"info" : {
"version" : 1,
"author" : "xcode"
},
"colors" : [
{
"idiom" : "universal",
"color" : {
"color-space" : "srgb",
"components" : {
"red" : "0",
"alpha" : "1.000",
"blue" : "211",
"green" : "214"
}
}
}
]
}

View File

@ -0,0 +1,20 @@
{
"info" : {
"version" : 1,
"author" : "xcode"
},
"colors" : [
{
"idiom" : "universal",
"color" : {
"color-space" : "srgb",
"components" : {
"red" : "0",
"alpha" : "1.000",
"blue" : "214",
"green" : "79"
}
}
}
]
}

View File

@ -0,0 +1,20 @@
{
"info" : {
"version" : 1,
"author" : "xcode"
},
"colors" : [
{
"idiom" : "universal",
"color" : {
"color-space" : "srgb",
"components" : {
"red" : "0",
"alpha" : "1.000",
"blue" : "71",
"green" : "214"
}
}
}
]
}

View File

@ -0,0 +1,20 @@
{
"info" : {
"version" : 1,
"author" : "xcode"
},
"colors" : [
{
"idiom" : "universal",
"color" : {
"color-space" : "srgb",
"components" : {
"red" : "255",
"alpha" : "1.000",
"blue" : "0",
"green" : "128"
}
}
}
]
}

View File

@ -0,0 +1,20 @@
{
"info" : {
"version" : 1,
"author" : "xcode"
},
"colors" : [
{
"idiom" : "universal",
"color" : {
"color-space" : "srgb",
"components" : {
"red" : "168",
"alpha" : "1.000",
"blue" : "214",
"green" : "0"
}
}
}
]
}

View File

@ -0,0 +1,20 @@
{
"info" : {
"version" : 1,
"author" : "xcode"
},
"colors" : [
{
"idiom" : "universal",
"color" : {
"color-space" : "srgb",
"components" : {
"red" : "214",
"alpha" : "1.000",
"blue" : "61",
"green" : "0"
}
}
}
]
}

View File

@ -0,0 +1,20 @@
{
"info" : {
"version" : 1,
"author" : "xcode"
},
"colors" : [
{
"idiom" : "universal",
"color" : {
"color-space" : "srgb",
"components" : {
"red" : "255",
"alpha" : "1.000",
"blue" : "71",
"green" : "229"
}
}
}
]
}

View File

@ -9,10 +9,10 @@
"color" : { "color" : {
"color-space" : "srgb", "color-space" : "srgb",
"components" : { "components" : {
"red" : "0xDD", "red" : "0.800",
"alpha" : "1.000", "alpha" : "1.000",
"blue" : "0xDD", "blue" : "0.800",
"green" : "0xDD" "green" : "0.800"
} }
} }
}, },
@ -27,10 +27,10 @@
"color" : { "color" : {
"color-space" : "srgb", "color-space" : "srgb",
"components" : { "components" : {
"red" : "0x22", "red" : "0.157",
"alpha" : "1.000", "alpha" : "1.000",
"blue" : "0x22", "blue" : "0.157",
"green" : "0x22" "green" : "0.157"
} }
} }
} }

View File

@ -9,33 +9,23 @@
import SwiftUI import SwiftUI
import TetrisKit import TetrisKit
fileprivate extension Color {
static let tetrominoAqua = Color(red: 0, green: 214/255, blue: 211/255)
static let tetrominoBlue = Color(red: 0, green: 79/255, blue: 214/255)
static let tetrominoOrange = Color(red: 255/255, green: 128/255, blue: 0)
static let tetrominoYellow = Color(red: 255/255, green: 229/255, blue: 0)
static let tetrominoGreen = Color(red: 0, green: 214/255, blue: 71/255)
static let tetrominoPurple = Color(red: 168/255, green: 0, blue: 214/255)
static let tetrominoRed = Color(red: 214/255, green: 0, blue: 61/255)
}
extension Tetromino { extension Tetromino {
var color: Color { var color: Color {
switch self { switch self {
case .i: case .i:
return .tetrominoAqua return Color("TetrominoAqua", bundle: .tetrisUI)
case .o: case .o:
return .tetrominoYellow return Color("TetrominoYellow", bundle: .tetrisUI)
case .t: case .t:
return .tetrominoPurple return Color("TetrominoPurple", bundle: .tetrisUI)
case .j: case .j:
return .tetrominoOrange return Color("TetrominoOrange", bundle: .tetrisUI)
case .l: case .l:
return .tetrominoBlue return Color("TetrominoBlue", bundle: .tetrisUI)
case .s: case .s:
return .tetrominoRed return Color("TetrominoRed", bundle: .tetrisUI)
case .z: case .z:
return .tetrominoGreen return Color("TetrominoGreen", bundle: .tetrisUI)
} }
} }
} }

View File

@ -14,9 +14,16 @@ struct TilesView: View {
var body: some View { var body: some View {
GridView(rows: board.height, columns: board.width) { (col, row, size) in GridView(rows: board.height, columns: board.width) { (col, row, size) in
Rectangle() if self.board[col, row] {
.frame(width: size, height: size) Rectangle()
.foregroundColor(self.board[col, row]?.color ?? Color("Background")) .frame(width: size, height: size)
.foregroundColor(self.board[col, row]?.color ?? Color("Background", bundle: .tetrisUI))
} else {
Rectangle()
.frame(width: size, height: size)
.foregroundColor(Color("Background", bundle: .tetrisUI))
.border(Color("TileBorder"), width: 1)
}
} }
} }
} }