Skip to content

Commit 47fe8bd

Browse files
committed
move max recursion to __init__.py
1 parent 2755f90 commit 47fe8bd

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

src/Rules.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,11 @@ def checkRequireStringForArea(state: CollectionState, area: dict):
7878
if requires_list == "":
7979
return True
8080

81-
def findAndRecursivelyExecuteFunctions(requires_list: str, maxRecursion: int, recursionDepth: int = 0) -> str:
81+
def findAndRecursivelyExecuteFunctions(requires_list: str, recursionDepth: int = 0) -> str:
8282
found_functions = re.findall(r'\{(\w+)\((.*?)\)\}', requires_list)
8383
if found_functions:
84-
if recursionDepth >= maxRecursion:
85-
raise RecursionError(f'One or more functions in "{area.get("name", f"An area with these parameters: {area}")}"\'s requires looped too many time (maximum recursion is {maxRecursion}) \
84+
if recursionDepth >= world.rules_functions_maximum_recursion:
85+
raise RecursionError(f'One or more functions in "{area.get("name", f"An area with these parameters: {area}")}"\'s requires looped too many time (maximum recursion is {world.rules_functions_maximum_recursion}) \
8686
\n As of this Exception the following function(s) are waiting to run: {[f[0] for f in found_functions]} \
8787
\n And the currently processed requires look like this: "{requires_list}"')
8888
else:
@@ -107,10 +107,10 @@ def findAndRecursivelyExecuteFunctions(requires_list: str, maxRecursion: int, re
107107
else:
108108
requires_list = requires_list.replace("{" + func_name + "(" + item[1] + ")}", str(result))
109109

110-
requires_list = findAndRecursivelyExecuteFunctions(requires_list, maxRecursion, recursionDepth + 1)
110+
requires_list = findAndRecursivelyExecuteFunctions(requires_list, recursionDepth + 1)
111111
return requires_list
112112

113-
requires_list = findAndRecursivelyExecuteFunctions(requires_list, maxRecursion=5)
113+
requires_list = findAndRecursivelyExecuteFunctions(requires_list)
114114

115115
# parse user written statement into list of each item
116116
for item in re.findall(r'\|[^|]+\|', requires_list):

src/__init__.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -339,21 +339,26 @@ def write_spoiler(self, spoiler_handle):
339339

340340
def extend_hint_information(self, hint_data: dict[int, dict[int, str]]) -> None:
341341
before_extend_hint_information(hint_data, self, self.multiworld, self.player)
342-
342+
343343
for location in self.multiworld.get_locations(self.player):
344344
if not location.address:
345345
continue
346346
if "hint_entrance" in self.location_name_to_location[location.name]:
347347
if self.player not in hint_data:
348348
hint_data.update({self.player: {}})
349349
hint_data[self.player][location.address] = self.location_name_to_location[location.name]["hint_entrance"]
350-
350+
351351
after_extend_hint_information(hint_data, self, self.multiworld, self.player)
352352

353353
###
354354
# Non-standard AP world methods
355355
###
356356

357+
rules_functions_maximum_recursion: int = 5
358+
"""Default: 5\n
359+
The maximum time a location/region's requirement can loop to check for functions\n
360+
One thing to remember is the more you loop the longer generation will take. So probably leave it as is unless you really needs it."""
361+
357362
def add_filler_items(self, item_pool, traps):
358363
Utils.deprecate("Use adjust_filler_items instead.")
359364
return self.adjust_filler_items(item_pool, traps)

0 commit comments

Comments
 (0)