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