Skip to content

Commit b46de8d

Browse files
committed
feat: remove empty hex
1 parent 044f225 commit b46de8d

File tree

3 files changed

+7
-4
lines changed

3 files changed

+7
-4
lines changed

src/classes/sprite.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export class Sprite extends AssetBase {
4747
r.align(4);
4848
}
4949
if (version[0] >= 2017) {
50-
this.renderDataKey = bufferToHex(r.readBuffer(16 + 8));
50+
this.renderDataKey = bufferToHex(r.readBuffer(24), true);
5151
this.atlasTags = r.readAlignedStringArray();
5252
this.spriteAtlas = new PPtr(this.__info, r);
5353
}

src/classes/spriteAtlas.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export class SpriteAtlas extends AssetBase {
3333

3434
const renderDataMapSize = r.readUInt32();
3535
for (let i = 0; i < renderDataMapSize; i++) {
36-
const key = bufferToHex(r.readBuffer(16 + 8));
36+
const key = bufferToHex(r.readBuffer(24), true);
3737
const data = new SpriteAtlasData(this.__info, r);
3838
this.renderDataMap.set(key, data);
3939
}

src/utils/buffer.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,11 @@ export const hexToUInt8Array = (hex: string) => {
1717
return new Uint8Array((hex.match(/[\da-f]{2}/gi) || []).map(h => parseInt(h, 16)));
1818
};
1919

20-
export const bufferToHex = (buffer: ArrayBuffer) =>
21-
[...new Uint8Array(buffer)].map(x => x.toString(16).padStart(2, '0')).join('');
20+
export const bufferToHex = (buffer: ArrayBuffer, allZeroToEmpty = false) => {
21+
const arr = [...new Uint8Array(buffer)];
22+
if (allZeroToEmpty && arr.every(v => !v)) return '';
23+
return arr.map(x => x.toString(16).padStart(2, '0')).join('');
24+
};
2225

2326
export const bufferToString = (data: AllowSharedBufferSource, encoding?: string) =>
2427
new TextDecoder(encoding).decode(data);

0 commit comments

Comments
 (0)