3
3
"""
4
4
5
5
from collections import defaultdict
6
+ from enum import StrEnum
6
7
import typing
7
8
8
9
from BaseClasses import ItemClassification
14
15
15
16
from ..types .items import ItemData , ProgressiveItemChainSingle , SingleItemData , ItemPoolEntry , ProgressiveItemChain
16
17
from ..types .locations import AccessInfo , LocationData
17
- from ..types .condition import Condition , RegionCondition , OrCondition , ShopSlotCondition
18
+ from ..types .condition import Condition , NeverCondition , RegionCondition , OrCondition , ShopSlotCondition
18
19
from ..types .shops import ShopData
19
20
21
+ class LocationCategory (StrEnum ):
22
+ """
23
+ Enum of check types, used for location categorization and markers.
24
+ """
25
+ CHEST = "Chest"
26
+ CUTSCENE = "Cutscene"
27
+ ELEMENT = "Element"
28
+ QUEST = "Quest"
29
+
20
30
21
31
class ListInfo :
22
32
"""
@@ -120,13 +130,13 @@ def build(self):
120
130
file = self .ctx .rando_data
121
131
122
132
if "chests" in file :
123
- self .__add_location_list (file ["chests" ])
133
+ self .__add_location_list (file ["chests" ], LocationCategory . CHEST )
124
134
if "cutscenes" in file :
125
- self .__add_location_list (file ["cutscenes" ])
135
+ self .__add_location_list (file ["cutscenes" ], LocationCategory . CUTSCENE )
126
136
if "elements" in file :
127
- self .__add_location_list (file ["elements" ])
137
+ self .__add_location_list (file ["elements" ], LocationCategory . ELEMENT )
128
138
if "quests" in file :
129
- self .__add_location_list (file ["quests" ], True )
139
+ self .__add_location_list (file ["quests" ], LocationCategory . QUEST , True )
130
140
131
141
self .__add_shop_list (self .ctx .rando_data ["shops" ])
132
142
@@ -182,7 +192,7 @@ def __get_or_allocate_item_id(self, name: str) -> int:
182
192
183
193
return item_id
184
194
185
- def __add_location (self , name : str , raw_loc : dict [str , typing .Any ], create_event : bool = False ):
195
+ def __add_location (self , name : str , raw_loc : dict [str , typing .Any ], category : LocationCategory , create_event : bool = False ):
186
196
"""
187
197
Add a location to the lists.
188
198
"""
@@ -191,6 +201,8 @@ def __add_location(self, name: str, raw_loc: dict[str, typing.Any], create_event
191
201
item_rewards = rewards .get ("items" , [])
192
202
num_rewards = max (1 , len (item_rewards ))
193
203
204
+ properties = raw_loc .get ("properties" , {})
205
+
194
206
found = False
195
207
196
208
if name in self .reward_amounts :
@@ -202,7 +214,11 @@ def __add_location(self, name: str, raw_loc: dict[str, typing.Any], create_event
202
214
"Cannot add or overwrite with {num_rewards}."
203
215
)
204
216
205
- area = raw_loc .get ("location" , {}).get ("area" , None )
217
+ if category == LocationCategory .QUEST :
218
+ area = dbentry ["area" ]
219
+ else :
220
+ area = raw_loc .get ("location" , {}).get ("area" , None )
221
+ area_name = self .ctx .area_names [area ]
206
222
207
223
location_names : list [str ] = []
208
224
@@ -233,10 +249,14 @@ def __add_location(self, name: str, raw_loc: dict[str, typing.Any], create_event
233
249
self .pool_locations .append (loc )
234
250
if area != None :
235
251
try :
236
- self .location_groups [self .ctx .database ["areas" ][area ]["name" ]["en_US" ]].append (loc )
252
+ self .location_groups [area_name ].append (loc )
253
+ self .location_groups [f"{ area_name } { category } s" ].append (loc )
237
254
except KeyError :
238
255
print (f"Cannot add location '{ name } ' in area '{ area } '" )
239
256
257
+ if properties .get ("alwaysQuest" , False ):
258
+ self .location_groups ["Always Quests" ].append (loc )
259
+
240
260
if locked :
241
261
self .locked_locations .append (locid )
242
262
@@ -256,12 +276,12 @@ def __add_location(self, name: str, raw_loc: dict[str, typing.Any], create_event
256
276
)
257
277
self .events_data [event_name ] = event
258
278
259
- def __add_location_list (self , loc_list : dict [str , dict [str , typing .Any ]], create_events : bool = False ):
279
+ def __add_location_list (self , loc_list : dict [str , dict [str , typing .Any ]], category : LocationCategory , create_events : bool = False ):
260
280
"""
261
281
Add a list of locations to the list.
262
282
"""
263
283
for name , raw_loc in loc_list .items ():
264
- self .__add_location (name , raw_loc , create_events )
284
+ self .__add_location (name , raw_loc , category , create_events )
265
285
266
286
def __add_item_data (self , name : str , raw_item : dict [str , typing .Any ]) -> tuple [SingleItemData , ItemData ]:
267
287
"""
@@ -303,6 +323,8 @@ def __add_shop_unlock_item(self, name: str) -> ItemData:
303
323
304
324
def __add_shop (self , shop_display_name : str , raw_shop : dict [str , typing .Any ]):
305
325
shop_name = raw_shop ["location" ]["shop" ]
326
+ area = raw_shop ["location" ]["area" ]
327
+ area_name = self .ctx .area_names [area ]
306
328
shop_base_name = shop_display_name .split (" +" )[0 ] # this is a hack until there are heirarchical shops
307
329
308
330
dbentry = self .ctx .database ["shops" ][shop_name ]
@@ -334,14 +356,17 @@ def __add_shop(self, shop_display_name: str, raw_shop: dict[str, typing.Any]):
334
356
slot_location = LocationData (
335
357
name = slot_location_name ,
336
358
code = locid ,
337
- area = None ,
359
+ area = area ,
338
360
metadata = metadata ,
339
361
access = AccessInfo (
340
362
region = { name : shop_display_name for name in access_info .region },
341
363
cond = [ShopSlotCondition (shop_name , item_id )],
342
364
),
343
365
)
344
366
367
+ self .location_groups [area_name ].append (slot_location )
368
+ self .location_groups [f"{ area_name } Shops" ].append (slot_location )
369
+
345
370
shop_locs [item_id ] = slot_location
346
371
self .locations_data [slot_location .name ] = slot_location
347
372
@@ -476,10 +501,19 @@ def __add_progressive_chains(self, raw: dict[str, dict[str, typing.Any]]):
476
501
for name , chain in raw .items ():
477
502
self .__add_progressive_chain (name , chain )
478
503
479
- def __add_vars (self , variables : dict [str , dict [str , list [typing .Any ]]]):
504
+ def __add_vars (self , variables : dict [str , str | dict [str , list [typing .Any ]]]):
480
505
"""
481
506
Add a list of variable conditions to the list..
482
507
"""
483
508
for name , values in variables .items ():
509
+ if isinstance (values , str ):
510
+ if values == "boolean" :
511
+ self .variable_definitions [name ] = {
512
+ "off" : [NeverCondition ()],
513
+ "on" : []
514
+ }
515
+ continue
516
+ else :
517
+ raise RuntimeError (f"{ values } is not a valid variable type shorthand." )
484
518
for value , conds in values .items ():
485
519
self .variable_definitions [name ][value ] = self .json_parser .parse_condition (conds )
0 commit comments