mirror of
https://github.com/Kugelschieber/breach.git
synced 2026-01-18 12:00:25 +00:00
Count down timer and some styling.
This commit is contained in:
@@ -14,6 +14,7 @@
|
||||
import Buffer from "./components/Buffer.vue";
|
||||
import Matrix from "./components/Matrix.vue";
|
||||
import { Game } from "./game/Game";
|
||||
import {useTimer} from "./components/timer";
|
||||
|
||||
export default defineComponent({
|
||||
components: {
|
||||
@@ -23,6 +24,7 @@
|
||||
Matrix
|
||||
},
|
||||
setup() {
|
||||
const {updateCountdown} = useTimer();
|
||||
const game = new Game({
|
||||
matrix: [
|
||||
"AA", "BB", "CC",
|
||||
@@ -50,6 +52,7 @@
|
||||
provide("sequences", readonly(sequences));
|
||||
provide("size", readonly(size));
|
||||
provide("matrix", readonly(matrix));
|
||||
updateCountdown(game, remainingMilliseconds);
|
||||
|
||||
return {
|
||||
level
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@ $yellow: #d0ee58;
|
||||
|
||||
* {
|
||||
box-sizing: border-box;
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
html, body {
|
||||
@@ -105,6 +106,7 @@ main {
|
||||
width: 32px;
|
||||
height: 32px;
|
||||
margin: 0 5px 5px 0;
|
||||
cursor: pointer;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user