npm run format
This commit is contained in:
@@ -1,16 +1,27 @@
|
||||
import { ref, computed, type Ref, onUnmounted } from 'vue';
|
||||
import { ref, computed, type Ref, onUnmounted, toRef, isRef } from 'vue';
|
||||
import type { Sprite } from '@/types/sprites';
|
||||
|
||||
export interface AnimationFramesOptions {
|
||||
sprites: Ref<Sprite[]> | Sprite[];
|
||||
sprites: Ref<Sprite[]> | Sprite[] | (() => Sprite[]);
|
||||
onDraw: () => void;
|
||||
}
|
||||
|
||||
export function useAnimationFrames(options: AnimationFramesOptions) {
|
||||
const { onDraw } = options;
|
||||
|
||||
// Convert sprites to a computed ref for reactivity
|
||||
const spritesRef = computed(() => {
|
||||
if (typeof options.sprites === 'function') {
|
||||
return options.sprites();
|
||||
}
|
||||
if (isRef(options.sprites)) {
|
||||
return options.sprites.value;
|
||||
}
|
||||
return options.sprites;
|
||||
});
|
||||
|
||||
// Helper to get sprites array
|
||||
const getSprites = () => (Array.isArray(options.sprites) ? options.sprites : options.sprites.value);
|
||||
const getSprites = () => spritesRef.value;
|
||||
|
||||
// State
|
||||
const currentFrameIndex = ref(0);
|
||||
|
||||
Reference in New Issue
Block a user