Skip to content

Commit c3ef5bc

Browse files
committed
Add support for loadTable and loadBytes with old signatures
1 parent 5dccb2b commit c3ef5bc

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

Diff for: src/preload.js

+35
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,41 @@ function addPreload(p5, fn, lifecycles) {
3535
}
3636
}
3737

38+
const prevLoadBytes = fn.loadBytes;
39+
fn.loadBytes = function(...args) {
40+
if (!this._isInPreload) return prevLoadBytes.apply(this, args);
41+
42+
const obj = {};
43+
const promise = prevLoadBytes.apply(this, args).then((result) => {
44+
obj.bytes = result;
45+
});
46+
promises.push(promise);
47+
return obj;
48+
};
49+
50+
const prevLoadTable = fn.loadTable;
51+
fn.loadTable = function(...args) {
52+
if (args.length > 1 && args[1] instanceof String) {
53+
if (args[1] === 'csv') {
54+
args[1] = ',';
55+
} else if (args[1] === 'tsv') {
56+
args[1] = '\t';
57+
} else if (args[1] === 'ssv') {
58+
args[1] = ';';
59+
}
60+
}
61+
if (!this._isInPreload) return prevLoadTable.apply(this, args);
62+
63+
const obj = new p5.Table();
64+
const promise = prevLoadTable.apply(this, args).then((result) => {
65+
for (const key in result) {
66+
obj[key] = result[key];
67+
}
68+
});
69+
promises.push(promise);
70+
return obj;
71+
};
72+
3873
lifecycles.presetup = async function() {
3974
if (!window.preload) return;
4075

0 commit comments

Comments
 (0)