Profectus-Demo/src/components/system/Save.vue

197 lines
4.7 KiB
Vue
Raw Normal View History

2021-06-20 23:29:55 -05:00
<template>
<div class="save" :class="{ active }">
<div class="handle material-icons">drag_handle</div>
<div class="actions" v-if="!editing">
<feedback-button
@click="$emit('export')"
class="button"
left
v-if="save.error == undefined && !confirming"
>
<span class="material-icons">content_paste</span>
</feedback-button>
<button
@click="$emit('duplicate')"
class="button"
v-if="save.error == undefined && !confirming"
>
<span class="material-icons">content_copy</span>
</button>
<button
@click="toggleEditing"
class="button"
v-if="save.error == undefined && !confirming"
>
<span class="material-icons">edit</span>
</button>
<danger-button
:disabled="active"
@click="$emit('delete')"
@confirmingChanged="confirmingChanged"
>
<span class="material-icons" style="margin: -2px">delete</span>
</danger-button>
</div>
<div class="actions" v-else>
<button @click="changeName" class="button">
<span class="material-icons">check</span>
</button>
<button @click="toggleEditing" class="button">
<span class="material-icons">close</span>
</button>
</div>
<div class="details" v-if="save.error == undefined && !editing">
<button class="button open" @click="$emit('open')">
<h3>{{ save.name }}</h3>
</button>
<span class="save-version">v{{ save.modVersion }}</span
><br />
<div v-if="time">Last played {{ dateFormat.format(time) }}</div>
</div>
<div class="details" v-else-if="save.error == undefined && editing">
<TextField v-model="newName" class="editname" @submit="changeName" />
</div>
<div v-else class="details error">Error: Failed to load save with id {{ save.id }}</div>
</div>
2021-06-20 23:29:55 -05:00
</template>
<script lang="ts">
import player from "@/game/player";
import { PlayerData } from "@/typings/player";
import { defineComponent, PropType } from "vue";
export default defineComponent({
name: "save",
props: {
save: {
type: Object as PropType<Partial<PlayerData>>,
required: true
}
},
emits: ["export", "open", "duplicate", "delete", "editSave"],
data() {
return {
dateFormat: new Intl.DateTimeFormat("en-US", {
year: "numeric",
month: "numeric",
day: "numeric",
hour: "numeric",
minute: "numeric",
second: "numeric"
}),
editing: false,
confirming: false,
newName: ""
};
},
computed: {
active(): boolean {
return this.save.id === player.id;
},
time(): number | undefined {
return this.active ? player.time : this.save.time;
}
},
methods: {
confirmingChanged(confirming: boolean) {
this.confirming = confirming;
},
toggleEditing() {
this.newName = this.save.name || "";
this.editing = !this.editing;
},
changeName() {
this.$emit("editSave", this.newName);
this.editing = false;
}
}
});
2021-06-20 23:29:55 -05:00
</script>
<style scoped>
.save {
position: relative;
border: solid 4px var(--separator);
padding: 4px;
background: var(--secondary-background);
margin: var(--feature-margin);
display: flex;
2021-06-20 23:29:55 -05:00
align-items: center;
min-height: 30px;
}
.save.active {
border-color: var(--bought);
2021-06-20 23:29:55 -05:00
}
.open {
display: inline;
margin: 0;
padding-left: 0;
}
.handle {
flex-grow: 0;
margin-right: 8px;
margin-left: 0;
cursor: pointer;
2021-06-20 23:29:55 -05:00
}
.details {
margin: 0;
2021-06-20 23:29:55 -05:00
flex-grow: 1;
margin-right: 80px;
}
.error {
font-size: 0.8em;
2021-06-20 23:29:55 -05:00
color: var(--danger);
}
.save-version {
margin-left: 4px;
font-size: 0.7em;
opacity: 0.7;
2021-06-20 23:29:55 -05:00
}
.actions {
position: absolute;
top: 0;
bottom: 0;
right: 4px;
display: flex;
padding: 4px;
background: inherit;
2021-06-20 23:29:55 -05:00
z-index: 1;
}
.editname {
margin: 0;
2021-06-20 23:29:55 -05:00
}
</style>
<style>
.save button {
transition-duration: 0s;
2021-06-20 23:29:55 -05:00
}
.save .actions button {
display: flex;
font-size: 1.2em;
2021-06-20 23:29:55 -05:00
}
.save .actions button .material-icons {
font-size: unset;
2021-06-20 23:29:55 -05:00
}
.save .button.danger {
display: flex;
align-items: center;
padding: 4px;
2021-06-20 23:29:55 -05:00
}
.save .field {
margin: 0;
2021-06-20 23:29:55 -05:00
}
</style>