Shows wins and losses in info

This commit is contained in:
thepaperpilot 2023-02-25 16:05:00 -06:00
parent 60dbd9c583
commit ed0f782f32
3 changed files with 27 additions and 4 deletions

View file

@ -43,6 +43,9 @@
</div> </div>
<br /> <br />
<div>Time Played: {{ timePlayed }}</div> <div>Time Played: {{ timePlayed }}</div>
<br />
<div>Games won: {{ victories }}</div>
<div>Games lost: {{ losses }}</div>
<component :is="infoComponent" /> <component :is="infoComponent" />
</div> </div>
</template> </template>
@ -55,7 +58,7 @@ import type Changelog from "data/Changelog.vue";
import projInfo from "data/projInfo.json"; import projInfo from "data/projInfo.json";
import { jsx } from "features/feature"; import { jsx } from "features/feature";
import player from "game/player"; import player from "game/player";
import { infoComponents } from "game/settings"; import settings, { infoComponents } from "game/settings";
import { formatTime } from "util/bignum"; import { formatTime } from "util/bignum";
import { coerceComponent, render } from "util/vue"; import { coerceComponent, render } from "util/vue";
import { computed, ref, toRefs, unref } from "vue"; import { computed, ref, toRefs, unref } from "vue";
@ -69,6 +72,8 @@ const isOpen = ref(false);
const timePlayed = computed(() => formatTime(player.timePlayed)); const timePlayed = computed(() => formatTime(player.timePlayed));
const { victories, losses } = toRefs(settings);
const infoComponent = computed(() => { const infoComponent = computed(() => {
return coerceComponent(jsx(() => (<>{infoComponents.map(render)}</>))); return coerceComponent(jsx(() => (<>{infoComponents.map(render)}</>)));
}); });

View file

@ -11,7 +11,7 @@ import type { Player } from "game/player";
import settings from "game/settings"; import settings from "game/settings";
import { formatWhole } from "util/bignum"; import { formatWhole } from "util/bignum";
import { render } from "util/vue"; import { render } from "util/vue";
import { computed, ref, TransitionGroup } from "vue"; import { computed, ref, TransitionGroup, watch } from "vue";
import autoplay from "../../public/autoplay.png"; import autoplay from "../../public/autoplay.png";
import defeatButton from "../../public/Defeat Button.png"; import defeatButton from "../../public/Defeat Button.png";
import defeatFace from "../../public/defeat face.png"; import defeatFace from "../../public/defeat face.png";
@ -864,6 +864,15 @@ export const main = createLayer("main", function (this: BaseLayer) {
} }
})); }));
watch([wins, lives], ([wins, lives]) => {
if (wins >= 5) {
settings.victories++;
}
if (lives <= 0) {
settings.losses++;
}
});
return { return {
name: "Game", name: "Game",
minimizable: false, minimizable: false,

View file

@ -25,6 +25,8 @@ export interface Settings {
showTutorial: boolean; showTutorial: boolean;
privateRoomName: string; privateRoomName: string;
privateRoomPassword: string; privateRoomPassword: string;
victories: number;
losses: number;
} }
const state = reactive<Partial<Settings>>({ const state = reactive<Partial<Settings>>({
@ -38,7 +40,9 @@ const state = reactive<Partial<Settings>>({
fast: false, fast: false,
showTutorial: true, showTutorial: true,
privateRoomName: "", privateRoomName: "",
privateRoomPassword: "" privateRoomPassword: "",
victories: 0,
losses: 0
}); });
watch( watch(
@ -73,7 +77,12 @@ export const hardResetSettings = (window.hardResetSettings = () => {
theme: Themes.Nordic, theme: Themes.Nordic,
alignUnits: false, alignUnits: false,
autoplay: false, autoplay: false,
fast: false fast: false,
showTutorial: true,
privateRoomName: "",
privateRoomPassword: "",
victories: 0,
losses: 0
}; };
globalBus.emit("loadSettings", settings); globalBus.emit("loadSettings", settings);
Object.assign(state, settings); Object.assign(state, settings);