mirror of
https://github.com/YouHaveTrouble/GuildMaster.git
synced 2026-05-12 06:26:59 +00:00
save data export and import
This commit is contained in:
@@ -0,0 +1,112 @@
|
||||
<template>
|
||||
<div class="changelog panel pinned-paper">
|
||||
<div class="nail top-left">
|
||||
<img src="/img/quests/overlays/nail.png" alt="" draggable="false"/>
|
||||
</div>
|
||||
<div class="nail top-right">
|
||||
<img src="/img/quests/overlays/nail.png" alt="" draggable="false"/>
|
||||
</div>
|
||||
<h1>Changelog</h1>
|
||||
<div class="changelog-entry" v-for="release in releases">
|
||||
<hr>
|
||||
<h2><span>Version {{ release.name }}</span><small class="date">{{ timeFormat.format(release.createdAt) }}</small></h2>
|
||||
<pre>{{ release.body }}</pre>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import {defineComponent} from "vue";
|
||||
|
||||
|
||||
export default defineComponent({
|
||||
name: "ChangelogComponent",
|
||||
data: () => ({
|
||||
timeFormat: Intl.DateTimeFormat(Intl.DateTimeFormat().resolvedOptions().locale, {
|
||||
year: "numeric",
|
||||
month: "numeric",
|
||||
day: "numeric",
|
||||
}),
|
||||
releases: [] as Array<{body: string, name: string, createdAt: Date}>,
|
||||
lastPage: 1,
|
||||
}),
|
||||
methods: {
|
||||
async getReleases(page: number): Promise<void> {
|
||||
const result = await fetch("https://api.github.com/repos/YouHaveTrouble/GuildMaster/releases?per_page=10")
|
||||
.catch((e) => {
|
||||
return null;
|
||||
});
|
||||
|
||||
if (result === null) return;
|
||||
const json = await result.json();
|
||||
|
||||
|
||||
for (const release of json) {
|
||||
const version = {} as any;
|
||||
version.body = release.body.trim();
|
||||
version.name = release.name;
|
||||
version.createdAt = new Date(release.published_at);
|
||||
if (release.body.length === 0) continue;
|
||||
this.releases.push(version);
|
||||
}
|
||||
}
|
||||
},
|
||||
async mounted() {
|
||||
this.getReleases(1);
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.changelog {
|
||||
padding-block: 3rem;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
gap: 1rem;
|
||||
max-width: 45rem;
|
||||
width: 100%;
|
||||
|
||||
h1 {
|
||||
font-size: 3rem;
|
||||
line-height: 1;
|
||||
margin: 0;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.changelog-entry {
|
||||
width: 100%;
|
||||
|
||||
h2 {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
flex-wrap: wrap;
|
||||
justify-content: flex-start;
|
||||
align-items: flex-end;
|
||||
margin: 0;
|
||||
padding-inline: 1rem;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
|
||||
.date {
|
||||
color: rgba(0,0,0, 0.6);
|
||||
font-size: 1rem;
|
||||
}
|
||||
|
||||
hr {
|
||||
border: 0;
|
||||
width: calc(100% - 2rem);
|
||||
border-bottom: 1px solid black;
|
||||
}
|
||||
|
||||
pre {
|
||||
line-height: 1.2;
|
||||
margin: 0;
|
||||
white-space: pre-wrap;
|
||||
font-family: 'EB Garamond', serif;
|
||||
padding-inline: 1rem;
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,146 @@
|
||||
<template>
|
||||
<div class="save-manager panel pinned-paper">
|
||||
<dialog ref="importDialog" >
|
||||
<div class="import-dialog">
|
||||
<textarea
|
||||
v-model="importSaveText"
|
||||
placeholder="Paste your save data here"
|
||||
></textarea>
|
||||
<div style="display: flex; flex-direction: row; flex-wrap: wrap; gap: 0.5rem;">
|
||||
<button type="button" class="button metal" @click="importSave()" :disabled="importSaveText === ''">
|
||||
Import
|
||||
</button>
|
||||
<button class="close" @click="closeSaveImport">✗</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</dialog>
|
||||
<div class="nail top-left">
|
||||
<img src="/img/quests/overlays/nail.png" alt="" draggable="false"/>
|
||||
</div>
|
||||
<div class="nail top-right">
|
||||
<img src="/img/quests/overlays/nail.png" alt="" draggable="false"/>
|
||||
</div>
|
||||
<h1>Save file</h1>
|
||||
<div class="buttons">
|
||||
<button class="button metal" @click="exportSave()">
|
||||
Export
|
||||
</button>
|
||||
<button class="button metal" @click="openSaveImport()">
|
||||
Import
|
||||
</button>
|
||||
<button class="button metal" @click="wipeSave()">
|
||||
<span class="red">Wipe</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import {defineComponent} from "vue";
|
||||
|
||||
export default defineComponent({
|
||||
name: "ChangelogComponent",
|
||||
data: () => ({
|
||||
importSaveText: "",
|
||||
}),
|
||||
methods: {
|
||||
openSaveImport() {
|
||||
const dialog = this.$refs.importDialog as HTMLDialogElement;
|
||||
dialog.showModal();
|
||||
},
|
||||
closeSaveImport() {
|
||||
const dialog = this.$refs.importDialog as HTMLDialogElement;
|
||||
dialog.close();
|
||||
},
|
||||
exportSave() {
|
||||
const save = window.localStorage.getItem("savedGame");
|
||||
if (!save) {
|
||||
alert("No save file found!");
|
||||
return;
|
||||
}
|
||||
navigator.clipboard.writeText(btoa(save));
|
||||
setTimeout(() => alert("Save data copied to clipboard!"), 100);
|
||||
},
|
||||
importSave() {
|
||||
const saveBase64 = this.importSaveText;
|
||||
try {
|
||||
const save = atob(saveBase64);
|
||||
JSON.parse(save);
|
||||
window.localStorage.setItem("savedGame", save);
|
||||
window.location.reload();
|
||||
} catch (e) {
|
||||
alert("Invalid save file!");
|
||||
return;
|
||||
}
|
||||
|
||||
},
|
||||
wipeSave() {
|
||||
if (!confirm("You are about to wipe your save file. Are you sure?")) return;
|
||||
window.localStorage.removeItem("savedGame");
|
||||
window.location.reload();
|
||||
},
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<style scoped lang="scss">
|
||||
.save-manager {
|
||||
padding-block: 1rem;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
gap: 1rem;
|
||||
max-width: 45rem;
|
||||
width: 100%;
|
||||
h1 {
|
||||
margin-block: 0;
|
||||
font-size: 2rem;
|
||||
}
|
||||
dialog {
|
||||
padding: 0;
|
||||
}
|
||||
.buttons {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
flex-wrap: wrap;
|
||||
gap: 0.25rem;
|
||||
.red {
|
||||
color: #d52121;
|
||||
}
|
||||
}
|
||||
.import-dialog {
|
||||
padding: 1rem;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
background: url("/img/background/panels/plaster.png");
|
||||
background-size: 100% 100%;
|
||||
gap: 1rem;
|
||||
position: relative;
|
||||
textarea {
|
||||
width: 90%;
|
||||
height: 10rem;
|
||||
resize: none;
|
||||
border: 1px solid var(--color-metal);
|
||||
border-radius: 0.25rem;
|
||||
padding: 0.5rem;
|
||||
font-family: monospace;
|
||||
}
|
||||
.close {
|
||||
color: #ab0707;
|
||||
font-size: 2rem;
|
||||
border: none;
|
||||
background: transparent;
|
||||
&:hover {
|
||||
color: #d52121;
|
||||
cursor: pointer;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user