Skip to content
This repository has been archived by the owner on May 5, 2020. It is now read-only.

Commit

Permalink
Moving Constants to Separate File Using Swift Standard Style Guidelines
Browse files Browse the repository at this point in the history
  • Loading branch information
SIMRAN1 committed Apr 20, 2018
1 parent 70e8dbd commit 3dda31e
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 78 deletions.
4 changes: 4 additions & 0 deletions Powerup.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
4DF1CBB120152582008B5359 /* CompletedViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4DF1CBB020152582008B5359 /* CompletedViewController.swift */; };
5BB66DBF2055D5D800DE3B9C /* SegueHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5BB66DBE2055D5D800DE3B9C /* SegueHandler.swift */; };
5BD864812046F61900004B39 /* Strings.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5BD864802046F61900004B39 /* Strings.swift */; };
5BF8784D2088FF88009C1433 /* Constants.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5BF8784C2088FF88009C1433 /* Constants.swift */; };
D910FF191F04AB3200C444DA /* DataSource.swift in Sources */ = {isa = PBXBuildFile; fileRef = D910FF181F04AB3200C444DA /* DataSource.swift */; };
D910FF1F1F04DD4F00C444DA /* ResultViewControllerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D910FF1E1F04DD4F00C444DA /* ResultViewControllerTests.swift */; };
D910FF211F05E22400C444DA /* ScenarioViewControllerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D910FF201F05E22400C444DA /* ScenarioViewControllerTests.swift */; };
Expand Down Expand Up @@ -118,6 +119,7 @@
4DF1CBB020152582008B5359 /* CompletedViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CompletedViewController.swift; sourceTree = "<group>"; };
5BB66DBE2055D5D800DE3B9C /* SegueHandler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SegueHandler.swift; sourceTree = "<group>"; };
5BD864802046F61900004B39 /* Strings.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Strings.swift; sourceTree = "<group>"; };
5BF8784C2088FF88009C1433 /* Constants.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Constants.swift; sourceTree = "<group>"; };
D910FF181F04AB3200C444DA /* DataSource.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DataSource.swift; sourceTree = "<group>"; };
D910FF1E1F04DD4F00C444DA /* ResultViewControllerTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ResultViewControllerTests.swift; sourceTree = "<group>"; };
D910FF201F05E22400C444DA /* ScenarioViewControllerTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ScenarioViewControllerTests.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -287,6 +289,7 @@
children = (
5BD864802046F61900004B39 /* Strings.swift */,
5BB66DBE2055D5D800DE3B9C /* SegueHandler.swift */,
5BF8784C2088FF88009C1433 /* Constants.swift */,
);
name = Utlities;
sourceTree = "<group>";
Expand Down Expand Up @@ -493,6 +496,7 @@
D959CBCD1EE6489100C31753 /* Scenario.swift in Sources */,
D969D26C1EE8F36200A5133F /* FMResultSetNullCheckExtension.swift in Sources */,
D959CBCF1EE6491800C31753 /* Score.swift in Sources */,
5BF8784D2088FF88009C1433 /* Constants.swift in Sources */,
D910FF191F04AB3200C444DA /* DataSource.swift in Sources */,
2AD1A1E71B2B1ADA00BCA94D /* ModelManager.swift in Sources */,
D959CBD31EE64A3A00C31753 /* DatabaseAccessor.swift in Sources */,
Expand Down
40 changes: 40 additions & 0 deletions Powerup/Constants.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import Foundation
import SpriteKit
enum Colors {
static let textColor = UIColor(red: 21.0 / 255.0, green: 124.0 / 255.0, blue: 129.0 / 255.0, alpha: 1.0)
static let correctColor = UIColor(red: 105.0 / 255.0, green: 255.0 / 255.0, blue: 109.0 / 255.0, alpha: 1.0)
static let wrongColor = UIColor(red: 255.0 / 255.0, green: 105.0 / 255.0, blue: 105.0 / 255.0, alpha: 1.0)
static let scoreTextColor = UIColor.white
static let uiColor = UIColor(red: 42.0 / 255.0, green: 203.0 / 255.0, blue: 211.0 / 255.0, alpha: 1.0)
static let prosTextColor = UIColor(red: 105.0 / 255.0, green: 255.0 / 255.0, blue: 97.0 / 255.0, alpha: 1.0)
static let consTextColor = UIColor(red: 255.0 / 255.0, green: 105.0 / 255.0, blue: 105.0 / 255.0, alpha: 1.0)
}
enum Images {
static let vocabMatchingScoreBox = "vocabmatching_scorebox"
static let vocabMatchingBackground = "vocabmatching_background"
static let endScene = "end_scene"
static let continueButton = "continue_button"
static let vocabMatchingTile = "vocabmatching_tile"
static let vocabMatchingClipboard = "vocabmatching_clipboard"
static let vocabMatchingClipboardGreen = "vocabmatching_clipboard_green"
static let vocabMatchingClipboardRed = "vocabmatching_clipboard_red"
static let minesweeperBackground = "minesweeper_background"
static let minesweeperProsConsBanner = "minesweeper_pros_cons_banner"
static let successBanner = "success_banner"
static let failureBanner = "failure_banner"
static let minesweeperYellowstarBox = "minesweeper_yellowstar_box"
static let minesweeperRedstarBox = "minesweeper_redstar_box"
static let minesweeperGreenstarBox = "minesweeper_greenstar_box"
static let sinkToSwimBackground = "sink_to_swim_background"
static let sinkToSwimForeground = "sink_to_swim_foreground"
static let sinkToSwimGauge = "sink_to_swim_gauge"
static let sinkToSwimIndicator = "sink_to_swim_indicator"
static let sinkToSwimBoatAvatar = "sink_to_swim_boat_avatar"
static let sinkToSwimTimer = "sink_to_swim_timer"
static let sinkToSwimTrueFalseBox = "sink_to_swim_true_false_box"
static let sinkToSwimCorrectIcon = "sink_to_swim_correct_icon"
static let sinkToSwimWrongIcon = "sink_to_swim_wrong_icon"
}
enum FontName {
static let montserratBold = "Montserrat-Bold"
}
6 changes: 3 additions & 3 deletions Powerup/GuessingBox.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import SpriteKit
class GuessingBox: SKSpriteNode {

// MARK: Constants
let backsideTexture = SKTexture(imageNamed: "minesweeper_yellowstar_box")
let failureTexture = SKTexture(imageNamed: "minesweeper_redstar_box")
let successTexture = SKTexture(imageNamed: "minesweeper_greenstar_box")
let backsideTexture = SKTexture(imageNamed: Images.minesweeperYellowstarBox)
let failureTexture = SKTexture(imageNamed: Images.minesweeperRedstarBox)
let successTexture = SKTexture(imageNamed: Images.minesweeperGreenstarBox)

// Animation constants.
let flipDuration = 0.6
Expand Down
29 changes: 11 additions & 18 deletions Powerup/MinesweeperGameScene.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,6 @@ class MinesweeperGameScene: SKScene {
// How many boxes could be selected each round.
let selectionMaxCount = 5

// Colors of game UIs.
let uiColor = UIColor(red: 42.0 / 255.0, green: 203.0 / 255.0, blue: 211.0 / 255.0, alpha: 1.0)
let textColor = UIColor(red: 21.0 / 255.0, green: 124.0 / 255.0, blue: 129.0 / 255.0, alpha: 1.0)
let prosTextColor = UIColor(red: 105.0 / 255.0, green: 255.0 / 255.0, blue: 97.0 / 255.0, alpha: 1.0)
let consTextColor = UIColor(red: 255.0 / 255.0, green: 105.0 / 255.0, blue: 105.0 / 255.0, alpha: 1.0)

// Animation constants.
let boxEnlargingScale = CGFloat(1.2)
let boxEnlargingDuration = 0.25
Expand Down Expand Up @@ -59,7 +53,6 @@ class MinesweeperGameScene: SKScene {
let buttonTextFontSize = CGFloat(18)
let descriptionTitleFontSize = CGFloat(24)
let descriptionFontSize = CGFloat(20)
let fontName = "Montserrat-Bold"

let buttonStrokeWidth = CGFloat(3)

Expand All @@ -71,10 +64,10 @@ class MinesweeperGameScene: SKScene {
let gridSpacing: Double

// Sprite nodes
let backgroundImage = SKSpriteNode(imageNamed: "minesweeper_background")
let backgroundImage = SKSpriteNode(imageNamed: Images.minesweeperBackground)
let resultBanner = SKSpriteNode()
let descriptionBanner = SKSpriteNode(imageNamed: "minesweeper_pros_cons_banner")
let continueButton = SKSpriteNode(imageNamed: "continue_button")
let descriptionBanner = SKSpriteNode(imageNamed: Images.minesweeperProsConsBanner)
let continueButton = SKSpriteNode(imageNamed: Images.continueButton)

// Label wrapper nodes
let scoreLabelNode = SKNode()
Expand All @@ -87,8 +80,8 @@ class MinesweeperGameScene: SKScene {
let consLabel = SKLabelNode(text: "Cons text goes here...")

// Textures
let successBannerTexture = SKTexture(imageNamed: "success_banner")
let failureBannerTexture = SKTexture(imageNamed: "failure_banner")
let successBannerTexture = SKTexture(imageNamed: Images.successBanner)
let failureBannerTexture = SKTexture(imageNamed: Images.failureBanner)

// TODO: Replace the temporary sprite.
let endGameText = "End Game"
Expand Down Expand Up @@ -152,10 +145,10 @@ class MinesweeperGameScene: SKScene {
scoreLabelNode.position = CGPoint(x: Double(size.width) - scoreTextOffsetX, y: Double(size.height) - scoreTextOffsetY)
scoreLabelNode.zPosition = bannerLayer
scoreLabel.position = CGPoint.zero
scoreLabel.fontName = fontName
scoreLabel.fontName = FontName.montserratBold
scoreLabel.fontSize = scoreTextFontSize
scoreLabel.zPosition = uiLayer
scoreLabel.fontColor = uiColor
scoreLabel.fontColor = Colors.uiColor
scoreLabel.horizontalAlignmentMode = .right
scoreLabelNode.addChild(scoreLabel)

Expand All @@ -171,9 +164,9 @@ class MinesweeperGameScene: SKScene {
prosLabelNode.zPosition = bannerLayer
prosLabel.position = CGPoint.zero
prosLabel.horizontalAlignmentMode = .left
prosLabel.fontName = fontName
prosLabel.fontName = FontName.montserratBold
prosLabel.fontSize = descriptionFontSize
prosLabel.fontColor = prosTextColor
prosLabel.fontColor = Colors.prosTextColor
prosLabel.zPosition = uiLayer
prosLabelNode.addChild(prosLabel)
descriptionBanner.addChild(prosLabelNode)
Expand All @@ -183,9 +176,9 @@ class MinesweeperGameScene: SKScene {
consLabelNode.zPosition = bannerLayer
consLabel.position = CGPoint.zero
consLabel.horizontalAlignmentMode = .left
consLabel.fontName = fontName
consLabel.fontName = FontName.montserratBold
consLabel.fontSize = descriptionFontSize
consLabel.fontColor = consTextColor
consLabel.fontColor = Colors.consTextColor
consLabel.zPosition = uiLayer
consLabelNode.addChild(consLabel)
descriptionBanner.addChild(consLabelNode)
Expand Down
51 changes: 23 additions & 28 deletions Powerup/SinkToSwimGameScene.swift
Original file line number Diff line number Diff line change
Expand Up @@ -120,38 +120,33 @@ class SinkToSwimGameScene: SKScene {

let PointerToBoatRatio = 0.5

// Colors
let textColor = UIColor(red: 21.0 / 255.0, green: 124.0 / 255.0, blue: 129.0 / 255.0, alpha: 1.0)
let correctColor = UIColor(red: 105.0 / 255.0, green: 255.0 / 255.0, blue: 109.0 / 255.0, alpha: 1.0)
let wrongColor = UIColor(red: 255.0 / 255.0, green: 105.0 / 255.0, blue: 105.0 / 255.0, alpha: 1.0)
let scoreTextColor = UIColor.white


// Fonts
let fontName = "Montserrat-Bold"
let questionFontSize = CGFloat(18)
let scoreFontSize = CGFloat(22)
let timerFontSize = CGFloat(17)
let endSceneCountFontSize = CGFloat(55)
let endSceneScoreFontSize = CGFloat(80)

// Sprite nodes
let backgroundSprite = SKSpriteNode(imageNamed: "sink_to_swim_background")
let foregroundSprite = SKSpriteNode(imageNamed: "sink_to_swim_foreground")
let waterGaugeSprite = SKSpriteNode(imageNamed: "sink_to_swim_gauge")
let waterGaugePointerSprite = SKSpriteNode(imageNamed: "sink_to_swim_indicator")
let avatarBoatSprite = SKSpriteNode(imageNamed: "sink_to_swim_boat_avatar")
let timerSprite = SKSpriteNode(imageNamed: "sink_to_swim_timer")
let questionBoxSprite = SKSpriteNode(imageNamed: "sink_to_swim_true_false_box")
let backgroundSprite = SKSpriteNode(imageNamed: Images.sinkToSwimBackground)
let foregroundSprite = SKSpriteNode(imageNamed: Images.sinkToSwimForeground)
let waterGaugeSprite = SKSpriteNode(imageNamed: Images.sinkToSwimGauge)
let waterGaugePointerSprite = SKSpriteNode(imageNamed: Images.sinkToSwimIndicator)
let avatarBoatSprite = SKSpriteNode(imageNamed: Images.sinkToSwimBoatAvatar)
let timerSprite = SKSpriteNode(imageNamed: Images.sinkToSwimTimer)
let questionBoxSprite = SKSpriteNode(imageNamed: Images.sinkToSwimTrueFalseBox)
let trueButton = SKSpriteNode()
let falseButton = SKSpriteNode()
let dontKnowButton = SKSpriteNode()
let correctWrongSprite = SKSpriteNode()
let endSceneSprite = SKSpriteNode(imageNamed: "end_scene")
let continueButton = SKSpriteNode(imageNamed: "continue_button")
let endSceneSprite = SKSpriteNode(imageNamed: Images.endScene)
let continueButton = SKSpriteNode(imageNamed: Images.continueButton)

// Textures
let correctIconTexture = SKTexture(imageNamed: "sink_to_swim_correct_icon")
let wrongIconTexture = SKTexture(imageNamed: "sink_to_swim_wrong_icon")
let correctIconTexture = SKTexture(imageNamed: Images.sinkToSwimCorrectIcon)
let wrongIconTexture = SKTexture(imageNamed: Images.sinkToSwimWrongIcon)

// Labels
let scoreLabel = SKLabelNode()
Expand Down Expand Up @@ -282,7 +277,7 @@ class SinkToSwimGameScene: SKScene {
dontKnowButton.color = UIColor.clear

// Positioning question label.
questionLabel = SKMultilineLabel(text: "", labelWidth: Int(CGFloat(questionLabelWidth) * questionBoxSprite.size.width), pos: CGPoint.zero, fontName: fontName, fontSize: questionFontSize, fontColor: textColor,leading: questionLabelLeading)
questionLabel = SKMultilineLabel(text: "", labelWidth: Int(CGFloat(questionLabelWidth) * questionBoxSprite.size.width), pos: CGPoint.zero, fontName: FontName.montserratBold, fontSize: questionFontSize, fontColor: Colors.textColor,leading: questionLabelLeading)
questionLabel.zPosition = uiTextLayer
questionBoxSprite.addChild(questionLabel)
questionLabel.pos = CGPoint(x: questionBoxSprite.size.width * CGFloat(questionLabelPosX), y: questionBoxSprite.size.height * CGFloat(questionLabelPosY))
Expand All @@ -294,9 +289,9 @@ class SinkToSwimGameScene: SKScene {

// Positioning and configuring font properties of score label.
scoreLabel.text = scoreLabelPrefix + String(score)
scoreLabel.fontColor = scoreTextColor
scoreLabel.fontColor = Colors.scoreTextColor
scoreLabel.fontSize = scoreFontSize
scoreLabel.fontName = fontName
scoreLabel.fontName = FontName.montserratBold
scoreLabel.horizontalAlignmentMode = .center
scoreLabel.verticalAlignmentMode = .center
scoreLabel.zPosition = uiTextLayer
Expand All @@ -307,9 +302,9 @@ class SinkToSwimGameScene: SKScene {

// Positioning and configuring font properties of timer label.
timerLabel.text = String(timer)
timerLabel.fontColor = textColor
timerLabel.fontColor = Colors.textColor
timerLabel.fontSize = timerFontSize
timerLabel.fontName = fontName
timerLabel.fontName = FontName.montserratBold
timerLabel.horizontalAlignmentMode = .center
timerLabel.verticalAlignmentMode = .center
timerLabel.zPosition = uiTextLayer
Expand Down Expand Up @@ -337,8 +332,8 @@ class SinkToSwimGameScene: SKScene {
endSceneCorrectCountLabelWrapper.zPosition = uiTextLayer
endSceneCorrectCountLabelWrapper.addChild(endSceneCorrectCountLabel)

endSceneCorrectCountLabel.fontName = fontName
endSceneCorrectCountLabel.fontColor = correctColor
endSceneCorrectCountLabel.fontName = FontName.montserratBold
endSceneCorrectCountLabel.fontColor = Colors.correctColor
endSceneCorrectCountLabel.fontSize = endSceneCountFontSize
endSceneCorrectCountLabel.horizontalAlignmentMode = .center
endSceneCorrectCountLabel.verticalAlignmentMode = .center
Expand All @@ -349,8 +344,8 @@ class SinkToSwimGameScene: SKScene {
endSceneWrongCountLabelWrapper.zPosition = uiTextLayer
endSceneWrongCountLabelWrapper.addChild(endSceneWrongCountLabel)

endSceneWrongCountLabel.fontName = fontName
endSceneWrongCountLabel.fontColor = wrongColor
endSceneWrongCountLabel.fontName = FontName.montserratBold
endSceneWrongCountLabel.fontColor = Colors.wrongColor
endSceneWrongCountLabel.fontSize = endSceneCountFontSize
endSceneWrongCountLabel.horizontalAlignmentMode = .center
endSceneWrongCountLabel.verticalAlignmentMode = .center
Expand All @@ -361,8 +356,8 @@ class SinkToSwimGameScene: SKScene {
endSceneScoreLabelWrapper.zPosition = uiTextLayer
endSceneScoreLabelWrapper.addChild(endSceneScoreLabel)

endSceneScoreLabel.fontName = fontName
endSceneScoreLabel.fontColor = textColor
endSceneScoreLabel.fontName = FontName.montserratBold
endSceneScoreLabel.fontColor = Colors.textColor
endSceneScoreLabel.fontSize = endSceneScoreFontSize
endSceneScoreLabel.horizontalAlignmentMode = .center
endSceneScoreLabel.verticalAlignmentMode = .center
Expand Down
Loading

0 comments on commit 3dda31e

Please sign in to comment.