Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
patinthehat committed Mar 15, 2023
1 parent 5bb16cc commit f8b404b
Showing 1 changed file with 22 additions and 8 deletions.
30 changes: 22 additions & 8 deletions src/Assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ export class Assets {
return parsed.pathname.replaceAll('..', '');
}

/**
* Loads a file from a script asset URL using `p5.loadStrings()`, and returns an array of strings.
* @param {string} path
* @returns {string[]}
*/
public async loadStrings(path: string) {
path = getMerakiScriptDataAssetsUrl() + this.sanitizeUrl(ensureSuffix(path, '/data.txt'));

Expand All @@ -43,6 +48,11 @@ export class Assets {
return '';
}

/**
* Loads a file from a script asset URL using `p5.loadXML()`, and returns an XML object.
* @param {string} path
* @returns {object}
*/
public async loadXML(path: string) {
path = getMerakiScriptDataAssetsUrl() + this.sanitizeUrl(ensureSuffix(path, '/data.xml'));

Expand All @@ -58,10 +68,10 @@ export class Assets {
}

/**
* Loads a JSON file from a script asset URL, and returns an Object.
* Loads a JSON file from a script asset URL using `p5.loadJSON()`, and returns an Object.
* Note that even if the JSON file contains an Array, an Object will be returned with index numbers as keys.
* @param path
* @returns
* @param {string} path
* @returns {object}
*/
public async loadJSON(path: string) {
path = getMerakiScriptDataAssetsUrl() + this.sanitizeUrl(ensureSuffix(path, '/data.json'));
Expand All @@ -78,12 +88,13 @@ export class Assets {
}

/**
* Reads the contents of a script asset URL and creates a p5.Table object with its values.
* Reads the contents of a script asset URL and creates a `p5.Table` object with its values.
* @param {string} path
* @param {string} extension
* @param {string} header
* @param {any} callback
* @param {any} allback
* @param {any} errorCallback
* @returns {import('p5').Table} p5.Table
*/
public async loadTable(path: string, extension: string, header: string, callback: any, errorCallback: any) {
path = getMerakiScriptDataAssetsUrl() + this.sanitizeUrl(ensureSuffix(path, '/data.csv'));
Expand All @@ -100,10 +111,11 @@ export class Assets {
}

/**
* Loads an image from the `path` script asset url and creates a p5.Image from it.
* Loads an image from the `path` script asset URL and creates a `p5.Image` from it.
* @param {string} path
* @param {any} successCallback
* @param {any} failureCallback
* @returns {import('p5').Image} p5.Image
*/
public async loadImage(path: string, successCallback, failureCallback) {
if (!path.startsWith('data:image/png;base64')) {
Expand All @@ -122,10 +134,11 @@ export class Assets {
}

/**
* Loads a font from the `path` script asset url and creates a p5.Font from it.
* Loads a font from the `path` script asset URL and creates a `p5.Font` from it.
* @param {string} path
* @param {any} callback
* @param {any} onError
* @returns {import('p5').Font} p5.Font
*/
public async loadFont(path: string, callback: any, onError: any) {
path = getMerakiScriptFileAssetsUrl() + this.sanitizeUrl(path);
Expand All @@ -142,11 +155,12 @@ export class Assets {
}

/**
* Creates a new p5.Shader object from the provided vertex and fragment shader script asset file urls.
* Creates a new `p5.Shader` object from the provided vertex and fragment shader script asset file urls.
* @param {string} vertFilename
* @param {string} fragFilename
* @param {any} callback
* @param {any} errorCallback
* @returns {import('p5').Shader} p5.Shader
*/
public async loadShader(vertFilename: string, fragFilename: string, callback, errorCallback) {
vertFilename = getMerakiScriptFileAssetsUrl() + this.sanitizeUrl(vertFilename);
Expand Down

0 comments on commit f8b404b

Please sign in to comment.