Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _load_monster(self, monster_json: Dict) -> None:
"""Convert the `monster_json` into a :class:`MonsterProperties` and store it.
:param monster_json: A dict from an open and loaded JSON file.
:raises ValueError: Cannot populate monster.
"""
# Load the monster using the MonsterProperties class
try:
monster_def = MonsterProperties.from_json(monster_json)
except TypeError as e:
raise ValueError("Error: Invalid JSON structure found, check supplied input. Exiting") from e
# Add monsters to list
self.all_monsters.append(monster_def)
self.all_monsters_dict[monster_def.id] = monster_def
def __init__(self, input_data_file_or_directory: Path = PATH_TO_MONSTERS_COMPLETE):
self.all_monsters: List[MonsterProperties] = list()
self.all_monsters_dict: Dict[int, MonsterProperties] = dict()
self.load_all_monsters(input_data_file_or_directory)
def generate_monster_object(self):
"""Generate the `MonsterProperties` object from the monster_dict dictionary."""
self.monster_properties = MonsterProperties(**self.monster_dict)
def check_duplicate_monster(self) -> MonsterProperties:
"""Determine if this is a duplicate monster.
:return: A MonsterProperties object.
"""
# Start by setting the duplicate property to False
self.monster_dict["duplicate"] = False
# Create an MonsterProperties object
monster_properties = MonsterProperties(**self.monster_dict)
# Set the monster properties that we want to compare
correlation_properties = {
"wiki_name": False,
"combat_level": False,
"members": False
}
# Loop the list of currently (already processed) monsters
for known_monster in self.known_monsters:
# Do a quick name check before deeper inspection
if monster_properties.name != known_monster.name:
continue
# If the cache names are equal, do further inspection
for cprop in correlation_properties: