forked from erudnick-cohen/Pokemon-Crystal-Item-Randomizer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGeneratePatches.py
35 lines (30 loc) · 924 Bytes
/
GeneratePatches.py
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
import json
import shutil
import os
def makePatches():
try:
shutil.rmtree("Patches")
except:
print("No existing folder created, nothing to remove")
os.mkdir("Patches")
#load the json data so that we know what the addresses actually SHOULD be
with open('crystal-speedchoice-label-details.json',encoding='utf-8') as f:
addrText = f.read()
addrData = json.loads(addrText)
for root, dir, files in os.walk("Patches Base//"):
for i in files:
print("File: "+i)
with open("Patches Base//"+i,encoding='utf-8') as f:
patchText = f.read()
patchData = json.loads(patchText)
for j in patchData:
#find the relevant address data
addRange = []
for k in addrData:
if j['label'] == k["label"]:
j["address_range"] = k["address_range"]
with open(r"Patches/"+i, 'w') as f:
json.dump(patchData, f)
if __name__ == "__main__":
# execute only if run as a script
makePatches()