inventoryhandler.py
956 Bytes
import utils
class InventoryHandler(object):
def __init__(self, directory):
self.directory = directory
def _get_inventory_file(self, item_name):
filename = self.directory + '/' + item_name + ".txt"
item_data = utils.load_object_from_file(filename)
if item_data is None:
print("Error opening inventory file: {}".format(item_name))
return {}
return item_name
def get_title(self, item_name):
return self._get_inventory_file(item_name)['title']
def get_description(self, item_name):
return self._get_inventory_file(item_name)['description']
def get_type(self, item_name):
return self._get_inventory_file(item_name)['type']
def get_power(self, item_name):
return self._get_inventory_file(item_name)['power']
def get_damage(self, item_name):
return self._get_inventory_file(item_name)['damage']
def get_weight(self, item_name):
return self._get_inventory_file(item_name)['weight']