Exemplo n.º 1
0
def _make_block(block_dict):
    cls_name = '%sBlock' % camel_case(str(block_dict['name']))
    bases = (Block,)
    harvest_tools = []
    if "harvestTools" in block_dict:
        for tool in block_dict['harvestTools'].keys():
            harvest_tools.append(int(tool))
    variations = {}
    if "variations" in block_dict:
        for var in block_dict['variations']:
            variations[var['metadata']] = {"display_name": var['displayName']}
    mat = None
    if "material" in block_dict:
        mat = materials.get_material(block_dict['material'])
    bounding_box = _convert_boundingbox(block_dict['boundingBox'])
    attrs = {
        '__module__': sys.modules[__name__],
        'id': block_dict['id'],
        'display_name': block_dict['displayName'],
        'name': block_dict['name'],
        'hardness': block_dict['hardness'],
        'stack_size': block_dict['stackSize'],
        'diggable': block_dict['diggable'],
        'bounding_box': bounding_box,
        'material': mat,
        'harvest_tools': harvest_tools,
        'variations': variations,
        'drops': block_dict['drops'],
    }

    cls = type(cls_name, bases, attrs)
    assert not hasattr(sys.modules[__name__], cls_name), \
        'Block "%s" already registered at %s' % (cls_name, __name__)
    setattr(sys.modules[__name__], cls_name, cls)
    return cls
Exemplo n.º 2
0
def _make_block(block_dict):
    cls_name = '%sBlock' % camel_case(str(block_dict['name']))
    bases = (Block,)
    harvest_tools = []
    if "harvestTools" in block_dict:
        for tool in block_dict['harvestTools'].keys():
            harvest_tools.append(int(tool))
    variations = {}
    if "variations" in block_dict:
        for var in block_dict['variations']:
            variations[var['metadata']] = {"display_name": var['displayName']}
    mat = None
    if "material" in block_dict:
        mat = materials.get_material(block_dict['material'])
    bounding_box = _convert_boundingbox(block_dict['boundingBox'])
    attrs = {
        '__module__': sys.modules[__name__],
        'id': block_dict['id'],
        'display_name': block_dict['displayName'],
        'name': block_dict['name'],
        'hardness': block_dict['hardness'],
        'stack_size': block_dict['stackSize'],
        'diggable': block_dict['diggable'],
        'bounding_box': bounding_box,
        'material': mat,
        'harvest_tools': harvest_tools,
        'variations': variations,
        'drops': block_dict['drops'],
    }

    cls = type(cls_name, bases, attrs)
    assert not hasattr(sys.modules[__name__], cls_name), \
        'Block "%s" already registered at %s' % (cls_name, __name__)
    setattr(sys.modules[__name__], cls_name, cls)
    return cls
Exemplo n.º 3
0
def _make_biome(biome_dict):
    name = biome_dict['name'].replace("+", " Plus")  # Extreme Hills+
    nt_name = '%sBiome' % camel_case(str(name))
    # Convert dict to a namedtuple
    nt = namedtuple(nt_name, biome_dict.keys())(**biome_dict)
    assert not hasattr(sys.modules[__name__], nt_name), \
        'Biome "%s" already registered at %s' % (nt_name, __name__)
    setattr(sys.modules[__name__], nt_name, nt)
    return nt
Exemplo n.º 4
0
def _make_biome(biome_dict):
    name = biome_dict['name'].replace("+", " Plus")  # Extreme Hills+
    nt_name = '%sBiome' % camel_case(str(name))
    # Convert dict to a namedtuple
    nt = namedtuple(nt_name, biome_dict.keys())(**biome_dict)
    assert not hasattr(sys.modules[__name__], nt_name), \
        'Biome "%s" already registered at %s' % (nt_name, __name__)
    setattr(sys.modules[__name__], nt_name, nt)
    return nt
Exemplo n.º 5
0
def _make_material(name, material_dict):
    eff = {int(k): float(v) for k, v in material_dict.items()}
    eff = defaultdict(lambda: 1.0, eff)
    nt_name = '%sMaterial' % camel_case(str(name))
    # Convert dict to a namedtuple
    nt_class = namedtuple(nt_name, ['name', 'tool_effectiveness'])
    nt = nt_class(name=name, tool_effectiveness=eff)
    assert not hasattr(sys.modules[__name__], nt_name), \
        'Material "%s" already registered at %s' % (nt_name, __name__)
    setattr(sys.modules[__name__], nt_name, nt)
    return nt
Exemplo n.º 6
0
def _make_material(name, material_dict):
    eff = {int(k): float(v) for k, v in material_dict.items()}
    eff = defaultdict(lambda: 1.0, eff)
    nt_name = '%sMaterial' % camel_case(str(name))
    # Convert dict to a namedtuple
    nt_class = namedtuple(nt_name, ['name', 'tool_effectiveness'])
    nt = nt_class(name=name, tool_effectiveness=eff)
    assert not hasattr(sys.modules[__name__], nt_name), \
        'Material "%s" already registered at %s' % (nt_name, __name__)
    setattr(sys.modules[__name__], nt_name, nt)
    return nt
