// Clip playback. Rate and frame count come from the manifest; this file has no // opinion about either. export function createPlayer(clip) { return { clip, time: 0, reset() { this.time = 0; }, advance(dt) { this.time += dt; }, get index() { const raw = Math.floor(this.time * this.clip.fps); if (!this.clip.loop) return Math.min(Math.max(raw, 0), this.clip.count - 1); return ((raw % this.clip.count) + this.clip.count) % this.clip.count; }, get finished() { return !this.clip.loop && this.time * this.clip.fps >= this.clip.count - 1; }, frame() { return this.clip.frames[this.index]; }, }; }