-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathapp.vue
More file actions
159 lines (149 loc) · 3.45 KB
/
app.vue
File metadata and controls
159 lines (149 loc) · 3.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
<script setup lang="ts">
const lightBackground = useLightBackground();
const theme = useTheme();
function setBackground() {
if (Math.random() > (1 - squarePolynomial(new Date().getHours(), -0.00694444, 0.1666666))) {
lightBackground.value += " hovLight";
theme.value.isLight = true;
return "light";
} else {
theme.value.isLight = false;
return "dark";
}
}
function routeToTitle(route: string) {
switch(route) {
case "/":
return "Journey Parser";
case "/stats/":
return "Journey Statistics";
case "/editor/":
return "Journey Editor";
case "/about/":
return "About";
case "/help/":
return "Finding your Save.bin";
}
}
useHead({
bodyAttrs: {
class: setBackground()
}
});
</script>
<template>
<Title>{{ routeToTitle($route.path) }}</Title>
<NavBar />
<div v-if="displayDropZone && !['/about/', '/help/'].includes($route.path)" class="dropZoneContainer">
<div
class="dropZone"
@click="clickInput"
@dragenter.prevent
@dragover.prevent
@drop.prevent="dropHandler($event)"
>
Click or Drop your Journey Save.bin here
<input
ref="input"
type="file"
style="display: none;"
accept=".bin"
@change="inputHandler()"
>
</div>
<NuxtLink to="/help/" :class="'help-link ' + lightBackground">I need help finding my Save.bin!</NuxtLink>
</div>
<div
v-else
class="hidden-dropZone"
@drop.prevent="dropHandler($event)"
@dragenter.prevent
@dragover.prevent
>
<NuxtPage />
</div>
</template>
<script lang="ts">
export default defineComponent({
data() {
return {
saves: useSaves(),
displayDropZone: useDisplayDropZone(),
fileReader: new FileReader(),
tooltipEnabled: false
};
},
mounted() {
this.fileReader.onload = (callbackEvent) => this.callback(callbackEvent);
},
methods: {
clickInput() {
(this.$refs.input as HTMLInputElement).click();
},
inputHandler() {
this.fileReader.readAsArrayBuffer(((this.$refs.input as HTMLInputElement).files as FileList)[0]);
},
dropHandler(ev: DragEvent) {
// Moz wiki https://developer.mozilla.org/en-US/docs/Web/API/HTML_Drag_and_Drop_API/File_drag_and_drop
this.fileReader.onload = (callbackEvent) => this.callback(callbackEvent);
ev.preventDefault();
if (ev.dataTransfer?.items) {
if (ev.dataTransfer.items[0].kind === "file") {
const file = ev.dataTransfer.items[0].getAsFile() as File;
this.fileReader.readAsArrayBuffer(file);
}
} else {
this.fileReader.readAsArrayBuffer(ev.dataTransfer?.files[0] as File);
}
},
callback(callbackEvent: ProgressEvent) {
const buffer = (callbackEvent.target as FileReader).result as ArrayBuffer;
this.saves.u8 = new Uint8Array(buffer);
this.saves.u32 = new Uint32Array(buffer);
this.saves.u64 = new BigUint64Array(buffer);
this.displayDropZone = false;
}
}
});
</script>
<style scoped>
.dropZoneContainer {
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
width: 100%;
height: 100vh;
}
.dropZone {
display: flex;
justify-content: center;
align-items: center;
text-align: center;
border-radius: 5px;
border: 4px dashed #ffffff;
font-size: var(--font-size--section);
margin-bottom: 10px;
width: 95%;
height: 33%;
}
.help-link {
font-size: var(--font-size--subscript);
text-align: center;
margin-top: 20px;
padding: 5px 10px;
}
a,
a:visited {
color: var(--color-text);
text-decoration: none;
}
.hidden-dropZone {
z-index: 999;
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
</style>