aaffa3771c
Two-target restructure: shared sources (models, services, settings, extensions, team logos) move into Shared/, consumed by both the existing macOS menu bar app and a new iOS app. MainService no longer imports AppKit — platform code attaches via a MainServiceObserver protocol (MacObserverAdapter wires back to MenuManager / StatusItemManager / NotificationManager). iPhone app is a single SwiftUI page mirroring the macOS menu (playoff round + yesterday/today/tomorrow), with a gear-icon settings sheet (display option + IndieAbout for license/changelog). Persistent JSON snapshot in Application Support paints last-known data on cold launch; "Updated …" header escalates secondary → orange (>5min) → red (>30min) so staleness is visually unmistakable. Foreground polling, scenePhase refresh, and pull-to-refresh; no notifications on iOS in v1.
95 lines
2.9 KiB
Swift
95 lines
2.9 KiB
Swift
//
|
|
// PlayByPlayModel.swift
|
|
// IceGlass
|
|
//
|
|
// Copyright 2026 Rouslan Zenetl. All Rights Reserved.
|
|
//
|
|
|
|
import Foundation
|
|
|
|
struct PlayByPlay: Codable {
|
|
let awayTeam: Team
|
|
let homeTeam: Team
|
|
let plays: [Play]
|
|
let rosterSpots: [RosterSpot]
|
|
|
|
struct Team: Codable {
|
|
let id: Int
|
|
let abbrev: String
|
|
}
|
|
|
|
struct Play: Codable {
|
|
let typeDescKey: String
|
|
let situationCode: String?
|
|
let details: Details?
|
|
|
|
struct Details: Codable {
|
|
let scoringPlayerId: Int?
|
|
let eventOwnerTeamId: Int?
|
|
let awayScore: Int?
|
|
let homeScore: Int?
|
|
}
|
|
}
|
|
|
|
struct RosterSpot: Codable {
|
|
let teamId: Int
|
|
let playerId: Int
|
|
let firstName: LocalizedString
|
|
let lastName: LocalizedString
|
|
let sweaterNumber: Int
|
|
|
|
struct LocalizedString: Codable {
|
|
let `default`: String
|
|
}
|
|
}
|
|
|
|
/// Find the goal play whose trailing score matches the given totals exactly.
|
|
/// Returns nil if play-by-play hasn't caught up with the scoreboard yet —
|
|
/// safer than guessing, since a stale fallback could name the previous scorer.
|
|
func goal(matchingAwayScore awayScore: Int, homeScore: Int) -> Play? {
|
|
plays.last { play in
|
|
play.typeDescKey == "goal"
|
|
&& play.details?.awayScore == awayScore
|
|
&& play.details?.homeScore == homeScore
|
|
}
|
|
}
|
|
|
|
func player(id: Int) -> RosterSpot? {
|
|
rosterSpots.first { $0.playerId == id }
|
|
}
|
|
|
|
/// Derived strength tag for a goal ("PPG", "SHG", "EN"), or nil for even-strength.
|
|
/// `situationCode` is 4 digits: awayGoalie, awaySkaters, homeSkaters, homeGoalie.
|
|
static func strengthTag(situationCode: String?, scoringTeamIsAway: Bool) -> String? {
|
|
guard let code = situationCode, code.count == 4 else { return nil }
|
|
let digits = code.compactMap { $0.wholeNumberValue }
|
|
guard digits.count == 4 else { return nil }
|
|
let awayGoalie = digits[0]
|
|
let awaySkaters = digits[1]
|
|
let homeSkaters = digits[2]
|
|
let homeGoalie = digits[3]
|
|
|
|
let scoringSkaters = scoringTeamIsAway ? awaySkaters : homeSkaters
|
|
let opposingSkaters = scoringTeamIsAway ? homeSkaters : awaySkaters
|
|
let opposingGoalie = scoringTeamIsAway ? homeGoalie : awayGoalie
|
|
|
|
if opposingGoalie == 0 { return "EN" }
|
|
if scoringSkaters > opposingSkaters { return "PPG" }
|
|
if scoringSkaters < opposingSkaters { return "SHG" }
|
|
return nil
|
|
}
|
|
}
|
|
|
|
struct GoalScorer {
|
|
let name: String
|
|
let sweaterNumber: Int
|
|
let strength: String?
|
|
|
|
/// "#14 J. Eriksson Ek (PPG)" — strength suffix omitted for even-strength goals.
|
|
var displayLine: String {
|
|
let head = "#\(sweaterNumber) \(name)"
|
|
if let strength = strength { return "\(head) (\(strength))" }
|
|
return head
|
|
}
|
|
}
|