Skip to content

Commit d24e93e

Browse files
authored
Merge pull request #92 from ManualForArchipelago/Detangling-Helper.py
Detangling helper.py
2 parents a5e12c9 + 940408f commit d24e93e

File tree

4 files changed

+39
-30
lines changed

4 files changed

+39
-30
lines changed

Diff for: src/Data.py

+7-16
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,18 @@
1-
import json
21
import logging
3-
import os
4-
import pkgutil
52

63
from .DataValidation import DataValidation, ValidationError
4+
from .Helpers import load_data_file as helpers_load_data_file
75

86
from .hooks.Data import \
97
after_load_game_file, \
108
after_load_item_file, after_load_location_file, \
119
after_load_region_file, after_load_category_file, \
1210
after_load_meta_file
1311

14-
1512
# blatantly copied from the minecraft ap world because why not
1613
def load_data_file(*args) -> dict:
17-
fname = os.path.join("data", *args)
18-
19-
try:
20-
filedata = json.loads(pkgutil.get_data(__name__, fname).decode())
21-
except:
22-
filedata = []
23-
24-
return filedata
14+
logging.warning("Deprecated usage of importing load_data_file from Data.py uses the one from Helper.py instead")
15+
return helpers_load_data_file(*args)
2516

2617
def convert_to_list(data, property_name: str) -> list:
2718
if isinstance(data, dict):
@@ -32,17 +23,17 @@ def convert_to_list(data, property_name: str) -> list:
3223
class ManualFile:
3324
filename: str
3425
data_type: dict|list
35-
26+
3627
def __init__(self, filename, data_type):
3728
self.filename = filename
3829
self.data_type = data_type
3930

4031
def load(self):
41-
contents = load_data_file(self.filename)
42-
32+
contents = helpers_load_data_file(self.filename)
33+
4334
if not contents and type(contents) != self.data_type:
4435
return self.data_type()
45-
36+
4637
return contents
4738

4839

Diff for: src/Helpers.py

+24-7
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,29 @@
1-
from BaseClasses import MultiWorld, Item
2-
from typing import Optional, List
1+
import os
2+
import pkgutil
3+
import json
4+
5+
from BaseClasses import MultiWorld, Item, Location
6+
from typing import Optional, List, TYPE_CHECKING
37
from worlds.AutoWorld import World
4-
from .Data import category_table
5-
from .Items import ManualItem
6-
from .Locations import ManualLocation
78
from .hooks.Helpers import before_is_category_enabled, before_is_item_enabled, before_is_location_enabled
89

910
from typing import Union
1011

12+
if TYPE_CHECKING:
13+
from .Items import ManualItem
14+
from .Locations import ManualLocation
15+
16+
# blatantly copied from the minecraft ap world because why not
17+
def load_data_file(*args) -> dict:
18+
fname = os.path.join("data", *args)
19+
20+
try:
21+
filedata = json.loads(pkgutil.get_data(__name__, fname).decode())
22+
except:
23+
filedata = []
24+
25+
return filedata
26+
1127
def is_option_enabled(multiworld: MultiWorld, player: int, name: str) -> bool:
1228
return get_option_value(multiworld, player, name) > 0
1329

@@ -28,6 +44,7 @@ def clamp(value, min, max):
2844
return value
2945

3046
def is_category_enabled(multiworld: MultiWorld, player: int, category_name: str) -> bool:
47+
from .Data import category_table
3148
"""Check if a category has been disabled by a yaml option."""
3249
hook_result = before_is_category_enabled(multiworld, player, category_name)
3350
if hook_result is not None:
@@ -56,7 +73,7 @@ def is_item_name_enabled(multiworld: MultiWorld, player: int, item_name: str) ->
5673

5774
return is_item_enabled(multiworld, player, item)
5875

59-
def is_item_enabled(multiworld: MultiWorld, player: int, item: ManualItem) -> bool:
76+
def is_item_enabled(multiworld: MultiWorld, player: int, item: "ManualItem") -> bool:
6077
"""Check if an item has been disabled by a yaml option."""
6178
hook_result = before_is_item_enabled(multiworld, player, item)
6279
if hook_result is not None:
@@ -72,7 +89,7 @@ def is_location_name_enabled(multiworld: MultiWorld, player: int, location_name:
7289

7390
return is_location_enabled(multiworld, player, location)
7491

75-
def is_location_enabled(multiworld: MultiWorld, player: int, location: ManualLocation) -> bool:
92+
def is_location_enabled(multiworld: MultiWorld, player: int, location: "ManualLocation") -> bool:
7693
"""Check if a location has been disabled by a yaml option."""
7794
hook_result = before_is_location_enabled(multiworld, player, location)
7895
if hook_result is not None:

Diff for: src/Rules.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ def convert_req_function_args(func, args: list[str], areaName: str, warn: bool =
328328
value = bool(value)
329329
if warn:
330330
# warning here spam the console if called from rules.py, might be worth to make it a data validation instead
331-
logging.warn(f"A call of the {func.__name__} function in '{areaName}'s requirement, asks for a value of type {argType}\nfor its argument '{info.name}' but an unknown string was passed and thus converted to {value}")
331+
logging.warning(f"A call of the {func.__name__} function in '{areaName}'s requirement, asks for a value of type {argType}\nfor its argument '{info.name}' but an unknown string was passed and thus converted to {value}")
332332

333333
else:
334334
try:

Diff for: src/hooks/Helpers.py

+7-6
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
from typing import Optional
2-
from BaseClasses import MultiWorld
3-
from ..Locations import ManualLocation
4-
from ..Items import ManualItem
1+
from typing import Optional, TYPE_CHECKING
2+
from BaseClasses import MultiWorld, Item, Location
53

4+
if TYPE_CHECKING:
5+
from ..Items import ManualItem
6+
from ..Locations import ManualLocation
67

78
# Use this if you want to override the default behavior of is_option_enabled
89
# Return True to enable the category, False to disable it, or None to use the default behavior
@@ -11,10 +12,10 @@ def before_is_category_enabled(multiworld: MultiWorld, player: int, category_nam
1112

1213
# Use this if you want to override the default behavior of is_option_enabled
1314
# Return True to enable the item, False to disable it, or None to use the default behavior
14-
def before_is_item_enabled(multiworld: MultiWorld, player: int, item: ManualItem) -> Optional[bool]:
15+
def before_is_item_enabled(multiworld: MultiWorld, player: int, item: "ManualItem") -> Optional[bool]:
1516
return None
1617

1718
# Use this if you want to override the default behavior of is_option_enabled
1819
# Return True to enable the location, False to disable it, or None to use the default behavior
19-
def before_is_location_enabled(multiworld: MultiWorld, player: int, location: ManualLocation) -> Optional[bool]:
20+
def before_is_location_enabled(multiworld: MultiWorld, player: int, location: "ManualLocation") -> Optional[bool]:
2021
return None

0 commit comments

Comments
 (0)