Ejemplo n.º 1
0
    def upgrade_project(self, old_version, new_version, rom, resource_open_r, resource_open_w, resource_delete):
        if old_version == new_version:
            return
        elif old_version <= 2:
            replace_field_in_yml(resource_name="map_sectors",
                                 resource_open_r=resource_open_r,
                                 resource_open_w=resource_open_w,
                                 key="Town Map",
                                 value_map={"scummers": "summers"})

            self.read_from_rom(rom)

            with resource_open_r("map_sectors", 'yml') as f:
                data = yml_load(f)
                for i in data:
                    data[i]["Town Map Image"] = TOWNMAP_IMAGE_ENTRY.to_yml_rep(self.sector_town_map_table[i][0] & 0xf)
                    data[i]["Town Map Arrow"] = TOWNMAP_ARROW_ENTRY.to_yml_rep(self.sector_town_map_table[i][0] >> 4)
                    data[i]["Town Map X"] = TOWNMAP_X.to_yml_rep(self.sector_town_map_table[i][1])
                    data[i]["Town Map Y"] = TOWNMAP_Y.to_yml_rep(self.sector_town_map_table[i][2])
            with resource_open_w("map_sectors", 'yml') as f:
                yaml.dump(data, f, Dumper=yaml.CSafeDumper, default_flow_style=False)

            self.upgrade_project(3, new_version, rom, resource_open_r, resource_open_w, resource_delete)
        else:
            self.upgrade_project(old_version + 1, new_version, rom, resource_open_r, resource_open_w, resource_delete)
Ejemplo n.º 2
0
 def upgrade_project(self, old_version, new_version, rom, resource_open_r, resource_open_w, resource_delete):
     if old_version == new_version:
         return
     elif old_version == 4:
         with resource_open_r("sprite_groups", "yml", True) as f:
             data = yml_load(f)
             for i in data:
                 entry = data[i]
                 collision_settings = entry["Collision Settings"]
                 entry["North/South Collision Width"] = collision_settings[0]
                 entry["North/South Collision Height"] = collision_settings[1]
                 entry["East/West Collision Width"] = collision_settings[2]
                 entry["East/West Collision Height"] = collision_settings[3]
                 del entry["Collision Settings"]
         with resource_open_w("sprite_groups", "yml", True) as f:
             yml_dump(data, f)
         self.upgrade_project(old_version + 1, new_version, rom, resource_open_r, resource_open_w, resource_delete)
     elif old_version == 2:
         replace_field_in_yml(resource_name="sprite_groups",
                              resource_open_r=resource_open_r,
                              resource_open_w=resource_open_w,
                              key="Unknown A",
                              new_key="Size",
                              value_map=dict(enumerate(SPRITE_SIZES)))
         replace_field_in_yml(resource_name="sprite_groups",
                              resource_open_r=resource_open_r,
                              resource_open_w=resource_open_w,
                              key="Unknown B",
                              new_key="Collision Settings")
         self.upgrade_project(old_version + 1, new_version, rom, resource_open_r, resource_open_w, resource_delete)
     else:
         self.upgrade_project(old_version + 1, new_version, rom, resource_open_r, resource_open_w, resource_delete)
Ejemplo n.º 3
0
 def upgrade_project(self, old_version, new_version, rom, resource_open_r,
                     resource_open_w, resource_delete):
     if old_version == new_version:
         return
     elif old_version == 4:
         with resource_open_r("sprite_groups", "yml") as f:
             data = yml_load(f)
             for i in data:
                 entry = data[i]
                 collision_settings = entry["Collision Settings"]
                 entry["North/South Collision Width"] = collision_settings[
                     0]
                 entry["North/South Collision Height"] = collision_settings[
                     1]
                 entry["East/West Collision Width"] = collision_settings[2]
                 entry["East/West Collision Height"] = collision_settings[3]
                 del entry["Collision Settings"]
         with resource_open_w("sprite_groups", "yml") as f:
             yml_dump(data, f)
         self.upgrade_project(old_version + 1, new_version, rom,
                              resource_open_r, resource_open_w,
                              resource_delete)
     elif old_version == 2:
         replace_field_in_yml(resource_name="sprite_groups",
                              resource_open_r=resource_open_r,
                              resource_open_w=resource_open_w,
                              key="Unknown A",
                              new_key="Size",
                              value_map=dict(enumerate(SPRITE_SIZES)))
         replace_field_in_yml(resource_name="sprite_groups",
                              resource_open_r=resource_open_r,
                              resource_open_w=resource_open_w,
                              key="Unknown B",
                              new_key="Collision Settings")
         self.upgrade_project(old_version + 1, new_version, rom,
                              resource_open_r, resource_open_w,
                              resource_delete)
     else:
         self.upgrade_project(old_version + 1, new_version, rom,
                              resource_open_r, resource_open_w,
                              resource_delete)
Ejemplo n.º 4
0
 def upgrade_project(self, old_version, new_version, rom, resource_open_r,
                     resource_open_w, resource_delete):
     if old_version == new_version:
         return
     elif old_version == 3:
         replace_field_in_yml(resource_name="enemy_configuration_table",
                              resource_open_r=resource_open_r,
                              resource_open_w=resource_open_w,
                              key='"The" Flag',
                              value_map={
                                  0: "False",
                                  1: "True"
                              }),
         replace_field_in_yml(resource_name="enemy_configuration_table",
                              resource_open_r=resource_open_r,
                              resource_open_w=resource_open_w,
                              key="Boss Flag",
                              value_map={
                                  0: "False",
                                  1: "True"
                              }),
         replace_field_in_yml(resource_name="enemy_configuration_table",
                              resource_open_r=resource_open_r,
                              resource_open_w=resource_open_w,
                              key="Run Flag",
                              value_map={
                                  6: "Unknown",
                                  7: "True",
                                  8: "False"
                              }),
         replace_field_in_yml(resource_name="enemy_configuration_table",
                              resource_open_r=resource_open_r,
                              resource_open_w=resource_open_w,
                              key="Item Rarity",
                              value_map={
                                  0: "1/128",
                                  1: "2/128",
                                  2: "4/128",
                                  3: "8/128",
                                  4: "16/128",
                                  5: "32/128",
                                  6: "64/128",
                                  7: "128/128"
                              })
         self.upgrade_project(old_version + 1, new_version, rom,
                              resource_open_r, resource_open_w,
                              resource_delete)
     else:
         self.upgrade_project(old_version + 1, new_version, rom,
                              resource_open_r, resource_open_w,
                              resource_delete)
Ejemplo n.º 5
0
 def upgrade_project(self, old_version, new_version, rom, resource_open_r, resource_open_w, resource_delete):
     if old_version == new_version:
         return
     elif old_version == 3:
         replace_field_in_yml(resource_name="enemy_configuration_table",
                              resource_open_r=resource_open_r,
                              resource_open_w=resource_open_w,
                              key='"The" Flag',
                              value_map={0: "False",
                                         1: "True"}),
         replace_field_in_yml(resource_name="enemy_configuration_table",
                              resource_open_r=resource_open_r,
                              resource_open_w=resource_open_w,
                              key="Boss Flag",
                              value_map={0: "False",
                                         1: "True"}),
         replace_field_in_yml(resource_name="enemy_configuration_table",
                              resource_open_r=resource_open_r,
                              resource_open_w=resource_open_w,
                              key="Run Flag",
                              value_map={6: "Unknown",
                                         7: "True",
                                         8: "False"}),
         replace_field_in_yml(resource_name="enemy_configuration_table",
                              resource_open_r=resource_open_r,
                              resource_open_w=resource_open_w,
                              key="Item Rarity",
                              value_map={0: "1/128",
                                         1: "2/128",
                                         2: "4/128",
                                         3: "8/128",
                                         4: "16/128",
                                         5: "32/128",
                                         6: "64/128",
                                         7: "128/128"})
         self.upgrade_project(
             old_version + 1, new_version, rom, resource_open_r, resource_open_w, resource_delete)
     else:
         self.upgrade_project(
             old_version + 1, new_version, rom, resource_open_r, resource_open_w, resource_delete)
