SPB Git

Repository Public License

Feedback.swift 2.3 KB 64 lines swift

1// ORIX Alarm2// File: App/Wake/Feedback.swift3// Description: Haptic and sound-effect facades used by every feature (engines live in HapticEngine.swift and SoundPlayer.swift).4//5// Author: Simon-Pierre Boucher6// Contact: contact@spboucher.ai7import AlarmCore8import UIKit910/// Haptic feedback facade. Call sites never touch the haptic engine directly.11enum Haptics {12    enum Event: CaseIterable {13        /// A choice changed (chip, toggle, list row).14        case selection15        /// One step of a time wheel or slider: very light, safe to call many times per second.16        case tick17        /// A puzzle round was solved.18        case success19        /// A wrong answer.20        case failure21        /// Something needs attention (destructive confirmation, validation issue).22        case warning23        /// The whole mission sequence is done: rising triple.24        case missionComplete25        /// "I'm up" confirmed: long warm swell.26        case wakeConfirmed27        /// An alarm was saved and scheduled.28        case alarmSet29    }3031    /// Mirrors the user's setting (the app model sets it at launch and on every settings change).32    static var isEnabled = true 3334    static func play(_ event: Event) {35        guard isEnabled else { return }36        HapticEngine.shared.play(event)37    }3839    /// Optional: warms the engine up before a burst of feedback (a mission, the time picker) to avoid a late first tap.40    static func prepare() {41        guard isEnabled else { return }42        HapticEngine.shared.prepare()43    }44}4546/// Short interface sounds (mission feedback). They mix with other audio and follow the silent switch.47enum SoundFX {48    enum Effect: String, CaseIterable {49        case tap, correct, wrong, complete50        var fileName: String { "fx-\(rawValue)" }51    }5253    static var isEnabled = true5455    static func play(_ effect: Effect) {56        // The settings value is read here as well so the user's choice applies even if nobody mirrors it into `isEnabled`.57        guard isEnabled, AppDependencies.model?.settings.soundEffectsEnabled ?? true else { return }58        SoundPlayer.shared.playEffect(effect)59    }6061    /// Optional: loads the effect files ahead of time (first `play` otherwise pays the file-open cost).62    static func prepare() { SoundPlayer.shared.prepareEffects() }63}64
Files main
Menu

Theme