mirror of
https://github.com/Kugelschieber/breach.git
synced 2026-01-18 20:10:25 +00:00
Manage game state through object injection everywhere, fixed filling buffer and stopping clock in Game.
This commit is contained in:
@@ -6,15 +6,31 @@
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import {defineComponent, computed, inject, Ref} from "vue";
|
||||
import { Game } from "@/game/Game";
|
||||
import {defineComponent, computed, inject, Ref, ref} from "vue";
|
||||
|
||||
export default defineComponent({
|
||||
setup() {
|
||||
const remainingMilliseconds = inject("remainingMilliseconds") as Ref<number>;
|
||||
const timeoutMilliseconds = inject("timeoutMilliseconds") as Ref<number>;
|
||||
const game = inject("game") as Ref<Game>;
|
||||
const remainingMilliseconds = ref(game.value.remainingMilliseconds);
|
||||
const timeoutMilliseconds = computed(() => game.value.timeoutMilliseconds);
|
||||
const progress = computed(() => remainingMilliseconds.value/timeoutMilliseconds.value*100);
|
||||
const countdown = computed(() => (remainingMilliseconds.value/1000).toFixed(2));
|
||||
|
||||
const updateTime = () => {
|
||||
remainingMilliseconds.value = game.value.remainingMilliseconds;
|
||||
|
||||
if (remainingMilliseconds.value > 0) {
|
||||
requestAnimationFrame(() => {
|
||||
updateTime();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
requestAnimationFrame(() => {
|
||||
updateTime();
|
||||
});
|
||||
|
||||
return {
|
||||
countdown,
|
||||
progress
|
||||
|
||||
Reference in New Issue
Block a user