Ejemplo n.º 6
0
    def test_replace_field_in_yml(self):
        with open(os.path.join(TEST_DATA_DIR, "yml", "sample.yml"),
                  "r") as sample_yml:

            def resource_open_r(name, extension):
                assert_equal(name, "sample_resource")
                assert_equal(extension, "yml")
                return open(os.path.join(TEST_DATA_DIR, "yml", "sample.yml"))

            def resource_open_r2(name, extension):
                assert_equal(name, "sample_resource")
                assert_equal(extension, "yml")
                return open(self.temporary_wo_file_name, "r")

            def resource_open_w(name, extension):
                assert_equal(name, "sample_resource")
                assert_equal(extension, "yml")
                return open(self.temporary_wo_file_name, "w")

            replace_field_in_yml(resource_name="sample_resource",
                                 resource_open_r=resource_open_r,
                                 resource_open_w=resource_open_w,
                                 key="Action type",
                                 new_key="Cool fish type")
            replace_field_in_yml(resource_name="sample_resource",
                                 resource_open_r=resource_open_r2,
                                 resource_open_w=resource_open_w,
                                 key="Target",
                                 value_map={
                                     "none": "nobody",
                                     "one": "just one guy"
                                 })
            replace_field_in_yml(resource_name="sample_resource",
                                 resource_open_r=resource_open_r2,
                                 resource_open_w=resource_open_w,
                                 key="Direction",
                                 new_key="Where At",
                                 value_map={
                                     "party": "back at ya",
                                     "enemy": "at them"
                                 })

            print(open(self.temporary_wo_file_name, "r")).read()

            assert_files_equal(
                open(os.path.join(TEST_DATA_DIR, "yml", "sample-replaced.yml"),
                     "r"), open(self.temporary_wo_file_name, "r"))
Ejemplo n.º 7
0
    def test_replace_field_in_yml(self):
        with open(os.path.join(TEST_DATA_DIR, "yml", "sample.yml"), "r") as sample_yml:
            def resource_open_r(name, extension, astext):
                assert_equal(name, "sample_resource")
                assert_equal(extension, "yml")
                assert_equal(astext, True)
                return open(os.path.join(TEST_DATA_DIR, "yml", "sample.yml"), encoding="utf-8", newline="\n")

            def resource_open_r2(name, extension, astext):
                assert_equal(name, "sample_resource")
                assert_equal(extension, "yml")
                assert_equal(astext, True)
                return open(self.temporary_wo_file_name, "r", encoding="utf-8", newline="\n")

            def resource_open_w(name, extension, astext):
                assert_equal(name, "sample_resource")
                assert_equal(extension, "yml")
                assert_equal(astext, True)
                return open(self.temporary_wo_file_name, "w", encoding="utf-8", newline="\n")

            replace_field_in_yml(resource_name="sample_resource",
                                 resource_open_r=resource_open_r,
                                 resource_open_w=resource_open_w,
                                 key="Action type",
                                 new_key="Cool fish type")
            replace_field_in_yml(resource_name="sample_resource",
                                 resource_open_r=resource_open_r2,
                                 resource_open_w=resource_open_w,
                                 key="Target",
                                 value_map={"none": "nobody",
                                            "one": "just one guy"})
            replace_field_in_yml(resource_name="sample_resource",
                                 resource_open_r=resource_open_r2,
                                 resource_open_w=resource_open_w,
                                 key="Direction",
                                 new_key="Where At",
                                 value_map={"party": "back at ya",
                                            "enemy": "at them"})

            with open(self.temporary_wo_file_name, "r", encoding="utf-8", newline="\n") as f:
                print(f.read())

            with open(os.path.join(TEST_DATA_DIR, "yml", "sample-replaced.yml"), "r", encoding="utf-8", newline="\n") as f1:
                with open(self.temporary_wo_file_name, "r", encoding="utf-8", newline="\n") as f2:
                    assert_files_equal(f1, f2)
