import Package from './Package'; import XmlNode, {ComponentNode} from './XmlNode'; import Setting from '../Setting'; import Path from '../Path'; import StringUtils from '../StringUtils'; import {fgui} from './FguiComponentType'; import {ResourceComponentType} from './ResourceComponentType'; import TsPathOut from '../export/ts_layabox2/TsPathOut'; import PathHelper from '../PathHelper'; import Ts2PathOut from '../export/ts_layabox2merge/Ts2PathOut'; import Ts3PathOut from '../export/ts_layabox2mergejs/Ts3PathOut'; /** 资源url信息 */ export class AssetUrlInfo { public pkg: string = ""; public src: string = ""; static CreateByUrl(url: string) { if(url && url.trim() != "") { var info = new AssetUrlInfo(); info.pkg = url.substr(5, 8); info.src = url.substring(5 + 8); return info; } return null; } static CreateByGearUrl(gearUrl: string) { var list = []; var arr = gearUrl.split('|'); for(var i = 0; i < arr.length; i ++) { list.push(this.CreateByUrl(arr[i])); } return list; } static Create(pkg: string, src: string) { var info = new AssetUrlInfo(); info.pkg = pkg; info.src = src; return info; } } export default class ResourceComponent { constructor(obj: Object) { let keys = Object.keys(obj); for(let key of keys) { this[key] = obj[key]; } } public package: Package; /** 资源类型 */ public type: ResourceComponentType; /** id: 9nrl0 */ public id: string; /** 名称: GMMain.xml */ public name: string; /** 相对包的目录路径: / */ public path: string; /** 全路径: ../../fgui//assets/GameGM/GMMain.xml */ public pathFull: string; /** 是否设置为导出 */ public exported: boolean = false; /** 继承的类名: fgui.ExtendType.Component */ public extention: string; /** 控制器列表 */ controllerList: XmlNode[] = new Array(); /** 动效列表 */ transitionList: XmlNode[] = new Array(); /** 显示列表 */ displayList: XmlNode[] = new Array(); /** 显示列表--Component */ componentNodeList: ComponentNode[] = new Array(); /** 依赖的包列表 */ dependPackageList: Package[] = new Array(); /** 被依赖的组件列表 */ beDependList: ResourceComponent[] = new Array(); /** 是否被导出组件依赖 */ public beenDependentorExtported: boolean = false; /** 依赖的资源列表 */ dependAssetUrlList: AssetUrlInfo[] = []; public AddDependAssetUrlInfo(item: AssetUrlInfo | AssetUrlInfo[]) { if(item) { if(item instanceof Array) { for(var ii of item) { if(ii == null) { // console.error(ii); // console.trace("添加的依赖是空的"); continue; } this.dependAssetUrlList.push(ii); } } else { this.dependAssetUrlList.push(item); } } } public AddDependPackage(pkg: Package) { if(this.dependPackageList.length == 0) this.dependPackageList.push(this.package); if(this.dependPackageList.findIndex(function(v){return v.id == pkg.id}) == -1) this.dependPackageList.push(pkg); } public AddNode(node: ComponentNode) { node.parent = this; this.componentNodeList.push(node); } public get URL(): string { return `ui://${this.package.id}${this.id}`; } static EnableRegex: RegExp = new RegExp(/^[A-Za-z_]+[A-Za-z0-9_]*/); public get classNameIsEnable(): boolean { return ResourceComponent.EnableRegex.test(this.className); } public get isIgnore(): boolean { if(!this.package.genCode) return true; if(this.name.startsWith('_')) return true; if(PathHelper.CheckPathDirFirst(this.path)) { return true; } for(var exclude of this.package.genCodeExcludedArr) { if(this.path.indexOf(exclude) != -1) { return true; } } if(Setting.Options.codeIgnorNCode) { if(this.pathFull.toLowerCase().indexOf(Setting.Options.codeIgnorNCodeFlag.toLowerCase()) != -1) { return true; } } if(Setting.Options.codeIgnorNoExported) { if(!this.exported) { if(Setting.Options.codeExportDepend) { if(!this.beenDependentorExtported) { return true; } } else { return true; } } } if(Setting.Options.codeIgnorIllegalClassName) { return !this.classNameIsEnable; } else { return false; } } private _soundKey: string; public get soundKey(): string { if(!this._soundKey) { let key = Path.GetFileNameWithoutExtension(this.name); key = key.replace(/[^A-Za-z0-9_]/g,"_") this._soundKey = key; } return this._soundKey; } private _className: string; public get className(): string { if(!this._className) { let clsName = Path.GetFileNameWithoutExtension(this.name); if(!Setting.Options.codeIgnorIllegalClassName) { clsName = clsName.replace(/[^A-Za-z0-9_]/,"") } clsName = StringUtils.FirstUpper(clsName); if(Setting.Options.codeClassNamePrefix) { clsName = Setting.Options.codeClassNamePrefix + clsName; } this._className = clsName; } return this._className; } public set className(name: string) { this._className = name; } private _structImports: any[]; public get structImports(): any[] { if(!this._structImports) { this._structImports = []; this._structImports.push(Path.GetImportParams(this)); } return this._structImports; } private _extendsImports: any[]; public get extendsImports(): any[] { if(!this._extendsImports) { this._extendsImports = [Path.GetImportParams(this, true)]; let clsName = []; for (const com of this.componentNodeList) { let res = com.resourceComponent; if(res && res.classNameExtend == "PlaneBg") { res.isIgnore } if(res && !com.isIgnore && clsName.indexOf(res.classNameExtend) == -1) { this._extendsImports.push(Path.GetImportParams(res,true)); clsName.push(res.classNameExtend); } } } return this._extendsImports; } private _extendClassName: string; public get extendClassName(): string { if(!this._extendClassName) { this._extendClassName = fgui.ExtendType.GetExtendClass(this.extention); } return this._extendClassName; } public set extendClassName(name: string) { this._extendClassName = name; } public get packageName(): string { return this.package.name; } public get nameSpace(): string { return this.package.nameSpace; } public get classNameFGUI(): string { return this.extendClassName; } public get classNameExtend(): string { return this.className; } public get classNameStruct(): string { return this.className + "Struct"; } // 类全名,包含命名空间 public get classNameFull(): string { return this.nameSpace + "." + this.classNameExtend; } // 保存的代码路径--Struct public get tsStructPath(): string { return TsPathOut.ComponentStruct.format(this.package.codeFolderName, this.className); } // 保存的代码路径--Extend public get tsExtendPath(): string { return TsPathOut.ComponentExtend.format(this.package.codeFolderName, this.className); } // 保存的代码路径--Extend public get ts2ExtendPath(): string { return Ts2PathOut.ComponentExtend.format(this.package.codeFolderName, this.className); } // 保存的代码路径--Extend public get ts3ExtendPath(): string { return Ts3PathOut.ComponentExtend.format(this.package.codeFolderName, this.className); } }