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

Optimising String access for efficient usage using enums #356

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Powerup/CompletedViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ class CompletedViewController: UIViewController, SegueHandler {
karmaPointsLabel.text = String(score.karmaPoints)
} catch _ {
// If the saving failed, show an alert dialogue.
let alert = UIAlertController(title: warningTitleMessage, message: errorLoadingKarmaPoints, preferredStyle: .alert)
alert.addAction(UIAlertAction(title: okText, style: .default))
let alert = UIAlertController(title: CustomMessage.warningTitle, message: CustomError.loadingKarmaPoints, preferredStyle: .alert)
alert.addAction(UIAlertAction(title: CustomText.ok, style: .default))
self.present(alert, animated: true, completion: nil)

return
Expand Down
4 changes: 2 additions & 2 deletions Powerup/CustomizeAvatarViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,10 @@ class CustomizeAvatarViewController: UIViewController,SegueHandler {
try dataSource.boughtAccessory(accessory: avatar.hair)
try dataSource.boughtAccessory(accessory: avatar.clothes)
} catch _ {
let alert = UIAlertController(title: warningTitleMessage, message: failedtoSaveAvatarMessage, preferredStyle: .alert)
let alert = UIAlertController(title: CustomMessage.warningTitle, message: CustomError.failedtoSaveAvatarMessage, preferredStyle: .alert)

// Unwind to Start View when Ok Button is pressed.
let okButton = UIAlertAction(title: okText, style: .cancel, handler: {action in
let okButton = UIAlertAction(title: CustomText.ok, style: .cancel, handler: {action in
self.performSegueWithIdentifier(.unwindToStartView, sender: self)
})
alert.addAction(okButton)
Expand Down
4 changes: 2 additions & 2 deletions Powerup/EndViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ class EndViewController: UIViewController {
karmaPointsLabel.text = String(score.karmaPoints)
} catch _ {
// If the saving failed, show an alert dialogue.
let alert = UIAlertController(title: warningTitleMessage, message: errorLoadingKarmaPoints, preferredStyle: .alert)
alert.addAction(UIAlertAction(title: okText, style: .default))
let alert = UIAlertController(title: CustomMessage.warningTitle, message: CustomError.loadingKarmaPoints, preferredStyle: .alert)
alert.addAction(UIAlertAction(title: CustomText.ok, style: .default))
self.present(alert, animated: true, completion: nil)

return
Expand Down
8 changes: 4 additions & 4 deletions Powerup/MapViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ class MapViewController: UIViewController, SegueHandler {
do {
currScenario = try dataSource.getScenario(of: scenarioID)
} catch _ {
let alert = UIAlertController(title: warningTitleMessage, message: errorLoadingScenarioMessage, preferredStyle: .alert)
alert.addAction(UIAlertAction(title: okText, style: .default))
let alert = UIAlertController(title: CustomMessage.warningTitle, message: CustomError.loadingScenarioMessage, preferredStyle: .alert)
alert.addAction(UIAlertAction(title: CustomText.ok, style: .default))
self.present(alert, animated: true, completion: nil)

return
Expand All @@ -74,8 +74,8 @@ class MapViewController: UIViewController, SegueHandler {
do {
selectedScenario = try dataSource.getScenario(of: sender.tag)
} catch _ {
let alert = UIAlertController(title: warningTitleMessage, message: errorLoadingScenarioMessage, preferredStyle: .alert)
alert.addAction(UIAlertAction(title: okText, style: .default))
let alert = UIAlertController(title: CustomMessage.warningTitle, message: CustomError.loadingScenarioMessage, preferredStyle: .alert)
alert.addAction(UIAlertAction(title: CustomText.ok, style: .default))
self.present(alert, animated: true, completion: nil)

return
Expand Down
8 changes: 4 additions & 4 deletions Powerup/MinesweeperGameScene.swift
Original file line number Diff line number Diff line change
Expand Up @@ -452,8 +452,8 @@ class MinesweeperGameScene: SKScene {
currBox = guessingBox

// Perform animation.
guessingBox.removeAction(forKey: boxShrinkingKey)
guessingBox.run(SKAction.scale(to: boxEnlargingScale, duration: boxEnlargingDuration), withKey: boxEnlargingKey)
guessingBox.removeAction(forKey: CustomText.boxShrinkingKey)
guessingBox.run(SKAction.scale(to: boxEnlargingScale, duration: boxEnlargingDuration), withKey: CustomText.boxEnlargingKey)
}
}

Expand All @@ -473,8 +473,8 @@ class MinesweeperGameScene: SKScene {
} else if let box = currBox {

// Animate (shrink) back the card.
box.removeAction(forKey: boxEnlargingKey)
box.run(SKAction.scale(to: 1.0, duration: boxEnlargingDuration), withKey: boxEnlargingKey)
box.removeAction(forKey: CustomText.boxEnlargingKey)
box.run(SKAction.scale(to: 1.0, duration: boxEnlargingDuration), withKey: CustomText.boxEnlargingKey)

currBox = nil
}
Expand Down
20 changes: 10 additions & 10 deletions Powerup/ResultsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ class ResultsViewController: UIViewController, SegueHandler {
karmaPointsLabel.text = String(score.karmaPoints)
} catch _ {
// If the saving failed, show an alert dialogue.
let alert = UIAlertController(title: warningTitleMessage, message: errorLoadingKarmaPoints, preferredStyle: .alert)
alert.addAction(UIAlertAction(title: okText, style: .default))
let alert = UIAlertController(title: CustomMessage.warningTitle, message: CustomError.loadingKarmaPoints, preferredStyle: .alert)
alert.addAction(UIAlertAction(title: CustomText.ok, style: .default))
self.present(alert, animated: true, completion: nil)

return
Expand All @@ -67,14 +67,14 @@ class ResultsViewController: UIViewController, SegueHandler {
if !(try dataSource.getScenario(of: completedScenarioID)).completed {

// Notify the players of the karma gain with a pop-up.
let notification = UIAlertController(title: hoorayTitleMesssage, message: "You gained \(karmaGain) Karma points!", preferredStyle: .alert)
notification.addAction(UIAlertAction(title: okText, style: .default, handler: { action in self.gainKarmaPoints() }))
let notification = UIAlertController(title: CustomMessage.hoorayTitle, message: "You gained \(karmaGain) Karma points!", preferredStyle: .alert)
notification.addAction(UIAlertAction(title: CustomText.ok, style: .default, handler: { action in self.gainKarmaPoints() }))
self.present(notification, animated: true, completion: nil)
}

} catch _ {
let alert = UIAlertController(title: warningTitleMessage, message: errorFetchingScenarioMessage, preferredStyle: .alert)
alert.addAction(UIAlertAction(title: okText, style: .default))
let alert = UIAlertController(title: CustomMessage.warningTitle, message: CustomError.fetchingScenarioMessage, preferredStyle: .alert)
alert.addAction(UIAlertAction(title: CustomText.ok, style: .default))
self.present(alert, animated: true, completion: nil)

return
Expand All @@ -92,8 +92,8 @@ class ResultsViewController: UIViewController, SegueHandler {
try dataSource.saveScore(score: newScore)
} catch _ {
// If the saving failed, show an alert dialogue.
let alert = UIAlertController(title: warningTitleMessage, message: errorSavingKarmaPointsMessage, preferredStyle: .alert)
alert.addAction(UIAlertAction(title: okText, style: .default))
let alert = UIAlertController(title: CustomMessage.warningTitle, message: CustomError.savingKarmaPointsMessage, preferredStyle: .alert)
alert.addAction(UIAlertAction(title: CustomText.ok, style: .default))
self.present(alert, animated: true, completion: nil)

return
Expand Down Expand Up @@ -123,8 +123,8 @@ class ResultsViewController: UIViewController, SegueHandler {
try dataSource.saveScenario(nextScenario)

} catch _ {
let alert = UIAlertController(title: warningTitleMessage, message: errorSavingScenarioCompletionMessage, preferredStyle: .alert)
alert.addAction(UIAlertAction(title: okText, style: .default))
let alert = UIAlertController(title: CustomMessage.warningTitle, message: CustomError.savingScenarioCompletionMessage, preferredStyle: .alert)
alert.addAction(UIAlertAction(title: CustomText.ok, style: .default))
self.present(alert, animated: true, completion: nil)

return
Expand Down
18 changes: 9 additions & 9 deletions Powerup/ScenarioViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ class ScenarioViewController: UIViewController, UITableViewDelegate, UITableView
} catch _ {
// Unwind back to map view if cound't fetch choices from database.

let alert = UIAlertController(title: warningTitleMessage, message: errorLoadingChoicesMessage, preferredStyle: .alert)
let okButton = UIAlertAction(title: okText, style: .default, handler: { action in self.performSegueWithIdentifier(.unwindToMapView, sender: self) })
let alert = UIAlertController(title: CustomMessage.warningTitle, message: CustomError.loadingChoicesMessage, preferredStyle: .alert)
let okButton = UIAlertAction(title: CustomText.ok, style: .default, handler: { action in self.performSegueWithIdentifier(.unwindToMapView, sender: self) })

alert.addAction(okButton)

Expand Down Expand Up @@ -88,8 +88,8 @@ class ScenarioViewController: UIViewController, UITableViewDelegate, UITableView
} catch _ {
// Unwind back to map view if cound't fetch avatar from database.

let alert = UIAlertController(title: warningTitleMessage, message: errorLoadingAvatarMessage, preferredStyle: .alert)
let okButton = UIAlertAction(title: okText, style: .default, handler: { action in self.performSegueWithIdentifier(.unwindToMapView, sender: self) })
let alert = UIAlertController(title: CustomMessage.warningTitle, message: CustomError.loadingAvatarMessage, preferredStyle: .alert)
let okButton = UIAlertAction(title: CustomText.ok, style: .default, handler: { action in self.performSegueWithIdentifier(.unwindToMapView, sender: self) })

alert.addAction(okButton)

Expand Down Expand Up @@ -143,8 +143,8 @@ class ScenarioViewController: UIViewController, UITableViewDelegate, UITableView
} catch _ {
// Unwind back to map view if cound't fetch questions from database.

let alert = UIAlertController(title: warningTitleMessage, message: errorLoadingScenarioMessage, preferredStyle: .alert)
let okButton = UIAlertAction(title: okText, style: .default, handler: { action in self.performSegueWithIdentifier(.unwindToMapView, sender: self) })
let alert = UIAlertController(title: CustomMessage.warningTitle, message: CustomError.loadingScenarioMessage, preferredStyle: .alert)
let okButton = UIAlertAction(title: CustomText.ok, style: .default, handler: { action in self.performSegueWithIdentifier(.unwindToMapView, sender: self) })

alert.addAction(okButton)

Expand Down Expand Up @@ -360,9 +360,9 @@ class ScenarioViewController: UIViewController, UITableViewDelegate, UITableView

// Alert the user about possibly losing karma points upon migrating back to the map.
@IBAction func homeButtonPressed(_ sender: Any) {
let alert = UIAlertController(title: confirmationTitleMessage, message: mapMigrationAlertMessage, preferredStyle: .alert)
let okButton = UIAlertAction(title: okText, style: .default, handler: { action in self.performSegueWithIdentifier(.unwindToMapView, sender: self) })
let cancelButton = UIAlertAction(title: cancelText, style: .cancel, handler: { action in self.dismiss(animated: true, completion: nil) })
let alert = UIAlertController(title: CustomMessage.confirmationTitle, message: CustomWarning.mapMigrationAlert, preferredStyle: .alert)
let okButton = UIAlertAction(title: CustomText.ok, style: .default, handler: { action in self.performSegueWithIdentifier(.unwindToMapView, sender: self) })
let cancelButton = UIAlertAction(title: CustomText.cancel, style: .cancel, handler: { action in self.dismiss(animated: true, completion: nil) })

alert.addAction(okButton)
alert.addAction(cancelButton)
Expand Down
36 changes: 18 additions & 18 deletions Powerup/ShopViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ class ShopViewController: UIViewController {
score = try dataSource.getScore()
avatar = try dataSource.getAvatar()
} catch _ {
let alert = UIAlertController(title: warningTitleMessage, message: errorFetchingAvatarMessage, preferredStyle: .alert)
let alert = UIAlertController(title: CustomMessage.warningTitle, message: CustomError.fetchingAvatarMessage, preferredStyle: .alert)

// Exit shop when ok button is pressed.
let okButton = UIAlertAction(title: okText, style: .default, handler: {action in self.dismiss(animated: true, completion: nil)})
let okButton = UIAlertAction(title: CustomText.ok, style: .default, handler: {action in self.dismiss(animated: true, completion: nil)})
alert.addAction(okButton)

self.present(alert, animated: true, completion: nil)
Expand Down Expand Up @@ -150,10 +150,10 @@ class ShopViewController: UIViewController {

// If the item isn't bought and it is unaffordable, grey out the box.
if !currItem.purchased && currItem.points > score.karmaPoints {
displayBoxes[boxIndex].image = UIImage(named: greyOutBoxImageName)
displayBoxes[boxIndex].image = UIImage(named: CustomImage.greyOutBox)
buttonTexts[boxIndex].text = ""
} else {
displayBoxes[boxIndex].image = UIImage(named: boxImageName)
displayBoxes[boxIndex].image = UIImage(named: CustomImage.box)
}
}
}
Expand All @@ -175,8 +175,8 @@ class ShopViewController: UIViewController {

// Show alert dialog if players are trying to buy items they can't afford.
if score.karmaPoints < accessoryPrice {
let alertDialog = UIAlertController(title: oopsTitleMessage, message: notEnoughPointsMessage, preferredStyle: .alert)
alertDialog.addAction(UIAlertAction(title: okText, style: .default))
let alertDialog = UIAlertController(title: CustomMessage.oopsTitle, message: CustomWarning.notEnoughPoints, preferredStyle: .alert)
alertDialog.addAction(UIAlertAction(title: CustomText.ok, style: .default))
self.present(alertDialog, animated: true, completion: nil)

return false
Expand All @@ -186,8 +186,8 @@ class ShopViewController: UIViewController {
}

func presentBuyingErrorDiaologue() {
let alert = UIAlertController(title: warningTitleMessage, message: errorPurchasingMessage, preferredStyle: .alert)
let okButton = UIAlertAction(title: okText, style: .default)
let alert = UIAlertController(title: CustomMessage.warningTitle, message: CustomError.purchasingMessage, preferredStyle: .alert)
let okButton = UIAlertAction(title: CustomText.ok, style: .default)
alert.addAction(okButton)
self.present(alert, animated: true, completion: nil)
}
Expand Down Expand Up @@ -242,21 +242,21 @@ class ShopViewController: UIViewController {
self.updateAvatarImageView()

// Set the preview label's text to "Preview".
previewLabel.text = previewLabelText
previewLabel.text = CustomText.previewLabel

// If have enough points, buy the item.
// Alert the player that the purchase couldn't be reverted.

let cannotRevertAlert = UIAlertController(title: confirmationTitleMessage, message: "You will be spending \(itemChosen.points) Karma Points!", preferredStyle: .alert)
let cancelButton = UIAlertAction(title: cancelText, style: .cancel, handler: {action in
let cannotRevertAlert = UIAlertController(title: CustomMessage.confirmationTitle, message: "You will be spending \(itemChosen.points) Karma Points!", preferredStyle: .alert)
let cancelButton = UIAlertAction(title: CustomText.cancel, style: .cancel, handler: {action in
// Revert to whatever accessory the user had before.
self.avatar.setAccessoryByType(itemChosen.type, accessory: currentItem)
self.updateAvatarImageView()

// Get rid of the preview text.
self.previewLabel.text = ""
})
let purchaseButton = UIAlertAction(title: purchaseButtonText, style: .default, handler: {action in
let purchaseButton = UIAlertAction(title: CustomText.purchaseButton, style: .default, handler: {action in

// Save the purchased data into the database.
do {
Expand All @@ -267,8 +267,8 @@ class ShopViewController: UIViewController {
self.score.karmaPoints -= itemChosen.points
try self.dataSource.saveScore(score: self.score)
} catch _ {
let failedAlert = UIAlertController(title: oopsTitleMessage, message: errorSavingPurchaseMessage, preferredStyle: .alert)
failedAlert.addAction(UIAlertAction(title: okText, style: .default))
let failedAlert = UIAlertController(title: CustomMessage.oopsTitle, message: CustomError.savingPurchaseMessage, preferredStyle: .alert)
failedAlert.addAction(UIAlertAction(title: CustomText.ok, style: .default))
self.present(failedAlert, animated: true, completion: nil)

return
Expand All @@ -288,8 +288,8 @@ class ShopViewController: UIViewController {
self.updateAvatarImageView()

// Show purchase successful dialogue.
let successfulDiologue = UIAlertController(title: yayTitleMessage, message: successFullPurchaseMessage, preferredStyle: .alert)
let confirmButton = UIAlertAction(title: okText, style: .default)
let successfulDiologue = UIAlertController(title: CustomMessage.yayTitle, message: CustomMessage.successFullPurchase, preferredStyle: .alert)
let confirmButton = UIAlertAction(title: CustomText.ok, style: .default)
successfulDiologue.addAction(confirmButton)
self.present(successfulDiologue, animated: true, completion: nil)

Expand Down Expand Up @@ -333,8 +333,8 @@ class ShopViewController: UIViewController {
// Save the avatar.
try self.dataSource.saveAvatar(self.avatar)
} catch _ {
let failedAlert = UIAlertController(title: oopsTitleMessage, message: errorFetchingAvatarMessage, preferredStyle: .alert)
failedAlert.addAction(UIAlertAction(title: okText, style: .default))
let failedAlert = UIAlertController(title: CustomMessage.oopsTitle, message: CustomError.fetchingAvatarMessage, preferredStyle: .alert)
failedAlert.addAction(UIAlertAction(title: CustomText.ok, style: .default))
self.present(failedAlert, animated: true, completion: nil)

return
Expand Down
Loading