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 < 5:
            with resource_open_r("map_changes", "yml", True) as f:
                data = yml_load(f)

            for i in data:
                if data[i] is None:
                    data[i] = []
                else:
                    for entry in data[i]:
                        entry["Tile Changes"] = entry["Changes"]
                        del entry["Changes"]

                        for j, change in enumerate(entry["Tile Changes"]):
                            entry["Tile Changes"][
                                j] = MapEventSubTableEntry.to_yml_rep(change)

            with resource_open_w("map_changes", "yml", True) as f:
                yml_dump(data, f)

            convert_values_to_hex_repr_in_yml_file("map_changes",
                                                   resource_open_r,
                                                   resource_open_w,
                                                   ["Event Flag"],
                                                   default_flow_style=None)

            self.upgrade_project(5, 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)
Example #2
0
    def write_to_project(self, resource_open):
        with resource_open("enemy_configuration_table", "yml") as f:
            self.enemy_config_table.to_yml_file(f)

        # Write the battle sprite images
        log.debug("Writing battle sprites")
        for i in range(self.enemy_config_table.num_rows):
            battle_sprite_id = self.enemy_config_table[i][4]
            if battle_sprite_id > 0:
                palette_id = self.enemy_config_table[i][14]
                palette = self.palettes[palette_id]

                image = self.battle_sprites[battle_sprite_id - 1].image(palette=palette)
                with resource_open("BattleSprites/" + str(i).zfill(3), "png") as f:
                    image.save(f, "png", transparency=0)
                del image

        # Write the groups
        log.debug("Writing groups")
        out = dict()
        enemy_group_table_yml_rep = self.enemy_group_table.to_yml_rep()
        enemy_group_bg_table_yml_rep = self.enemy_group_bg_table.to_yml_rep()
        for i, group in enumerate(self.enemy_groups):
            entry = enemy_group_table_yml_rep[i]
            entry.update(enemy_group_bg_table_yml_rep[i])

            group_yml_rep = []
            for enemy_entry in group:
                group_yml_rep.append(EnemyGroupTableEntry.to_yml_rep(enemy_entry))
            entry["Enemies"] = group_yml_rep

            out[i] = entry

        with resource_open("enemy_groups", "yml") as f:
            yml_dump(out, f)
Example #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("TownMaps/icon_positions", "yml", True) as f:
                data = yml_load(f)

                for i in range(6):
                    old_key = TownMapEnum.tostring(i).lower()
                    data[i] = data[old_key]
                    del data[old_key]
            with resource_open_w("TownMaps/icon_positions", "yml", True) as f:
                yml_dump(data, f, default_flow_style=False)

            convert_values_to_hex_repr_in_yml_file("TownMaps/icon_positions",
                                                   resource_open_r,
                                                   resource_open_w,
                                                   ["Event Flag"])

            self.upgrade_project(5, new_version, rom, resource_open_r,
                                 resource_open_w, resource_delete)
        elif old_version <= 2:
            self.read_from_rom(rom)
            self.write_to_project(resource_open_w)
            self.upgrade_project(new_version, 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)
Example #4
0
    def write_to_project(self, resource_open):
        with resource_open("enemy_configuration_table", "yml") as f:
            self.enemy_config_table.to_yml_file(f)

        # Write the battle sprite images
        log.debug("Writing battle sprites")
        for i in range(self.enemy_config_table.num_rows):
            battle_sprite_id = self.enemy_config_table[i][4]
            if battle_sprite_id > 0:
                palette_id = self.enemy_config_table[i][14]
                palette = self.palettes[palette_id]

                image = self.battle_sprites[battle_sprite_id - 1].image(palette=palette)
                with resource_open("BattleSprites/" + str(i).zfill(3), "png") as f:
                    image.save(f, "png", transparency=0)
                del image

        # Write the groups
        log.debug("Writing groups")
        out = dict()
        enemy_group_table_yml_rep = self.enemy_group_table.to_yml_rep()
        enemy_group_bg_table_yml_rep = self.enemy_group_bg_table.to_yml_rep()
        for i, group in enumerate(self.enemy_groups):
            entry = enemy_group_table_yml_rep[i]
            entry.update(enemy_group_bg_table_yml_rep[i])

            group_yml_rep = []
            for enemy_entry in group:
                group_yml_rep.append(EnemyGroupTableEntry.to_yml_rep(enemy_entry))
            entry["Enemies"] = group_yml_rep

            out[i] = entry

        with resource_open("enemy_groups", "yml") as f:
            yml_dump(out, f)
