Skip to content

Commit

Permalink
fix: player
Browse files Browse the repository at this point in the history
  • Loading branch information
sheepbox8646 committed Dec 3, 2024
1 parent d960646 commit 77792b4
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
9 changes: 7 additions & 2 deletions packages/core/src/player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import type { App, Ref } from "vue";
import { inject, ref } from "vue";
import { AnimationManager } from "./animation";

const studioListenerAdded = { value: false };

export function createPlayer(options: {
studio?: boolean;
fps?: number;
Expand All @@ -24,8 +26,11 @@ export function usePlayer() {
const fps = inject("fps") as number;
const playing = ref(false);

if (studio) {
document.addEventListener("click", () => {
if (studio && !studioListenerAdded.value) {
studioListenerAdded.value = true;
document.addEventListener("click", (e) => {
console.log(elapsed.value);
e.stopImmediatePropagation();
elapsed.value += 1 / fps;
});
}
Expand Down
6 changes: 5 additions & 1 deletion test/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const rect = useWidget<RectIns>();
const line = useWidget<LineIns>();
const arrow = useWidget<ArrowIns>();
const { play } = usePlayer();
const { play, elapsed } = usePlayer();
onMounted(() => {
rect.move(100, 100);
Expand Down Expand Up @@ -49,6 +49,10 @@ onMounted(() => {
line.grow();
arrow.grow();
play();
document.addEventListener("click", () => {
console.log(elapsed.value);
});
});
</script>

Expand Down
8 changes: 7 additions & 1 deletion test/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,10 @@ import "./style.css";
import { createPlayer } from "@vue-motion/core";
import App from "./App.vue";

createApp(App).use(createPlayer({})).mount("#app");
createApp(App)
.use(
createPlayer({
studio: true,
}),
)
.mount("#app");

0 comments on commit 77792b4

Please sign in to comment.