import Package from "../../data/Package"; import Path from '../../Path'; import { TemplateSystem } from "../../TemplateSystem"; import PathHelper from "../../PathHelper"; import FairyManager from "../../reader/FairyManager"; import Ts2PathTemplate from "./Ts2PathTemplate"; import Ts2ExportComponent from "./Ts2ExportComponent"; import Ts2PathOut from "./Ts2PathOut"; import Setting from "../../Setting"; import { FileUtils } from "../../FileUtils"; import Ts2ExportGuiPackageNames from "./Ts2ExportGuiPackageNames"; import Ts2ExportGuiSoundKey from "./Ts2ExportGuiSoundKey"; export default class Ts2ExportAll { fairyManager: FairyManager; get packageList() { return this.fairyManager.packageList; } constructor(fairyManager: FairyManager) { this.fairyManager = fairyManager; } componentList: Ts2ExportComponent[] = []; importContext: string; binderContext: string; public async ExportAll() { Path.Delete(Ts2PathOut.genCodePath); Path.CheckPath(Ts2PathOut.genCodePath, false) this.ExportTSComponent(); this.ExportTSImports(); this.WriteGuiStruct(); Ts2ExportGuiPackageNames.Export(this.packageList); this.ExportTSExportSoundKey(); await this.CopyToClient(); } ExportTSExportSoundKey() { let sound: Package = this.fairyManager.GetPackageByName(Setting.Options.soundPackageName); if(sound != null) { Ts2ExportGuiSoundKey.Export(sound); } } public async CopyToClient() { var s = Ts2PathOut.GeneratesPath; var t = Setting.Options.outCodePath + "/Generates/"; FileUtils.copy(s, t, true); var s = Ts2PathOut.ExtendsPath; var t = Setting.Options.outCodePath + "/Extends/"; FileUtils.copy(s, t, false); FileUtils.contrastCleaningAskHas = false; FileUtils.contrastCleaningAskResult = false; // 清理删除了的组件 var s = Setting.Options.outCodePath + "/Generates/"; var t = Ts2PathOut.GeneratesPath; await FileUtils.contrastCleaning(s, t, false, true); var s = Setting.Options.outCodePath + "/Extends/"; var t = Ts2PathOut.ExtendsPath; await FileUtils.contrastCleaning(s, t, false, true); } private WriteGuiStruct() { var content = ""; for(var com of this.componentList) { content += com.structClassContent; } content += this.importContext; content += this.binderContext; let path = Ts2PathOut.FguiStruct; Path.CheckPath(path); Path.WriteTxt(path, content); } private ExportTSComponent() { for(let pkg of this.packageList) { if(!pkg.genCode) { continue; } for(let component of pkg.ComponentList) { if(component.isIgnore) continue; let ept = new Ts2ExportComponent(component); ept.Export(); this.componentList.push(ept); } } } private ExportTSImports() { var guiStructFilepath = Ts2PathOut.FguiStruct; var tmpl = Path.ReadTxt(Ts2PathTemplate.FguiBinder) let coms = []; let imports = []; let importDict = new Map(); for(let pkg of this.packageList) { if(!pkg.genCode) { continue; } for(let component of pkg.ComponentList) { if (component.isIgnore) { continue; } coms.push([ component.classNameStruct , component.classNameExtend]); if (!importDict.has(component.classNameExtend)) { importDict.set(component.classNameExtend, true); imports.push([ component.classNameExtend, PathHelper.GetImportPath(guiStructFilepath, component.ts2ExtendPath) ]); } } } var template: TemplateSystem = new TemplateSystem(Path.ReadTxt(Ts2PathTemplate.ComponentStructImport)); template.AddVariable("imports",imports); var content = template.Parse(); this.importContext = content; var template: TemplateSystem = new TemplateSystem(Path.ReadTxt(Ts2PathTemplate.FguiBinder)); template.AddVariable("coms",coms); var content = template.Parse(); this.binderContext = content; } }