# Path: DnD/modules/lib/exceptionsLib.py
# class OutOfItems(DnDError):
#     def __init__(self, name):
#         self.name = name
# 
#     def __str__(self):
#         formatstr = 'You have no {item}s remaining.'
#         return formatstr.format(item=self.name)
# 
# Path: DnD/modules/lib/interface.py
# class DataInterface:
#     class JsonPointerCache:
#         def __init__(self):
#             self.cache = {}
# 
#         def __getitem__(self, key: str) -> jsonpointer.JsonPointer:
#             if key not in self.cache:
#                 self.cache[key] = jsonpointer.JsonPointer(key)
#             return self.cache[key]
# 
#     def __init__(self, data: Union[list, Dict[str, Any]], readonly=False, basepath=""):
#         self.data = data
#         self.basepath = basepath.rstrip('/')
#         self.readonly = readonly
#         self._cache = type(self).JsonPointerCache()
# 
#     def __iter__(self):
#         obj = self.get('/')
#         if isinstance(obj, dict):
#             yield from obj.items()
#         elif isinstance(obj, list):
#             yield from obj
# 
#     def get(self, path: str):
#         if self.basepath + path == '/':
#             return self.data
#         if path == '/':
#             path = ''
#         pointer = self._cache[self.basepath + path]
#         return pointer.resolve(self.data, None)
# 
#     def delete(self, path):
#         if self.readonly:
#             raise ex.ReadonlyError('{} is readonly'.format(self.data))
#         if self.basepath + path == '/':
#             self.data = {}
#             return
#         if path == '/':
#             path = ''
#         pointer = self._cache[self.basepath + path]
#         subdoc, key = pointer.to_last(self.data)
#         del subdoc[key]
# 
#     def set(self, path, value):
#         if self.readonly:
#             raise ex.ReadonlyError('{} is readonly'.format(self.data))
#         if self.basepath + path == '/':
#             self.data = value
#             return
#         if path == '/':
#             path = ''
#         pointer = self._cache[self.basepath + path]
#         pointer.set(self.data, value)
# 
#     def cd(self, path, readonly=False):
#         return DataInterface(self.data, readonly=self.readonly or readonly,
#                              basepath=self.basepath + path)
# 
# Path: DnD/modules/lib/itemLib.py
# class Item:
#     def __init__(self, name: str, spec: dict):
#         types = spec['type'].split()
#         fmt = '{}/{}.{}'
#         filename = fmt.format(types[-1], sanitize_filename(name), '.'.join(types))
#         self.record = JsonInterface(filename, readonly=True)
#         self.name = self.record.get('/name')
#         self.value = self.record.get('/value')
#         self.weight = self.record.get('/weight')
#         self.consumes = self.record.get('/consumes')
#         self.effect: str = self.record.get('/effect')
#         self.description: str = self.record.get('/description')
# 
#     def use(self) -> str:
#         # TODO: consume item
#         return self.effect
# 
#     def describe(self) -> str:
#         return self.description


import enum
from typing import Optional
from . import abilitiesLib as abil
from . import characterLib as char
from . import exceptionsLib as ex
from .exceptionsLib import OutOfItems
from .interface import DataInterface
from .itemLib import Item
    SHIELD = 'shield'
    WEAPON_1H = 'one_hand_weapon'
    WEAPON_2H = 'two_hand_weapon'

    __slotMap = {
        GLOVES: [EquipmentSlot.OFF_HAND, EquipmentSlot.MAIN_HAND],
        BELT: [EquipmentSlot.BELT],
        LIGHT_ARMOR: [EquipmentSlot.CLOTHES, EquipmentSlot.PANTS],
        MEDIUM_ARMOR: [EquipmentSlot.CLOTHES, EquipmentSlot.PANTS],
        HEAVY_ARMOR: [EquipmentSlot.CLOTHES, EquipmentSlot.PANTS],
        CLOTHES: [EquipmentSlot.CLOTHES, EquipmentSlot.PANTS],
        HEADWEAR: [EquipmentSlot.HEAD],
        BOOTS: [EquipmentSlot.LEFT_FOOT, EquipmentSlot.RIGHT_FOOT],
        NECKLACE: [EquipmentSlot.NECK],
        CLOAK: [EquipmentSlot.CLOAK],
        SHIELD: [EquipmentSlot.OFF_HAND],
        WEAPON_1H: [EquipmentSlot.MAIN_HAND],
        WEAPON_2H: [EquipmentSlot.OFF_HAND],
    }

    def slots(self):
        return self.__slotMap[self]


class ItemEntry:
    __slots__ = ('record', 'item', 'inventory', 'name', 'value', 'weight',
                 'consumes', 'effect', 'description')

    def __init__(self, name: str, jf: DataInterface, parent: Inventory):
        self.record = jf

