* Load package from buffer * 从缓冲区加载包
(buffer: ByteBuffer)
| 268 | * 从缓冲区加载包 |
| 269 | */ |
| 270 | private loadPackage(buffer: ByteBuffer): void { |
| 271 | if (buffer.getUint32() !== PACKAGE_MAGIC) { |
| 272 | throw new Error('FairyGUI: invalid package format in \'' + this._resKey + '\''); |
| 273 | } |
| 274 | |
| 275 | buffer.version = buffer.getInt32(); |
| 276 | const compressed = buffer.readBool(); |
| 277 | this.id = buffer.readUTFString(); |
| 278 | this.name = buffer.readUTFString(); |
| 279 | buffer.skip(20); |
| 280 | |
| 281 | // Handle compressed data |
| 282 | if (compressed) { |
| 283 | // Note: Compression requires pako or similar library |
| 284 | // For now, we'll throw an error if the package is compressed |
| 285 | throw new Error('FairyGUI: compressed packages are not supported yet'); |
| 286 | } |
| 287 | |
| 288 | const ver2 = buffer.version >= 2; |
| 289 | const indexTablePos = buffer.pos; |
| 290 | |
| 291 | // Read string table |
| 292 | buffer.seek(indexTablePos, 4); |
| 293 | const strCount = buffer.getInt32(); |
| 294 | const stringTable: string[] = []; |
| 295 | for (let i = 0; i < strCount; i++) { |
| 296 | stringTable[i] = buffer.readUTFString(); |
| 297 | } |
| 298 | buffer.stringTable = stringTable; |
| 299 | |
| 300 | // Read custom strings (version 2+) |
| 301 | if (buffer.seek(indexTablePos, 5)) { |
| 302 | const customCount = buffer.readInt32(); |
| 303 | for (let i = 0; i < customCount; i++) { |
| 304 | const index = buffer.readUint16(); |
| 305 | const len = buffer.readInt32(); |
| 306 | stringTable[index] = buffer.getCustomString(len); |
| 307 | } |
| 308 | } |
| 309 | |
| 310 | // Read dependencies |
| 311 | buffer.seek(indexTablePos, 0); |
| 312 | const depCount = buffer.getInt16(); |
| 313 | for (let i = 0; i < depCount; i++) { |
| 314 | this._dependencies.push({ |
| 315 | id: buffer.readS(), |
| 316 | name: buffer.readS() |
| 317 | }); |
| 318 | } |
| 319 | |
| 320 | // Read branches (version 2+) |
| 321 | let branchIncluded = false; |
| 322 | if (ver2) { |
| 323 | const branchCount = buffer.getInt16(); |
| 324 | if (branchCount > 0) { |
| 325 | this._branches = buffer.readSArray(branchCount); |
| 326 | if (UIPackage._branch) { |
| 327 | this._branchIndex = this._branches.indexOf(UIPackage._branch); |
no test coverage detected