2018-02-12 16:01:20 +00:00
|
|
|
/**
|
|
|
|
* @author Richard Davey <rich@photonstorm.com>
|
|
|
|
* @copyright 2018 Photon Storm Ltd.
|
|
|
|
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
|
|
|
*/
|
|
|
|
|
2018-01-12 17:09:09 +00:00
|
|
|
var Class = require('../utils/Class');
|
2016-12-06 15:15:42 +00:00
|
|
|
var CONST = require('./const');
|
2017-10-04 22:48:16 +00:00
|
|
|
var CustomSet = require('../structs/Set');
|
2018-01-12 17:09:09 +00:00
|
|
|
var EventEmitter = require('eventemitter3');
|
2018-01-19 14:47:16 +00:00
|
|
|
var FileTypesManager = require('./FileTypesManager');
|
2018-01-19 16:56:41 +00:00
|
|
|
var GetFastValue = require('../utils/object/GetFastValue');
|
2018-02-12 23:03:48 +00:00
|
|
|
var PluginManager = require('../boot/PluginManager');
|
2018-01-19 14:54:50 +00:00
|
|
|
var XHRSettings = require('./XHRSettings');
|
2016-11-30 17:16:45 +00:00
|
|
|
|
2018-03-23 15:54:12 +00:00
|
|
|
/**
|
2018-05-04 10:33:51 +00:00
|
|
|
* @typedef {object} MultiFileObject
|
2018-03-23 15:54:12 +00:00
|
|
|
*
|
|
|
|
* @property {string} type - [description]
|
|
|
|
* @property {Phaser.Loader.File} fileA - [description]
|
|
|
|
* @property {Phaser.Loader.File} fileB - [description]
|
|
|
|
*/
|
|
|
|
|
2018-03-22 12:51:30 +00:00
|
|
|
/**
|
|
|
|
* @typedef {object} LoaderFileObject
|
|
|
|
*
|
|
|
|
* @property {string} key - [description]
|
|
|
|
* @property {string} type - [description]
|
|
|
|
* @property {string} [url] - [description]
|
|
|
|
* @property {string[]} [urls] - [description]
|
|
|
|
* @property {string} [textureURL] - [description]
|
|
|
|
* @property {string} [atlasURL] - [description]
|
|
|
|
* @property {string} [xmlURL] - [description]
|
|
|
|
* @property {string[]} [textureURLs] - [description]
|
|
|
|
* @property {string[]} [atlasURLs] - [description]
|
|
|
|
* @property {object} [config] - [description]
|
|
|
|
* @property {object} [json] - [description]
|
|
|
|
* @property {XHRSettingsObject} [xhrSettings] - [description]
|
|
|
|
* @property {XHRSettingsObject} [textureXhrSettings] - [description]
|
|
|
|
* @property {XHRSettingsObject} [atlasXhrSettings] - [description]
|
|
|
|
* @property {XHRSettingsObject} [xmlXhrSettings] - [description]
|
|
|
|
* @property {XHRSettingsObject} [audioXhrSettings] - [description]
|
|
|
|
* @property {XHRSettingsObject} [jsonXhrSettings] - [description]
|
|
|
|
*/
|
|
|
|
|
2018-02-09 17:56:43 +00:00
|
|
|
/**
|
|
|
|
* @classdesc
|
2018-05-04 16:13:27 +00:00
|
|
|
* The Loader handles loading all external content such as Images, Sounds, Texture Atlases and data files.
|
|
|
|
* You typically interact with it via `this.load` in your Scene. Scenes can have a `preload` method, which is always
|
|
|
|
* called before the Scenes `create` method, allowing you to preload assets that the Scene may need.
|
|
|
|
*
|
|
|
|
* If you call any `this.load` methods from outside of `Scene.preload` then you need to start the Loader going
|
|
|
|
* yourself by calling `Loader.start()`. It's only automatically started during the Scene preload.
|
|
|
|
*
|
|
|
|
* The Loader uses a combination of tag loading (eg. Audio elements) and XHR and provides progress and completion events.
|
|
|
|
* Files are loaded in parallel by default. The amount of concurrent connections can be controlled in your Game Configuration.
|
|
|
|
*
|
|
|
|
* Once the Loader has started loading you are still able to add files to it. These can be injected as a result of a loader
|
|
|
|
* event, the type of file being loaded (such as a pack file) or other external events. As long as the Loader hasn't finished
|
|
|
|
* simply adding a new file to it, while running, will ensure it's added into the current queue.
|
|
|
|
*
|
|
|
|
* Every Scene has its own instance of the Loader and they are bound to the Scene in which they are created. However,
|
|
|
|
* assets loaded by the Loader are placed into global game-level caches. For example, loading an XML file will place that
|
|
|
|
* file inside `Game.cache.xml`, which is accessible from every Scene in your game, no matter who was responsible
|
|
|
|
* for loading it. The same is true of Textures. A texture loaded in one Scene is instantly available to all other Scenes
|
|
|
|
* in your game.
|
|
|
|
*
|
|
|
|
* The Loader works by using custom File Types. These are stored in the FileTypesManager, which injects them into the Loader
|
|
|
|
* when it's instantiated. You can create your own custom file types by extending either the File or MultiFile classes.
|
|
|
|
* See those files for more details.
|
2018-02-09 17:56:43 +00:00
|
|
|
*
|
|
|
|
* @class LoaderPlugin
|
2018-03-28 14:04:09 +00:00
|
|
|
* @extends Phaser.Events.EventEmitter
|
2018-02-09 17:56:43 +00:00
|
|
|
* @memberOf Phaser.Loader
|
|
|
|
* @constructor
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-05-04 16:13:27 +00:00
|
|
|
* @param {Phaser.Scene} scene - The Scene which owns this Loader instance.
|
2018-02-09 17:56:43 +00:00
|
|
|
*/
|
2018-01-19 14:54:50 +00:00
|
|
|
var LoaderPlugin = new Class({
|
2016-11-30 17:16:45 +00:00
|
|
|
|
2018-01-12 17:09:09 +00:00
|
|
|
Extends: EventEmitter,
|
|
|
|
|
2017-07-03 15:05:22 +00:00
|
|
|
initialize:
|
2016-11-30 17:16:45 +00:00
|
|
|
|
2018-01-19 14:54:50 +00:00
|
|
|
function LoaderPlugin (scene)
|
2017-07-03 15:05:22 +00:00
|
|
|
{
|
2018-01-12 17:09:09 +00:00
|
|
|
EventEmitter.call(this);
|
2017-08-04 17:43:05 +00:00
|
|
|
|
2018-05-02 12:11:17 +00:00
|
|
|
var gameConfig = scene.sys.game.config;
|
|
|
|
var sceneConfig = scene.sys.settings.loader;
|
|
|
|
|
2018-02-09 17:56:43 +00:00
|
|
|
/**
|
2018-05-04 16:13:27 +00:00
|
|
|
* The Scene which owns this Loader instance.
|
2018-02-09 17:56:43 +00:00
|
|
|
*
|
|
|
|
* @name Phaser.Loader.LoaderPlugin#scene
|
|
|
|
* @type {Phaser.Scene}
|
2018-05-04 16:13:27 +00:00
|
|
|
* @protected
|
2018-02-09 17:56:43 +00:00
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2018-01-12 17:09:09 +00:00
|
|
|
this.scene = scene;
|
2017-07-03 15:05:22 +00:00
|
|
|
|
2018-02-09 17:56:43 +00:00
|
|
|
/**
|
2018-05-04 16:13:27 +00:00
|
|
|
* A reference to the Scene Systems.
|
2018-02-09 17:56:43 +00:00
|
|
|
*
|
|
|
|
* @name Phaser.Loader.LoaderPlugin#systems
|
|
|
|
* @type {Phaser.Scenes.Systems}
|
2018-05-04 16:13:27 +00:00
|
|
|
* @protected
|
2018-02-09 17:56:43 +00:00
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2018-01-19 14:47:16 +00:00
|
|
|
this.systems = scene.sys;
|
|
|
|
|
2018-04-25 16:16:09 +00:00
|
|
|
/**
|
|
|
|
* A reference to the global Cache Manager.
|
|
|
|
*
|
|
|
|
* @name Phaser.Loader.LoaderPlugin#cacheManager
|
|
|
|
* @type {Phaser.Cache.CacheManager}
|
2018-05-04 16:13:27 +00:00
|
|
|
* @protected
|
2018-04-25 16:16:09 +00:00
|
|
|
* @since 3.7.0
|
|
|
|
*/
|
|
|
|
this.cacheManager = scene.sys.cache;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A reference to the global Texture Manager.
|
|
|
|
*
|
|
|
|
* @name Phaser.Loader.LoaderPlugin#textureManager
|
|
|
|
* @type {Phaser.Textures.TextureManager}
|
2018-05-04 16:13:27 +00:00
|
|
|
* @protected
|
2018-04-25 16:16:09 +00:00
|
|
|
* @since 3.7.0
|
|
|
|
*/
|
|
|
|
this.textureManager = scene.sys.textures;
|
|
|
|
|
2018-01-19 14:47:16 +00:00
|
|
|
// Inject the available filetypes into the Loader
|
|
|
|
FileTypesManager.install(this);
|
|
|
|
|
2018-05-02 12:11:17 +00:00
|
|
|
/**
|
|
|
|
* An optional prefix that is automatically prepended to the start of every file key.
|
2018-05-04 16:13:27 +00:00
|
|
|
* If prefix was `MENU.` and you load an image with the key 'Background' the resulting key would be `MENU.Background`.
|
|
|
|
* You can set this directly, or call `Loader.setPrefix()`. It will then affect every file added to the Loader
|
|
|
|
* from that point on. It does _not_ change any file already in the load queue.
|
2018-05-02 12:11:17 +00:00
|
|
|
*
|
|
|
|
* @name Phaser.Loader.LoaderPlugin#prefix
|
|
|
|
* @type {string}
|
|
|
|
* @default ''
|
|
|
|
* @since 3.7.0
|
|
|
|
*/
|
|
|
|
this.prefix = '';
|
2018-01-19 17:07:38 +00:00
|
|
|
|
2018-02-09 17:56:43 +00:00
|
|
|
/**
|
2018-05-04 16:13:27 +00:00
|
|
|
* The value of `path`, if set, is placed before any _relative_ file path given. For example:
|
|
|
|
*
|
|
|
|
* ```javascript
|
|
|
|
* this.load.path = "images/sprites/";
|
|
|
|
* this.load.image("ball", "ball.png");
|
|
|
|
* this.load.image("tree", "level1/oaktree.png");
|
|
|
|
* this.load.image("boom", "http://server.com/explode.png");
|
|
|
|
* ```
|
|
|
|
*
|
|
|
|
* Would load the `ball` file from `images/sprites/ball.png` and the tree from
|
|
|
|
* `images/sprites/level1/oaktree.png` but the file `boom` would load from the URL
|
|
|
|
* given as it's an absolute URL.
|
|
|
|
*
|
|
|
|
* Please note that the path is added before the filename but *after* the baseURL (if set.)
|
|
|
|
*
|
|
|
|
* If you set this property directly then it _must_ end with a "/". Alternatively, call `setPath()` and it'll do it for you.
|
2018-02-09 17:56:43 +00:00
|
|
|
*
|
|
|
|
* @name Phaser.Loader.LoaderPlugin#path
|
|
|
|
* @type {string}
|
|
|
|
* @default ''
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2018-01-19 17:07:38 +00:00
|
|
|
this.path = '';
|
2018-02-09 17:56:43 +00:00
|
|
|
|
|
|
|
/**
|
2018-05-04 16:13:27 +00:00
|
|
|
* If you want to append a URL before the path of any asset you can set this here.
|
|
|
|
*
|
|
|
|
* Useful if allowing the asset base url to be configured outside of the game code.
|
|
|
|
*
|
|
|
|
* If you set this property directly then it _must_ end with a "/". Alternatively, call `setBaseURL()` and it'll do it for you.
|
2018-02-09 17:56:43 +00:00
|
|
|
*
|
|
|
|
* @name Phaser.Loader.LoaderPlugin#baseURL
|
|
|
|
* @type {string}
|
|
|
|
* @default ''
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2018-01-19 17:07:38 +00:00
|
|
|
this.baseURL = '';
|
2016-11-30 17:16:45 +00:00
|
|
|
|
2018-01-19 17:10:23 +00:00
|
|
|
this.setBaseURL(GetFastValue(sceneConfig, 'baseURL', gameConfig.loaderBaseURL));
|
2018-02-09 17:56:43 +00:00
|
|
|
|
2018-01-19 17:07:38 +00:00
|
|
|
this.setPath(GetFastValue(sceneConfig, 'path', gameConfig.loaderPath));
|
2018-01-19 16:56:41 +00:00
|
|
|
|
2018-05-02 12:11:17 +00:00
|
|
|
this.setPrefix(GetFastValue(sceneConfig, 'prefix', gameConfig.loaderPrefix));
|
|
|
|
|
2018-02-09 17:56:43 +00:00
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @name Phaser.Loader.LoaderPlugin#maxParallelDownloads
|
|
|
|
* @type {integer}
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2018-01-19 16:56:41 +00:00
|
|
|
this.maxParallelDownloads = GetFastValue(sceneConfig, 'maxParallelDownloads', gameConfig.loaderMaxParallelDownloads);
|
2016-11-30 17:16:45 +00:00
|
|
|
|
2018-02-09 17:56:43 +00:00
|
|
|
/**
|
|
|
|
* xhr specific global settings (can be overridden on a per-file basis)
|
|
|
|
*
|
|
|
|
* @name Phaser.Loader.LoaderPlugin#xhr
|
2018-03-21 12:03:14 +00:00
|
|
|
* @type {XHRSettingsObject}
|
2018-02-09 17:56:43 +00:00
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2018-01-19 16:56:41 +00:00
|
|
|
this.xhr = XHRSettings(
|
|
|
|
GetFastValue(sceneConfig, 'responseType', gameConfig.loaderResponseType),
|
|
|
|
GetFastValue(sceneConfig, 'async', gameConfig.loaderAsync),
|
|
|
|
GetFastValue(sceneConfig, 'user', gameConfig.loaderUser),
|
|
|
|
GetFastValue(sceneConfig, 'password', gameConfig.loaderPassword),
|
|
|
|
GetFastValue(sceneConfig, 'timeout', gameConfig.loaderTimeout)
|
|
|
|
);
|
2016-11-30 17:16:45 +00:00
|
|
|
|
2018-02-09 17:56:43 +00:00
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @name Phaser.Loader.LoaderPlugin#crossOrigin
|
|
|
|
* @type {string}
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2018-01-19 16:56:41 +00:00
|
|
|
this.crossOrigin = GetFastValue(sceneConfig, 'crossOrigin', gameConfig.loaderCrossOrigin);
|
2016-11-30 17:16:45 +00:00
|
|
|
|
2018-02-09 17:56:43 +00:00
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @name Phaser.Loader.LoaderPlugin#totalToLoad
|
2018-05-02 16:25:27 +00:00
|
|
|
* @type {integer}
|
2018-02-09 17:56:43 +00:00
|
|
|
* @default 0
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2018-01-19 16:28:59 +00:00
|
|
|
this.totalToLoad = 0;
|
2018-02-09 17:56:43 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @name Phaser.Loader.LoaderPlugin#progress
|
2018-05-02 16:25:27 +00:00
|
|
|
* @type {float}
|
2018-02-09 17:56:43 +00:00
|
|
|
* @default 0
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2018-01-19 16:28:59 +00:00
|
|
|
this.progress = 0;
|
|
|
|
|
2018-02-09 17:56:43 +00:00
|
|
|
/**
|
2018-05-02 16:25:27 +00:00
|
|
|
* Files are placed in this Set when they're added to the Loader via `addFile`.
|
|
|
|
*
|
|
|
|
* They are moved to the `inflight` Set when they start loading, and assuming a successful
|
|
|
|
* load, to the `queue` Set for further processing.
|
|
|
|
*
|
|
|
|
* By the end of the load process this Set will be empty.
|
2018-02-09 17:56:43 +00:00
|
|
|
*
|
|
|
|
* @name Phaser.Loader.LoaderPlugin#list
|
2018-03-23 15:54:12 +00:00
|
|
|
* @type {Phaser.Structs.Set.<Phaser.Loader.File>}
|
2018-02-09 17:56:43 +00:00
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-10-04 22:48:16 +00:00
|
|
|
this.list = new CustomSet();
|
2018-02-09 17:56:43 +00:00
|
|
|
|
|
|
|
/**
|
2018-05-02 16:25:27 +00:00
|
|
|
* Files are stored in this Set while they're in the process of being loaded.
|
|
|
|
*
|
|
|
|
* Upon a successful load they are moved to the `queue` Set.
|
|
|
|
*
|
|
|
|
* By the end of the load process this Set will be empty.
|
2018-02-09 17:56:43 +00:00
|
|
|
*
|
|
|
|
* @name Phaser.Loader.LoaderPlugin#inflight
|
2018-03-23 15:54:12 +00:00
|
|
|
* @type {Phaser.Structs.Set.<Phaser.Loader.File>}
|
2018-02-09 17:56:43 +00:00
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-10-04 22:48:16 +00:00
|
|
|
this.inflight = new CustomSet();
|
2018-02-09 17:56:43 +00:00
|
|
|
|
|
|
|
/**
|
2018-05-02 16:25:27 +00:00
|
|
|
* Files are stored in this Set while they're being processed.
|
|
|
|
*
|
|
|
|
* If the process is successful they are moved to their final destination, which could be
|
|
|
|
* a Cache or the Texture Manager.
|
|
|
|
*
|
|
|
|
* At the end of the load process this Set will be empty.
|
2018-02-09 17:56:43 +00:00
|
|
|
*
|
2018-05-02 16:25:27 +00:00
|
|
|
* @name Phaser.Loader.LoaderPlugin#queue
|
2018-03-23 15:54:12 +00:00
|
|
|
* @type {Phaser.Structs.Set.<Phaser.Loader.File>}
|
2018-02-09 17:56:43 +00:00
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2018-05-02 16:25:27 +00:00
|
|
|
this.queue = new CustomSet();
|
2018-02-09 17:56:43 +00:00
|
|
|
|
2018-05-02 23:37:00 +00:00
|
|
|
/**
|
|
|
|
* A temporary Set in which files are stored after processing,
|
|
|
|
* awaiting destruction at the end of the load process.
|
|
|
|
*
|
|
|
|
* @name Phaser.Loader.LoaderPlugin#_deleteQueue
|
|
|
|
* @type {Phaser.Structs.Set.<Phaser.Loader.File>}
|
|
|
|
* @private
|
|
|
|
* @since 3.7.0
|
|
|
|
*/
|
|
|
|
this._deleteQueue = new CustomSet();
|
|
|
|
|
2018-02-09 17:56:43 +00:00
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
2018-05-02 16:25:27 +00:00
|
|
|
* @name Phaser.Loader.LoaderPlugin#totalFailed
|
|
|
|
* @type {integer}
|
|
|
|
* @default 0
|
|
|
|
* @since 3.7.0
|
2018-02-09 17:56:43 +00:00
|
|
|
*/
|
2018-05-02 16:25:27 +00:00
|
|
|
this.totalFailed = 0;
|
2018-02-09 17:56:43 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
2018-05-02 16:25:27 +00:00
|
|
|
* @name Phaser.Loader.LoaderPlugin#totalComplete
|
|
|
|
* @type {integer}
|
|
|
|
* @default 0
|
|
|
|
* @since 3.7.0
|
2018-02-09 17:56:43 +00:00
|
|
|
*/
|
2018-05-02 16:25:27 +00:00
|
|
|
this.totalComplete = 0;
|
2016-11-30 17:16:45 +00:00
|
|
|
|
2018-02-09 17:56:43 +00:00
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @name Phaser.Loader.LoaderPlugin#state
|
|
|
|
* @type {integer}
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-07-14 13:30:20 +00:00
|
|
|
this.state = CONST.LOADER_IDLE;
|
2018-04-13 16:12:17 +00:00
|
|
|
|
2018-04-17 11:25:45 +00:00
|
|
|
scene.sys.events.once('boot', this.boot, this);
|
2018-04-17 01:34:07 +00:00
|
|
|
scene.sys.events.on('start', this.pluginStart, this);
|
2017-07-03 15:05:22 +00:00
|
|
|
},
|
2016-11-30 17:16:45 +00:00
|
|
|
|
2018-04-17 11:25:45 +00:00
|
|
|
/**
|
|
|
|
* This method is called automatically, only once, when the Scene is first created.
|
|
|
|
* Do not invoke it directly.
|
|
|
|
*
|
|
|
|
* @method Phaser.Loader.LoaderPlugin#boot
|
|
|
|
* @private
|
|
|
|
* @since 3.5.1
|
|
|
|
*/
|
|
|
|
boot: function ()
|
|
|
|
{
|
|
|
|
this.systems.events.once('destroy', this.destroy, this);
|
|
|
|
},
|
|
|
|
|
2018-02-09 17:56:43 +00:00
|
|
|
/**
|
2018-04-13 16:12:17 +00:00
|
|
|
* This method is called automatically by the Scene when it is starting up.
|
|
|
|
* It is responsible for creating local systems, properties and listening for Scene events.
|
|
|
|
* Do not invoke it directly.
|
2018-02-09 17:56:43 +00:00
|
|
|
*
|
2018-04-17 01:34:07 +00:00
|
|
|
* @method Phaser.Loader.LoaderPlugin#pluginStart
|
2018-04-13 16:12:17 +00:00
|
|
|
* @private
|
2018-04-17 01:34:07 +00:00
|
|
|
* @since 3.5.1
|
2018-02-09 17:56:43 +00:00
|
|
|
*/
|
2018-04-17 01:34:07 +00:00
|
|
|
pluginStart: function ()
|
2018-01-19 14:47:16 +00:00
|
|
|
{
|
2018-04-17 11:25:45 +00:00
|
|
|
this.systems.events.once('shutdown', this.shutdown, this);
|
2018-01-19 14:47:16 +00:00
|
|
|
},
|
|
|
|
|
2018-02-09 17:56:43 +00:00
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @method Phaser.Loader.LoaderPlugin#setBaseURL
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-05-02 23:37:00 +00:00
|
|
|
* @param {string} url - The URL to use. Leave empty to reset.
|
2018-02-09 17:56:43 +00:00
|
|
|
*
|
|
|
|
* @return {Phaser.Loader.LoaderPlugin} This Loader object.
|
|
|
|
*/
|
2018-01-19 16:28:59 +00:00
|
|
|
setBaseURL: function (url)
|
|
|
|
{
|
2018-05-02 23:37:00 +00:00
|
|
|
if (url === undefined) { url = ''; }
|
|
|
|
|
2018-01-19 17:28:48 +00:00
|
|
|
if (url !== '' && url.substr(-1) !== '/')
|
2018-01-19 17:10:23 +00:00
|
|
|
{
|
|
|
|
url = url.concat('/');
|
|
|
|
}
|
|
|
|
|
2018-01-19 16:28:59 +00:00
|
|
|
this.baseURL = url;
|
|
|
|
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
2018-02-09 17:56:43 +00:00
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @method Phaser.Loader.LoaderPlugin#setPath
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-05-02 23:37:00 +00:00
|
|
|
* @param {string} path - The path to use. Leave empty to reset.
|
2018-02-09 17:56:43 +00:00
|
|
|
*
|
|
|
|
* @return {Phaser.Loader.LoaderPlugin} This Loader object.
|
|
|
|
*/
|
2017-08-04 15:15:00 +00:00
|
|
|
setPath: function (path)
|
|
|
|
{
|
2018-05-02 23:37:00 +00:00
|
|
|
if (path === undefined) { path = ''; }
|
|
|
|
|
2018-01-19 17:28:48 +00:00
|
|
|
if (path !== '' && path.substr(-1) !== '/')
|
2017-08-04 15:15:00 +00:00
|
|
|
{
|
|
|
|
path = path.concat('/');
|
|
|
|
}
|
|
|
|
|
|
|
|
this.path = path;
|
|
|
|
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
2018-05-02 12:11:17 +00:00
|
|
|
/**
|
|
|
|
* An optional prefix that is automatically prepended to the start of every file key.
|
2018-05-04 16:13:27 +00:00
|
|
|
* If prefix was `MENU.` and you load an image with the key 'Background' the resulting key would be `MENU.Background`.
|
|
|
|
* Once a prefix is set it will then affect every file added to the Loader from that point on.
|
|
|
|
* It does _not_ change any file _already_ in the load queue.
|
2018-05-02 12:11:17 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Loader.LoaderPlugin#setPrefix
|
|
|
|
* @since 3.7.0
|
|
|
|
*
|
2018-05-04 16:13:27 +00:00
|
|
|
* @param {string} [prefix] - The prefix to use. Leave empty to reset.
|
2018-05-02 12:11:17 +00:00
|
|
|
*
|
|
|
|
* @return {Phaser.Loader.LoaderPlugin} This Loader object.
|
|
|
|
*/
|
|
|
|
setPrefix: function (prefix)
|
|
|
|
{
|
|
|
|
if (prefix === undefined) { prefix = ''; }
|
|
|
|
|
|
|
|
this.prefix = prefix;
|
|
|
|
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
2018-02-13 05:54:43 +00:00
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @method Phaser.Loader.LoaderPlugin#setCORS
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
|
|
|
* @param {string} crossOrigin - [description]
|
|
|
|
*
|
|
|
|
* @return {Phaser.Loader.LoaderPlugin} This Loader object.
|
|
|
|
*/
|
|
|
|
setCORS: function (crossOrigin)
|
|
|
|
{
|
|
|
|
this.crossOrigin = crossOrigin;
|
|
|
|
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
2018-02-09 17:56:43 +00:00
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @method Phaser.Loader.LoaderPlugin#addFile
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-05-02 16:25:27 +00:00
|
|
|
* @param {(Phaser.Loader.File|Phaser.Loader.File[])} file - The file, or array of files, to be added to the load queue.
|
2018-02-09 17:56:43 +00:00
|
|
|
*/
|
2016-11-30 17:16:45 +00:00
|
|
|
addFile: function (file)
|
|
|
|
{
|
2018-05-02 16:25:27 +00:00
|
|
|
if (!Array.isArray(file))
|
2016-11-30 17:16:45 +00:00
|
|
|
{
|
2018-05-02 16:25:27 +00:00
|
|
|
file = [ file ];
|
2016-11-30 17:16:45 +00:00
|
|
|
}
|
|
|
|
|
2018-05-02 16:25:27 +00:00
|
|
|
for (var i = 0; i < file.length; i++)
|
2018-04-27 17:44:12 +00:00
|
|
|
{
|
2018-05-02 16:25:27 +00:00
|
|
|
var item = file[i];
|
|
|
|
|
|
|
|
// Does the file already exist in the cache or texture manager?
|
|
|
|
// Or will it conflict with a file already in the queue or inflight?
|
|
|
|
if (!this.keyExists(item))
|
2018-04-27 17:44:12 +00:00
|
|
|
{
|
2018-05-02 16:25:27 +00:00
|
|
|
this.list.set(item);
|
2018-04-27 17:44:12 +00:00
|
|
|
|
2018-05-02 16:25:27 +00:00
|
|
|
if (this.isLoading())
|
|
|
|
{
|
|
|
|
this.totalToLoad++;
|
|
|
|
this.updateProgress();
|
2018-04-27 17:44:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-05-02 16:25:27 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks the key and type of the given file to see if it will conflict with anything already
|
|
|
|
* in a Cache, the Texture Manager, or the list or inflight queues.
|
|
|
|
*
|
|
|
|
* @method Phaser.Loader.LoaderPlugin#keyExists
|
|
|
|
* @since 3.7.0
|
|
|
|
*
|
|
|
|
* @param {Phaser.Loader.File} file - The file to check the key of.
|
|
|
|
*
|
|
|
|
* @return {boolean} `true` if adding this file will cause a cache or queue conflict, otherwise `false`.
|
|
|
|
*/
|
|
|
|
keyExists: function (file)
|
|
|
|
{
|
|
|
|
var keyConflict = file.hasCacheConflict();
|
|
|
|
|
|
|
|
if (!keyConflict)
|
2018-04-25 16:16:09 +00:00
|
|
|
{
|
2018-05-02 16:25:27 +00:00
|
|
|
this.list.iterate(function (item)
|
|
|
|
{
|
|
|
|
if (item.type === file.type && item.key === file.key)
|
|
|
|
{
|
|
|
|
keyConflict = true;
|
2016-11-30 17:16:45 +00:00
|
|
|
|
2018-05-02 16:25:27 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
2018-04-25 16:16:09 +00:00
|
|
|
}
|
2018-05-02 16:25:27 +00:00
|
|
|
|
|
|
|
if (!keyConflict && this.isLoading())
|
|
|
|
{
|
|
|
|
this.inflight.iterate(function (item)
|
|
|
|
{
|
|
|
|
if (item.type === file.type && item.key === file.key)
|
|
|
|
{
|
|
|
|
keyConflict = true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
this.queue.iterate(function (item)
|
|
|
|
{
|
|
|
|
if (item.type === file.type && item.key === file.key)
|
|
|
|
{
|
|
|
|
keyConflict = true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
return keyConflict;
|
2016-11-30 17:16:45 +00:00
|
|
|
},
|
|
|
|
|
2018-05-02 23:37:00 +00:00
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @method Phaser.Loader.LoaderPlugin#addPack
|
|
|
|
* @since 3.7.0
|
|
|
|
*
|
|
|
|
* @param {any} data - The Pack File data, or an array of Pack File data, to be added to the load queue.
|
2018-05-04 13:33:44 +00:00
|
|
|
*
|
|
|
|
* @return {boolean} `true` if any files were added to the queue, otherwise `false`.
|
2018-05-02 23:37:00 +00:00
|
|
|
*/
|
|
|
|
addPack: function (pack, packKey)
|
|
|
|
{
|
|
|
|
// if no packKey provided we'll add everything to the queue
|
|
|
|
if (packKey && pack.hasOwnProperty(packKey))
|
|
|
|
{
|
|
|
|
pack = { packKey: pack[packKey] };
|
|
|
|
}
|
|
|
|
|
2018-05-04 13:33:44 +00:00
|
|
|
var total = 0;
|
|
|
|
|
2018-05-02 23:37:00 +00:00
|
|
|
// Store the loader settings in case this pack replaces them
|
|
|
|
var currentBaseURL = this.baseURL;
|
|
|
|
var currentPath = this.path;
|
|
|
|
var currentPrefix = this.prefix;
|
|
|
|
|
|
|
|
// Here we go ...
|
|
|
|
for (var key in pack)
|
|
|
|
{
|
|
|
|
var config = pack[key];
|
|
|
|
|
|
|
|
// Any meta data to process?
|
|
|
|
var baseURL = GetFastValue(config, 'baseURL', currentBaseURL);
|
|
|
|
var path = GetFastValue(config, 'path', currentPath);
|
|
|
|
var prefix = GetFastValue(config, 'prefix', currentPrefix);
|
|
|
|
var files = GetFastValue(config, 'files', null);
|
|
|
|
var defaultType = GetFastValue(config, 'defaultType', 'void');
|
|
|
|
|
|
|
|
if (Array.isArray(files))
|
|
|
|
{
|
|
|
|
this.setBaseURL(baseURL);
|
|
|
|
this.setPath(path);
|
|
|
|
this.setPrefix(prefix);
|
|
|
|
|
|
|
|
for (var i = 0; i < files.length; i++)
|
|
|
|
{
|
|
|
|
var file = files[i];
|
|
|
|
var type = (file.hasOwnProperty('type')) ? file.type : defaultType;
|
|
|
|
|
|
|
|
if (this[type])
|
|
|
|
{
|
|
|
|
this[type](file);
|
2018-05-04 13:33:44 +00:00
|
|
|
total++;
|
2018-05-02 23:37:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Reset the loader settings
|
|
|
|
this.setBaseURL(currentBaseURL);
|
|
|
|
this.setPath(currentPath);
|
|
|
|
this.setPrefix(currentPrefix);
|
|
|
|
|
2018-05-04 13:33:44 +00:00
|
|
|
return (total > 0);
|
2018-05-02 23:37:00 +00:00
|
|
|
},
|
|
|
|
|
2018-02-09 17:56:43 +00:00
|
|
|
/**
|
|
|
|
* Is the Loader actively loading (or processing loaded files)
|
|
|
|
*
|
|
|
|
* @method Phaser.Loader.LoaderPlugin#isLoading
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
|
|
|
* @return {boolean} [description]
|
|
|
|
*/
|
2016-11-30 17:16:45 +00:00
|
|
|
isLoading: function ()
|
|
|
|
{
|
2017-07-14 13:30:20 +00:00
|
|
|
return (this.state === CONST.LOADER_LOADING || this.state === CONST.LOADER_PROCESSING);
|
2016-11-30 17:16:45 +00:00
|
|
|
},
|
|
|
|
|
2018-02-09 17:56:43 +00:00
|
|
|
/**
|
|
|
|
* Is the Loader ready to start a new load?
|
|
|
|
*
|
|
|
|
* @method Phaser.Loader.LoaderPlugin#isReady
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
|
|
|
* @return {boolean} [description]
|
|
|
|
*/
|
2016-11-30 17:16:45 +00:00
|
|
|
isReady: function ()
|
|
|
|
{
|
2018-04-09 12:55:41 +00:00
|
|
|
return (this.state === CONST.LOADER_IDLE || this.state === CONST.LOADER_COMPLETE);
|
2016-11-30 17:16:45 +00:00
|
|
|
},
|
|
|
|
|
2018-02-09 17:56:43 +00:00
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @method Phaser.Loader.LoaderPlugin#start
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2016-11-30 17:16:45 +00:00
|
|
|
start: function ()
|
|
|
|
{
|
|
|
|
if (!this.isReady())
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-01-19 16:28:59 +00:00
|
|
|
this.progress = 0;
|
2018-05-02 16:25:27 +00:00
|
|
|
|
|
|
|
this.totalFailed = 0;
|
|
|
|
this.totalComplete = 0;
|
2018-01-19 16:28:59 +00:00
|
|
|
this.totalToLoad = this.list.size;
|
|
|
|
|
2018-01-12 17:09:09 +00:00
|
|
|
this.emit('start', this);
|
2016-12-05 17:19:12 +00:00
|
|
|
|
2016-11-30 17:16:45 +00:00
|
|
|
if (this.list.size === 0)
|
|
|
|
{
|
2018-05-02 16:25:27 +00:00
|
|
|
this.loadComplete();
|
2016-11-30 17:16:45 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-07-14 13:30:20 +00:00
|
|
|
this.state = CONST.LOADER_LOADING;
|
2016-11-30 17:16:45 +00:00
|
|
|
|
|
|
|
this.inflight.clear();
|
|
|
|
this.queue.clear();
|
|
|
|
|
|
|
|
this.updateProgress();
|
|
|
|
|
|
|
|
this.processLoadQueue();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2018-02-09 17:56:43 +00:00
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @method Phaser.Loader.LoaderPlugin#updateProgress
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2016-11-30 17:16:45 +00:00
|
|
|
updateProgress: function ()
|
|
|
|
{
|
2018-03-16 15:01:39 +00:00
|
|
|
this.progress = 1 - ((this.list.size + this.inflight.size) / this.totalToLoad);
|
2016-11-30 17:16:45 +00:00
|
|
|
|
2018-01-19 16:28:59 +00:00
|
|
|
this.emit('progress', this.progress);
|
2016-11-30 17:16:45 +00:00
|
|
|
},
|
|
|
|
|
2018-02-09 17:56:43 +00:00
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @method Phaser.Loader.LoaderPlugin#processLoadQueue
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2016-11-30 17:16:45 +00:00
|
|
|
processLoadQueue: function ()
|
|
|
|
{
|
|
|
|
this.list.each(function (file)
|
|
|
|
{
|
2018-01-19 17:53:07 +00:00
|
|
|
if (file.state === CONST.FILE_POPULATED || (file.state === CONST.FILE_PENDING && this.inflight.size < this.maxParallelDownloads))
|
2016-11-30 17:16:45 +00:00
|
|
|
{
|
2017-10-04 22:48:16 +00:00
|
|
|
this.inflight.set(file);
|
2016-11-30 17:16:45 +00:00
|
|
|
|
2017-10-04 22:48:16 +00:00
|
|
|
this.list.delete(file);
|
2016-11-30 17:16:45 +00:00
|
|
|
|
2018-05-02 16:25:27 +00:00
|
|
|
// If the file doesn't have its own crossOrigin set,
|
|
|
|
// we'll use the Loaders (which is undefined by default)
|
|
|
|
if (!file.crossOrigin)
|
|
|
|
{
|
|
|
|
file.crossOrigin = this.crossOrigin;
|
|
|
|
}
|
|
|
|
|
|
|
|
file.load();
|
2016-11-30 17:16:45 +00:00
|
|
|
}
|
|
|
|
|
2017-10-04 22:48:16 +00:00
|
|
|
if (this.inflight.size === this.maxParallelDownloads)
|
2016-11-30 17:16:45 +00:00
|
|
|
{
|
|
|
|
// Tells the Set iterator to abort
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-10-04 22:48:16 +00:00
|
|
|
}, this);
|
2016-11-30 17:16:45 +00:00
|
|
|
},
|
|
|
|
|
2018-02-09 17:56:43 +00:00
|
|
|
/**
|
2018-05-02 16:25:27 +00:00
|
|
|
* Called automatically by the Files XHRLoader function.
|
2018-02-09 17:56:43 +00:00
|
|
|
*
|
2018-05-02 16:25:27 +00:00
|
|
|
* @method Phaser.Loader.LoaderPlugin#nextFile
|
2018-02-09 17:56:43 +00:00
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-05-02 16:25:27 +00:00
|
|
|
* @param {Phaser.Loader.File} file - The File that just finished loading, or errored during load.
|
|
|
|
* @param {boolean} success - `true` if the file loaded successfully, otherwise `false`.
|
2018-02-09 17:56:43 +00:00
|
|
|
*/
|
2018-05-02 16:25:27 +00:00
|
|
|
nextFile: function (file, success)
|
2016-11-30 17:16:45 +00:00
|
|
|
{
|
2018-05-02 16:25:27 +00:00
|
|
|
this.inflight.delete(file);
|
2016-11-30 17:16:45 +00:00
|
|
|
|
2018-05-02 16:25:27 +00:00
|
|
|
this.updateProgress();
|
2016-11-30 17:16:45 +00:00
|
|
|
|
|
|
|
if (success)
|
|
|
|
{
|
2018-05-02 16:25:27 +00:00
|
|
|
this.totalComplete++;
|
2016-11-30 17:16:45 +00:00
|
|
|
|
2018-05-02 16:25:27 +00:00
|
|
|
this.queue.set(file);
|
2016-11-30 17:16:45 +00:00
|
|
|
|
2018-05-02 16:25:27 +00:00
|
|
|
this.emit('load', file);
|
2018-01-19 16:28:59 +00:00
|
|
|
|
2018-05-02 16:25:27 +00:00
|
|
|
file.onProcess();
|
2018-01-08 16:38:56 +00:00
|
|
|
}
|
2018-05-02 16:25:27 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
this.totalFailed++;
|
2018-01-08 16:38:56 +00:00
|
|
|
|
2018-05-02 23:37:00 +00:00
|
|
|
this._deleteQueue.set(file);
|
|
|
|
|
2018-05-02 16:25:27 +00:00
|
|
|
this.emit('loaderror', file);
|
2018-01-19 17:28:48 +00:00
|
|
|
}
|
2018-05-02 16:25:27 +00:00
|
|
|
|
|
|
|
if (this.list.size > 0)
|
2018-01-19 17:28:48 +00:00
|
|
|
{
|
2018-05-02 16:25:27 +00:00
|
|
|
this.processLoadQueue();
|
2018-01-19 17:28:48 +00:00
|
|
|
}
|
2016-12-07 00:27:56 +00:00
|
|
|
},
|
2016-11-30 17:16:45 +00:00
|
|
|
|
2018-02-09 17:56:43 +00:00
|
|
|
/**
|
|
|
|
* Called automatically by the File when it has finished processing.
|
|
|
|
*
|
2018-05-02 16:25:27 +00:00
|
|
|
* @method Phaser.Loader.LoaderPlugin#fileProcessComplete
|
|
|
|
* @since 3.7.0
|
2018-02-09 17:56:43 +00:00
|
|
|
*
|
|
|
|
* @param {Phaser.Loader.File} file - [description]
|
|
|
|
*/
|
2018-05-02 16:25:27 +00:00
|
|
|
fileProcessComplete: function (file)
|
2016-12-07 00:27:56 +00:00
|
|
|
{
|
2018-05-02 16:25:27 +00:00
|
|
|
// This file has failed, so move it to the failed Set
|
2016-12-07 01:13:17 +00:00
|
|
|
if (file.state === CONST.FILE_ERRORED)
|
|
|
|
{
|
2018-05-04 10:33:51 +00:00
|
|
|
if (file.multiFile)
|
2016-12-07 04:43:02 +00:00
|
|
|
{
|
2018-05-04 10:33:51 +00:00
|
|
|
file.multiFile.onFileFailed(file);
|
2016-12-07 04:43:02 +00:00
|
|
|
}
|
2018-05-02 16:25:27 +00:00
|
|
|
}
|
|
|
|
else if (file.state === CONST.FILE_COMPLETE)
|
|
|
|
{
|
2018-05-04 10:33:51 +00:00
|
|
|
if (file.multiFile)
|
2018-05-02 16:25:27 +00:00
|
|
|
{
|
2018-05-04 10:33:51 +00:00
|
|
|
if (file.multiFile.isReadyToProcess())
|
2018-05-04 01:39:49 +00:00
|
|
|
{
|
|
|
|
// If we got here then all files the link file needs are ready to add to the cache
|
2018-05-04 10:33:51 +00:00
|
|
|
file.multiFile.addToCache();
|
2018-05-04 01:39:49 +00:00
|
|
|
}
|
2018-05-02 16:25:27 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-05-02 23:37:00 +00:00
|
|
|
// If we got here, then the file processed, so let it add itself to its cache
|
2018-05-02 16:25:27 +00:00
|
|
|
file.addToCache();
|
|
|
|
}
|
2016-12-07 01:13:17 +00:00
|
|
|
}
|
2016-12-07 04:43:02 +00:00
|
|
|
|
2018-05-02 23:37:00 +00:00
|
|
|
// Remove it from the queue
|
2016-12-08 16:21:16 +00:00
|
|
|
this.queue.delete(file);
|
|
|
|
|
2018-05-02 16:25:27 +00:00
|
|
|
// Nothing left to do?
|
|
|
|
if (this.list.size === 0 && this.inflight.size === 0 && this.queue.size === 0)
|
2016-12-08 16:21:16 +00:00
|
|
|
{
|
2018-05-02 16:25:27 +00:00
|
|
|
this.loadComplete();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// In case we've added to the list by processing this file
|
|
|
|
this.processLoadQueue();
|
2016-12-08 16:21:16 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2018-02-09 17:56:43 +00:00
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
2018-05-02 16:25:27 +00:00
|
|
|
* @method Phaser.Loader.LoaderPlugin#loadComplete
|
|
|
|
* @since 3.7.0
|
2018-02-09 17:56:43 +00:00
|
|
|
*/
|
2018-05-02 16:25:27 +00:00
|
|
|
loadComplete: function ()
|
2016-12-07 00:27:56 +00:00
|
|
|
{
|
2018-05-02 23:37:00 +00:00
|
|
|
this.emit('loadcomplete', this);
|
|
|
|
|
2016-11-30 17:16:45 +00:00
|
|
|
this.list.clear();
|
|
|
|
this.inflight.clear();
|
|
|
|
this.queue.clear();
|
|
|
|
|
2018-05-02 16:25:27 +00:00
|
|
|
this.progress = 1;
|
2016-11-30 17:16:45 +00:00
|
|
|
|
2017-07-14 13:30:20 +00:00
|
|
|
this.state = CONST.LOADER_COMPLETE;
|
2016-11-30 17:16:45 +00:00
|
|
|
|
2018-05-02 23:37:00 +00:00
|
|
|
// Call 'destroy' on each file ready for deletion
|
|
|
|
this._deleteQueue.iterateLocal('destroy');
|
|
|
|
|
|
|
|
this._deleteQueue.clear();
|
|
|
|
|
2018-05-02 16:25:27 +00:00
|
|
|
this.emit('complete', this, this.totalComplete, this.totalFailed);
|
2016-11-30 17:16:45 +00:00
|
|
|
},
|
|
|
|
|
2018-05-02 23:37:00 +00:00
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @method Phaser.Loader.LoaderPlugin#flagForRemoval
|
|
|
|
* @since 3.7.0
|
|
|
|
*
|
|
|
|
* @param {Phaser.Loader.File} file - [description]
|
|
|
|
*/
|
|
|
|
flagForRemoval: function (file)
|
|
|
|
{
|
|
|
|
this._deleteQueue.set(file);
|
|
|
|
},
|
|
|
|
|
2018-02-09 17:56:43 +00:00
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @method Phaser.Loader.LoaderPlugin#saveJSON
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-03-20 16:15:49 +00:00
|
|
|
* @param {*} data - [description]
|
2018-03-19 00:54:19 +00:00
|
|
|
* @param {string} [filename=file.json] - [description]
|
2018-02-09 17:56:43 +00:00
|
|
|
*
|
2018-03-19 00:54:19 +00:00
|
|
|
* @return {Phaser.Loader.LoaderPlugin} This Loader plugin.
|
2018-02-09 17:56:43 +00:00
|
|
|
*/
|
2017-10-02 21:41:52 +00:00
|
|
|
saveJSON: function (data, filename)
|
|
|
|
{
|
|
|
|
return this.save(JSON.stringify(data), filename);
|
|
|
|
},
|
|
|
|
|
2018-02-09 17:56:43 +00:00
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @method Phaser.Loader.LoaderPlugin#save
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-03-20 16:15:49 +00:00
|
|
|
* @param {*} data - [description]
|
2018-03-19 00:54:19 +00:00
|
|
|
* @param {string} [filename=file.json] - [description]
|
|
|
|
* @param {string} [filetype=application/json] - [description]
|
2018-02-09 17:56:43 +00:00
|
|
|
*
|
|
|
|
* @return {Phaser.Loader.LoaderPlugin} This Loader plugin.
|
|
|
|
*/
|
2017-10-02 21:41:52 +00:00
|
|
|
save: function (data, filename, filetype)
|
|
|
|
{
|
|
|
|
if (filename === undefined) { filename = 'file.json'; }
|
|
|
|
if (filetype === undefined) { filetype = 'application/json'; }
|
|
|
|
|
2018-01-19 14:54:50 +00:00
|
|
|
var blob = new Blob([ data ], { type: filetype });
|
2017-10-02 21:41:52 +00:00
|
|
|
|
|
|
|
var url = URL.createObjectURL(blob);
|
|
|
|
|
|
|
|
var a = document.createElement('a');
|
|
|
|
|
|
|
|
a.download = filename;
|
|
|
|
a.textContent = 'Download ' + filename;
|
|
|
|
a.href = url;
|
|
|
|
a.click();
|
|
|
|
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
2018-02-09 17:56:43 +00:00
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @method Phaser.Loader.LoaderPlugin#reset
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2016-11-30 17:16:45 +00:00
|
|
|
reset: function ()
|
|
|
|
{
|
|
|
|
this.list.clear();
|
|
|
|
this.inflight.clear();
|
|
|
|
this.queue.clear();
|
|
|
|
|
2018-01-19 17:07:38 +00:00
|
|
|
var gameConfig = this.systems.game.config;
|
|
|
|
var sceneConfig = this.systems.settings.loader;
|
|
|
|
|
2018-01-19 17:10:23 +00:00
|
|
|
this.setBaseURL(GetFastValue(sceneConfig, 'baseURL', gameConfig.loaderBaseURL));
|
2018-01-19 17:07:38 +00:00
|
|
|
this.setPath(GetFastValue(sceneConfig, 'path', gameConfig.loaderPath));
|
2018-05-02 16:25:27 +00:00
|
|
|
this.setPrefix(GetFastValue(sceneConfig, 'prefix', gameConfig.loaderPrefix));
|
2016-11-30 17:16:45 +00:00
|
|
|
|
2017-07-14 13:30:20 +00:00
|
|
|
this.state = CONST.LOADER_IDLE;
|
2016-11-30 17:16:45 +00:00
|
|
|
},
|
|
|
|
|
2018-02-09 17:56:43 +00:00
|
|
|
/**
|
2018-04-13 16:12:17 +00:00
|
|
|
* The Scene that owns this plugin is shutting down.
|
|
|
|
* We need to kill and reset all internal properties as well as stop listening to Scene events.
|
2018-02-09 17:56:43 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Loader.LoaderPlugin#shutdown
|
2018-04-13 16:12:17 +00:00
|
|
|
* @private
|
2018-02-09 17:56:43 +00:00
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2018-01-19 14:54:50 +00:00
|
|
|
shutdown: function ()
|
|
|
|
{
|
|
|
|
this.reset();
|
2018-04-13 16:12:17 +00:00
|
|
|
|
2018-01-19 14:54:50 +00:00
|
|
|
this.state = CONST.LOADER_SHUTDOWN;
|
2018-04-13 16:12:17 +00:00
|
|
|
|
2018-04-17 11:25:45 +00:00
|
|
|
this.systems.events.off('shutdown', this.shutdown, this);
|
2018-01-19 14:54:50 +00:00
|
|
|
},
|
|
|
|
|
2018-02-09 17:56:43 +00:00
|
|
|
/**
|
2018-04-13 16:12:17 +00:00
|
|
|
* The Scene that owns this plugin is being destroyed.
|
|
|
|
* We need to shutdown and then kill off all external references.
|
2018-02-09 17:56:43 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Loader.LoaderPlugin#destroy
|
2018-04-13 16:12:17 +00:00
|
|
|
* @private
|
2018-02-09 17:56:43 +00:00
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2016-11-30 17:16:45 +00:00
|
|
|
destroy: function ()
|
|
|
|
{
|
2018-04-13 16:12:17 +00:00
|
|
|
this.shutdown();
|
|
|
|
|
2017-07-14 13:30:20 +00:00
|
|
|
this.state = CONST.LOADER_DESTROYED;
|
2018-04-13 16:12:17 +00:00
|
|
|
|
2018-04-17 01:34:07 +00:00
|
|
|
this.systems.events.off('start', this.pluginStart, this);
|
2018-04-13 16:12:17 +00:00
|
|
|
|
|
|
|
this.list = null;
|
|
|
|
this.inflight = null;
|
|
|
|
this.queue = null;
|
|
|
|
|
|
|
|
this.scene = null;
|
|
|
|
this.systems = null;
|
2018-04-25 16:16:39 +00:00
|
|
|
this.textureManager = null;
|
|
|
|
this.cacheManager = null;
|
2016-11-30 17:16:45 +00:00
|
|
|
}
|
|
|
|
|
2017-07-03 15:05:22 +00:00
|
|
|
});
|
2016-11-30 17:16:45 +00:00
|
|
|
|
2018-01-19 14:54:50 +00:00
|
|
|
PluginManager.register('Loader', LoaderPlugin, 'load');
|
2018-01-19 14:47:16 +00:00
|
|
|
|
2018-01-19 14:54:50 +00:00
|
|
|
module.exports = LoaderPlugin;
|