import ResourceComponent from "../../data/ResourceComponent"; import XmlNode from '../../data/XmlNode'; import TsPathTemplate from "./TsPathTemplate"; import Path from "../../Path"; import TsPathOut from "./TsPathOut"; import {TemplateSystem} from "../../TemplateSystem"; import PathHelper from "../../PathHelper"; export interface ILines { } export default class TsExportComponent { public com: ResourceComponent; constructor(com: ResourceComponent) { this.com = com; } public name: string; public Export() { this.name = this.com.className; this.ExportStruct(); this.ExportExtend(); } /// /// 导出结构 /// private ExportStruct() { let com = this.com; let imports: any[] = []; let fields: any[] = []; let setControllerList: any[] = []; let setTransitionList: any[] = []; let setDisplayList: any[] = []; // fields for(let node of this.com.controllerList) { if(node.isIgnore) continue; let line = [node.fieldName,node.type]; fields.push(line); let lineCtrl = [node.fieldName, node.name]; setControllerList.push(lineCtrl); } for (let node of this.com.transitionList) { if (node.isIgnore) continue; let line = [node.fieldName, node.type]; fields.push(line); let lineTrans = [node.fieldName, node.name]; setTransitionList.push(lineTrans); } for(let node of this.com.displayList) { if(node.isIgnore) continue; let lines = [node.fieldName,node.type]; fields.push(lines); let lineDis = [node.fieldName,node.name,node.type]; setDisplayList.push(lineDis); } for(let node of this.com.componentNodeList) { if(node.isIgnore) continue; let type = node.GetTypeForLaya2(this.com); let lines = [node.fieldName, type]; fields.push(lines); let lines2 = [node.fieldName,node.name, type]; setDisplayList.push(lines2); } // dependPackages let dependPackages = ""; let dependPackageList: string[] = new Array(); for (let pkg of this.com.dependPackageList) { dependPackageList.push(`\"${pkg.name}\"`); } dependPackages = dependPackageList.toString(); // imports let importDict = new Map(); for(let node of this.com.componentNodeList) { if (node.isIgnore) continue; if (node.resourceComponent == null) continue; if (node.resourceComponent.isIgnore) continue; if (!importDict.has(node.resourceComponent.classNameExtend)) { importDict.set(node.resourceComponent.classNameExtend, true); let lines = [node.resourceComponent.classNameExtend, node.GetImportPathForStruct(com) ]; imports.push(lines); } } imports.push([ com.classNameExtend, PathHelper.GetImportPath(com.tsStructPath, com.tsExtendPath)]); let template = new TemplateSystem(Path.ReadTxt(TsPathTemplate.ComponentStruct)); template.AddVariable("imports", imports); template.AddVariable("classNameFGUI", com.classNameFGUI); template.AddVariable("classNameStruct", com.classNameStruct); template.AddVariable("classNameExtend", com.classNameExtend); template.AddVariable("packagename", com.packageName); template.AddVariable("dependPackages", dependPackages); template.AddVariable("comname", Path.GetFileNameWithoutExtension(com.name)); template.AddVariable("URL", com.URL); template.AddVariable("fields", fields); template.AddVariable("setControllerList", setControllerList); template.AddVariable("setDisplayList", setDisplayList); template.AddVariable("setTransitionList", setTransitionList); let content = template.Parse(); let structPath = TsPathOut.ComponentStruct; let folderName = com.package.codeFolderName; let path = structPath.format(folderName,this.name); Path.CheckPath(path); Path.WriteTxt(path, content); } /// /// 导出扩展 /// private ExportExtend() { let com = this.com; let path = TsPathOut.ComponentExtend.format(com.package.codeFolderName,this.name); if(Path.IsFile(path)) return; // imports var imports = []; var lines = [ com.classNameStruct, PathHelper.GetImportPath(com.tsExtendPath, com.tsStructPath) ]; imports.push(lines); let template: TemplateSystem = new TemplateSystem(Path.ReadTxt(TsPathTemplate.ComponentExtend)); template.AddVariable("imports", imports); template.AddVariable("classNameFGUI", com.classNameFGUI); template.AddVariable("classNameStruct", com.classNameStruct); template.AddVariable("classNameExtend", com.classNameExtend); let content = template.Parse(); Path.CheckPath(path); Path.WriteTxt(path, content); } }