Example #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 < 5:
            with resource_open_r("map_changes", "yml") as f:
                data = yml_load(f)

            for i in data:
                if data[i] is None:
                    data[i] = []
                else:
                    for entry in data[i]:
                        entry["Tile Changes"] = entry["Changes"]
                        del entry["Changes"]

                        for j, change in enumerate(entry["Tile Changes"]):
                            entry["Tile Changes"][j] = MapEventSubTableEntry.to_yml_rep(change)

            with resource_open_w("map_changes", "yml") as f:
                yml_dump(data, f)

            convert_values_to_hex_repr_in_yml_file("map_changes", resource_open_r, resource_open_w, ["Event Flag"],
                                                   default_flow_style=None)

            self.upgrade_project(5, 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)
 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)
Example #7
0
 def write(self, filename):
     tmp = {
         'romtype': self.romtype,
         'resources': self._resources,
         'version': FORMAT_VERSION}
     f = open(filename, 'w+')
     yml_dump(tmp, f)
     f.close()
Example #8
0
    def to_files(self, image_file, widths_file, image_format="png", widths_format="yml"):
        image = _FONT_IMAGE_ARRANGEMENT.image(self.tileset, _FONT_IMAGE_PALETTE)
        image.save(image_file, image_format)
        del image

        character_widths_dict = dict(enumerate(self.character_widths))
        if widths_format == "yml":
            yml_dump(character_widths_dict, widths_file, default_flow_style=False)
Example #9
0
 def write(self, filename):
     tmp = {
         'romtype': self.romtype,
         'resources': self._resources,
         'version': FORMAT_VERSION}
     f = open(filename, 'w+')
     yml_dump(tmp, f)
     f.close()
Example #10
0
 def write_to_project(self, resource_open):
     swirl_data = {}
     for i, swirl in enumerate(self.swirls):
         swirl_data[i] = {"speed": swirl.speed, "frames": len(swirl.frames)}
         for j, frame in enumerate(swirl.frames):
             with resource_open("Swirls/{}/{}".format(i, str(j).zfill(3)), "png") as f:
                 image = frame.image()
                 image.save(f, "png")
     with resource_open("Swirls/swirls", "yml") as f:
         yml_dump(swirl_data, f, default_flow_style=False)
Example #11
0
    def to_files(self, image_file, widths_file, image_format="png", widths_format="yml"):
        if self.num_characters == 96:
            image = _FONT_IMAGE_ARRANGEMENT_96.image(self.tileset, FONT_IMAGE_PALETTE)
        elif self.num_characters == 128:
            image = _FONT_IMAGE_ARRANGEMENT_128.image(self.tileset, FONT_IMAGE_PALETTE)
        image.save(image_file, image_format)
        del image

        character_widths_dict = dict(enumerate(self.character_widths))
        if widths_format == "yml":
            yml_dump(character_widths_dict, widths_file, default_flow_style=False)
Example #12
0
    def write_to_project(self, resource_open):
        formatting_data = {}

        for i, entry in enumerate(self.entries):
            formatting_data[i] = {
                'begin': entry.begin,
                'size': entry.size,
                'misc': entry.misc
            }

        with resource_open(CAST_FORMATTING_FILE_NAME, 'yml', True) as f:
            yml_dump(formatting_data, f, default_flow_style=False)
 def write_to_project(self, resource_open):
     out = {"Enable Skip": False,
            "Enable Summary": False,
            "Name1": "Ness",
            "Name2": "Paula",
            "Name3": "Jeff",
            "Name4": "Poo",
            "Pet": "King",
            "Food": "Steak",
            "Thing": "Rockin"}
     with resource_open("naming_skip", "yml", True) as f:
         yml_dump(out, f, default_flow_style=False)
