(comp: FGUIComponent)
| 113 | } |
| 114 | |
| 115 | private async _doLoad(comp: FGUIComponent): Promise<void> { |
| 116 | const packageRef = comp.packageGuid; |
| 117 | |
| 118 | // Dispose previous content before loading new package |
| 119 | comp.dispose(); |
| 120 | |
| 121 | try { |
| 122 | // Check if packageRef is a path (contains / or . before extension) or a GUID |
| 123 | // GUID format: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx |
| 124 | // Path format: assets/ui/Bag.fui or similar |
| 125 | const isPath = packageRef.includes('/') || packageRef.includes('\\') || packageRef.endsWith('.fui'); |
| 126 | const result = isPath |
| 127 | ? await this._assetManager!.loadAssetByPath<IFUIAsset>(packageRef) |
| 128 | : await this._assetManager!.loadAsset<IFUIAsset>(packageRef); |
| 129 | if (!result || !result.asset) { |
| 130 | return; |
| 131 | } |
| 132 | |
| 133 | const fuiAsset = result.asset; |
| 134 | |
| 135 | if (fuiAsset.package) { |
| 136 | const width = comp.width > 0 ? comp.width : 1920; |
| 137 | const height = comp.height > 0 ? comp.height : 1080; |
| 138 | comp.initRoot(width, height); |
| 139 | comp.setLoadedPackage(fuiAsset.package); |
| 140 | |
| 141 | if (comp.componentName) { |
| 142 | comp.createComponent(comp.componentName); |
| 143 | } |
| 144 | } else { |
| 145 | const asset = fuiAsset as unknown; |
| 146 | let data: ArrayBuffer | null = null; |
| 147 | |
| 148 | if (asset instanceof ArrayBuffer) { |
| 149 | data = asset; |
| 150 | } else if (typeof asset === 'object' && asset !== null && 'data' in asset && (asset as { data: ArrayBuffer }).data instanceof ArrayBuffer) { |
| 151 | data = (asset as { data: ArrayBuffer }).data; |
| 152 | } else if (typeof asset === 'object' && asset !== null && 'buffer' in asset) { |
| 153 | data = (asset as { buffer: ArrayBuffer }).buffer; |
| 154 | } |
| 155 | |
| 156 | if (!data) { |
| 157 | return; |
| 158 | } |
| 159 | |
| 160 | const width = comp.width > 0 ? comp.width : 1920; |
| 161 | const height = comp.height > 0 ? comp.height : 1080; |
| 162 | comp.initRoot(width, height); |
| 163 | comp.loadPackage(packageRef, data); |
| 164 | |
| 165 | if (comp.componentName) { |
| 166 | comp.createComponent(comp.componentName); |
| 167 | } |
| 168 | } |
| 169 | |
| 170 | const renderSystem = getFGUIRenderSystem(); |
| 171 | if (renderSystem && comp.isReady) { |
| 172 | renderSystem.registerComponent(comp); |
no test coverage detected