29 lines
857 B
Python
29 lines
857 B
Python
|
import json
|
||
|
|
||
|
|
||
|
class Monsters:
|
||
|
monsters = None
|
||
|
|
||
|
@staticmethod
|
||
|
def load_monsters_data():
|
||
|
"""Loads the monsters data from a JSON file"""
|
||
|
with open('app/tables/monsters.json') as f:
|
||
|
Monsters.monsters = json.load(f)
|
||
|
|
||
|
def __init__(self):
|
||
|
if not Monsters.monsters:
|
||
|
self.load_monsters_data()
|
||
|
|
||
|
def get_monster(self, monster_name):
|
||
|
"""Returns the dictionary of the specified monster."""
|
||
|
return self.monsters.get(monster_name)
|
||
|
|
||
|
def add_monster(self, monster_name, attributes):
|
||
|
"""Adds a new monster to the monsters dictionary."""
|
||
|
self.monsters[monster_name] = attributes
|
||
|
|
||
|
def remove_monster(self, monster_name):
|
||
|
"""Removes a monster from the monsters dictionary."""
|
||
|
if monster_name in self.monsters:
|
||
|
del self.monsters[monster_name]
|