-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
91 lines (85 loc) · 3.3 KB
/
index.html
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
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8>
<title>Universal Pokemon Randomizer</title>
<meta name=color-scheme content=dark>
<meta name=viewport content=width=device-width,initial-scale=1.0>
<script src=https://cjrtnc.leaningtech.com/2.3/loader.js></script>
</head>
<body>
<label for=rompicker>Select Pokémon rom:</label>
<input type=file id=rompicker accept=.gb,.sgb,.gbc,.gba,.nds>
<p>When the app starts, find your rom in the <code>/str/</code> folder.
<p><strong>Save your randomized rom in the <code>/files/</code> folder.</strong>
<p><button id=save>Download contents of <code>/files/</code> folder</button>
<p>Tip: if the app stops working, try a <a href=https://www.howtogeek.com/672607/how-to-hard-refresh-your-web-browser-to-bypass-your-cache/ target=_blank>hard refresh</a>. Also, <strong>the app will take a long time to load</strong>, so please be patient.
<script>
const rompicker=document.getElementById("rompicker")
rompicker.addEventListener('change', addFileToVFSandStart);
document.getElementById("save").addEventListener('click', exportfiles)
async function addFileToVFSandStart(e){
await cheerpjInit();
// put settings files in filesystem
for (let i of ['balanced','classic','randomizer_race','super_randomizer_race','trainers_only']) {
settingFile=await fetch('settings/'+i+'.rnqs')
settingFile=await settingFile.arrayBuffer()
settingFileUint8=new Uint8Array(settingFile);
cheerpjAddStringFile("/str/settings/"+i+".rnqs", settingFileUint8);
}
await cheerpjCreateDisplay(1500,500);
//rompicker.files[0]
const reader=new FileReader();
reader.readAsArrayBuffer(e.target.files[0]);
reader.onloadend = (evt) => {
if (evt.target.readyState === FileReader.DONE) {
let arrayBuffer = evt.target.result
var array = new Uint8Array(arrayBuffer);
cheerpjAddStringFile("/str/"+e.target.files[0].name, array);
cheerpjRunJar("/app/OnlineUniversalPokemonRandomizer/randomizer.jar");
}
}
}
function exportfiles(){
let db;
const request = indexedDB.open("cjFS_/files/");
request.onsuccess = (event) => {
db = event.target.result;
/*db.transaction("files").objectStore("files").get("test-output.gbc").onsuccess = (event) => {
var romdataObj=event.target.result.contents
romdataValues=Object.values(romdataObj) // array
//const buffer=new ArrayBuffer(romdataValues.length)
//const view = new Uint8Array(buffer);
const romdata8array = Uint8Array.from(romdataValues);
const file = new File([romdata8array], 'test-output.gbc')
download(file)
};*/
db.transaction("files").objectStore("files").getAll().onsuccess = (event) => {
files=event.target.result
filenames=files[0].contents
files.shift()
for (let i=0, l=files.length; i<l; i++) {
const file = new File([files[i].contents], filenames[i].substring(1))
download(file)
}
/*var romdataObj=event.target.result.contents
romdataValues=Object.values(romdataObj) // array
const romdata8array = Uint8Array.from(romdataValues);
const file = new File([romdata8array], 'test-output.gbc')
download(file)*/
};
};
}
function download(file) {
const link = document.createElement('a')
const url = URL.createObjectURL(file)
link.href = url
link.download = file.name
document.body.appendChild(link)
link.click()
document.body.removeChild(link)
window.URL.revokeObjectURL(url)
}
</script>
</body>
</html>