Ejemplo n.º 8
0
    def upgrade_project(self, old_version, new_version, rom, resource_open_r, resource_open_w, resource_delete):
        if old_version == new_version:
            return
        elif old_version == 3:
            replace_field_in_yml(resource_name="item_configuration_table",
                                 resource_open_r=resource_open_r,
                                 resource_open_w=resource_open_w,
                                 key="Effect",
                                 new_key="Action")
            replace_field_in_yml(resource_name="psi_ability_table",
                                 resource_open_r=resource_open_r,
                                 resource_open_w=resource_open_w,
                                 key="Effect",
                                 new_key="Action")
            replace_field_in_yml(resource_name="psi_ability_table",
                                 resource_open_r=resource_open_r,
                                 resource_open_w=resource_open_w,
                                 key="PSI Name",
                                 value_map={0: None,
                                            1: 0,
                                            2: 1,
                                            3: 2,
                                            4: 3,
                                            5: 4,
                                            6: 5,
                                            7: 6,
                                            8: 7,
                                            9: 8,
                                            10: 9,
                                            11: 10,
                                            12: 11,
                                            13: 12,
                                            14: 13,
                                            15: 14,
                                            16: 15,
                                            17: 16})

            resource_delete("cmd_window_text")
            resource_delete("psi_anim_palettes")
            resource_delete("sound_stone_palette")

            self.upgrade_project(old_version=old_version + 1,
                                 new_version=new_version,
                                 rom=rom,
                                 resource_open_r=resource_open_r,
                                 resource_open_w=resource_open_w,
                                 resource_delete=resource_delete)
        elif old_version == 2:
            replace_field_in_yml(resource_name="timed_delivery_table",
                                 resource_open_r=resource_open_r,
                                 resource_open_w=resource_open_w,
                                 key="Suitable Area Text Pointer",
                                 new_key="Delivery Success Text Pointer")
            replace_field_in_yml(resource_name="timed_delivery_table",
                                 resource_open_r=resource_open_r,
                                 resource_open_w=resource_open_w,
                                 key="Unsuitable Area Text Pointer",
                                 new_key="Delivery Failure Text Pointer")

            with resource_open_r("timed_delivery_table", "yml") as f:
                out = yml_load(f)
                yml_str_rep = yml_dump(out, default_flow_style=False)

            yml_str_rep = convert_values_to_hex_repr(yml_str_rep, "Event Flag")

            with resource_open_w("timed_delivery_table", "yml") as f:
                f.write(yml_str_rep)

            self.upgrade_project(old_version=old_version + 1,
                                 new_version=new_version,
                                 rom=rom,
                                 resource_open_r=resource_open_r,
                                 resource_open_w=resource_open_w,
                                 resource_delete=resource_delete)
        elif old_version == 1:
            replace_field_in_yml(resource_name="psi_ability_table",
                                 resource_open_r=resource_open_r,
                                 resource_open_w=resource_open_w,
                                 key="Target",
                                 new_key="Usability Outside of Battle",
                                 value_map={"Nobody": "Other",
                                            "Enemies": "Unusable",
                                            "Allies": "Usable"})
            replace_field_in_yml(resource_name="battle_action_table",
                                 resource_open_r=resource_open_r,
                                 resource_open_w=resource_open_w,
                                 key="Direction",
                                 value_map={"Party": "Enemy",
                                            "Enemy": "Party"})

            self.upgrade_project(old_version=old_version + 1,
                                 new_version=new_version,
                                 rom=rom,
                                 resource_open_r=resource_open_r,
                                 resource_open_w=resource_open_w,
                                 resource_delete=resource_delete)
        else:
            self.upgrade_project(old_version + 1, new_version, rom, resource_open_r, resource_open_w, resource_delete)
