Exemple #1
0
            FileType.PKDPX.deserialize(
                FileType.SIR0.deserialize(
                    level_bin[stat_id]).content).decompress())

    if stat_id > -1 and stat_id < kao.toc_len:
        portraits = []
        for kao_i in range(0, SUBENTRIES):
            portraits.append(kao.get(stat_id, kao_i))

    if stat_id > -1 and NUM_ENTITIES + stat_id < kao.toc_len:
        portraits2 = []
        for kao_i in range(0, SUBENTRIES):
            portraits2.append(kao.get(NUM_ENTITIES + stat_id, kao_i))

    xml = monster_xml_export(config.game_version, md_gender1, md_gender2,
                             names, moveset, moveset2, stats, portraits,
                             portraits2)
    fn = f'{md_base_index:04}_{languages["English"].strings[string_id].replace("?", "_")}.xml'
    print(fn)
    write_xml(xml, fn)

# try to replace Bulbasaur data with Charmanders
charmander_xml = ElementTree.parse(
    os.path.join(output_dir, '0004_Charmander.xml')).getroot()

#config.game_version
md_gender1 = md.entries[1]
md_gender2 = md.entries[601]
names = {}
string_id = config.string_index_data.string_blocks['Pokemon Names'].begin + 1
cat_string_id = config.string_index_data.string_blocks[
Exemple #2
0
    def on_btn_export_clicked(self, *args):
        dialog: Gtk.Dialog = self.builder.get_object('export_dialog')
        dialog.resize(640, 560)
        dialog.set_attached_to(SkyTempleMainController.window())
        dialog.set_transient_for(SkyTempleMainController.window())

        # Fill Pokémon tree
        store: Gtk.TreeStore = self.builder.get_object('export_dialog_store')
        store.clear()
        monster_entries_by_base_id: Dict[int, List[MdEntry]] = {}
        for entry in self.module.monster_md.entries:
            if entry.md_index_base not in monster_entries_by_base_id:
                monster_entries_by_base_id[entry.md_index_base] = []
            monster_entries_by_base_id[entry.md_index_base].append(entry)

        for baseid, entry_list in monster_entries_by_base_id.items():
            name = self.module.project.get_string_provider().get_value(StringType.POKEMON_NAMES, baseid)
            entry_main_tree = self.module.generate_entry__entity_root(baseid, name)
            ent_root = store.append(None, [
                -1, -1, False, entry_main_tree[0],
                entry_main_tree[1], False, False
            ])

            for entry in entry_list:
                entry_main_tree = self.module.generate_entry__entry(entry.md_index, entry.gender)
                store.append(
                    ent_root, [
                        entry_main_tree[4], -1, True, entry_main_tree[0],
                        entry_main_tree[1], False, False
                    ]
                )

        names, md_gender1, md_gender2, moveset, moveset2, stats, portraits, portraits2 = self.module.get_export_data(self.entry)
        we_are_gender1 = md_gender1 == self.entry

        if md_gender2 is None:
            sw: Gtk.Switch = self.builder.get_object('export_type_other_gender')
            sw.set_active(False)
            sw.set_sensitive(False)

        if portraits is None:
            sw: Gtk.Switch = self.builder.get_object('export_type_portraits_current_gender')
            sw.set_active(False)
            sw.set_sensitive(False)

        if portraits2 is None:
            sw: Gtk.Switch = self.builder.get_object('export_type_portraits_other_gender')
            sw.set_active(False)
            sw.set_sensitive(False)

        if stats is None:
            sw: Gtk.Switch = self.builder.get_object('export_type_stats')
            sw.set_active(False)
            sw.set_sensitive(False)

        if moveset is None:
            sw: Gtk.Switch = self.builder.get_object('export_type_moveset1')
            sw.set_active(False)
            sw.set_sensitive(False)

        if moveset2 is None:
            sw: Gtk.Switch = self.builder.get_object('export_type_moveset2')
            sw.set_active(False)
            sw.set_sensitive(False)

        resp = dialog.run()
        dialog.hide()

        if resp == Gtk.ResponseType.APPLY:
            # Create output XML

            if not self.builder.get_object('export_type_current_gender').get_active():
                if we_are_gender1:
                    md_gender1 = None
                else:
                    md_gender2 = None
            if not self.builder.get_object('export_type_other_gender').get_active():
                if not we_are_gender1:
                    md_gender1 = None
                else:
                    md_gender2 = None
            if not self.builder.get_object('export_type_names').get_active():
                names = None
            if not self.builder.get_object('export_type_stats').get_active():
                stats = None
            if not self.builder.get_object('export_type_moveset1').get_active():
                moveset = None
            if not self.builder.get_object('export_type_moveset2').get_active():
                moveset2 = None
            if not self.builder.get_object('export_type_portraits_current_gender').get_active():
                if we_are_gender1:
                    portraits = None
                else:
                    portraits2 = None
            if not self.builder.get_object('export_type_portraits_other_gender').get_active():
                if not we_are_gender1:
                    portraits = None
                else:
                    portraits2 = None

            xml = monster_xml_export(
                self.module.project.get_rom_module().get_static_data().game_version,
                md_gender1, md_gender2, names, moveset, moveset2, stats, portraits, portraits2
            )

            # 1. Export to file
            if self.builder.get_object('export_file_switch').get_active():
                save_diag = Gtk.FileChooserNative.new(
                    _("Export Pokémon as..."),
                    SkyTempleMainController.window(),
                    Gtk.FileChooserAction.SAVE,
                    None, None
                )

                add_dialog_xml_filter(save_diag)
                response = save_diag.run()
                fn = save_diag.get_filename()
                if '.' not in fn:
                    fn += '.xml'
                save_diag.destroy()

                if response == Gtk.ResponseType.ACCEPT:
                    with open(fn, 'w') as f:
                        f.write(prettify(xml))
                else:
                    md = SkyTempleMessageDialog(SkyTempleMainController.window(),
                                                Gtk.DialogFlags.DESTROY_WITH_PARENT, Gtk.MessageType.WARNING,
                                                Gtk.ButtonsType.OK, "Export was canceled.")
                    md.set_position(Gtk.WindowPosition.CENTER)
                    md.run()
                    md.destroy()
                    return

            # 2. Import to selected Pokémon
            selected_monsters: List[int] = []
            def collect_monsters_recurse(titer: Optional[Gtk.TreeIter]):
                for i in range(store.iter_n_children(titer)):
                    child = store.iter_nth_child(titer, i)
                    if store[child][2] and store[child][5]:  # is floor and is selected
                        selected_monsters.append(store[child][0])
                    collect_monsters_recurse(child)

            collect_monsters_recurse(None)
            self.module.import_from_xml(selected_monsters, xml)
                    level_bin[stat_id]).content).decompress())

    if stat_id > -1 and stat_id < kao.toc_len:
        portraits = []
        for kao_i in range(0, SUBENTRIES):
            portraits.append(kao.get(stat_id, kao_i))

    if stat_id > -1 and MdProperties.NUM_ENTITIES + stat_id < kao.toc_len:
        portraits2 = []
        for kao_i in range(0, SUBENTRIES):
            portraits2.append(
                kao.get(MdProperties.NUM_ENTITIES + stat_id, kao_i))

    xml = monster_xml_export(
        config.game_version, md_gender1, md_gender2, names, moveset, moveset2,
        stats, portraits, portraits2,
        tbl_talk.get_monster_personality(md_gender1.md_index),
        tbl_talk.get_monster_personality(md_gender2.md_index)
        if md_gender2 is not None else None)
    fn = f'{md_base_index:04}_{languages["English"].strings[string_id].replace("?", "_")}.xml'
    print(fn)
    write_xml(xml, fn)

# try to replace Bulbasaur data with Charmanders
charmander_xml = ElementTree.parse(
    os.path.join(output_dir, '0004_Charmander.xml')).getroot()

#config.game_version
md_gender1 = md.entries[1]
md_gender2 = md.entries[601]
names = {}
string_id = config.string_index_data.string_blocks['Pokemon Names'].begin + 1