Beispiel #1
0
    def add_from_object_set(self,
                            object_set_index: int,
                            graphic_set_index: int = -1):
        if graphic_set_index == -1:
            graphic_set_index = object_set_index

        factory = LevelObjectFactory(object_set_index,
                                     graphic_set_index,
                                     0, [],
                                     vertical_level=False,
                                     size_minimal=True)

        object_ids = list(range(0x00, 0x10)) + list(
            range(0x10, MAX_ID_VALUE, 0x10))

        for domain, obj_index in product(range(MAX_DOMAIN + 1), object_ids):
            level_object = factory.from_properties(domain=domain,
                                                   object_index=obj_index,
                                                   x=0,
                                                   y=0,
                                                   length=None,
                                                   index=0)

            if not isinstance(level_object,
                              LevelObject) or level_object.name in [
                                  "MSG_NOTHING", "MSG_CRASH"
                              ]:
                continue

            self.add_object(level_object)
def test_object_rendering_8_1(object_index, qtbot):
    object_factory = LevelObjectFactory(UNDERGROUND_OBJECT_SET, UNDERGROUND_GRAPHICS_SET, 0, [], False)

    object_domain = 0x00
    level_object = object_factory.from_properties(object_domain, object_index, 0, 0, None, 0)

    _test_object_against_reference(level_object, qtbot)
def gen_object_factories():
    ROM(root_dir.joinpath("SMB3.nes"))

    for object_set in range(MAX_OBJECT_SET + 1):
        if object_set in [WORLD_MAP_OBJECT_SET, MUSHROOM_OBJECT_SET, SPADE_BONUS_OBJECT_SET]:
            continue

        yield LevelObjectFactory(object_set, object_set, 0, [], False)
def test_no_change_to_bytes():
    object_factory = LevelObjectFactory(1, 1, 0, [], False)

    cloud_bytes = bytearray([0x00, 0x00, 0xE5])

    cloud_object = object_factory.from_data(cloud_bytes, 0)

    assert cloud_object.to_bytes() == cloud_bytes
Beispiel #5
0
def test_object_rendering_2_1(object_index, domain, object_set, graphic_set,
                              qtbot):
    object_factory = LevelObjectFactory(object_set, graphic_set, 0, [], False)

    level_object = object_factory.from_properties(domain, object_index, 0, 0,
                                                  None, 0)

    _test_object_against_reference(level_object, qtbot)
Beispiel #6
0
def test_object_rendering_4_2(domain, object_index, qtbot):
    object_factory = LevelObjectFactory(HILLY_OBJECT_SET, HILLY_GRAPHICS_SET,
                                        0, [], False)

    level_object = object_factory.from_properties(domain, object_index, 0, 0,
                                                  None, 0)

    _test_object_against_reference(level_object, qtbot)
Beispiel #7
0
    def set_object_set(self, object_set_index: int,
                       graphic_set_index: int) -> None:
        factory = LevelObjectFactory(object_set_index,
                                     graphic_set_index,
                                     0, [],
                                     vertical_level=False,
                                     size_minimal=True)

        self._on_object_factory_change(factory)
def test_change_attribute_to_bytes(attribute, increase):
    object_factory = LevelObjectFactory(1, 1, 0, [], False)

    cloud_object = object_factory.from_properties(0x00, 0xE0, 0, 0, None, 0)

    initial_bytes = cloud_object.to_bytes()

    setattr(cloud_object, attribute, getattr(cloud_object, attribute) + increase)

    assert cloud_object.to_bytes() != initial_bytes
Beispiel #9
0
    def __init__(self, parent, object_set, graphic_set=1, palette_index=0):
        super(ObjectDrawArea, self).__init__(parent)

        self.object_factory = LevelObjectFactory(object_set,
                                                 graphic_set,
                                                 palette_index, [],
                                                 False,
                                                 size_minimal=True)

        self.current_object = self.object_factory.from_data(
            bytearray([0x0, 0x0, 0x0]), 0)

        self.update_object()

        self.resize(QSize())
def test_object_icon(domain, obj_index, qtbot):
    factory = LevelObjectFactory(PLAINS_OBJECT_SET, PLAINS_GRAPHICS_SET, 0, [], False, True)

    level_object = factory.from_properties(domain, obj_index, 0, 0, None, 0)

    widget = QWidget()
    widget.setLayout(QVBoxLayout())

    widget.layout().addStretch()
    widget.layout().addWidget(ObjectIcon(level_object))
    widget.layout().addStretch()

    widget.show()
    widget.adjustSize()
    qtbot.wait_for_window_shown(widget)
Beispiel #11
0
    def _parse_header(self):
        self.header = LevelHeader(self.header_bytes, self.object_set_number)

        self.object_factory = LevelObjectFactory(
            self.object_set_number,
            self.header.graphic_set_index,
            self.header.object_palette_index,
            self.objects,
            bool(self.header.is_vertical),
        )
        self.enemy_item_factory = EnemyItemFactory(
            self.object_set_number, self.header.enemy_palette_index)

        self.size = self.header.width, self.header.height

        self.data_changed.emit()
Beispiel #12
0
    def _load_level_data(self,
                         object_data: bytearray,
                         enemy_data: bytearray,
                         new_level: bool = True):
        self.object_factory = LevelObjectFactory(
            self.object_set_number,
            self.header.graphic_set_index,
            self.header.object_palette_index,
            self.objects,
            bool(self.header.is_vertical),
        )
        self.enemy_item_factory = EnemyItemFactory(
            self.object_set_number, self.header.enemy_palette_index)

        self._load_objects(object_data)
        self._load_enemies(enemy_data)

        if new_level:
            self._update_level_size()

            self.undo_stack.clear(self.to_bytes())
            self._signal_emitter.data_changed.emit()
Beispiel #13
0
def test_ending_object(object_set, graphics_set, qtbot):
    object_factory = LevelObjectFactory(object_set, graphics_set, 0, [], False)

    ending_object = object_factory.from_properties(0x2, 0x09, 0, 0, None, 0)

    _test_object_against_reference(ending_object, qtbot)