Ejemplo n.º 9
0
    def upgrade_project(self, old_version, new_version, rom, resource_open_r, resource_open_w, resource_delete):
        if old_version == new_version:
            return
        elif old_version == 3:
            replace_field_in_yml(resource_name="item_configuration_table",
                                 resource_open_r=resource_open_r,
                                 resource_open_w=resource_open_w,
                                 key="Effect",
                                 new_key="Action")
            replace_field_in_yml(resource_name="psi_ability_table",
                                 resource_open_r=resource_open_r,
                                 resource_open_w=resource_open_w,
                                 key="Effect",
                                 new_key="Action")
            replace_field_in_yml(resource_name="psi_ability_table",
                                 resource_open_r=resource_open_r,
                                 resource_open_w=resource_open_w,
                                 key="PSI Name",
                                 value_map={0: None,
                                            1: 0,
                                            2: 1,
                                            3: 2,
                                            4: 3,
                                            5: 4,
                                            6: 5,
                                            7: 6,
                                            8: 7,
                                            9: 8,
                                            10: 9,
                                            11: 10,
                                            12: 11,
                                            13: 12,
                                            14: 13,
                                            15: 14,
                                            16: 15,
                                            17: 16})

            resource_delete("cmd_window_text")
            resource_delete("psi_anim_palettes")
            resource_delete("sound_stone_palette")

            self.upgrade_project(old_version=old_version + 1,
                                 new_version=new_version,
                                 rom=rom,
                                 resource_open_r=resource_open_r,
                                 resource_open_w=resource_open_w,
                                 resource_delete=resource_delete)
        elif old_version == 2:
            replace_field_in_yml(resource_name="timed_delivery_table",
                                 resource_open_r=resource_open_r,
                                 resource_open_w=resource_open_w,
                                 key="Suitable Area Text Pointer",
                                 new_key="Delivery Success Text Pointer")
            replace_field_in_yml(resource_name="timed_delivery_table",
                                 resource_open_r=resource_open_r,
                                 resource_open_w=resource_open_w,
                                 key="Unsuitable Area Text Pointer",
                                 new_key="Delivery Failure Text Pointer")

            with resource_open_r("timed_delivery_table", "yml", True) as f:
                out = yml_load(f)
                yml_str_rep = yml_dump(out, default_flow_style=False)

            yml_str_rep = convert_values_to_hex_repr(yml_str_rep, "Event Flag")

            with resource_open_w("timed_delivery_table", "yml", True) as f:
                f.write(yml_str_rep)

            self.upgrade_project(old_version=old_version + 1,
                                 new_version=new_version,
                                 rom=rom,
                                 resource_open_r=resource_open_r,
                                 resource_open_w=resource_open_w,
                                 resource_delete=resource_delete)
        elif old_version == 1:
            replace_field_in_yml(resource_name="psi_ability_table",
                                 resource_open_r=resource_open_r,
                                 resource_open_w=resource_open_w,
                                 key="Target",
                                 new_key="Usability Outside of Battle",
                                 value_map={"Nobody": "Other",
                                            "Enemies": "Unusable",
                                            "Allies": "Usable"})
            replace_field_in_yml(resource_name="battle_action_table",
                                 resource_open_r=resource_open_r,
                                 resource_open_w=resource_open_w,
                                 key="Direction",
                                 value_map={"Party": "Enemy",
                                            "Enemy": "Party"})

            self.upgrade_project(old_version=old_version + 1,
                                 new_version=new_version,
                                 rom=rom,
                                 resource_open_r=resource_open_r,
                                 resource_open_w=resource_open_w,
                                 resource_delete=resource_delete)
        else:
            self.upgrade_project(old_version + 1, new_version, rom, resource_open_r, resource_open_w, resource_delete)