Skip to content

Commit 9c2c5b5

Browse files
committed
fix: dump
1 parent ca075a6 commit 9c2c5b5

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

src/classes/base.ts

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,35 @@ import type { ArrayBufferReader } from '../utils/reader';
22
import type { ObjectInfo } from './types';
33
import { AssetType } from './types';
44

5-
const dumpObject = (obj: any, isTop = false): any => {
5+
const dumpObject = (obj: any): any => {
66
if (typeof obj === 'object') {
7-
if (!isTop && typeof obj.dump === 'function') return obj.dump();
87
if (Array.isArray(obj)) return obj.map(item => dumpObject(item));
8+
if (obj instanceof Map) {
9+
return Object.fromEntries(Array.from(obj.entries()).map(([k, v]) => [k, dumpObject(v)]));
10+
}
11+
if (obj instanceof Set) {
12+
return Array.from(obj.values()).map(item => dumpObject(item));
13+
}
914

1015
const result: any = {};
16+
1117
const className: string | undefined = obj.__class;
1218
if (className) result.__class = className;
19+
1320
for (const key in obj) {
14-
if (key.startsWith('__') || typeof obj[key] === 'function') continue;
15-
result[key] = dumpObject(obj[key]);
21+
const cur = obj[key];
22+
if (
23+
key.startsWith('__') ||
24+
typeof cur === 'function' ||
25+
cur instanceof ArrayBuffer ||
26+
cur instanceof Uint8Array ||
27+
(typeof cur === 'object' && cur.__doNotDump)
28+
) {
29+
continue;
30+
}
31+
result[key] = typeof cur?.dump === 'function' ? cur.dump() : dumpObject(cur);
1632
}
33+
1734
return result;
1835
}
1936

@@ -45,6 +62,6 @@ export abstract class AssetBase {
4562
}
4663

4764
dump(): Record<string, any> {
48-
return dumpObject(this, true);
65+
return dumpObject(this);
4966
}
5067
}

src/classes/texture2d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ export class Texture2D extends AssetBase {
169169
}
170170

171171
class TextureDecoder {
172+
protected readonly __doNotDump = true;
172173
private decoded = false;
173174

174175
constructor(

0 commit comments

Comments
 (0)