Repository Public License
1// ORIX Arcade2// File: ArcadeCore/GameCatalog.swift3// Description: Game identifiers, the descriptor contract each game publishes to the lobby, achievements and launch options.4//5// Author: Simon-Pierre Boucher6// Contact: contact@spboucher.ai7import SwiftUI89nonisolated enum GameID: String, Codable, CaseIterable, Sendable, Identifiable {10 case dominoCity, digToCore, trafficMayhem11 var id: String { rawValue }12}1314/// Everything the lobby needs to present and launch a game. Each game exposes one as `static let descriptor`.15struct GameDescriptor: Identifiable {16 let id: GameID17 let title: String18 let tagline: String19 let theme: GameTheme20 let music: AudioDirector.Music21 /// Animated cover art, drawn in code. Must be static when `OrixAppearance.reduceMotion` is true.22 let preview: () -> AnyView23 /// Personal best for the lobby card, e.g. "Best 12 400". `nil` when the game was never played.24 let bestLabel: (SaveData) -> String?25 /// Progress for the lobby card, e.g. ("7 / 15 levels", 0.46).26 let progress: (SaveData) -> (label: String, fraction: Double)?27 /// Root view of the game. Call `onExit` to return to the lobby.28 let root: (_ onExit: @escaping () -> Void) -> AnyView29}3031enum GameCatalog {32 static let all: [GameDescriptor] = [DominoCityGame.descriptor, DigToCoreGame.descriptor, TrafficMayhemGame.descriptor]33 static func descriptor(_ id: GameID) -> GameDescriptor { all.first { $0.id == id }! }34}3536nonisolated struct AchievementDef: Identifiable, Sendable, Equatable {37 let id: String38 let game: GameID?39 let title: String40 let detail: String41 let symbol: String42}4344enum AchievementCatalog {45 static let general: [AchievementDef] = [46 .init(id: "arcade.first", game: nil, title: "Insert Coin", detail: "Finish your first session.", symbol: "play.circle.fill"),47 .init(id: "arcade.trio", game: nil, title: "Triple Threat", detail: "Play all three games.", symbol: "square.stack.3d.up.fill"),48 .init(id: "arcade.regular", game: nil, title: "Regular", detail: "Finish 25 sessions.", symbol: "flame.fill"),49 .init(id: "arcade.marathon", game: nil, title: "Marathon", detail: "Play for 30 minutes in total.", symbol: "timer"),50 .init(id: "arcade.record", game: nil, title: "Record Breaker", detail: "Beat one of your own records.", symbol: "trophy.fill"),51 ]52 static let all: [AchievementDef] = general + DominoCityGame.achievements + DigToCoreGame.achievements + TrafficMayhemGame.achievements53 static func def(_ id: String) -> AchievementDef? { all.first { $0.id == id } }54}5556/// Launch arguments (`-ORIXKey value`), used by UI tests, screenshots and performance captures.57enum LaunchOptions {58 private static let defaults = UserDefaults.standard59 static func string(_ key: String) -> String? { defaults.string(forKey: "ORIX" + key) }60 static func flag(_ key: String) -> Bool { defaults.bool(forKey: "ORIX" + key) }61 static func int(_ key: String) -> Int? { defaults.object(forKey: "ORIX" + key) == nil ? nil : defaults.integer(forKey: "ORIX" + key) }6263 /// `-ORIXSaveName uitest` uses a separate save file.64 static var saveName: String { string("SaveName") ?? "save" }65 /// `-ORIXReset YES` starts from an empty save.66 static var reset: Bool { flag("Reset") }67 /// `-ORIXMute YES` skips audio engine start-up.68 static var mute: Bool { flag("Mute") }69 /// `-ORIXGame dominoCity|digToCore|trafficMayhem` opens a game directly.70 static var game: GameID? { string("Game").flatMap(GameID.init(rawValue:)) }71 /// `-ORIXTab arcade|awards|settings` opens a lobby tab directly.72 static var tab: String? { string("Tab") }73 /// `-ORIXAutoplay YES` lets each game's built-in bot play (screenshots, soak and performance runs).74 static var autoplay: Bool { flag("Autoplay") }75 /// `-ORIXPerfLog YES` writes frame-time statistics to Documents/perf-<game>.json.76 static var perfLog: Bool { flag("PerfLog") }77 /// `-ORIXSkipIntro YES` skips the splash and the welcome sheet.78 static var skipIntro: Bool { flag("SkipIntro") }79 /// `-ORIXSeed 42` forces a seed where a game supports it.80 static var seed: UInt64? { int("Seed").map { UInt64(max(0, $0)) } }81}82