Profectus-Niffix/src/components/NaNScreen.vue

124 lines
3.7 KiB
Vue
Raw Normal View History

2021-06-16 00:36:13 -05:00
<template>
2022-01-13 22:25:47 -06:00
<Modal v-model="hasNaN" v-bind="$attrs">
<template v-slot:header>
<div class="nan-modal-header">
<h2>NaN value detected!</h2>
</div>
</template>
<template v-slot:body>
<div>
2022-01-13 22:25:47 -06:00
Attempted to assign "{{ path }}" to NaN<span v-if="previous">
{{ " " }}(previously {{ format(previous) }})</span
>. Auto-saving has been {{ autosave ? "enabled" : "disabled" }}. Check the console
for more details, and consider sharing it with the developers on discord.
</div>
<br />
<div>
<a :href="discordLink" class="nan-modal-discord-link">
2022-01-24 22:25:34 -06:00
<span class="material-icons nan-modal-discord">discord</span>
{{ discordName }}
</a>
</div>
<br />
2022-01-13 22:25:47 -06:00
<Toggle title="Autosave" v-model="autosave" />
<Toggle title="Pause game" v-model="isPaused" />
</template>
<template v-slot:footer>
<div class="nan-footer">
2022-01-24 22:23:30 -06:00
<button @click="savesManager?.open()" class="button">Open Saves Manager</button>
<button @click="setZero" class="button">Set to 0</button>
<button @click="setOne" class="button">Set to 1</button>
<button
2022-01-13 22:25:47 -06:00
@click="hasNaN = false"
class="button"
2022-01-13 22:25:47 -06:00
v-if="previous && Decimal.neq(previous, 0) && Decimal.neq(previous, 1)"
>
Set to previous
</button>
<button @click="ignore" class="button danger">Ignore</button>
</div>
</template>
</Modal>
2022-01-13 22:25:47 -06:00
<SavesManager ref="savesManager" />
2021-06-16 00:36:13 -05:00
</template>
2022-01-13 22:25:47 -06:00
<script setup lang="ts">
2022-02-27 16:04:56 -06:00
import Modal from "@/components/Modal.vue";
import projInfo from "@/data/projInfo.json";
import player from "@/game/player";
import state from "@/game/state";
2022-01-13 22:25:47 -06:00
import Decimal, { DecimalSource, format } from "@/util/bignum";
2022-01-24 22:25:34 -06:00
import { ComponentPublicInstance, computed, ref, toRef } from "vue";
2022-02-27 16:04:56 -06:00
import Toggle from "./fields/Toggle.vue";
2022-01-13 22:25:47 -06:00
import SavesManager from "./SavesManager.vue";
2021-06-16 00:36:13 -05:00
const { discordName, discordLink } = projInfo;
2022-01-13 22:25:47 -06:00
const autosave = toRef(player, "autosave");
const hasNaN = toRef(state, "hasNaN");
2022-01-24 22:25:34 -06:00
const savesManager = ref<ComponentPublicInstance<typeof SavesManager> | null>(null);
2022-01-13 22:25:47 -06:00
const path = computed(() => state.NaNPath?.join("."));
const property = computed(() => state.NaNPath?.slice(-1)[0]);
const previous = computed<DecimalSource | null>(() => {
if (state.NaNReceiver && property.value) {
return state.NaNReceiver[property.value] as DecimalSource;
}
return null;
});
const isPaused = computed({
get() {
return player.devSpeed === 0;
},
2022-01-13 22:25:47 -06:00
set(value: boolean) {
player.devSpeed = value ? null : 0;
}
});
2022-01-13 22:25:47 -06:00
function setZero() {
if (state.NaNReceiver && property.value) {
state.NaNReceiver[property.value] = new Decimal(0);
state.hasNaN = false;
}
}
function setOne() {
if (state.NaNReceiver && property.value) {
state.NaNReceiver[property.value] = new Decimal(1);
state.hasNaN = false;
}
}
function ignore() {
if (state.NaNReceiver && property.value) {
state.NaNReceiver[property.value] = new Decimal(NaN);
state.hasNaN = false;
}
}
2021-06-16 00:36:13 -05:00
</script>
<style scoped>
.nan-modal-header {
padding: 10px 0;
2021-06-16 00:36:13 -05:00
margin-left: 10px;
}
.nan-footer {
display: flex;
2021-06-16 00:36:13 -05:00
justify-content: flex-end;
}
.nan-footer button {
margin: 0 10px;
2021-06-16 00:36:13 -05:00
}
.nan-modal-discord-link {
display: flex;
align-items: center;
2021-06-16 00:36:13 -05:00
}
.nan-modal-discord {
margin: 0;
margin-right: 4px;
2021-06-16 00:36:13 -05:00
}
</style>