# Path: DnD/modules/lib/exceptionsLib.py
# class OutOfItems(DnDError):
#     def __init__(self, name):
#         self.name = name
# 
#     def __str__(self):
#         formatstr = 'You have no {item}s remaining.'
#         return formatstr.format(item=self.name)
# 
# Path: DnD/modules/lib/interface.py
# class DataInterface:
#     class JsonPointerCache:
#         def __init__(self):
#             self.cache = {}
# 
#         def __getitem__(self, key: str) -> jsonpointer.JsonPointer:
#             if key not in self.cache:
#                 self.cache[key] = jsonpointer.JsonPointer(key)
#             return self.cache[key]
# 
#     def __init__(self, data: Union[list, Dict[str, Any]], readonly=False, basepath=""):
#         self.data = data
#         self.basepath = basepath.rstrip('/')
#         self.readonly = readonly
#         self._cache = type(self).JsonPointerCache()
# 
#     def __iter__(self):
#         obj = self.get('/')
#         if isinstance(obj, dict):
#             yield from obj.items()
#         elif isinstance(obj, list):
#             yield from obj
# 
#     def get(self, path: str):
#         if self.basepath + path == '/':
#             return self.data
#         if path == '/':
#             path = ''
#         pointer = self._cache[self.basepath + path]
#         return pointer.resolve(self.data, None)
# 
#     def delete(self, path):
#         if self.readonly:
#             raise ex.ReadonlyError('{} is readonly'.format(self.data))
#         if self.basepath + path == '/':
#             self.data = {}
#             return
#         if path == '/':
#             path = ''
#         pointer = self._cache[self.basepath + path]
#         subdoc, key = pointer.to_last(self.data)
#         del subdoc[key]
# 
#     def set(self, path, value):
#         if self.readonly:
#             raise ex.ReadonlyError('{} is readonly'.format(self.data))
#         if self.basepath + path == '/':
#             self.data = value
#             return
#         if path == '/':
#             path = ''
#         pointer = self._cache[self.basepath + path]
#         pointer.set(self.data, value)
# 
#     def cd(self, path, readonly=False):
#         return DataInterface(self.data, readonly=self.readonly or readonly,
#                              basepath=self.basepath + path)
# 
# Path: DnD/modules/lib/itemLib.py
# class Item:
#     def __init__(self, name: str, spec: dict):
#         types = spec['type'].split()
#         fmt = '{}/{}.{}'
#         filename = fmt.format(types[-1], sanitize_filename(name), '.'.join(types))
#         self.record = JsonInterface(filename, readonly=True)
#         self.name = self.record.get('/name')
#         self.value = self.record.get('/value')
#         self.weight = self.record.get('/weight')
#         self.consumes = self.record.get('/consumes')
#         self.effect: str = self.record.get('/effect')
#         self.description: str = self.record.get('/description')
# 
#     def use(self) -> str:
#         # TODO: consume item
#         return self.effect
# 
#     def describe(self) -> str:
#         return self.description


# Path: DnD/modules/lib/inventoryLib.py
import enum
from typing import Optional
from . import abilitiesLib as abil
from . import characterLib as char
from . import exceptionsLib as ex
from .exceptionsLib import OutOfItems
from .interface import DataInterface
from .itemLib import Item

    SHIELD = 'shield'
    WEAPON_1H = 'one_hand_weapon'
    WEAPON_2H = 'two_hand_weapon'

    __slotMap = {
        GLOVES: [EquipmentSlot.OFF_HAND, EquipmentSlot.MAIN_HAND],
        BELT: [EquipmentSlot.BELT],
        LIGHT_ARMOR: [EquipmentSlot.CLOTHES, EquipmentSlot.PANTS],
        MEDIUM_ARMOR: [EquipmentSlot.CLOTHES, EquipmentSlot.PANTS],
        HEAVY_ARMOR: [EquipmentSlot.CLOTHES, EquipmentSlot.PANTS],
        CLOTHES: [EquipmentSlot.CLOTHES, EquipmentSlot.PANTS],
        HEADWEAR: [EquipmentSlot.HEAD],
        BOOTS: [EquipmentSlot.LEFT_FOOT, EquipmentSlot.RIGHT_FOOT],
        NECKLACE: [EquipmentSlot.NECK],
        CLOAK: [EquipmentSlot.CLOAK],
        SHIELD: [EquipmentSlot.OFF_HAND],
        WEAPON_1H: [EquipmentSlot.MAIN_HAND],
        WEAPON_2H: [EquipmentSlot.OFF_HAND],
    }

    def slots(self):
        return self.__slotMap[self]


class ItemEntry:
    __slots__ = ('record', 'item', 'inventory', 'name', 'value', 'weight',
                 'consumes', 'effect', 'description')

    def __init__(self, name: str, jf: DataInterface, parent: Inventory):
        self.record = jf

        self.item = Item(name, jf.get('/'))