-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathFFL2R_web.py
More file actions
55 lines (52 loc) · 2.11 KB
/
Copy pathFFL2R_web.py
File metadata and controls
55 lines (52 loc) · 2.11 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
from js import Uint8Array, File, URL, document
from pyscript import web, when, display
import mmap
import hashlib
from FFL2R_io import FFL2_HASH
import FFL2R
thefile = None
rom = mmap.mmap(-1, length=262144, access=mmap.ACCESS_COPY,offset=0)
@when("click", "#cook")
def process():
global thefile
global rom
if thefile == None:
error_div = web.page["error"]
error_div.innerText = "No valid Final Fantasy Legend 2 ROM found."
valid_div = web.page["valid"]
valid_div.innerText = ""
else:
rom.write(thefile.to_bytes())
valid_div = web.page["valid"]
valid_div.innerText = "Generating..."
error_div = web.page["error"]
error_div.innerText = ""
results = FFL2R.main(True, rom, None, int(web.page["seed"].value), int(web.page["encounterRate"].value),
int(web.page["goldDrops"].value), int(web.page["worldType"].value), int(web.page["shuffleType"].value),
int(web.page["dadMagi"].value))
js_array = Uint8Array.new(len(results[0]))
js_array.assign(results[0])
f = File.new([js_array], "ffl2r.gb")
url = URL.createObjectURL(f)
download = document.createElement("a")
download.setAttribute("download", f"Final Fantasy Legend 2 - {str(results[1])}.gb")
download.setAttribute("href", url)
download.click()
@when("input", "#rom")
async def loadedROM(event):
file_list = event.target.files.to_py()
first_item = file_list.item(0)
global thefile
thefile = await first_item.bytes()
hashCheck = hashlib.md5(thefile.to_bytes())
if hashCheck.hexdigest() != FFL2_HASH:
error_div = web.page["error"]
error_div.innerText = "MD5 hash mismatch. Invalid Final Fantasy Legend 2 ROM file."
valid_div = web.page["valid"]
valid_div.innerText = ""
thefile = None
else:
valid_div = web.page["valid"]
valid_div.innerText = "Final Fantasy Legend 2 ROM loaded."
error_div = web.page["error"]
error_div.innerText = ""