- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
- 84
- 85
- 86
- 87
- 88
- 89
- 90
- 91
- 92
- 93
- 94
- 95
- 96
- 97
- 98
- 99
- 100
- 101
- 102
- 103
- 104
- 105
- 106
- 107
- 108
- 109
- 110
- 111
- 112
- 113
- 114
- 115
- 116
- 117
- 118
- 119
- 120
- 121
- 122
- 123
- 124
- 125
- 126
- 127
- 128
- 129
- 130
- 131
- 132
- 133
- 134
- 135
- 136
- 137
- 138
- 139
- 140
- 141
- 142
- 143
- 144
- 145
- 146
- 147
- 148
- 149
- 150
- 151
- 152
- 153
- 154
- 155
- 156
- 157
- 158
- 159
- 160
- 161
- 162
- 163
- 164
- 165
- 166
- 167
- 168
- 169
- 170
- 171
- 172
- 173
- 174
- 175
- 176
- 177
- 178
- 179
- 180
- 181
- 182
- 183
- 184
- 185
- 186
- 187
- 188
- 189
- 190
- 191
- 192
- 193
- 194
- 195
- 196
- 197
- 198
- 199
- 200
- 201
- 202
- 203
- 204
- 205
- 206
- 207
- 208
- 209
- 210
- 211
- 212
- 213
- 214
- 215
- 216
- 217
- 218
- 219
- 220
- 221
- 222
- 223
- 224
- 225
- 226
- 227
- 228
- 229
- 230
- 231
- 232
- 233
- 234
- 235
- 236
- 237
- 238
- 239
- 240
- 241
- 242
- 243
- 244
- 245
- 246
- 247
- 248
- 249
- 250
- 251
- 252
- 253
- 254
- 255
- 256
- 257
- 258
- 259
- 260
- 261
- 262
- 263
- 264
- 265
- 266
- 267
- 268
- 269
- 270
- 271
- 272
- 273
- 274
- 275
- 276
- 277
- 278
- 279
- 280
- 281
- 282
- 283
- 284
- 285
- 286
- 287
- 288
- 289
- 290
- 291
- 292
- 293
- 294
- 295
- 296
- 297
- 298
- 299
- 300
- 301
- 302
- 303
- 304
- 305
- 306
- 307
- 308
- 309
- 310
- 311
- 312
- 313
- 314
- 315
- 316
- 317
- 318
- 319
- 320
- 321
- 322
- 323
- 324
- 325
- 326
- 327
- 328
- 329
- 330
- 331
- 332
- 333
- 334
- 335
- 336
- 337
- 338
- 339
- 340
- 341
- 342
- 343
- 344
- 345
- 346
- 347
- 348
- 349
- 350
- 351
- 352
- 353
- 354
- 355
- 356
- 357
- 358
- 359
- 360
- 361
- 362
- 363
- 364
- 365
- 366
- 367
- 368
- 369
- 370
- 371
- 372
- 373
- 374
- 375
- 376
- 377
- 378
- 379
- 380
- 381
- 382
- 383
- 384
- 385
- 386
- 387
- 388
- 389
- 390
- 391
- 392
- 393
- 394
- 395
- 396
- 397
- 398
- 399
- 400
- 401
- 402
- 403
- 404
- 405
- 406
- 407
- 408
- 409
- 410
- 411
- 412
- 413
- 414
- 415
- 416
- 417
- 418
- 419
- 420
- 421
- 422
- 423
- 424
- 425
- 426
- 427
- 428
- 429
- 430
- 431
- 432
- 433
- 434
- 435
- 436
- 437
- 438
- 439
- 440
- 441
- 442
- 443
- 444
- 445
- 446
- 447
- 448
- 449
- 450
- 451
- 452
- 453
- 454
- 455
- 456
- 457
- 458
- 459
- 460
- 461
- 462
- 463
- 464
- 465
- 466
- 467
- 468
- 469
- 470
- 471
- 472
- 473
- 474
- 475
- 476
- 477
- 478
- 479
- 480
- 481
- 482
- 483
- 484
- 485
- 486
- 487
- 488
- 489
- 490
- 491
- 492
- 493
- 494
- 495
- 496
- 497
- 498
- 499
- 500
- 501
- 502
- 503
- 504
- 505
- 506
- 507
- 508
- 509
- 510
- 511
- 512
- 513
- 514
- 515
- 516
- 517
- 518
- 519
- 520
- 521
- 522
- 523
- 524
- 525
- 526
- 527
- 528
- 529
- 530
- 531
- 532
- 533
- 534
- 535
- 536
- 537
- 538
- 539
- 540
- 541
- 542
- 543
- 544
- 545
- 546
- 547
- 548
- 549
- 550
- 551
- 552
- 553
- 554
- 555
- 556
- 557
- 558
- 559
- 560
- 561
- 562
- 563
- 564
- 565
- 566
- 567
- 568
- 569
- 570
- 571
- 572
- 573
- 574
- 575
- 576
- 577
- 578
- 579
- 580
- 581
- 582
- 583
- 584
- 585
- 586
- 587
- 588
- 589
- 590
- 591
- 592
- 593
- 594
- 595
- 596
- 597
- 598
- 599
- 600
- 601
- 602
- 603
- 604
- 605
- 606
- 607
- 608
- 609
- 610
- 611
- 612
- 613
- 614
- 615
- 616
- 617
- 618
- 619
- 620
- 621
- 622
- 623
- 624
- 625
- 626
- 627
- 628
- 629
- 630
- 631
- 632
- 633
- 634
- 635
- 636
- 637
- 638
- 639
- 640
- 641
- 642
- 643
- 644
- 645
- 646
- 647
- 648
- 649
- 650
- 651
- 652
- 653
- 654
- 655
- 656
- 657
- 658
- 659
- 660
- 661
- 662
- 663
- 664
- 665
- 666
- 667
- 668
- 669
- 670
- 671
- 672
- 673
- 674
- 675
- 676
- 677
- 678
- 679
- 680
- 681
- 682
- 683
- 684
- 685
- 686
- 687
- 688
- 689
- 690
- 691
- 692
- 693
- 694
- 695
- 696
- 697
- 698
- 699
- 700
- 701
- 702
- 703
- 704
- 705
- 706
- 707
- 708
- 709
- 710
- 711
- 712
- 713
- 714
- 715
- 716
- 717
- 718
- 719
- 720
- 721
- 722
- 723
- 724
- 725
- 726
- 727
- 728
import * as fileUtil from "./../utils/file.js";
import * as event from "./../system/event.js";
import * as audio from "./../audio/audio.js";
import state from "./../state/state.js";
import { imgList, tmxList, binList, jsonList, videoList, fontList } from "./cache.js";
import { preloadImage } from "./parsers/image.js";
import { preloadFontFace } from "./parsers/fontface.js";
import { preloadTMX } from "./parsers/tmx.js";
import { preloadJSON } from "./parsers/json.js";
import { preloadBinary } from "./parsers/binary.js";
import { preloadJavascript } from "./parsers/script.js";
import { preloadVideo } from "./parsers/video.js";
import { warning } from "../lang/console.js";
/**
* a small class to manage loading of stuff and manage resources
* @namespace loader
*/
// to enable/disable caching
export let nocache = "";
// baseURL
export let baseURL = {};
/**
* crossOrigin attribute to configure the CORS requests for Image and Video data element.
* By default (that is, when the attribute is not specified), CORS is not used at all.
* The "anonymous" keyword means that there will be no exchange of user credentials via cookies,
* client-side SSL certificates or HTTP authentication as described in the Terminology section of the CORS specification.<br>
* @type {string}
* @name crossOrigin
* @default undefined
* @see loader.setOptions
* @memberof loader
* @see https://developer.mozilla.org/en-US/docs/Web/HTML/CORS_settings_attributes
* @example
* // allow for cross-origin texture loading
* me.loader.crossOrigin = "anonymous";
*
* // set all ressources to be loaded
* me.loader.preload(game.resources, () => this.loaded());
*/
export let crossOrigin;
/**
* indicates whether or not cross-site Access-Control requests should be made using credentials such as cookies,
* authorization headers or TLS client certificates. Setting withCredentials has no effect on same-site requests.
* @public
* @type {boolean}
* @name withCredentials
* @see loader.setOptions
* @default false
* @memberof loader
* @see https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/withCredentials
* @example
* // enable withCredentials
* me.loader.withCredentials = true;
*
* // set all ressources to be loaded
* me.loader.preload(game.resources, () => this.loaded());
*/
export let withCredentials = false;
/**
* enable the nocache mechanism
* @ignore
*/
export function setNocache(enable = false) {
nocache = enable ? "?" + ~~(Math.random() * 10000000) : "";
}
/**
* Sets the options for the loader.
* @memberof loader
* @param {Object} options - The options to set.
* @param {string} [options.crossOrigin] - The crossOrigin attribute to configure the CORS requests for Image and Video data element.
* @param {boolean} [options.nocache] - Enable or disable the nocache mechanism.
* @param {boolean} [options.withCredentials] - Indicates whether or not cross-site Access-Control requests should be made using credentials.
* @example
* // Set the crossOrigin attribute to "anonymous"
* me.loader.setOptions({ crossOrigin: "anonymous" });
*
* // Enable the nocache mechanism
* me.loader.setOptions({ nocache: true });
*
* // Enable withCredentials
* me.loader.setOptions({ withCredentials: true });
*/
export function setOptions(options) {
if (options.crossOrigin !== undefined) {
crossOrigin = options.crossOrigin;
}
if (options.nocache !== undefined) {
setNocache(options.nocache);
}
if (options.withCredentials !== undefined) {
withCredentials = options.withCredentials;
}
}
/**
* change the default baseURL for the given asset type.<br>
* (this will prepend the asset URL and must finish with a '/')
* @name setBaseURL
* @memberof loader
* @public
* @param {string} type - "*", "audio", "video", "binary", "image", "json", "js", "tmx", "tsx"
* @param {string} [url="./"] - default base URL
* @example
* // change the base URL relative address for audio assets
* me.loader.setBaseURL("audio", "data/audio/");
* // change the base URL absolute address for all object types
* me.loader.setBaseURL("*", "http://myurl.com/")
*/
export function setBaseURL(type, url) {
if (type !== "*") {
baseURL[type] = url;
} else {
// "wildcards"
baseURL["audio"] = url;
baseURL["video"] = url;
baseURL["binary"] = url;
baseURL["image"] = url;
baseURL["json"] = url;
baseURL["js"] = url;
baseURL["tmx"] = url;
baseURL["tsx"] = url;
// XXX ?
//baseURL["fontface"] = url;
}
}
/**
* onload callback
* @default undefined
* @memberof loader
* @type {function}
* @example
* // set a callback when everything is loaded
* me.loader.onload = this.loaded.bind(this);
*/
export let onload;
/**
* onProgress callback<br>
* each time a resource is loaded, the loader will fire the specified function,
* giving the actual progress [0 ... 1], as argument, and an object describing the resource loaded
* @default undefined
* @memberof loader
* @type {function}
* @example
* // set a callback for progress notification
* me.loader.onProgress = this.updateProgress.bind(this);
*/
export let onProgress;
/**
* onError callback<br>
* each time a resource loading is failed, the loader will fire the specified function giving the actual asset as argument.
* @default undefined
* @memberof loader
* @type {function}
* @example
* // set a callback for error notification
* me.loader.onError = this.loaderError.bind(this);
*/
export let onError;
/**
* list of parser function for supported format type
*/
let parsers = new Map();
/**
* keep track if parsers were registered
*/
let parserInitialized = false;
// flag to check loading status
let resourceCount = 0;
let loadCount = 0;
let timerId = 0;
/**
* Assets uploaded with an error
*/
const failureLoadedAssets = {};
/**
* init all supported parsers
* @ignore
*/
function initParsers() {
setParser("binary", preloadBinary);
setParser("image", preloadImage);
setParser("json", preloadJSON);
setParser("js", preloadJavascript);
setParser("tmx", preloadTMX);
setParser("tsx", preloadTMX);
setParser("audio", audio.load);
setParser("fontface", preloadFontFace);
setParser("video", preloadVideo);
parserInitialized = true;
}
/**
* check the loading status
* @ignore
*/
function checkLoadStatus(onloadcb) {
if (loadCount === resourceCount) {
// wait 1/2s and execute callback (cheap workaround to ensure everything is loaded)
if (typeof onloadcb === "function" || onload) {
// make sure we clear the timer
clearTimeout(timerId);
// trigger the onload callback
// we call either the supplied callback (which takes precedence) or the global one
let callback = onloadcb || onload;
setTimeout(() => {
callback();
event.emit(event.LOADER_COMPLETE);
}, 300);
}
else {
throw new Error("no load callback defined");
}
}
else {
timerId = setTimeout(() => {
checkLoadStatus(onloadcb);
}, 100);
}
}
/**
* just increment the number of already loaded resources
* @ignore
*/
function onResourceLoaded(res) {
delete failureLoadedAssets[res.src];
// increment the loading counter
loadCount++;
// currrent progress
let progress = loadCount / resourceCount;
// call callback if defined
if (typeof onProgress === "function") {
// pass the load progress in percent, as parameter
onProgress(progress, res);
}
event.emit(event.LOADER_PROGRESS, progress, res);
}
/**
* on error callback for image loading
* @param {loader.Asset} asset - asset that loaded with failure
* @ignore
*/
function onLoadingError(res) {
failureLoadedAssets[res.src] = res;
if (this.onError) {
this.onError(res);
}
event.emit(event.LOADER_ERROR, res);
throw new Error("Failed loading resource " + res.src);
}
/**
* an asset definition to be used with the loader
* @typedef {object} loader.Asset
* @property {string} name - name of the asset
* @property {string} type - the type of the asset ("audio"|"binary"|"image"|"json"|"js"|"tmx"|"tmj"|"tsx"|"tsj"|"fontface"|"video")
* @property {string} [src] - path and/or file name of the resource (for audio assets only the path is required)
* @property {string} [data] - TMX data if not provided through a src url
* @property {boolean} [stream=false] - Set to true to not to wait for large audio or video file to be downloaded before playing.
* @property {boolean} [autoplay=false] - Set to true to automatically start playing audio or video when loaded or added to a scene (using autoplay might require user iteraction to enable it)
* @property {boolean} [loop=false] - Set to true to automatically loop the audio or video when playing
* @see loader.preload
* @see loader.load
* @example
* // PNG tileset
* {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)
* {name: "map1", type: "tmx", src: "data/map/map1.json"}
* {name: "map2", type: "tmx", src: "data/map/map2.tmx"}
* {name: "map3", type: "tmx", format: "json", data: {"height":15,"layers":[...],"tilewidth":32,"version":1,"width":20}}
* {name: "map4", type: "tmx", format: "xml", data: {xml representation of tmx}}
* // 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)
* {name: "texture", type: "json", src: "data/gfx/texture.json"}
* // JavaScript file
* {name: "plugin", type: "js", src: "data/js/plugin.js"}
* // Font Face
* { name: "'kenpixel'", type: "fontface", src: "url('data/font/kenvector_future.woff2')" }
* // video resources
* {name: "intro", type: "video", src: "data/video/"}
*/
/**
* specify a parser/preload function for the given asset type
* @memberof loader
* @param {string} type - asset type
* @param {function} parserFn - parser function
* @see loader.Asset.type
* @example
* // specify a custom function for "abc" format
* function customAbcParser(data, onload, onerror) {
* // preload and do something with the data
* let parsedData = doSomething(data);
* // when done, call the onload callback with the parsed data
* onload(parsedData);
* // in case of error, call the onerror callback
* onerror();
* // return the amount of asset parsed
* return 1
* }
* // set the parser for the custom format
* loader.setParser("abc", customAbcParser);
*/
export function setParser(type, parserFn) {
if (typeof parserFn !== "function") {
throw new Error("invalid parser function for " + type);
}
if (typeof parsers.get(type) !== "undefined") {
warning("overriding parser for " + type + " format");
}
parsers.set(type, parserFn);
}
/**
* set all the specified game assets to be preloaded.
* @memberof loader
* @param {loader.Asset[]} assets - list of assets to load
* @param {Function} [onloadcb=loader.onload] - function to be called when all resources are loaded
* @param {boolean} [switchToLoadState=true] - automatically switch to the loading screen
* @example
* game.assets = [
* // PNG tileset
* {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)
* {name: "map1", type: "tmx", src: "data/map/map1.json"},
* {name: "map2", type: "tmx", src: "data/map/map2.tmx"},
* {name: "map3", type: "tmx", format: "json", data: {"height":15,"layers":[...],"tilewidth":32,"version":1,"width":20}},
* {name: "map4", type: "tmx", format: "xml", data: {xml representation of tmx}},
* // 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)
* {name: "texture", type: "json", src: "data/gfx/texture.json"},
* // JavaScript file
* {name: "plugin", type: "js", src: "data/js/plugin.js"},
* // Font Face
* {name: "'kenpixel'", type: "fontface", src: "url('data/font/kenvector_future.woff2')"},
* // video resources
* {name: "intro", type: "video", src: "data/video/"},
* // base64 encoded video asset
* me.loader.load({name: "avatar", type:"video", src: "data:video/mp4;base64,AAAAIGZ0eXBpc29tAAACAGlzb21pc28yYXZjMW1wNDEAAAAIZnJlZ..."};
* ];
* ...
* // set all resources to be loaded
* me.loader.preload(game.assets, () => this.loaded());
*/
export function preload(assets, onloadcb, switchToLoadState = true) {
// parse the resources
for (let i = 0; i < assets.length; i++) {
resourceCount += load(
assets[i],
onResourceLoaded.bind(this, assets[i]),
onLoadingError.bind(this, assets[i])
);
}
// set the onload callback if defined
if (typeof(onloadcb) !== "undefined") {
onload = onloadcb;
}
if (switchToLoadState === true) {
// swith to the loading screen
state.change(state.LOADING);
}
// check load status
checkLoadStatus(onload);
}
/**
* retry loading assets after a loading failure
* @memberof loader
* @param {string} src - src of asset to reload
* @example
* event.on(
* event.LOADER_ERROR,
* (res) => {
* // custom function
* showErrorNotification({
* text: `Error during loading content: ${res.name}`,
* done: loader.reload(res.src);
* })
* }
* );
**/
export function reload(src) {
const assetToReload = failureLoadedAssets[src];
this.unload(assetToReload);
resourceCount -= 1;
resourceCount += this.load(
assetToReload,
this.onResourceLoaded.bind(this, assetToReload),
this.onLoadingError.bind(this, assetToReload)
);
// check load status
checkLoadStatus(this.onload);
}
/**
* Load a single asset (to be used if you need to load additional asset(s) during the game)
* @memberof loader
* @param {loader.Asset} asset
* @param {Function} [onload] - function to be called when the asset 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(), () => this.onerror());
* // load a base64 image asset
* me.loader.load({name: "avatar", type:"image", src: "data:image/png;base64,iVBORw0KAAAQAAAAEACA..."};
* // load a base64 video asset
* me.loader.load({
* name: "avatar",
* type:"video",
* src: "data:video/mp4;base64,AAAAIGZ0eXBpc29tAAACAGlzb21pc28yYXZjMW1wNDEAAAAIZnJlZ.."
* };
* // start loading music
* me.loader.load({
* name : "bgmusic",
* type : "audio",
* src : "data/audio/"
* }, function () {
* me.audio.play("bgmusic");
* });
*/
export function load(asset, onload, onerror) {
// make sure all parsers have been initialized
if (parserInitialized === false) {
initParsers();
}
// transform the url if necessary
if (typeof (baseURL[asset.type]) !== "undefined") {
asset.src = baseURL[asset.type] + asset.src;
}
let parser = parsers.get(asset.type);
if (typeof parser === "undefined") {
throw new Error("load : unknown or invalid resource type : " + asset.type);
}
// parser returns the amount of asset to be loaded (usually 1 unless an asset is splitted into several ones)
return parser.call(this, asset, onload, onerror, {
nocache: nocache,
crossOrigin: crossOrigin,
withCredentials: withCredentials
});
}
/**
* unload the specified asset to free memory
* @memberof loader
* @param {loader.Asset} asset
* @returns {boolean} true if unloaded
* @example me.loader.unload({name: "avatar", type:"image"});
*/
export function unload(asset) {
switch (asset.type) {
case "binary":
if (!(asset.name in binList)) {
return false;
}
delete binList[asset.name];
return true;
case "image":
if (!(asset.name in imgList)) {
return false;
}
delete imgList[asset.name];
return true;
case "json":
if (!(asset.name in jsonList)) {
return false;
}
delete jsonList[asset.name];
return true;
case "js":
// ??
return true;
case "fontface":
if (typeof typeof globalThis.document !== "undefined" && typeof globalThis.document.fonts !== "undefined") {
globalThis.document.fonts.delete(fontList[asset.name]);
delete fontList[asset.name];
return true;
}
return false;
case "tmx":
case "tsx":
if (!(asset.name in tmxList)) {
return false;
}
delete tmxList[asset.name];
return true;
case "audio":
return audio.unload(asset.name);
case "video":
if (!(asset.name in videoList)) {
return false;
}
delete videoList[asset.name];
return true;
default:
throw new Error("unload : unknown or invalid resource type : " + asset.type);
}
}
/**
* unload all resources to free memory
* @memberof loader
* @example me.loader.unloadAll();
*/
export function unloadAll() {
let name;
// unload all binary resources
for (name in binList) {
if (binList.hasOwnProperty(name)) {
unload({
"name" : name,
"type" : "binary"
});
}
}
// unload all image resources
for (name in imgList) {
if (imgList.hasOwnProperty(name)) {
unload({
"name" : name,
"type" : "image"
});
}
}
// unload all tmx resources
for (name in tmxList) {
if (tmxList.hasOwnProperty(name)) {
unload({
"name" : name,
"type" : "tmx"
});
}
}
// unload all json resources
for (name in jsonList) {
if (jsonList.hasOwnProperty(name)) {
unload({
"name" : name,
"type" : "json"
});
}
}
// unload all video resources
for (name in videoList) {
if (videoList.hasOwnProperty(name)) {
unload({
"name" : name,
"type" : "json"
});
}
}
// unload all video resources
for (name in fontList) {
if (fontList.hasOwnProperty(name)) {
unload({
"name" : name,
"type" : "font"
});
}
}
// unload all audio resources
audio.unloadAll();
}
/**
* return the specified TMX/TSX object
* @memberof loader
* @param {string} elt - name of the tmx/tsx element ("map1");
* @returns {object} requested element or null if not found
*/
export function getTMX(elt) {
// force as string
elt = "" + elt;
if (elt in tmxList) {
return tmxList[elt];
}
return null;
}
/**
* return the specified Binary object
* @memberof loader
* @param {string} elt - name of the binary object ("ymTrack");
* @returns {object} requested element or null if not found
*/
export function getBinary(elt) {
// force as string
elt = "" + elt;
if (elt in binList) {
return binList[elt];
}
return null;
}
/**
* return the specified Image Object
* @memberof loader
* @param {string} image - name of the Image element ("tileset-platformer");
* @returns {HTMLImageElement} requested element or null if not found
*/
export function getImage(image) {
// force as string and extract the base name
image = fileUtil.getBasename("" + image);
if (image in imgList) {
// return the corresponding Image object
return imgList[image];
}
return null;
}
/**
* return the specified JSON Object
* @memberof loader
* @param {string} elt - name of the json file
* @returns {JSON}
*/
export function getJSON(elt) {
// force as string
elt = "" + elt;
if (elt in jsonList) {
return jsonList[elt];
}
return null;
}
/**
* return the specified Video Object
* @memberof loader
* @param {string} elt - name of the video file
* @returns {HTMLVideoElement}
*/
export function getVideo(elt) {
// force as string
elt = "" + elt;
if (elt in videoList) {
return videoList[elt];
}
return null;
}
/**
* return the specified FontFace Object
* @memberof loader
* @param {string} elt - name of the font file
* @returns {FontFace}
*/
export function getFont(elt) {
// force as string
elt = "" + elt;
if (elt in fontList) {
return fontList[elt];
}
return null;
}