mirror of
https://github.com/Kugelschieber/breach.git
synced 2026-01-18 20:10:25 +00:00
Count down timer and some styling.
This commit is contained in:
@@ -10,23 +10,10 @@
|
||||
|
||||
export default defineComponent({
|
||||
setup() {
|
||||
const remainingTime = inject("remainingMilliseconds") as Ref<number>;
|
||||
const remainingMilliseconds = inject("remainingMilliseconds") as Ref<number>;
|
||||
const timeoutMilliseconds = inject("timeoutMilliseconds") as Ref<number>;
|
||||
const progress = computed(() => remainingTime.value/timeoutMilliseconds.value*100);
|
||||
const countdown = computed(() => (remainingTime.value/1000).toFixed(2));
|
||||
|
||||
/*const updateTime = () => {
|
||||
remainingTime.value = Math.max(0, (props.time.getTime() - new Date().getTime()) / 1000);
|
||||
if (remainingTime.value > 0) {
|
||||
requestAnimationFrame(() => {
|
||||
updateTime();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
requestAnimationFrame(() => {
|
||||
updateTime();
|
||||
});*/
|
||||
const progress = computed(() => remainingMilliseconds.value/timeoutMilliseconds.value*100);
|
||||
const countdown = computed(() => (remainingMilliseconds.value/1000).toFixed(2));
|
||||
|
||||
return {
|
||||
countdown,
|
||||
|
||||
28
src/components/timer.ts
Normal file
28
src/components/timer.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
import { Game } from '@/game/Game';
|
||||
import { Ref } from 'vue';
|
||||
|
||||
interface Timer {
|
||||
updateCountdown(game: Game, remainingMilliseconds: Ref<number>): void
|
||||
}
|
||||
|
||||
export function useTimer(): Timer {
|
||||
function updateCountdown(game: Game, remainingMilliseconds: Ref<number>) {
|
||||
const updateTime = () => {
|
||||
remainingMilliseconds.value = game.remainingMilliseconds;
|
||||
|
||||
if (remainingMilliseconds.value > 0) {
|
||||
requestAnimationFrame(() => {
|
||||
updateTime();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
requestAnimationFrame(() => {
|
||||
updateTime();
|
||||
});
|
||||
}
|
||||
|
||||
return {
|
||||
updateCountdown
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user