def import_from_xml(self, selected_monsters: List[int], xml: Element): b_attr = self.effective_base_attr for monster_id in selected_monsters: entry = self.get_entry(monster_id) names, md_gender1, md_gender2, moveset, moveset2, stats, portraits, portraits2 = self.get_export_data( entry) we_are_gender1 = monster_id < MdProperties.NUM_ENTITIES md_gender1_imp = md_gender1 portraits1_imp = portraits md_gender2_imp = md_gender2 portraits2_imp = portraits2 if md_gender2: if we_are_gender1: md_gender2_imp = None portraits2_imp = None else: md_gender1_imp = None portraits1_imp = None monster_xml_import(xml, md_gender1_imp, md_gender2_imp, names, moveset, moveset2, stats, portraits1_imp, portraits2_imp) if stats: self.set_m_level_bin_entry(getattr(entry, b_attr) - 1, stats) if names: sp = self.project.get_string_provider() for lang_name, (name, category) in names.items(): model = sp.get_model(lang_name) model.strings[sp.get_index(StringType.POKEMON_NAMES, getattr(entry, b_attr))] = name model.strings[sp.get_index(StringType.POKEMON_CATEGORIES, getattr(entry, b_attr))] = category self.update_monster_sort_lists(lang_name) sp.mark_as_modified() portrait_module = self.project.get_module('portrait') kao: Kao = portrait_module.kao portraits = portraits if we_are_gender1 else portraits2 if portraits: for i, portrait in enumerate(portraits): existing = kao.get(monster_id - 1, i) if portrait: if existing: existing.compressed_img_data = portrait.compressed_img_data existing.pal_data = portrait.pal_data existing.modified = True existing.as_pil = None else: kao.set(monster_id - 1, i, portrait) else: # TODO: Support removing portraits pass self.refresh(monster_id) self.mark_md_as_modified(monster_id) self.project.mark_as_modified(WAZA_P_BIN) self.project.mark_as_modified(WAZA_P2_BIN) self.project.get_string_provider().mark_as_modified() self.project.mark_as_modified(PORTRAIT_FILE)
def import_from_xml(self, selected_monsters: List[int], xml: Element): b_attr = 'md_index_base' if self.project.is_patch_applied('ExpandPokeList'): b_attr = 'md_index' for monster_id in selected_monsters: entry = self.get_entry(monster_id) names, md_gender1, md_gender2, moveset, moveset2, stats, portraits, portraits2, personality1, personality2, idle_anim1, idle_anim2 = self.get_export_data( entry) we_are_gender1 = monster_id < MdProperties.NUM_ENTITIES md_gender1_imp = md_gender1 portraits1_imp = portraits md_gender2_imp = md_gender2 portraits2_imp = portraits2 if md_gender2: if we_are_gender1: md_gender2_imp = None portraits2_imp = None personality2 = None idle_anim2 = None else: md_gender1_imp = None portraits1_imp = None personality1 = None idle_anim1 = None md_gender1_imp_wrapped = GenderedConvertEntry( md_gender1, personality1, idle_anim1.value if idle_anim1 else None) md_gender2_imp_wrapped = GenderedConvertEntry( md_gender2, personality2, idle_anim2.value if idle_anim2 else None) monster_xml_import(xml, md_gender1_imp_wrapped, md_gender2_imp_wrapped, names, moveset, moveset2, stats, portraits1_imp, portraits2_imp) if md_gender2: if we_are_gender1: if md_gender1_imp_wrapped.personality is not None: self.set_personality( md_gender1.md_index, md_gender1_imp_wrapped.personality) if md_gender1_imp_wrapped.idle_anim is not None: self.set_idle_anim_type( md_gender1.md_index, md_gender1_imp_wrapped.idle_anim) else: if md_gender2_imp_wrapped.personality is not None: self.set_personality( md_gender2.md_index, md_gender2_imp_wrapped.personality) if md_gender2_imp_wrapped.idle_anim is not None: self.set_idle_anim_type( md_gender2.md_index, md_gender2_imp_wrapped.idle_anim) else: if md_gender1_imp_wrapped.personality is not None: self.set_personality(md_gender1.md_index, md_gender1_imp_wrapped.personality) if md_gender1_imp_wrapped.idle_anim is not None: self.set_idle_anim_type(md_gender1.md_index, md_gender1_imp_wrapped.idle_anim) if stats: self.set_m_level_bin_entry(getattr(entry, b_attr) - 1, stats) if names: sp = self.project.get_string_provider() for lang_name, (name, category) in names.items(): model = sp.get_model(lang_name) model.strings[sp.get_index(StringType.POKEMON_NAMES, getattr(entry, b_attr))] = name model.strings[sp.get_index(StringType.POKEMON_CATEGORIES, getattr(entry, b_attr))] = category self.update_monster_sort_lists(lang_name) sp.mark_as_modified() portrait_module = self.project.get_module('portrait') kao: KaoProtocol = portrait_module.kao portraits = portraits if we_are_gender1 else portraits2 if portraits: for i, portrait in enumerate(portraits): if portrait: kao.set(monster_id - 1, i, portrait) else: kao.delete(monster_id - 1, i) self.refresh(monster_id) self.mark_md_as_modified(monster_id) self.project.mark_as_modified(WAZA_P_BIN) self.project.mark_as_modified(WAZA_P2_BIN) self.project.get_string_provider().mark_as_modified() self.project.mark_as_modified(PORTRAIT_FILE)
'Pokemon Categories'].begin + 1 for lang_name, lang_model in languages.items(): names[lang_name] = (lang_model.strings[string_id], lang_model.strings[cat_string_id]) moveset = waza_p.learnsets[1] moveset2 = waza_p.learnsets[1] stats = FileType.LEVEL_BIN_ENTRY.deserialize( FileType.PKDPX.deserialize( FileType.SIR0.deserialize(level_bin[0]).content).decompress()) portraits = [] for kao_i in range(0, SUBENTRIES): portraits.append(kao.get(0, kao_i)) portraits2 = [] for kao_i in range(0, SUBENTRIES): portraits2.append(kao.get(600, kao_i)) # IMPORT CHARMANDER assert monster_xml_import(charmander_xml, md_gender1, md_gender2, names, moveset, moveset2, stats, portraits, portraits2) == config.game_version bulbasaur_xml = monster_xml_export(config.game_version, md_gender1, md_gender2, names, moveset, moveset2, stats, portraits, portraits2) write_xml(bulbasaur_xml, 'bulbasaur_but_actually_charmander.xml') with open(os.path.join(output_dir, '0004_Charmander.xml')) as f_char: with open(os.path.join( output_dir, 'bulbasaur_but_actually_charmander.xml')) as f_bulba: assert f_char.read() == f_bulba.read()