Exemplo n.º 1
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.º 2
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.º 3
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
Exemplo n.º 4
0
def _create_biomes():
    for biome in biomes_list:
        nt = _make_biome(biome)
        biomes[nt.id] = nt
        biomes_name[snake_case(nt.name)] = nt
Exemplo n.º 5
0
def _create_biomes():
    for biome in biomes_list:
        nt = _make_biome(biome)
        biomes[nt.id] = nt
        biomes_name[snake_case(nt.name)] = nt