def outfile_name(res, ext='.json'): name = 'UNKNOWN' if '_Name' not in res else res['_Name'] if '_BaseId' in res: return get_valid_filename( f'{res["_BaseId"]}_{res["_VariationId"]:02}_{name}{ext}') else: return get_valid_filename(f'{res["_Id"]:02}_{name}{ext}')
PARAM_GROUP = re.compile(r'([^\d]+)_\d{2}_\d{2}_E_?\d{2}') def export_all_to_folder(self, out_dir='./out', ext='.json', exclude_falsy=True): # super().export_all_to_folder(out_dir, ext, fn_mode='a', exclude_falsy=exclude_falsy, full_actions=False) out_dir = os.path.join(out_dir, 'enemies') all_res = self.get_all(exclude_falsy=exclude_falsy) check_target_path(out_dir) sorted_res = defaultdict(lambda: []) for res in tqdm(all_res, desc='enemies'): if '_ParamGroupName' in res: if (match := self.PARAM_GROUP.match(res['_ParamGroupName'])): sorted_res[match.group(1)].append( self.process_result(res, exclude_falsy=exclude_falsy)) else: sorted_res[res['_ParamGroupName'].split('_', 1)[0]].append( self.process_result(res, exclude_falsy=exclude_falsy)) for group_name, res_list in sorted_res.items(): out_name = get_valid_filename(f'{group_name}{ext}') output = os.path.join(out_dir, out_name) with open(output, 'w', newline='', encoding='utf-8') as fp: json.dump(res_list, fp, indent=2, ensure_ascii=False) if __name__ == '__main__': index = DBViewIndex() view = EnemyParam(index) view.export_all_to_folder()
def outfile_name(res, ext='.json'): name = 'UNKNOWN' if '_Name' not in res else res['_Name'] return get_valid_filename(f'{res["_Id"]:02}_{name}{ext}')