-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
115 lines (107 loc) · 3.72 KB
/
main.js
File metadata and controls
115 lines (107 loc) · 3.72 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
"use strict";
const actnBlazeSimVer = 3
const compUIList = [];
const closeHandler = c => compUIList.splice(compUIList.indexOf(c), 1)
document.addEventListener("DOMContentLoaded", function(event){
const mainCont = document.getElementById("mainCont")
document.getElementById("archSelect").addEventListener("change", e => {
document.querySelector(".archoptions.active").classList.remove("active")
document.getElementById(`${e.target.value}options`).classList.add("active")
})
document.getElementById("newCompBtn").addEventListener("click", e => {
const arch = document.getElementById("archSelect").value
const options = {}
document.querySelectorAll(`#${arch}options [name]`).forEach(v => {
const k = v.id.slice(v.id.indexOf("_") + 1)
switch (v.dataset.parse) {
case "int":
options[k] = parseInt(v.value)
break;
default:
options[k] = v.value
break;
}
})
switch (arch) {
case "nblaze":
compUIList.push(new CompUI(mainCont, Comp, locSimUI, options, false, closeHandler, actnBlazeSimVer))
break;
case "kp6":
compUIList.push(new CompUI(mainCont, CompKP6, locSimUIKP6, options, false, closeHandler, actnBlazeSimVer))
default:
break;
}
})
document.getElementById("connToHard").addEventListener("click", e => {
new CompUI(mainCont, Comp, serSimUI, null, true)
})
document.getElementById("loadBtn").addEventListener("click",async e => {
loadMng(await vhdGen.getFile())
})
document.getElementById("exampleSelect").addEventListener("change", async e => {
const response = await fetch("examples/" + e.target.value)
const data = await response.text()
loadMng(data)
e.target.value = "default"
})
// compUI = new CompUI(mainCont, locSimUI)
window.addEventListener("drop", dropHandler)
window.addEventListener("dragover", e => {
e.preventDefault();
});
window.addEventListener("beforeunload", e => {
const states = JSON.parse(localStorage.getItem("procs")) ?? []
for (const cui of compUIList) {
states.push(cui.saveState())
}
localStorage.setItem("procs", JSON.stringify(states))
})
const prevState = localStorage.getItem("procs")
if (prevState !== null) {
loadMng(prevState)
localStorage.removeItem("procs")
}
});
function loadMng(toLoad) {
if (typeof toLoad === "string") {
toLoad = JSON.parse(toLoad)
}
if (Array.isArray(toLoad)) {
for (const el of toLoad) {
loadMng(el)
}
return
}
if (toLoad?.nBlazeSimVer === undefined) {
return
}
if(toLoad?.nBlazeSimVer === actnBlazeSimVer) {
const arch = {
nblaze: [Comp, locSimUI],
kp6: [CompKP6, locSimUIKP6]
}[toLoad.arch]
const c = new CompUI(mainCont, arch[0], arch[1], toLoad.archopts, false, closeHandler, actnBlazeSimVer)
compUIList.push(c)
c.loadState(toLoad)
} else {
loadMng(saveConverter.update(toLoad, actnBlazeSimVer))
}
}
async function dropHandler(e) {
e.preventDefault();
const files = []
if (e.dataTransfer.items) {
for (const item of [...e.dataTransfer.items]) {
if (item.kind === "file") {
files.push(item.getAsFile())
}
}
} else {
for (const file of [...e.dataTransfer.files]) {
files.push(file)
}
}
for (const f of files) {
loadMng(await f.text())
}
}