Example #14
0
 def write_to_project(self, resource_open):
     swirl_data = {}
     for i, swirl in enumerate(self.swirls):
         swirl_data[i] = {"speed": swirl.speed, "frames": len(swirl.frames)}
         for j, frame in enumerate(swirl.frames):
             with resource_open("Swirls/{}/{}".format(i,
                                                      str(j).zfill(3)),
                                "png") as f:
                 image = frame.image()
                 image.save(f, "png")
     with resource_open("Swirls/swirls", "yml") as f:
         yml_dump(swirl_data, f, default_flow_style=False)
 def write_to_project(self, resource_open):
     with resource_open(DEATH_SCREEN_PATH, "png") as f:
         image = self.arrangement.image(self.tileset, self.palette, True)
         image.save(f)
     with resource_open(DEATH_SCREEN_SUBPALETTES_PATH, "yml", True) as f:
         subpalettes = {}
         for x in range(ARRANGEMENT_WIDTH):
             for y in range(ARRANGEMENT_HEIGHT):
                 subpalette = self.arrangement[x, y].subpalette
                 if subpalette not in subpalettes:
                     subpalettes[subpalette] = []
                 subpalettes[subpalette].append((x, y))
         yml_dump(subpalettes, f, None)
 def write_to_project(self, resource_open):
     with resource_open(DEATH_SCREEN_PATH, "png") as f:
         image = self.arrangement.image(self.tileset, self.palette, True)
         image.save(f)
     with resource_open(DEATH_SCREEN_SUBPALETTES_PATH, "yml") as f:
         subpalettes = {}
         for x in range(ARRANGEMENT_WIDTH):
             for y in range(ARRANGEMENT_HEIGHT):
                 subpalette = self.arrangement[x, y].subpalette
                 if subpalette not in subpalettes:
                     subpalettes[subpalette] = []
                 subpalettes[subpalette].append((x, y))
         yml_dump(subpalettes, f, None)
    def write_to_project(self, resource_open):
        # Write the palettes
        with resource_open("sprite_group_palettes", "yml", True) as f:
            self.palette_table.to_yml_file(f)

        out = {}
        for i, group in enumerate(self.groups):
            out[i] = group.yml_rep()
            image = group.image(self.palette_table[group.palette][0])
            with resource_open("SpriteGroups/" + str(i).zfill(3), 'png') as image_file:
                image.save(image_file, 'png', transparency=0)
            del image
        with resource_open("sprite_groups", "yml", True) as f:
            yml_dump(out, f)
Example #18
0
    def write_to_project(self, resource_open):
        # Write the palettes
        with resource_open("sprite_group_palettes", "yml") as f:
            self.palette_table.to_yml_file(f)

        out = {}
        for i, group in enumerate(self.groups):
            out[i] = group.yml_rep()
            image = group.image(self.palette_table[group.palette][0])
            with resource_open("SpriteGroups/" + str(i).zfill(3),
                               'png') as image_file:
                image.save(image_file, 'png', transparency=0)
            del image
        with resource_open("sprite_groups", "yml") as f:
            yml_dump(out, f)
Example #19
0
    def write_to_project(self, resource_open):
        animation_data = {}
        for i, animation in enumerate(self.animations):
            animation_data[i] = {
                'frames': animation.frames,
                'unknown': animation.unknown
            }
            for j, image in enumerate(animation.images()):
                with resource_open(
                        'Animations/{}/{}'.format(i,
                                                  str(j).zfill(3)),
                        'png') as f:
                    image.save(f, 'png')

        with resource_open('Animations/animations', 'yml', True) as f:
            yml_dump(animation_data, f, default_flow_style=False)
Example #20
0
    def write_to_project(self, resource_open):
        # Dump an additional YML with color0 data
        palette_settings = dict()
        log.debug("Writing palette settings")
        for i in range(0, 32):  # For each map tileset
            entry = dict()
            tileset = None
            for ts in self.tilesets:
                if ts.has_map_tileset(i):
                    tileset = ts
                    break

            palettes = tileset.get_palettes_by_map_tileset(i)
            palettes.sort()
            for (palette_id, palette) in palettes:
                entry[palette_id] = palette.settings_yml_rep()
            palette_settings[i] = entry

        with resource_open("map_palette_settings", "yml") as f:
            yml_str_rep = yml_dump(palette_settings, default_flow_style=False)
            yml_str_rep = convert_values_to_hex_repr(yml_str_rep, "Event Flag")
            f.write(yml_str_rep)

        # Dump the tilesets
        for i, tileset in enumerate(self.tilesets):
            log.debug("Writing tileset #{}".format(i))
            with resource_open("Tilesets/" + str(i).zfill(2), "fts") as f:
                tileset.to_file(f)
