Skip to content
This repository was archived by the owner on May 6, 2024. It is now read-only.
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
24 changes: 12 additions & 12 deletions MHacks.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -915,11 +915,11 @@
CODE_SIGN_ENTITLEMENTS = MHacksWatch/MHacksWatch.entitlements;
CODE_SIGN_IDENTITY = "iPhone Developer";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
CURRENT_PROJECT_VERSION = 18;
CURRENT_PROJECT_VERSION = 21;
DEVELOPMENT_TEAM = 478C74MJ7T;
IBSC_MODULE = MHacksWatch_Extension;
INFOPLIST_FILE = MHacksWatch/Info.plist;
MARKETING_VERSION = 12.2;
MARKETING_VERSION = 12.4.1;
PRODUCT_BUNDLE_IDENTIFIER = com.MPowered.MHacks.watchkitapp;
PRODUCT_NAME = MHacks;
SDKROOT = watchos;
Expand All @@ -942,11 +942,11 @@
CODE_SIGN_ENTITLEMENTS = MHacksWatch/MHacksWatch.entitlements;
CODE_SIGN_IDENTITY = "iPhone Developer";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
CURRENT_PROJECT_VERSION = 18;
CURRENT_PROJECT_VERSION = 21;
DEVELOPMENT_TEAM = 478C74MJ7T;
IBSC_MODULE = MHacksWatch_Extension;
INFOPLIST_FILE = MHacksWatch/Info.plist;
MARKETING_VERSION = 12.2;
MARKETING_VERSION = 12.4.1;
PRODUCT_BUNDLE_IDENTIFIER = com.MPowered.MHacks.watchkitapp;
PRODUCT_NAME = MHacks;
SDKROOT = watchos;
Expand All @@ -965,11 +965,11 @@
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
CLANG_WARN_SUSPICIOUS_MOVES = YES;
CODE_SIGN_ENTITLEMENTS = "MHacksWatch Extension/MHacksWatch Extension.entitlements";
CURRENT_PROJECT_VERSION = 18;
CURRENT_PROJECT_VERSION = 21;
DEVELOPMENT_TEAM = 478C74MJ7T;
INFOPLIST_FILE = "MHacksWatch Extension/Info.plist";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @executable_path/../../Frameworks";
MARKETING_VERSION = 12.2;
MARKETING_VERSION = 12.4.1;
PRODUCT_BUNDLE_IDENTIFIER = com.MPowered.MHacks.watchkitapp.watchkitextension;
PRODUCT_NAME = "${TARGET_NAME}";
SDKROOT = watchos;
Expand All @@ -989,11 +989,11 @@
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
CLANG_WARN_SUSPICIOUS_MOVES = YES;
CODE_SIGN_ENTITLEMENTS = "MHacksWatch Extension/MHacksWatch Extension.entitlements";
CURRENT_PROJECT_VERSION = 18;
CURRENT_PROJECT_VERSION = 21;
DEVELOPMENT_TEAM = 478C74MJ7T;
INFOPLIST_FILE = "MHacksWatch Extension/Info.plist";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @executable_path/../../Frameworks";
MARKETING_VERSION = 12.2;
MARKETING_VERSION = 12.4.1;
PRODUCT_BUNDLE_IDENTIFIER = com.MPowered.MHacks.watchkitapp.watchkitextension;
PRODUCT_NAME = "${TARGET_NAME}";
SDKROOT = watchos;
Expand Down Expand Up @@ -1122,7 +1122,7 @@
CODE_SIGN_ENTITLEMENTS = MHacks/MHacks.entitlements;
CODE_SIGN_IDENTITY = "iPhone Developer";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
CURRENT_PROJECT_VERSION = 18;
CURRENT_PROJECT_VERSION = 21;
DEVELOPMENT_TEAM = 478C74MJ7T;
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
Expand All @@ -1131,7 +1131,7 @@
INFOPLIST_FILE = MHacks/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
MARKETING_VERSION = 12.2;
MARKETING_VERSION = 12.4.1;
OTHER_SWIFT_FLAGS = "$(inherited)";
PRODUCT_BUNDLE_IDENTIFIER = com.MPowered.MHacks;
PRODUCT_MODULE_NAME = "$(PRODUCT_NAME:c99extidentifier)";
Expand All @@ -1154,7 +1154,7 @@
CODE_SIGN_ENTITLEMENTS = MHacks/MHacks.entitlements;
CODE_SIGN_IDENTITY = "iPhone Developer";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
CURRENT_PROJECT_VERSION = 18;
CURRENT_PROJECT_VERSION = 21;
DEVELOPMENT_TEAM = 478C74MJ7T;
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
Expand All @@ -1163,7 +1163,7 @@
INFOPLIST_FILE = MHacks/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
MARKETING_VERSION = 12.2;
MARKETING_VERSION = 12.4.1;
OTHER_SWIFT_FLAGS = "$(inherited)";
PRODUCT_BUNDLE_IDENTIFIER = com.MPowered.MHacks;
PRODUCT_MODULE_NAME = "$(PRODUCT_NAME:c99extidentifier)";
Expand Down
2 changes: 2 additions & 0 deletions MHacks/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@
<string>This application needs to access bluetooth for the purposes of scanning QR codes.</string>
<key>NSCameraUsageDescription</key>
<string>Privileged users can use the camera to scan tickets.</string>
<key>NSLocationAlwaysUsageDescription</key>
<string>Your location will be shown on the map.</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string>Your location will be shown on the map.</string>
<key>UIAppFonts</key>
Expand Down
2 changes: 1 addition & 1 deletion MHacks/SiMHacksInfoController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class SiMHacksInfoController: UIViewController {
let info = UITextView()
info.textColor = UIColor.white
info.backgroundColor = MHacksColor.backgroundDarkBlue
info.text = "SiMHacks = Sims + MHacks. A brand new way for hackers to interact and engage with each other!\n\n You will be given 5 quests at a time and once you complete a quest, you will be given a randomly generated new one.\n\n To complete a quest, you will need to find a fellow hacker who fulfills the description of the quest and scan their QR code. You also cannot scan the same hacker twice.\n\n You will have the option to refresh all quests every 3 hours in case you get stuck. \n\n Best of luck on your journey and most of all, have fun!"
info.text = "SiMHacks = Sims + MHacks. A brand new way for hackers to interact and engage with each other! The hacker with the top score at the end will receive a prize that will surely make them get their game on ;)\n\n You will be given 3 quests at a time and once you complete a quest, you will be given a randomly generated new one.\n\n To complete a quest, you will need to find a fellow hacker who's corresponding SiMHacks response fulfills the description of the quest and scan their QR code, located on their ticket. You also cannot scan the same hacker twice.\n\n Best of luck on your journey and most of all, have fun!"
info.translatesAutoresizingMaskIntoConstraints = false
info.textAlignment = .center
info.font = UIFont(name: "AndaleMono", size: 25)
Expand Down
56 changes: 36 additions & 20 deletions MHacks/SiMHacksViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class SiMHacksViewController: UIViewController, ScannerViewControllerDelegate, U

private var peopleOnBoard: [LeaderboardPosition] = []

private let refreshControl = UIRefreshControl()
private let leaderboardRefreshControl = UIRefreshControl()

private var selectedQuest: String = ""

Expand All @@ -47,7 +47,7 @@ class SiMHacksViewController: UIViewController, ScannerViewControllerDelegate, U

private let leaderboardUser: UILabel = {
let rankscore = UILabel()
rankscore.text = "Your rank: 0 | Your points: 0"
rankscore.text = "Your points: 0"
rankscore.textColor = UIColor.white
rankscore.numberOfLines = 0
rankscore.translatesAutoresizingMaskIntoConstraints = false
Expand Down Expand Up @@ -148,7 +148,9 @@ class SiMHacksViewController: UIViewController, ScannerViewControllerDelegate, U
let alert = UIAlertController(title: title, message: message, preferredStyle: .alert)
let alertAction = UIAlertAction(title: "OK", style: .default, handler: nil)
alert.addAction(alertAction)
self.present(alert, animated: true, completion: nil)
DispatchQueue.main.async {
self.present(alert, animated: true, completion: nil)
}
}

func setupCollectionview() {
Expand All @@ -165,22 +167,22 @@ class SiMHacksViewController: UIViewController, ScannerViewControllerDelegate, U

// Add Refresh Control to Table View
if #available(iOS 10.0, *) {
leaderboard.refreshControl = refreshControl
leaderboard.refreshControl = leaderboardRefreshControl
} else {
leaderboard.addSubview(refreshControl)
leaderboard.addSubview(leaderboardRefreshControl)
}

// Configure Refresh Control
refreshControl.addTarget(self, action: #selector(refreshLeaderboard(_:)), for: .valueChanged)
refreshControl.attributedTitle = NSAttributedString(string: "Updating leaderboard ...", attributes: [NSAttributedString.Key.font : UIFont(name: "AndaleMono", size: 12)!, NSAttributedString.Key.foregroundColor : MHacksColor.backgroundDarkBlue])
refreshControl.tintColor = MHacksColor.backgroundDarkBlue
leaderboardRefreshControl.addTarget(self, action: #selector(refreshLeaderboard(_:)), for: .valueChanged)
leaderboardRefreshControl.attributedTitle = NSAttributedString(string: "Updating leaderboard ...", attributes: [NSAttributedString.Key.font : UIFont(name: "AndaleMono", size: 12)!, NSAttributedString.Key.foregroundColor : MHacksColor.backgroundDarkBlue])
leaderboardRefreshControl.tintColor = MHacksColor.backgroundDarkBlue
}

@objc func refreshLeaderboard(_ sender: Any) {
leaderboard.reloadData()
getLeaderboard()
getUserRankScore()
self.refreshControl.endRefreshing()
self.leaderboardRefreshControl.endRefreshing()
}

func getUserRankScore() {
Expand All @@ -200,16 +202,20 @@ class SiMHacksViewController: UIViewController, ScannerViewControllerDelegate, U

// Refresh the UILabel to display the user's rank and score
DispatchQueue.main.async {
self.leaderboardUser.text = "Your rank: 0 | Your points: " + String(user_points)
self.leaderboardUser.text = "Your points: " + String(user_points)
}
}
}

func getLeaderboard() {
APIManager.shared.getLeaderboard { newLeaderBoard in
// TODO: find out the json keys for leaderboard
guard let leaderboardAndResponse = newLeaderBoard else {
self.makeAlertController(title: "ERROR: could not find game state.", message: "You must complete the SiMHacks questionnaire in order to play the game.")
return
}

guard let leaderboard = newLeaderBoard?["leaderboard"] as? NSArray else {
guard let leaderboard = leaderboardAndResponse["leaderboard"] as? NSArray else {
self.makeAlertController(title: "ERROR: could not parse leaderboard.", message: "Could not parse leaderboard from state.")
return
}
Expand All @@ -223,16 +229,16 @@ class SiMHacksViewController: UIViewController, ScannerViewControllerDelegate, U
let entry_points = e["points"] as! Int
let entry_user = e["user"] as! [String: Any]
let entry_user_name = entry_user["full_name"] as! String
print(entry_points)
print(entry_user_name)
// print(entry_points)
// print(entry_user_name)
let entry_rank = rank

new_board.append(LeaderboardPosition(position: entry_rank, name: entry_user_name, score: entry_points))
rank += 1;
}
self.peopleOnBoard = new_board

print(self.peopleOnBoard)
// print(self.peopleOnBoard)
// Refresh the leaderboard
DispatchQueue.main.async {
self.leaderboard.reloadData()
Expand All @@ -257,7 +263,12 @@ class SiMHacksViewController: UIViewController, ScannerViewControllerDelegate, U
// Get data from API
APIManager.shared.getGameState { newState in

guard let gState = newState?["state"] else {
guard let stateAndResponse = newState else {
self.makeAlertController(title: "ERROR: could not find game state.", message: "You must complete the SiMHacks questionnaire in order to play the game.")
return
}

guard let gState = stateAndResponse["state"] else {
self.makeAlertController(title: "ERROR: could not parse state.", message: "Could not parse state from the server response.")
return
}
Expand All @@ -269,6 +280,8 @@ class SiMHacksViewController: UIViewController, ScannerViewControllerDelegate, U
return
}

var newQuests: [Quest] = []

for quest in quests {
guard let q = quest as? [String: Any] else {
self.makeAlertController(title: "ERROR: could not parse individual quest into dictionary.", message: "Could not convert quest into dictionary.")
Expand All @@ -282,11 +295,13 @@ class SiMHacksViewController: UIViewController, ScannerViewControllerDelegate, U
// Find and replace the {} with the real question content
fullQuestion = fullQuestion.replacingOccurrences(of: "{}", with: answer)

self.currentQuests.append(Quest(title: fullQuestion, points: numPoints))
newQuests.append(Quest(title: fullQuestion, points: numPoints))

self.questNames.append(questionKeyword)
}

self.currentQuests = newQuests

// Refresh the collectionview to display the quests
DispatchQueue.main.async {
self.collectionView.reloadData()
Expand Down Expand Up @@ -372,16 +387,16 @@ class SiMHacksViewController: UIViewController, ScannerViewControllerDelegate, U
scannerNavigationController.isToolbarHidden = false

present(scannerNavigationController, animated: true, completion: nil)

self.getQuests()
self.getLeaderboard()
}
}

// MARK: ScannerViewControllerDelegate

func scannerViewControllerDidFinish(scannerViewController: ScannerViewController) {
dismiss(animated: true, completion: nil)
self.getUserRankScore()
self.getLeaderboard()
self.getQuests()
}

// MARK: CollectionView
Expand Down Expand Up @@ -482,7 +497,7 @@ class SiMHacksViewController: UIViewController, ScannerViewControllerDelegate, U
self.selectedQuest = ""
} else {
collectionView.selectItem(at: indexPath, animated: true, scrollPosition: [])
self.selectedQuest = questNames[indexPath.row]
self.selectedQuest = self.questNames[indexPath.row]
}

return false
Expand All @@ -500,6 +515,7 @@ class SiMHacksViewController: UIViewController, ScannerViewControllerDelegate, U
cell.positionLabel.text = "\(data.position)"
cell.nameLabel.text = data.name
cell.scoreLabel.text = "\(data.score)"
cell.selectionStyle = .none
return cell
}

Expand Down
5 changes: 4 additions & 1 deletion MHacks/UserViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,10 @@ final class UserViewController: UIViewController, LoginViewControllerDelegate, P

let passesViewController = PKAddPassesViewController(pass: pass)
passesViewController!.delegate = self
self.present(passesViewController!, animated: true, completion: nil)

DispatchQueue.main.async {
self.present(passesViewController!, animated: true, completion: nil)
}
}
}

Expand Down