SPB Git

Repository Public License

AwardsView.swift 5.8 KB 110 lines swift

1// ORIX Arcade2// File: App/AwardsView.swift3// Description: Awards tab — personal records per game, achievements grid and full session history, all from the local save.4//5// Author: Simon-Pierre Boucher6// Contact: contact@spboucher.ai7import SwiftUI89struct AwardsView: View {10    @Environment(ArcadeServices.self) private var services1112    var body: some View {13        let save = services.save14        ScrollView {15            VStack(alignment: .leading, spacing: OrixSpace.lg) {16                VStack(alignment: .leading, spacing: 4) {17                    Text("Awards").font(OrixFont.display).foregroundStyle(OrixColor.textPrimary)18                    Text("\(save.achievements.count) of \(AchievementCatalog.all.count) achievements unlocked")19                        .font(OrixFont.callout).foregroundStyle(OrixColor.textSecondary)20                    OrixProgressBar(fraction: Double(save.achievements.count) / Double(max(AchievementCatalog.all.count, 1)), height: 8)21                        .padding(.top, 4)22                }23                .padding(.top, OrixSpace.xs)2425                VStack(alignment: .leading, spacing: OrixSpace.sm) {26                    SectionHeader(title: "Records")27                    ForEach(GameCatalog.all) { descriptor in28                        HStack(spacing: OrixSpace.sm) {29                            RoundedRectangle(cornerRadius: 4).fill(descriptor.theme.gradient).frame(width: 6, height: 40)30                            VStack(alignment: .leading, spacing: 2) {31                                Text(descriptor.title).font(OrixFont.headline).foregroundStyle(OrixColor.textPrimary)32                                Text("\(save.stats.sessionCount[descriptor.id.rawValue, default: 0]) sessions · \(save.stats.playTime[descriptor.id.rawValue, default: 0].playTimeLabel)")33                                    .font(OrixFont.caption).foregroundStyle(OrixColor.textSecondary)34                            }35                            Spacer(minLength: OrixSpace.xs)36                            VStack(alignment: .trailing, spacing: 2) {37                                Text(descriptor.bestLabel(save) ?? "—").font(OrixFont.callout.weight(.heavy)).foregroundStyle(OrixColor.gold)38                                if let progress = descriptor.progress(save) {39                                    Text(progress.label).font(OrixFont.caption).foregroundStyle(OrixColor.textTertiary)40                                }41                            }42                        }43                        .glassPanel(radius: OrixRadius.md, tint: descriptor.theme.primary, padding: OrixSpace.sm)44                        .accessibilityElement(children: .combine)45                    }46                }4748                achievementSection("Arcade", defs: AchievementCatalog.general, theme: .orix, save: save)49                ForEach(GameCatalog.all) { descriptor in50                    achievementSection(descriptor.title, defs: AchievementCatalog.all.filter { $0.game == descriptor.id }, theme: descriptor.theme, save: save)51                }5253                if !save.stats.recent.isEmpty {54                    VStack(alignment: .leading, spacing: OrixSpace.sm) {55                        SectionHeader(title: "History", trailing: "last \(save.stats.recent.count)")56                        VStack(spacing: 0) {57                            ForEach(Array(save.stats.recent.enumerated()), id: \.element.id) { index, record in58                                SessionRow(record: record)59                                if index < save.stats.recent.count - 1 { Divider().overlay(OrixColor.stroke) }60                            }61                        }62                        .glassPanel(padding: OrixSpace.sm)63                    }64                }65            }66            .padding(.horizontal, OrixSpace.md)67            .padding(.bottom, 110)68        }69        .scrollIndicators(.hidden)70    }7172    @ViewBuilder73    private func achievementSection(_ title: String, defs: [AchievementDef], theme: GameTheme, save: SaveData) -> some View {74        if !defs.isEmpty {75            VStack(alignment: .leading, spacing: OrixSpace.sm) {76                SectionHeader(title: title, trailing: "\(defs.filter { save.achievements[$0.id] != nil }.count)/\(defs.count)")77                LazyVGrid(columns: [GridItem(.flexible(), spacing: OrixSpace.xs), GridItem(.flexible(), spacing: OrixSpace.xs)], spacing: OrixSpace.xs) {78                    ForEach(defs) { def in79                        AchievementTile(def: def, unlocked: save.achievements[def.id], theme: theme)80                    }81                }82            }83        }84    }85}8687struct AchievementTile: View {88    let def: AchievementDef89    let unlocked: Date?90    let theme: GameTheme9192    var body: some View {93        let isUnlocked = unlocked != nil94        VStack(alignment: .leading, spacing: 6) {95            Image(systemName: isUnlocked ? def.symbol : "lock.fill")96                .font(.system(size: 17, weight: .bold))97                .foregroundStyle(isUnlocked ? OrixColor.ink : OrixColor.textTertiary)98                .frame(width: 38, height: 38)99                .background(isUnlocked ? AnyShapeStyle(theme.gradient) : AnyShapeStyle(Color.white.opacity(0.07)), in: Circle())100            Text(def.title).font(OrixFont.callout.weight(.heavy))101                .foregroundStyle(isUnlocked ? OrixColor.textPrimary : OrixColor.textSecondary).lineLimit(1).minimumScaleFactor(0.75)102            Text(def.detail).font(OrixFont.caption).foregroundStyle(OrixColor.textTertiary).lineLimit(3).fixedSize(horizontal: false, vertical: true)103        }104        .frame(maxWidth: .infinity, minHeight: 118, alignment: .topLeading)105        .glassPanel(radius: OrixRadius.md, tint: isUnlocked ? theme.primary : .white, padding: OrixSpace.sm)106        .accessibilityElement(children: .ignore)107        .accessibilityLabel("\(def.title). \(def.detail). \(isUnlocked ? "Unlocked" : "Locked")")108    }109}110
Files main
Menu

Theme