Example #21
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 == 5:
            # Expand all the fonts from 96 characters to 128 characters
            for i, font in enumerate(self.fonts):
                log.debug("Expanding font #{}".format(FONT_FILENAMES[i]))
                image_resource_name = "Fonts/" + FONT_FILENAMES[i]
                widths_resource_name = "Fonts/" + FONT_FILENAMES[i] + "_widths"
                new_image_w, new_image_h = font.image_size()

                # Expand the image

                with resource_open_r(image_resource_name, 'png') as image_file:
                    image = open_indexed_image(image_file)

                    expanded_image = Image.new("P", (new_image_w, new_image_h), None)
                    for y in range(new_image_h):
                        for x in range(new_image_w):
                            expanded_image.putpixel((x, y), 1)
                    FONT_IMAGE_PALETTE.to_image(expanded_image)
                    expanded_image.paste(image, (0, 0))

                    with resource_open_w(image_resource_name, 'png') as image_file2:
                        expanded_image.save(image_file2, "png")

                # Expand the widths

                with resource_open_r(widths_resource_name, "yml", True) as widths_file:
                    widths_dict = yml_load(widths_file)

                for character_id in range(96, 128):
                    if character_id not in widths_dict:
                        widths_dict[character_id] = 0

                with resource_open_w(widths_resource_name, "yml", True) as widths_file:
                    yml_dump(widths_dict, widths_file, default_flow_style=False)

            self.upgrade_project(6, new_version, rom, resource_open_r, resource_open_w, resource_delete)
        elif old_version <= 2:
            # The credits font was a new feature in version 3

            self.read_credits_font_from_rom(rom)
            self.write_credits_font_to_project(resource_open_w)
            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)
Example #22
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 == 5:
            # Expand all the fonts from 96 characters to 128 characters
            for i, font in enumerate(self.fonts):
                log.debug("Expanding font #{}".format(FONT_FILENAMES[i]))
                image_resource_name = "Fonts/" + FONT_FILENAMES[i]
                widths_resource_name = "Fonts/" + FONT_FILENAMES[i] + "_widths"
                new_image_w, new_image_h = font.image_size()

                # Expand the image

                with resource_open_r(image_resource_name, 'png') as image_file:
                    image = open_indexed_image(image_file)

                    expanded_image = Image.new("P", (new_image_w, new_image_h), None)
                    for y in xrange(new_image_h):
                        for x in xrange(new_image_w):
                            expanded_image.putpixel((x, y), 1)
                    FONT_IMAGE_PALETTE.to_image(expanded_image)
                    expanded_image.paste(image, (0, 0))

                    with resource_open_w(image_resource_name, 'png') as image_file2:
                        expanded_image.save(image_file2, "png")

                # Expand the widths

                with resource_open_r(widths_resource_name, "yml") as widths_file:
                    widths_dict = yml_load(widths_file)

                for character_id in xrange(96, 128):
                    if character_id not in widths_dict:
                        widths_dict[character_id] = 0

                with resource_open_w(widths_resource_name, "yml") as widths_file:
                    yml_dump(widths_dict, widths_file, default_flow_style=False)

            self.upgrade_project(6, new_version, rom, resource_open_r, resource_open_w, resource_delete)
        elif old_version <= 2:
            # The credits font was a new feature in version 3

            self.read_credits_font_from_rom(rom)
            self.write_credits_font_to_project(resource_open_w)
            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)
    def write_chars_data_to_project(self, resource_open):
        # Build an arrangement combining every character for convenience
        chars_positions = {}
        arrangement = EbTileArrangement(3*9, 6)
        for c, layout in enumerate(self.chars_layouts):
            top_left = {'x': 128, 'y': 128}
            for e, entry in enumerate(layout):
                tile = entry.tile & (CHARS_NUM_TILES - 1)
                top_left['x'] = min(top_left['x'], int(entry.x))
                top_left['y'] = min(top_left['y'], int(entry.y))
                x = c*3 + (entry.x + 16) // 8
                y = (entry.y + 24) // 8
                arrangement[x, y].tile = tile
                if not entry.is_single():
                    arrangement[x+1, y].tile = tile + 1
                    arrangement[x, y+1].tile = tile + 16
                    arrangement[x+1, y+1].tile = tile + 17
            chars_positions[c] = {
                'x': c*3*8,
                'y': 0,
                'width': 3*8,
                'height': 6*8,
                'top_left_offset': top_left,
                'unknown': layout[0].unknown
            }

        # Write the characters animation frames
        for p in range(CHARS_NUM_ANIM_SUBPALETTES):
            with resource_open(CHARS_FRAMES_PATH.format(p), "png") as f:
                image = arrangement.image(
                    self.chars_tileset,
                    self.chars_anim_palette.get_subpalette(p)
                )
                image.save(f)

        # Write out the initial characters palette
        with resource_open(CHARS_INITIAL_PATH, "png") as f:
            image = arrangement.image(
                self.chars_tileset,
                self.chars_palette
            )
            image.save(f)

        # Write out the positions of the characters
        with resource_open(CHARS_POSITIONS_PATH, "yml", True) as f:
            yml_dump(chars_positions, f, False)
