Zum Inhalt

apple/PhysarumApp/Sources/Ambient/PlaylistDirector.swift

import Foundation

/// Pure auto-cycle scheduling for the tvOS ambient playlist. Holds no state itself —
/// callers pass elapsed dwell time and the current index; the director decides when to
/// advance and to which index. Platform-agnostic so it is fully unit-testable on the
/// macOS host (the tvOS view layer just feeds it time).
enum PlaylistDirector {
    /// Whether the current preset has been on screen long enough to advance.
    static func shouldAdvance(dwellElapsed: Double, dwell: Double) -> Bool {
        dwellElapsed >= dwell
    }

    /// Next index with wrap-around. `step` may be negative (previous) or positive (next).
    /// Returns `current` unchanged when the list is empty.
    static func nextIndex(current: Int, count: Int, step: Int) -> Int {
        guard count > 0 else { return current }
        return ((current + step) % count + count) % count
    }
}