Exemplo n.º 7
0
def _make_window(window_dict):
    """
    Creates a new class for that window and registers it at this module.
    """
    cls_name = '%sWindow' % camel_case(str(window_dict['name']))
    bases = (Window, )
    attrs = {
        '__module__': sys.modules[__name__],
        'name': str(window_dict['name']),
        'inv_type': str(window_dict['id']),
        'inv_data': window_dict,
    }

    # creates function-local index and size variables
    def make_slot_method(index, size=1):
        if size == 1:
            return lambda self: self.slots[index]
        else:
            return lambda self: self.slots[index:(index + size)]

    for slots in window_dict.get('slots', []):
        index = slots['index']
        size = slots.get('size', 1)
        attr_name = snake_case(str(slots['name']))
        attr_name += '_slot' if size == 1 else '_slots'
        slots_method = make_slot_method(index, size)
        slots_method.__name__ = attr_name
        attrs[attr_name] = property(slots_method)

    for i, prop_name in enumerate(window_dict.get('properties', [])):

        def make_prop_method(i):
            return lambda self: self.properties[i]

        prop_method = make_prop_method(i)
        prop_name = snake_case(str(prop_name))
        prop_method.__name__ = prop_name
        attrs[prop_name] = property(prop_method)

    cls = type(cls_name, bases, attrs)
    assert not hasattr(sys.modules[__name__], cls_name), \
        'Window "%s" already registered at %s' % (cls_name, __name__)
    setattr(sys.modules[__name__], cls_name, cls)
    return cls
Exemplo n.º 8
0
def _make_window(window_dict):
    """
    Creates a new class for that window and registers it at this module.
    """
    cls_name = '%sWindow' % camel_case(str(window_dict['name']))
    bases = (Window,)
    attrs = {
        '__module__': sys.modules[__name__],
        'name': str(window_dict['name']),
        'inv_type': str(window_dict['id']),
        'inv_data': window_dict,
    }

    # creates function-local index and size variables
    def make_slot_method(index, size=1):
        if size == 1:
            return lambda self: self.slots[index]
        else:
            return lambda self: self.slots[index:(index + size)]

    for slots in window_dict.get('slots', []):
        index = slots['index']
        size = slots.get('size', 1)
        attr_name = snake_case(str(slots['name']))
        attr_name += '_slot' if size == 1 else '_slots'
        slots_method = make_slot_method(index, size)
        slots_method.__name__ = attr_name
        attrs[attr_name] = property(slots_method)

    for i, prop_name in enumerate(window_dict.get('properties', [])):
        def make_prop_method(i):
            return lambda self: self.properties[i]
        prop_method = make_prop_method(i)
        prop_name = snake_case(str(prop_name))
        prop_method.__name__ = prop_name
        attrs[prop_name] = property(prop_method)

    cls = type(cls_name, bases, attrs)
    assert not hasattr(sys.modules[__name__], cls_name), \
        'Window "%s" already registered at %s' % (cls_name, __name__)
    setattr(sys.modules[__name__], cls_name, cls)
    return cls
Exemplo n.º 9
0
def _make_item(item_dict):
    cls_name = '%sItem' % camel_case(str(item_dict['name']))
    bases = (Item,)
    variations = {}
    if "variations" in item_dict:
        for var in item_dict['variations']:
            variations[var['metadata']] = {"display_name": var['displayName']}
    attrs = {
        '__module__': sys.modules[__name__],
        'id': item_dict['id'],
        'name': item_dict['name'],
        'display_name': item_dict['displayName'],
        'stack_size': item_dict['stackSize'],
        'variations': variations,
    }

    cls = type(cls_name, bases, attrs)
    assert not hasattr(sys.modules[__name__], cls_name), \
        'Item "%s" already registered at %s' % (cls_name, __name__)
    setattr(sys.modules[__name__], cls_name, cls)
    return cls
Exemplo n.º 10
0
def _make_item(item_dict):
    cls_name = '%sItem' % camel_case(str(item_dict['name']))
    bases = (Item, )
    variations = {}
    if "variations" in item_dict:
        for var in item_dict['variations']:
            variations[var['metadata']] = {"display_name": var['displayName']}
    attrs = {
        '__module__': sys.modules[__name__],
        'id': item_dict['id'],
        'name': item_dict['name'],
        'display_name': item_dict['displayName'],
        'stack_size': item_dict['stackSize'],
        'variations': variations,
    }

    cls = type(cls_name, bases, attrs)
    assert not hasattr(sys.modules[__name__], cls_name), \
        'Item "%s" already registered at %s' % (cls_name, __name__)
    setattr(sys.modules[__name__], cls_name, cls)
    return cls
Exemplo n.º 11
0
def _make_window(window_dict):
    """
    Creates a new class for that window and registers it at this module.
    """
    cls_name = "%sWindow" % camel_case(str(window_dict["name"]))
    bases = (Window,)
    attrs = {"__module__": sys.modules[__name__], "name": str(window_dict["name"]), "inv_type": str(window_dict["id"])}

    # creates function-local index and size variables
    def make_slot_method(index, size=1):
        if size == 1:
            return lambda self: self.slots[index]
        else:
            return lambda self: self.slots[index : (index + size)]

    for slots in window_dict.get("slots", []):
        index = slots["index"]
        size = slots.get("size", 1)
        attr_name = snake_case(str(slots["name"]))
        attr_name += "_slot" if size == 1 else "_slots"
        slots_method = make_slot_method(index, size)
        slots_method.__name__ = attr_name
        attrs[attr_name] = property(slots_method)

    for i, prop_name in enumerate(window_dict.get("properties", [])):

        def make_prop_method(i):
            return lambda self: self.properties[i]

        prop_method = make_prop_method(i)
        prop_name = snake_case(str(prop_name))
        prop_method.__name__ = prop_name
        attrs[prop_name] = property(prop_method)

    cls = type(cls_name, bases, attrs)
    assert not hasattr(sys.modules[__name__], cls_name), 'Window "%s" already registered at %s' % (cls_name, __name__)
    setattr(sys.modules[__name__], cls_name, cls)
    return cls