Repository Public License
1// ORIX Arcade2// File: App/ORIXArcadeApp.swift3// Description: App entry point and root navigation — splash, lobby tabs, the portal transition into a game, toasts and lifecycle handling.4//5// Author: Simon-Pierre Boucher6// Contact: contact@spboucher.ai7import SwiftUI89@main10struct ORIXArcadeApp: App {11 @State private var services = ArcadeServices.live()1213 var body: some Scene {14 WindowGroup {15 RootView()16 .environment(services)17 .preferredColorScheme(.dark)18 .statusBarHidden()19 .persistentSystemOverlays(.hidden)20 }21 }22}2324enum LobbyTab: String, CaseIterable {25 case arcade, awards, settings2627 var title: String {28 switch self {29 case .arcade: "Arcade"30 case .awards: "Awards"31 case .settings: "Settings"32 }33 }3435 var symbol: String {36 switch self {37 case .arcade: "gamecontroller.fill"38 case .awards: "trophy.fill"39 case .settings: "slider.horizontal.3"40 }41 }42}4344struct RootView: View {45 @Environment(ArcadeServices.self) private var services46 @Environment(\.scenePhase) private var scenePhase47 @State private var showSplash = !LaunchOptions.skipIntro && LaunchOptions.game == nil48 @State private var tab = LaunchOptions.tab.flatMap(LobbyTab.init(rawValue:)) ?? .arcade49 @State private var activeGame: GameID? = LaunchOptions.game50 @State private var portal: GameID?51 @State private var portalOpen = false5253 var body: some View {54 ZStack {55 lobby56 .id("\(services.settings.highContrast)-\(services.settings.reduceMotion)")57 .allowsHitTesting(activeGame == nil && portal == nil)58 .accessibilityHidden(activeGame != nil)5960 if let portal {61 GameCatalog.descriptor(portal).theme.deep62 .overlay(AuroraBackground(theme: GameCatalog.descriptor(portal).theme))63 .clipShape(Circle().scale(portalOpen ? 3 : 0.001))64 .ignoresSafeArea()65 .allowsHitTesting(false)66 }6768 if let game = activeGame {69 GameCatalog.descriptor(game).root { exit(game) }70 .transition(.opacity)71 .zIndex(2)72 }7374 ToastHost().zIndex(5)7576 if showSplash {77 SplashView { withAnimation(.easeOut(duration: 0.35)) { showSplash = false } }78 .transition(.opacity)79 .zIndex(10)80 }81 }82 .background(OrixColor.void.ignoresSafeArea())83 .onAppear {84 if let game = activeGame { services.markInterrupted(game: game) }85 syncMusic()86 }87 .onChange(of: activeGame) { _, _ in syncMusic() }88 .onChange(of: scenePhase) { _, phase in89 switch phase {90 case .active: services.audio.resume()91 case .background:92 services.store.flush()93 services.audio.suspend()94 default: services.store.flush()95 }96 }97 }9899 private var lobby: some View {100 ZStack(alignment: .bottom) {101 AuroraBackground()102 Group {103 switch tab {104 case .arcade: LobbyView(open: open)105 case .awards: AwardsView()106 case .settings: SettingsView()107 }108 }109 .transition(.opacity)110 LobbyTabBar(tab: $tab)111 .padding(.bottom, 6)112 }113 }114115 private func syncMusic() {116 services.audio.setMusic(activeGame.map { GameCatalog.descriptor($0).music } ?? .lobby)117 }118119 private func open(_ game: GameID) {120 guard activeGame == nil, portal == nil else { return }121 services.audio.play(.confirm)122 services.haptics.play(.select)123 services.markInterrupted(game: game)124 if OrixAppearance.reduceMotion {125 withAnimation(.easeOut(duration: 0.2)) { activeGame = game }126 return127 }128 portal = game129 portalOpen = false130 withAnimation(.easeIn(duration: 0.38)) { portalOpen = true }131 Task {132 try? await Task.sleep(for: .milliseconds(340))133 withAnimation(.easeOut(duration: 0.25)) { activeGame = game }134 try? await Task.sleep(for: .milliseconds(300))135 portal = nil136 }137 }138139 private func exit(_ game: GameID) {140 services.audio.play(.back)141 services.clearInterrupted()142 services.store.flush()143 withAnimation(.easeInOut(duration: 0.3)) { activeGame = nil }144 }145}146147struct LobbyTabBar: View {148 @Binding var tab: LobbyTab149 @Environment(ArcadeServices.self) private var services150 @Namespace private var namespace151152 var body: some View {153 HStack(spacing: 4) {154 ForEach(LobbyTab.allCases, id: \.self) { item in155 let selected = item == tab156 Button {157 guard tab != item else { return }158 services.feedbackTap()159 withAnimation(OrixMotion.decorative(OrixMotion.snappy)) { tab = item }160 } label: {161 HStack(spacing: 7) {162 Image(systemName: item.symbol).font(.system(size: 16, weight: .bold))163 if selected { Text(item.title).font(OrixFont.caption).lineLimit(1).fixedSize() }164 }165 .foregroundStyle(selected ? OrixColor.ink : OrixColor.textSecondary)166 .padding(.horizontal, selected ? 18 : 16)167 .frame(minWidth: 56, minHeight: 48)168 .background {169 if selected { Capsule().fill(GameTheme.orix.gradient).matchedGeometryEffect(id: "tab", in: namespace) }170 }171 .contentShape(Capsule())172 }173 .buttonStyle(.plain)174 .accessibilityLabel(item.title)175 .accessibilityAddTraits(selected ? .isSelected : [])176 .accessibilityIdentifier("tab-\(item.rawValue)")177 }178 }179 .padding(5)180 .background(.ultraThinMaterial, in: Capsule())181 .overlay(Capsule().strokeBorder(OrixColor.stroke, lineWidth: 1))182 .shadow(color: .black.opacity(0.5), radius: 18, y: 8)183 }184}185186struct ToastHost: View {187 @Environment(ArcadeServices.self) private var services188189 var body: some View {190 VStack(spacing: OrixSpace.xs) {191 ForEach(services.toasts) { toast in192 HStack(spacing: OrixSpace.sm) {193 Image(systemName: toast.symbol)194 .font(.system(size: 18, weight: .bold))195 .foregroundStyle(OrixColor.ink)196 .frame(width: 38, height: 38)197 .background(Color(hex: toast.tintHex), in: Circle())198 VStack(alignment: .leading, spacing: 1) {199 Text(toast.detail.uppercased()).font(OrixFont.overline).tracking(1.2).foregroundStyle(Color(hex: toast.tintHex))200 Text(toast.title).font(OrixFont.headline).foregroundStyle(OrixColor.textPrimary)201 }202 Spacer(minLength: 0)203 }204 .padding(10)205 .frame(maxWidth: 330)206 .background(OrixColor.surfaceRaised.opacity(0.96), in: Capsule())207 .overlay(Capsule().strokeBorder(Color(hex: toast.tintHex).opacity(0.5), lineWidth: 1))208 .shadow(color: .black.opacity(0.5), radius: 14, y: 6)209 .transition(.move(edge: .top).combined(with: .opacity))210 .accessibilityElement(children: .combine)211 }212 Spacer()213 }214 .padding(.top, 58)215 .padding(.horizontal, OrixSpace.md)216 .animation(OrixMotion.decorative(OrixMotion.bouncy), value: services.toasts)217 .allowsHitTesting(false)218 }219}220221/// Short logo reveal. Tap anywhere to skip; never blocks longer than about a second.222struct SplashView: View {223 let onDone: () -> Void224 @State private var progress: CGFloat = 0225 @State private var showWord = false226 @State private var finished = false227228 var body: some View {229 ZStack {230 OrixColor.void.ignoresSafeArea()231 AuroraBackground(intensity: 0.8)232 VStack(spacing: OrixSpace.lg) {233 OrixLogoMark(progress: progress).frame(width: 128, height: 128)234 OrixWordmark(size: 26).opacity(showWord ? 1 : 0).offset(y: showWord ? 0 : 10)235 }236 }237 .contentShape(Rectangle())238 .onTapGesture { finish() }239 .accessibilityLabel("ORIX Arcade")240 .accessibilityAddTraits(.isButton)241 .task {242 if OrixAppearance.reduceMotion {243 progress = 1244 showWord = true245 try? await Task.sleep(for: .milliseconds(450))246 } else {247 withAnimation(.easeOut(duration: 0.7)) { progress = 1 }248 try? await Task.sleep(for: .milliseconds(380))249 withAnimation(.easeOut(duration: 0.35)) { showWord = true }250 try? await Task.sleep(for: .milliseconds(750))251 }252 finish()253 }254 }255256 private func finish() {257 guard !finished else { return }258 finished = true259 onDone()260 }261}262