Example #24
0
    def to_yml_file(self, f, default_flow_style=False):
        yml_str_rep = yml_dump(self.to_yml_rep(), default_flow_style=default_flow_style)

        # Rewrite hexints in hexidecimal
        # The YAML parser does not offer this option, so this has to be done with a regex
        for hex_label in self.schema.yml_rep_hex_labels():
            yml_str_rep = convert_values_to_hex_repr(yml_str_rep, hex_label)

        f.write(yml_str_rep)
Example #25
0
    def write_to_project(self, resource_open):
        log.debug('Writing dynamic cast names')
        yml_data = {}

        for n in self.dynamic_names:
            n.write_to_yml_data(yml_data)

        with resource_open(CAST_DYNAMIC_NAMES_FILE_NAME, 'yml', True) as f:
            yml_dump(yml_data, f, default_flow_style=False)

        log.debug('Writing cast formatting data')
        self.formatting.write_to_project(resource_open)

        log.debug('Writing cast name graphics')
        self.write_gfx_to_project(self.name_gfx, resource_open)

        log.debug('Writing miscellaneous cast graphics')
        self.write_gfx_to_project(self.misc_gfx, resource_open)
Example #26
0
    def to_yml_file(self, f, default_flow_style=False):
        yml_str_rep = yml_dump(self.to_yml_rep(),
                               default_flow_style=default_flow_style)

        # Rewrite hexints in hexidecimal
        # The YAML parser does not offer this option, so this has to be done with a regex
        for hex_label in self.schema.yml_rep_hex_labels():
            yml_str_rep = convert_values_to_hex_repr(yml_str_rep, hex_label)

        f.write(yml_str_rep)
Example #27
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)
Example #28
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("TownMaps/icon_positions", "yml") as f:
                data = yml_load(f)

                for i in range(6):
                    old_key = TownMapEnum.tostring(i).lower()
                    data[i] = data[old_key]
                    del data[old_key]
            with resource_open_w("TownMaps/icon_positions", "yml") as f:
                yml_dump(data, f, default_flow_style=False)

            convert_values_to_hex_repr_in_yml_file("TownMaps/icon_positions", resource_open_r, resource_open_w,
                                                   ["Event Flag"])

            self.upgrade_project(5, new_version, rom, resource_open_r, resource_open_w, resource_delete)
        elif old_version <= 2:
            self.read_from_rom(rom)
            self.write_to_project(resource_open_w)
            self.upgrade_project(new_version, 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)
Example #29
0
    def write_to_project(self, resourceOpener):
        out = dict()
        x = y = 0
        rowOut = dict()
        for entry in self.door_areas:
            if not entry:
                rowOut[x % 32] = None
            else:
                rowOut[x % 32] = [z.yml_rep() for z in entry]
            if (x % 32) == 31:
                # Start new row
                out[y] = rowOut
                x = 0
                y += 1
                rowOut = dict()
            else:
                x += 1

        with resourceOpener("map_doors", "yml", True) as f:
            s = yml_dump(out, default_flow_style=False)
            s = convert_values_to_hex_repr(yml_str_rep=s, key="Event Flag")
            f.write(s)
