From 51afab39b33dcabfc2b795f5d54b43c0089a2eeb Mon Sep 17 00:00:00 2001 From: Patrick Organ Date: Wed, 15 Mar 2023 09:16:45 -0400 Subject: [PATCH] add loadBytes() support --- src/Assets.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/Assets.ts b/src/Assets.ts index 60afa5f..575fb7d 100644 --- a/src/Assets.ts +++ b/src/Assets.ts @@ -110,6 +110,25 @@ export class Assets { return {}; } + /** + * Loads a file from a script asset URL using `p5.loadBytes()`, and returns an object with a `bytes` property. + * @param {string} path + * @returns {object} an object whose 'bytes' property will be the loaded buffer + */ + public async loadBytes(path: string) { + path = getMerakiScriptFileAssetsUrl() + this.sanitizeUrl(path); + + try { + // @ts-ignore + // eslint-disable-next-line no-undef + return loadBytes(path); + } catch (e) { + // + } + + return { bytes: [] }; + } + /** * Loads an image from the `path` script asset URL and creates a `p5.Image` from it. * @param {string} path