Skip to content

Commit

Permalink
update dist files
Browse files Browse the repository at this point in the history
  • Loading branch information
obiot committed Jul 9, 2022
1 parent c82b9ad commit 3f5ef9e
Show file tree
Hide file tree
Showing 4 changed files with 242 additions and 97 deletions.
130 changes: 96 additions & 34 deletions dist/melonjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* http://www.melonjs.org
* melonjs is licensed under the MIT License.
* http://www.opensource.org/licenses/mit-license
* @copyright (C) 2011 - 2022 Olivier Biot
* @copyright (C) 2011 - 2022 Olivier Biot (AltByte Pte Ltd)
*/
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
Expand Down Expand Up @@ -1270,13 +1270,26 @@
}
return res;
}
/**
* returns true if the given string is a data url in the `data:[<mediatype>][;base64],<data>` format.
* (this will not test the validity of the Data or Base64 encoding)
* @public
* @memberof utils.string
* @name isDataUrl
* @param {string} str the string (url) to be tested
* @returns {boolean} true if the string is a data url
*/
function isDataUrl(str) {
return /^data:(.+);base64,(.+)$/.test(str);
}

var stringUtils = /*#__PURE__*/Object.freeze({
__proto__: null,
capitalize: capitalize,
isNumeric: isNumeric,
isBoolean: isBoolean,
toHex: toHex$1
toHex: toHex$1,
isDataUrl: isDataUrl
});

/**
Expand Down Expand Up @@ -5430,6 +5443,7 @@
/**
* True if the browser supports Touch Events
* @name touchEvent
* @memberof device
* @type {boolean}
* @readonly
* @public
Expand Down Expand Up @@ -13867,9 +13881,14 @@
if (audioExts.length === 0) {
throw new Error("target audio extension(s) should be set through me.audio.init() before calling the preloader.");
}
for (var i = 0; i < audioExts.length; i++) {
urls.push(sound.src + sound.name + "." + audioExts[i] + loader.nocache);
if (isDataUrl(sound.src) === true) {
urls.push(sound.src);
} else {
for (var i = 0; i < audioExts.length; i++) {
urls.push(sound.src + sound.name + "." + audioExts[i] + loader.nocache);
}
}

audioTracks[sound.name] = new howler.Howl({
src : urls,
volume : howler.Howler.volume(),
Expand Down Expand Up @@ -23134,21 +23153,29 @@
barHeight
), 1);

// TODO: create a sprite or texture from a Base64 encoded image
var image = new Image();
image.src = img;
// load the melonJS logo
loader.load({name: "melonjs_logo", type: "image", src: img});

// melonJS logo
world.addChild(new Sprite(
renderer.getWidth() / 2,
renderer.getHeight() / 2, {
image : image,
image : "melonjs_logo",
framewidth : 256,
frameheight : 256
}), 2
);
};

/**
* Called by engine before deleting the object
* @ignore
*/
DefaultLoadingScreen.prototype.onDestroyEvent = function onDestroyEvent () {
// cancel the callback
loader.unload({name: "melonjs_logo", type:"image"});
};

return DefaultLoadingScreen;
}(Stage));

