Skip to content

Commit

Permalink
Merge pull request cs3217-2324#113 from sp4ce-cowboy/feature/achievem…
Browse files Browse the repository at this point in the history
…ents-engine

[Feature] Storage API + Metrics API
  • Loading branch information
sp4ce-cowboy authored Apr 16, 2024
2 parents 1b0d8f9 + 14e4961 commit 602f44f
Show file tree
Hide file tree
Showing 80 changed files with 2,610 additions and 1,189 deletions.
288 changes: 198 additions & 90 deletions TowerForge/TowerForge.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

57 changes: 0 additions & 57 deletions TowerForge/TowerForge/Achievements/AchievementManager.swift

This file was deleted.

31 changes: 0 additions & 31 deletions TowerForge/TowerForge/Achievements/AchievementStorage.swift

This file was deleted.

37 changes: 0 additions & 37 deletions TowerForge/TowerForge/Achievements/Implemented/Achievement.swift

This file was deleted.

This file was deleted.

This file was deleted.

7 changes: 4 additions & 3 deletions TowerForge/TowerForge/AppMain/Application/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.

/// Load the local storage and data
StorageManager.initializeData()

/// Connect to Firebase
FirebaseApp.configure()

/// Initialize all local storage
StorageManager.initializeAllStorage()

/// Prepare audio player to begin playing music
AudioManager.shared.setupAllAudioPlayers()

return true
}

Expand Down
22 changes: 19 additions & 3 deletions TowerForge/TowerForge/Commons/Constants/Constants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,29 @@ class Constants {
static let DATABASE_URL = "https://towerforge-d5ba7-default-rtdb.asia-southeast1.firebasedatabase.app"

/// The name of the folder in which information is stored locally
static let STORAGE_CONTAINER_NAME = "TowerForge"
static let LOCAL_STORAGE_CONTAINER_NAME = "TowerForge"

/// The name of the TowerForge project to prefix
static let PROJECT_NAME_PREFIX = "TowerForge"

/// The name of the file that contains TowerForge data locally
static let TF_DATABASE_NAME = "TowerForgeDatabase"
static let LOCAL_STORAGE_FILE_NAME = "TowerForgeLocalStorage.json"

/// The name of the file that contains metadata about local storage
static let METADATA_FILE_NAME = "TowerForgeMetadata.json"

/// The name of the player currently logged in.
/// By default, this is set to the default id associated with the device
static var CURRENT_PLAYER_ID = ""

/// The default id associated with the device
static var CURRENT_DEVICE_ID = ""

/// The universally declared conflict resolution method
static var CONFLICT_RESOLTION: StorageConflictResolution = .MERGE

/// Universal setting to enable or disable sound effects
static var SOUND_EFFECTS_ENABLED = true
static var SOUND_EFFECTS_ENABLED = false

/// Universal background audio soundtrack to play during game modes
static let GAME_BACKGROUND_AUDIO: String = BackgroundMusic.gameMode.rawValue
Expand Down
64 changes: 30 additions & 34 deletions TowerForge/TowerForge/Commons/Enums/StorageEnums.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,51 +7,47 @@

import Foundation

typealias TFStorageType = StorageEnums.StorageType
typealias TFAchievementType = StorageEnums.StorableAchievementNameType
typealias StatisticsDatabaseCodingKeys = StorageEnums.StatisticsDatabaseCodingKeys
typealias StatisticCodingKeys = StorageEnums.StatisticsDefaultCodingKeys
typealias DynamicCodingKeys = StorageEnums.DynamicCodingKeys
typealias StorageLocation = StorageEnums.StorageLocation
typealias StorageConflictResolution = StorageEnums.StorageConflictResolution

class StorageEnums {

/// An enum for the names of every Storable that can be stored.
/// Adds an implicit "CheckRep", malicious actors cannot load
/// random storables perhaps using obj-c's dynamic runtime.
enum StorableNameType: String, CodingKey, Codable, CaseIterable {
case dummyStorable // Temp dummy case to replace later
case totalKillsAchievement
case totalGamesAchievement
enum StatisticsDatabaseCodingKeys: String, CodingKey, Codable {
case statistics
}

/// For achievements only.
/// Rep-invariant: All cases must also be contained within StorableNameType
enum StorableAchievementNameType: String, CodingKey, Codable, CaseIterable {
case totalKillsAchievement
case totalGamesAchievement
enum StatisticsDefaultCodingKeys: String, CodingKey, Codable {
case statisticName
case permanentValue
case currentValue
case maximumCurrentValue
}

/// Used in the default implementation of Storage
enum StorableDefaultCodingKeys: String, CodingKey {
case storableId
case storableName
case storableValue
enum StorageLocation: String, Codable {
case Local
case Remote
}

/// Used in StorageManager class
enum StorageType: String, CodingKey, Codable {
case achievementStorage
enum StorageConflictResolution: String {
case MERGE
case KEEP_LATEST_ONLY
}

/// Used in Storage class
enum StorageCodingKeys: String, CodingKey, Codable {
case storageName
case storedObjects
}
struct DynamicCodingKeys: CodingKey {
var stringValue: String
var intValue: Int?

enum DatabaseCodingKeys: String, CodingKey, Codable {
case storedData
}
init?(stringValue: String) {
self.stringValue = stringValue
self.intValue = nil
}

enum StatisticDefaultCodingKeys: String, CodingKey, Codable {
case statisticName
case statisticValue
init?(intValue: Int) {
self.stringValue = String(intValue)
self.intValue = intValue
}
}

}
Loading

0 comments on commit 602f44f

Please sign in to comment.