Example #30
0
    def write_to_project(self, resourceOpener):
        out = dict()
        x = y = 0
        rowOut = dict()
        for entry in self.door_areas:
            if not entry:
                rowOut[x % 32] = None
            else:
                rowOut[x % 32] = [z.yml_rep() for z in entry]
            if (x % 32) == 31:
                # Start new row
                out[y] = rowOut
                x = 0
                y += 1
                rowOut = dict()
            else:
                x += 1

        with resourceOpener("map_doors", "yml", True) as f:
            s = yml_dump(
                out,
                default_flow_style=False)
            s = convert_values_to_hex_repr(yml_str_rep=s, key="Event Flag")
            f.write(s)
Example #31
0
 def write_to_project(self, resource_open):
     with resource_open("patches", "yml") as f:
         yml_dump(self.patches, f, default_flow_style=False)
Example #32
0
 def write_map_palette_settings(self, palette_settings, resource_open):
     with resource_open("map_palette_settings", "yml") as f:
         yml_str_rep = yml_dump(palette_settings, default_flow_style=False)
         yml_str_rep = convert_values_to_hex_repr(yml_str_rep, "Event Flag")
         f.write(yml_str_rep)
Example #33
0
 def write_to_project(self, resourceOpener):
     with resourceOpener("text", "yml") as f:
         yml_dump(self._data, f, default_flow_style=False)
Example #34
0
 def write_to_project(self, resourceOpener):
     with resourceOpener("text", "yml") as f:
         yml_dump(self._data, f, default_flow_style=False)
Example #35
0
 def save(self):
     with open(self.PREFERENCES_FILENAME, "w") as f:
         yml_dump(self.preferences, f, default_flow_style=False)
Example #36
0
with open(sys.argv[1], "r") as f:
    with open(sys.argv[2], "w") as f2:
        i = 1
        for doc in yaml.load_all(f, Loader=yaml.CSafeLoader):
            if i == 1:
                f2.write("# This is a automatically generated trimmed version of the full EBYAML file.\n"
                         + "# This file only contains data block descriptions which have an \"entries\" entry.\n"
                         + "---\n...\n---\n")
                i += 1
            elif i == 2:
                newDoc = dict()
                for block in doc:
                    if not (doc[block] is None
                            or not ("type" in doc[block])
                            or ("data" in doc[block]["type"])
                            or not ("entries" in doc[block].has_key("entries"))):
                        newDoc[block] = doc[block]
                        if newDoc[block].has_key("description"):
                            del(newDoc[block]["description"])
                s = yml_dump(newDoc, default_flow_style=False)
                # Convert labels to hex
                s = sub("(\d+):\n",
                        lambda i: "0x" + hex(
                            int(i.group(0)[:-2]))[2:].upper() + ":\n", s)
                f2.write(s)
                f2.write('\n...')
                break

sys.exit(0)
Example #37
0
 def write_to_project(self, resource_open):
     with resource_open("text_misc", "yml") as f:
         yml_dump(self.data, f, default_flow_style=False)
Example #38
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)
Example #39
0
 def write_to_project(self, resource_open):
     with resource_open("text_misc", "yml", True) as f:
         yml_dump(self.data, f, default_flow_style=False)
Example #40
0
with open(sys.argv[1], "r") as f:
    with open(sys.argv[2], "w") as f2:
        i = 1
        for doc in yaml.load_all(f, Loader=yaml.CSafeLoader):
            if i == 1:
                f2.write("# This is a automatically generated trimmed version of the full EBYAML file.\n"
                         + "# This file only contains data block descriptions which have an \"entries\" entry.\n"
                         + "---\n...\n---\n")
                i += 1
            elif i == 2:
                newDoc = dict()
                for block in doc:
                    if not (doc[block] is None
                            or not ("type" in doc[block])
                            or ("data" in doc[block]["type"])
                            or not ("entries" in ("entries" in doc[block]))):
                        newDoc[block] = doc[block]
                        if "description" in newDoc[block]:
                            del(newDoc[block]["description"])
                s = yml_dump(newDoc, default_flow_style=False)
                # Convert labels to hex
                s = sub("(\d+):\n",
                        lambda i: "0x" + hex(
                            int(i.group(0)[:-2]))[2:].upper() + ":\n", s)
                f2.write(s)
                f2.write('\n...')
                break

sys.exit(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)
Example #42
0
 def write_to_project(self, resource_open):
     with resource_open("patches", "yml") as f:
         yml_dump(self.patches, f, default_flow_style=False)