Expand Down Expand Up @@ -28224,7 +28251,7 @@
function checkLoadStatus(onload) {
if (loadCount === resourceCount) {
// wait 1/2s and execute callback (cheap workaround to ensure everything is loaded)
if (onload || loader.onload) {
if (typeof onload === "function" || loader.onload) {
// make sure we clear the timer
clearTimeout(timerId);
// trigger the onload callback
Expand Down Expand Up @@ -28259,8 +28286,12 @@
function preloadImage(img, onload, onerror) {
// create new Image object and add to list
imgList[img.name] = new Image();
imgList[img.name].onload = onload;
imgList[img.name].onerror = onerror;
if (typeof onload === "function") {
imgList[img.name].onload = onload;
}
if (typeof onerror === "function") {
imgList[img.name].onerror = onerror;
}
if (typeof (loader.crossOrigin) === "string") {
imgList[img.name].crossOrigin = loader.crossOrigin;
}
Expand All @@ -28275,17 +28306,30 @@
* @ignore
*/
function preloadFontFace(data, onload, onerror) {

if (isDataUrl(data.src) === true) {
// make sure it in the `url(data:[<mediatype>][;base64],<data>)` format as expected by FontFace
if (!data.src.startsWith("url(")) {
data.src = "url(" + data.src + ")";
}
}

var font = new FontFace(data.name, data.src);

// loading promise
font.load().then(function () {
// apply the font after the font has finished downloading
document.fonts.add(font);
document.body.style.fontFamily = data.name;
// onloaded callback
onload();
if (typeof onload === "function") {
// onloaded callback
onload();
}
}, function () {
// rejected
onerror(data.name);
if (typeof onerror === "function") {
// rejected
onerror(data.name);
}
});
}
/**
Expand All @@ -28310,7 +28354,9 @@
//if the data is in the tmxData object, don't get it via a XMLHTTPRequest
if (tmxData.data) {
addToTMXList(tmxData.data);
onload();
if (typeof onload === "function") {
onload();
}
return;
}

Expand Down Expand Up @@ -28381,9 +28427,11 @@
addToTMXList(result);

// fire the callback
onload();
if (typeof onload === "function") {
onload();
}
}
else {
else if (typeof onerror === "function") {
onerror(tmxData.name);
}
}
Expand Down Expand Up @@ -28414,10 +28462,12 @@
if ((xmlhttp.status === 200) || ((xmlhttp.status === 0) && xmlhttp.responseText)) {
// get the Texture Packer Atlas content
jsonList[data.name] = JSON.parse(xmlhttp.responseText);
// fire the callback
onload();
if (typeof onload === "function") {
// fire the callback
onload();
}
}
else {
else if (typeof onerror === "function") {
onerror(data.name);
}
}
Expand Down Expand Up @@ -28446,8 +28496,11 @@
buffer[i] = String.fromCharCode(byteArray[i]);
}
binList[data.name] = buffer.join("");
// callback
onload();
if (typeof onload === "function") {
// callback
onload();
}

}
};
httpReq.send();
Expand All @@ -28466,15 +28519,19 @@
}
script.defer = true;

script.onload = function () {
// callback
onload();
};
if (typeof onload === "function") {
script.onload = function () {
// callback
onload();
};
}

script.onerror = function () {
// callback
onerror(data.name);
};
if (typeof onerror === "function") {
script.onerror = function () {
// callback
onerror(data.name);
};
}

document.getElementsByTagName("body")[0].appendChild(script);
}
Expand Down Expand Up @@ -28640,6 +28697,8 @@
* {name: "tileset-platformer", type: "image", src: "data/map/tileset.png"},
* // PNG packed texture
* {name: "texture", type:"image", src: "data/gfx/texture.png"}
* // PNG base64 encoded image
* {name: "texture", type:"image", src: "data:image/png;base64,iVBORw0KAAAQAAAAEACA..."}
* // TSX file
* {name: "meta_tiles", type: "tsx", src: "data/map/meta_tiles.tsx"},
* // TMX level (XML & JSON)
Expand All @@ -28650,6 +28709,8 @@
* // audio resources
* {name: "bgmusic", type: "audio", src: "data/audio/"},
* {name: "cling", type: "audio", src: "data/audio/"},
* // base64 encoded audio resources
* {name: "band", type: "audio", src: "data:audio/wav;base64,..."},
* // binary file
* {name: "ymTrack", type: "binary", src: "data/audio/main.ym"},
* // JSON file (used for texturePacker)
Expand Down Expand Up @@ -28698,13 +28759,14 @@
* @param {string} res.type "audio", binary", "image", "json", "tmx", "tsx"
* @param {string} res.src path and/or file name of the resource (for audio assets only the path is required)
* @param {boolean} [res.stream] Set to true to force HTML5 Audio, which allows not to wait for large file to be downloaded before playing.
* @param {Function} onload function to be called when the resource is loaded
* @param {Function} onerror function to be called in case of error
* @param {Function} [onload] function to be called when the resource is loaded
* @param {Function} [onerror] function to be called in case of error
* @returns {number} the amount of corresponding resource to be preloaded
* @example
* // load an image asset
* me.loader.load({name: "avatar", type:"image", src: "data/avatar.png"}, this.onload.bind(this), this.onerror.bind(this));
*
* // load a base64 image asset
* me.loader.load({name: "avatar", type:"image", src: "data:image/png;base64,iVBORw0KAAAQAAAAEACA..."};
* // start loading music
* me.loader.load({
* name : "bgmusic",
Expand Down
6 changes: 3 additions & 3 deletions dist/melonjs.min.js

Large diffs are not rendered by default.

37 changes: 29 additions & 8 deletions dist/melonjs.module.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10446,6 +10446,8 @@ export namespace loader {
* {name: "tileset-platformer", type: "image", src: "data/map/tileset.png"},
* // PNG packed texture
* {name: "texture", type:"image", src: "data/gfx/texture.png"}
* // PNG base64 encoded image
* {name: "texture", type:"image", src: "data:image/png;base64,iVBORw0KAAAQAAAAEACA..."}
* // TSX file
* {name: "meta_tiles", type: "tsx", src: "data/map/meta_tiles.tsx"},
* // TMX level (XML & JSON)
Expand All @@ -10456,6 +10458,8 @@ export namespace loader {
* // audio resources
* {name: "bgmusic", type: "audio", src: "data/audio/"},
* {name: "cling", type: "audio", src: "data/audio/"},
* // base64 encoded audio resources
* {name: "band", type: "audio", src: "data:audio/wav;base64,..."},
* // binary file
* {name: "ymTrack", type: "binary", src: "data/audio/main.ym"},
* // JSON file (used for texturePacker)
Expand Down Expand Up @@ -10493,6 +10497,8 @@ export namespace loader {
* {name: "tileset-platformer", type: "image", src: "data/map/tileset.png"},
* // PNG packed texture
* {name: "texture", type:"image", src: "data/gfx/texture.png"}
* // PNG base64 encoded image
* {name: "texture", type:"image", src: "data:image/png;base64,iVBORw0KAAAQAAAAEACA..."}
* // TSX file
* {name: "meta_tiles", type: "tsx", src: "data/map/meta_tiles.tsx"},
* // TMX level (XML & JSON)
Expand All @@ -10503,6 +10509,8 @@ export namespace loader {
* // audio resources
* {name: "bgmusic", type: "audio", src: "data/audio/"},
* {name: "cling", type: "audio", src: "data/audio/"},
* // base64 encoded audio resources
* {name: "band", type: "audio", src: "data:audio/wav;base64,..."},
* // binary file
* {name: "ymTrack", type: "binary", src: "data/audio/main.ym"},
* // JSON file (used for texturePacker)
Expand Down Expand Up @@ -10532,13 +10540,14 @@ export namespace loader {
* @param {string} res.type "audio", binary", "image", "json", "tmx", "tsx"
* @param {string} res.src path and/or file name of the resource (for audio assets only the path is required)
* @param {boolean} [res.stream] Set to true to force HTML5 Audio, which allows not to wait for large file to be downloaded before playing.
* @param {Function} onload function to be called when the resource is loaded
* @param {Function} onerror function to be called in case of error
* @param {Function} [onload] function to be called when the resource is loaded
* @param {Function} [onerror] function to be called in case of error
* @returns {number} the amount of corresponding resource to be preloaded
* @example
* // load an image asset
* me.loader.load({name: "avatar", type:"image", src: "data/avatar.png"}, this.onload.bind(this), this.onerror.bind(this));
*
* // load a base64 image asset
* me.loader.load({name: "avatar", type:"image", src: "data:image/png;base64,iVBORw0KAAAQAAAAEACA..."};
* // start loading music
* me.loader.load({
* name : "bgmusic",
Expand All @@ -10553,7 +10562,7 @@ export namespace loader {
type: string;
src: string;
stream?: boolean;
}, onload: Function, onerror: Function): number;
}, onload?: Function, onerror?: Function): number;
/**
* Load a single resource (to be used if you need to load additional resource during the game)
* @name load
Expand All @@ -10564,13 +10573,14 @@ export namespace loader {
* @param {string} res.type "audio", binary", "image", "json", "tmx", "tsx"
* @param {string} res.src path and/or file name of the resource (for audio assets only the path is required)
* @param {boolean} [res.stream] Set to true to force HTML5 Audio, which allows not to wait for large file to be downloaded before playing.
* @param {Function} onload function to be called when the resource is loaded
* @param {Function} onerror function to be called in case of error
* @param {Function} [onload] function to be called when the resource is loaded
* @param {Function} [onerror] function to be called in case of error
* @returns {number} the amount of corresponding resource to be preloaded
* @example
* // load an image asset
* me.loader.load({name: "avatar", type:"image", src: "data/avatar.png"}, this.onload.bind(this), this.onerror.bind(this));
*
* // load a base64 image asset
* me.loader.load({name: "avatar", type:"image", src: "data:image/png;base64,iVBORw0KAAAQAAAAEACA..."};
* // start loading music
* me.loader.load({
* name : "bgmusic",
Expand All @@ -10585,7 +10595,7 @@ export namespace loader {
type: string;
src: string;
stream?: boolean;
}, onload: Function, onerror: Function): number;
}, onload?: Function, onerror?: Function): number;
/**
* unload specified resource to free memory
* @name unload
Expand Down Expand Up @@ -12481,6 +12491,7 @@ declare var stringUtils: Readonly<{
isNumeric: typeof isNumeric;
isBoolean: typeof isBoolean;
toHex: typeof toHex$1;
isDataUrl: typeof isDataUrl;
}>;
declare var fnUtils: Readonly<{
__proto__: any;
Expand Down Expand Up @@ -12684,6 +12695,16 @@ declare function isBoolean(str: string): boolean;
* @returns {string} the converted hexadecimal value
*/
declare function toHex$1(str: string): string;
/**
* returns true if the given string is a data url in the `data:[<mediatype>][;base64],<data>` format.
* (this will not test the validity of the Data or Base64 encoding)
* @public
* @memberof utils.string
* @name isDataUrl
* @param {string} str the string (url) to be tested
* @returns {boolean} true if the string is a data url
*/
declare function isDataUrl(str: string): boolean;
/**
* a collection of utility functions
* @namespace utils.function
Expand Down
Loading

0 comments on commit 3f5ef9e

Please sign in to comment.