forked from erudnick-cohen/Pokemon-Crystal-Item-Randomizer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLoadLocationData.py
75 lines (69 loc) · 2 KB
/
LoadLocationData.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
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
import os
import Location
import Gym
import yaml
from collections import defaultdict
def LoadDataFromFolder(path, banList = None, allowList = None, modifierDict = {}, flags = []):
LocationList = []
LocCountDict = defaultdict(lambda: 0)
print("Creating Locations")
for root, dir, files in os.walk(path+"//Map Data"):
for file in files:
print("File: "+file)
entry = open(path+"//Map Data//"+file,'r',encoding='utf-8')
try:
yamlData = yaml.load(entry, Loader=yaml.FullLoader)
except Exception as inst:
raise(inst)
print("Locations in file are:")
for location in yamlData["Location"]:
print(location["Name"])
try:
nLoc =Location.Location(location)
nLoc.applyBanList(banList,allowList)
nLoc.applyModifiers(modifierDict)
LocationList.append(nLoc)
LocCountDict[nLoc.Name] = LocCountDict[nLoc.Name]+1
except Exception as inst:
print("-----------")
print("Failure in "+location["Name"])
raise(inst)
print("Creating Gyms")
for groot, gdir, gfiles in os.walk("Gym Data"):
for gfile in gfiles:
print("File: "+gfile)
entry = open(path+"//Gym Data//"+gfile,'r',Loader=yaml.FullLoader,encoding='utf-8')
yamlData = yaml.load(entry)
print("Locations in file are:")
for location in yamlData["Location"]:
print(location["Name"])
try:
nLoc = Gym.Gym(location)
nLoc.applyBanList(banList,allowList)
nLoc.applyModifiers(modifierDict)
LocationList.append(nLoc)
except Exception as inst:
print("-----------")
print("Failure in "+location["Name"])
raise(inst)
trashList = []
for i in LocationList:
trashList.extend(i.getTrashItemList(flags))
print('NameCounts')
print(LocCountDict)
return (LocationList,trashList)
def FlattenLocationTree(locations):
nList = []
aList = []
done = False
while not done:
done = True
aList = []
for i in locations:
nList.append(i)
print('Flattened :'+i.Name)
for j in i.Sublocations:
aList.append(j)
done = False
locations = aList
return nList