mirror of
https://github.com/photonstorm/phaser
synced 2025-02-17 06:28:30 +00:00
Lots more updates moving everything to consistent class structure.
This commit is contained in:
parent
b5348035a1
commit
4136ccf374
20 changed files with 774 additions and 670 deletions
|
@ -1,14 +1,20 @@
|
|||
var Class = require('../../../utils/Class');
|
||||
var Event = require('../../../events/Event');
|
||||
|
||||
var AddAnimationEvent = function (key, animation)
|
||||
{
|
||||
Event.call(this, 'ADD_ANIMATION_EVENT');
|
||||
var AddAnimationEvent = new Class({
|
||||
|
||||
this.key = key;
|
||||
this.animation = animation;
|
||||
};
|
||||
Extends: Event,
|
||||
|
||||
AddAnimationEvent.prototype = Object.create(Event.prototype);
|
||||
AddAnimationEvent.prototype.constructor = AddAnimationEvent;
|
||||
initialize:
|
||||
|
||||
function AddAnimationEvent (key, animation)
|
||||
{
|
||||
Event.call(this, 'ADD_ANIMATION_EVENT');
|
||||
|
||||
this.key = key;
|
||||
this.animation = animation;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
module.exports = AddAnimationEvent;
|
||||
|
|
|
@ -1,11 +1,17 @@
|
|||
var Class = require('../../../utils/Class');
|
||||
var Event = require('../../../events/Event');
|
||||
|
||||
var PauseAllAnimationEvent = function ()
|
||||
{
|
||||
Event.call(this, 'PAUSE_ALL_ANIMATION_EVENT');
|
||||
};
|
||||
var PauseAllAnimationEvent = new Class({
|
||||
|
||||
PauseAllAnimationEvent.prototype = Object.create(Event.prototype);
|
||||
PauseAllAnimationEvent.prototype.constructor = PauseAllAnimationEvent;
|
||||
Extends: Event,
|
||||
|
||||
initialize:
|
||||
|
||||
function PauseAllAnimationEvent ()
|
||||
{
|
||||
Event.call(this, 'PAUSE_ALL_ANIMATION_EVENT');
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
module.exports = PauseAllAnimationEvent;
|
||||
|
|
|
@ -1,14 +1,20 @@
|
|||
var Class = require('../../../utils/Class');
|
||||
var Event = require('../../../events/Event');
|
||||
|
||||
var RemoveAnimationEvent = function (key, animation)
|
||||
{
|
||||
Event.call(this, 'REMOVE_ANIMATION_EVENT');
|
||||
var RemoveAnimationEvent = new Class({
|
||||
|
||||
this.key = key;
|
||||
this.animation = animation;
|
||||
};
|
||||
Extends: Event,
|
||||
|
||||
RemoveAnimationEvent.prototype = Object.create(Event.prototype);
|
||||
RemoveAnimationEvent.prototype.constructor = RemoveAnimationEvent;
|
||||
initialize:
|
||||
|
||||
function RemoveAnimationEvent (key, animation)
|
||||
{
|
||||
Event.call(this, 'REMOVE_ANIMATION_EVENT');
|
||||
|
||||
this.key = key;
|
||||
this.animation = animation;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
module.exports = RemoveAnimationEvent;
|
||||
|
|
|
@ -1,11 +1,17 @@
|
|||
var Class = require('../../../utils/Class');
|
||||
var Event = require('../../../events/Event');
|
||||
|
||||
var ResumeAllAnimationEvent = function ()
|
||||
{
|
||||
Event.call(this, 'RESUME_ALL_ANIMATION_EVENT');
|
||||
};
|
||||
var ResumeAllAnimationEvent = new Class({
|
||||
|
||||
ResumeAllAnimationEvent.prototype = Object.create(Event.prototype);
|
||||
ResumeAllAnimationEvent.prototype.constructor = ResumeAllAnimationEvent;
|
||||
Extends: Event,
|
||||
|
||||
initialize:
|
||||
|
||||
function ResumeAllAnimationEvent ()
|
||||
{
|
||||
Event.call(this, 'RESUME_ALL_ANIMATION_EVENT');
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
module.exports = ResumeAllAnimationEvent;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
var CHECKSUM = {
|
||||
build: 'c709d480-5fe1-11e7-96a8-9381099cfcf1'
|
||||
build: 'dfe80200-6000-11e7-a426-abaf4c1292d1'
|
||||
};
|
||||
module.exports = CHECKSUM;
|
|
@ -1,7 +1,8 @@
|
|||
var GetValue = require('../../../utils/object/GetValue');
|
||||
var ResetKeyCombo = require('./ResetKeyCombo');
|
||||
var ProcessKeyCombo = require('./ProcessKeyCombo');
|
||||
var Class = require('../../../utils/Class');
|
||||
var GetFastValue = require('../../../utils/object/GetFastValue');
|
||||
var KeyComboMatchEvent = require('./KeyComboMatchEvent');
|
||||
var ProcessKeyCombo = require('./ProcessKeyCombo');
|
||||
var ResetKeyCombo = require('./ResetKeyCombo');
|
||||
|
||||
// Keys can be either:
|
||||
//
|
||||
|
@ -9,108 +10,118 @@ var KeyComboMatchEvent = require('./KeyComboMatchEvent');
|
|||
// An array of either integers (key codes) or strings, or a mixture of both
|
||||
// An array of objects (such as Key objects) with a public 'keyCode' property
|
||||
|
||||
var KeyCombo = function (keyboardManager, keys, config)
|
||||
{
|
||||
if (config === undefined) { config = {}; }
|
||||
var KeyCombo = new Class({
|
||||
|
||||
// Can't have a zero or single length combo (string or array based)
|
||||
if (keys.length < 2)
|
||||
initialize:
|
||||
|
||||
function KeyCombo (keyboardManager, keys, config)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (config === undefined) { config = {}; }
|
||||
|
||||
this.manager = keyboardManager;
|
||||
|
||||
this.enabled = true;
|
||||
|
||||
this.keyCodes = [];
|
||||
|
||||
// if 'keys' is a string we need to get the keycode of each character in it
|
||||
|
||||
for (var i = 0; i < keys.length; i++)
|
||||
{
|
||||
var char = keys[i];
|
||||
|
||||
if (typeof char === 'string')
|
||||
// Can't have a zero or single length combo (string or array based)
|
||||
if (keys.length < 2)
|
||||
{
|
||||
this.keyCodes.push(char.toUpperCase().charCodeAt(0));
|
||||
}
|
||||
else if (typeof char === 'number')
|
||||
{
|
||||
this.keyCodes.push(char);
|
||||
}
|
||||
else if (char.hasOwnProperty('keyCode'))
|
||||
{
|
||||
this.keyCodes.push(char.keyCode);
|
||||
}
|
||||
}
|
||||
|
||||
// The current keyCode the combo is waiting for
|
||||
this.current = this.keyCodes[0];
|
||||
|
||||
// The current index of the key being waited for in the 'keys' string
|
||||
this.index = 0;
|
||||
|
||||
// The length of this combo (in keycodes)
|
||||
this.size = this.keyCodes.length;
|
||||
|
||||
// The time the previous key in the combo was matched
|
||||
this.timeLastMatched = 0;
|
||||
|
||||
// Has this Key Combo been matched yet?
|
||||
this.matched = false;
|
||||
|
||||
// The time the entire combo was matched
|
||||
this.timeMatched = 0;
|
||||
|
||||
// Custom options ...
|
||||
|
||||
// If they press the wrong key do we reset the combo?
|
||||
this.resetOnWrongKey = GetValue(config, 'resetOnWrongKey', true);
|
||||
|
||||
// The max delay in ms between each key press. Above this the combo is reset. 0 means disabled.
|
||||
this.maxKeyDelay = GetValue(config, 'maxKeyDelay', 0);
|
||||
|
||||
// If previously matched and they press Key 1 again, will it reset?
|
||||
this.resetOnMatch = GetValue(config, 'resetOnMatch', false);
|
||||
|
||||
// If the combo matches, will it delete itself?
|
||||
this.deleteOnMatch = GetValue(config, 'deleteOnMatch', false);
|
||||
|
||||
var _this = this;
|
||||
|
||||
var onKeyDownHandler = function (event)
|
||||
{
|
||||
if (_this.matched || !_this.enabled)
|
||||
{
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
var matched = ProcessKeyCombo(event.data, _this);
|
||||
this.manager = keyboardManager;
|
||||
|
||||
if (matched)
|
||||
this.enabled = true;
|
||||
|
||||
this.keyCodes = [];
|
||||
|
||||
// if 'keys' is a string we need to get the keycode of each character in it
|
||||
|
||||
for (var i = 0; i < keys.length; i++)
|
||||
{
|
||||
_this.manager.events.dispatch(new KeyComboMatchEvent(_this, event));
|
||||
var char = keys[i];
|
||||
|
||||
if (_this.resetOnMatch)
|
||||
if (typeof char === 'string')
|
||||
{
|
||||
ResetKeyCombo(_this);
|
||||
this.keyCodes.push(char.toUpperCase().charCodeAt(0));
|
||||
}
|
||||
else if (_this.deleteOnMatch)
|
||||
else if (typeof char === 'number')
|
||||
{
|
||||
_this.destroy();
|
||||
this.keyCodes.push(char);
|
||||
}
|
||||
else if (char.hasOwnProperty('keyCode'))
|
||||
{
|
||||
this.keyCodes.push(char.keyCode);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
this.onKeyDown = onKeyDownHandler;
|
||||
// The current keyCode the combo is waiting for
|
||||
this.current = this.keyCodes[0];
|
||||
|
||||
this.manager.events.on('KEY_DOWN_EVENT', onKeyDownHandler);
|
||||
};
|
||||
// The current index of the key being waited for in the 'keys' string
|
||||
this.index = 0;
|
||||
|
||||
KeyCombo.prototype.constructor = KeyCombo;
|
||||
// The length of this combo (in keycodes)
|
||||
this.size = this.keyCodes.length;
|
||||
|
||||
KeyCombo.prototype = {
|
||||
// The time the previous key in the combo was matched
|
||||
this.timeLastMatched = 0;
|
||||
|
||||
// Has this Key Combo been matched yet?
|
||||
this.matched = false;
|
||||
|
||||
// The time the entire combo was matched
|
||||
this.timeMatched = 0;
|
||||
|
||||
// Custom options ...
|
||||
|
||||
// If they press the wrong key do we reset the combo?
|
||||
this.resetOnWrongKey = GetFastValue(config, 'resetOnWrongKey', true);
|
||||
|
||||
// The max delay in ms between each key press. Above this the combo is reset. 0 means disabled.
|
||||
this.maxKeyDelay = GetFastValue(config, 'maxKeyDelay', 0);
|
||||
|
||||
// If previously matched and they press Key 1 again, will it reset?
|
||||
this.resetOnMatch = GetFastValue(config, 'resetOnMatch', false);
|
||||
|
||||
// If the combo matches, will it delete itself?
|
||||
this.deleteOnMatch = GetFastValue(config, 'deleteOnMatch', false);
|
||||
|
||||
var _this = this;
|
||||
|
||||
var onKeyDownHandler = function (event)
|
||||
{
|
||||
if (_this.matched || !_this.enabled)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var matched = ProcessKeyCombo(event.data, _this);
|
||||
|
||||
if (matched)
|
||||
{
|
||||
_this.manager.events.dispatch(new KeyComboMatchEvent(_this, event));
|
||||
|
||||
if (_this.resetOnMatch)
|
||||
{
|
||||
ResetKeyCombo(_this);
|
||||
}
|
||||
else if (_this.deleteOnMatch)
|
||||
{
|
||||
_this.destroy();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
this.onKeyDown = onKeyDownHandler;
|
||||
|
||||
this.manager.events.on('KEY_DOWN_EVENT', onKeyDownHandler);
|
||||
},
|
||||
|
||||
progress: {
|
||||
|
||||
// How far complete is this combo? A value between 0 and 1.
|
||||
get: function ()
|
||||
{
|
||||
return this.index / this.size;
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
destroy: function ()
|
||||
{
|
||||
|
@ -121,22 +132,6 @@ KeyCombo.prototype = {
|
|||
this.manager = undefined;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
Object.defineProperties(KeyCombo.prototype, {
|
||||
|
||||
progress: {
|
||||
|
||||
enumerable: true,
|
||||
|
||||
// How far complete is this combo? A value between 0 and 1.
|
||||
get: function ()
|
||||
{
|
||||
return this.index / this.size;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
module.exports = KeyCombo;
|
||||
|
|
|
@ -1,15 +1,21 @@
|
|||
var Class = require('../../../utils/Class');
|
||||
var Event = require('../../../events/Event');
|
||||
|
||||
var KeyComboMatchEvent = function (keyCombo, keyboardEvent)
|
||||
{
|
||||
Event.call(this, 'KEY_COMBO_MATCH_EVENT');
|
||||
var KeyComboMatchEvent = new Class({
|
||||
|
||||
this.target = keyCombo;
|
||||
Extends: Event,
|
||||
|
||||
this.data = keyboardEvent;
|
||||
};
|
||||
initialize:
|
||||
|
||||
KeyComboMatchEvent.prototype = Object.create(Event.prototype);
|
||||
KeyComboMatchEvent.prototype.constructor = KeyComboMatchEvent;
|
||||
function KeyComboMatchEvent (keyCombo, keyboardEvent)
|
||||
{
|
||||
Event.call(this, 'KEY_COMBO_MATCH_EVENT');
|
||||
|
||||
this.target = keyCombo;
|
||||
|
||||
this.data = keyboardEvent;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
module.exports = KeyComboMatchEvent;
|
||||
|
|
|
@ -1,13 +1,19 @@
|
|||
var Class = require('../../../utils/Class');
|
||||
var Event = require('../../../events/Event');
|
||||
|
||||
var KeyDownEvent = function (keyboardEvent)
|
||||
{
|
||||
Event.call(this, 'KEY_DOWN_EVENT');
|
||||
var KeyDownEvent = new Class({
|
||||
|
||||
this.data = keyboardEvent;
|
||||
};
|
||||
Extends: Event,
|
||||
|
||||
KeyDownEvent.prototype = Object.create(Event.prototype);
|
||||
KeyDownEvent.prototype.constructor = KeyDownEvent;
|
||||
initialize:
|
||||
|
||||
function KeyDownEvent (keyboardEvent)
|
||||
{
|
||||
Event.call(this, 'KEY_DOWN_EVENT');
|
||||
|
||||
this.data = keyboardEvent;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
module.exports = KeyDownEvent;
|
||||
|
|
|
@ -1,13 +1,19 @@
|
|||
var Class = require('../../../utils/Class');
|
||||
var Event = require('../../../events/Event');
|
||||
|
||||
var KeyUpEvent = function (keyboardEvent)
|
||||
{
|
||||
Event.call(this, 'KEY_UP_EVENT');
|
||||
var KeyUpEvent = new Class({
|
||||
|
||||
this.data = keyboardEvent;
|
||||
};
|
||||
Extends: Event,
|
||||
|
||||
KeyUpEvent.prototype = Object.create(Event.prototype);
|
||||
KeyUpEvent.prototype.constructor = KeyUpEvent;
|
||||
initialize:
|
||||
|
||||
function KeyUpEvent (keyboardEvent)
|
||||
{
|
||||
Event.call(this, 'KEY_UP_EVENT');
|
||||
|
||||
this.data = keyboardEvent;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
module.exports = KeyUpEvent;
|
||||
|
|
|
@ -1,108 +1,112 @@
|
|||
// Can this become just a generic object instead of a class?
|
||||
|
||||
var Class = require('../../../utils/Class');
|
||||
|
||||
// Phaser.Input.Keyboard.Key
|
||||
|
||||
// A generic Key object which can be passed to the Process functions (and so on)
|
||||
// keycode must be an integer
|
||||
|
||||
var Key = function (keyCode)
|
||||
{
|
||||
/**
|
||||
* @property {integer} keyCode - The keycode of this key.
|
||||
*/
|
||||
this.keyCode = keyCode;
|
||||
var Key = new Class({
|
||||
|
||||
/**
|
||||
* @property {KeyboardEvent} originalEvent - The original DOM event.
|
||||
*/
|
||||
this.originalEvent = undefined;
|
||||
initialize:
|
||||
|
||||
/**
|
||||
* @property {boolean} preventDefault - Should this Key prevent event propagation?
|
||||
* @default
|
||||
*/
|
||||
this.preventDefault = true;
|
||||
function Key (keyCode)
|
||||
{
|
||||
/**
|
||||
* @property {integer} keyCode - The keycode of this key.
|
||||
*/
|
||||
this.keyCode = keyCode;
|
||||
|
||||
/**
|
||||
* @property {boolean} enabled - Can this Key be processed?
|
||||
* @default
|
||||
*/
|
||||
this.enabled = true;
|
||||
/**
|
||||
* @property {KeyboardEvent} originalEvent - The original DOM event.
|
||||
*/
|
||||
this.originalEvent = undefined;
|
||||
|
||||
/**
|
||||
* @property {boolean} isDown - The "down" state of the key. This will remain `true` for as long as the keyboard thinks this key is held down.
|
||||
* @default
|
||||
*/
|
||||
this.isDown = false;
|
||||
/**
|
||||
* @property {boolean} preventDefault - Should this Key prevent event propagation?
|
||||
* @default
|
||||
*/
|
||||
this.preventDefault = true;
|
||||
|
||||
/**
|
||||
* @property {boolean} isUp - The "up" state of the key. This will remain `true` for as long as the keyboard thinks this key is up.
|
||||
* @default
|
||||
*/
|
||||
this.isUp = true;
|
||||
/**
|
||||
* @property {boolean} enabled - Can this Key be processed?
|
||||
* @default
|
||||
*/
|
||||
this.enabled = true;
|
||||
|
||||
/**
|
||||
* @property {boolean} altKey - The down state of the ALT key, if pressed at the same time as this key.
|
||||
* @default
|
||||
*/
|
||||
this.altKey = false;
|
||||
/**
|
||||
* @property {boolean} isDown - The "down" state of the key. This will remain `true` for as long as the keyboard thinks this key is held down.
|
||||
* @default
|
||||
*/
|
||||
this.isDown = false;
|
||||
|
||||
/**
|
||||
* @property {boolean} ctrlKey - The down state of the CTRL key, if pressed at the same time as this key.
|
||||
* @default
|
||||
*/
|
||||
this.ctrlKey = false;
|
||||
/**
|
||||
* @property {boolean} isUp - The "up" state of the key. This will remain `true` for as long as the keyboard thinks this key is up.
|
||||
* @default
|
||||
*/
|
||||
this.isUp = true;
|
||||
|
||||
/**
|
||||
* @property {boolean} shiftKey - The down state of the SHIFT key, if pressed at the same time as this key.
|
||||
* @default
|
||||
*/
|
||||
this.shiftKey = false;
|
||||
/**
|
||||
* @property {boolean} altKey - The down state of the ALT key, if pressed at the same time as this key.
|
||||
* @default
|
||||
*/
|
||||
this.altKey = false;
|
||||
|
||||
/**
|
||||
* @property {integer} location - The location of the modifier key. 0 for standard (or unknown), 1 for left, 2 for right, 3 for numpad.
|
||||
* @default
|
||||
*/
|
||||
this.location = 0;
|
||||
/**
|
||||
* @property {boolean} ctrlKey - The down state of the CTRL key, if pressed at the same time as this key.
|
||||
* @default
|
||||
*/
|
||||
this.ctrlKey = false;
|
||||
|
||||
/**
|
||||
* @property {number} timeDown - The timestamp when the key was last pressed down. This is based on Game.time.now.
|
||||
*/
|
||||
this.timeDown = 0;
|
||||
/**
|
||||
* @property {boolean} shiftKey - The down state of the SHIFT key, if pressed at the same time as this key.
|
||||
* @default
|
||||
*/
|
||||
this.shiftKey = false;
|
||||
|
||||
/**
|
||||
* If the key is down this value holds the duration of that key press and is constantly updated.
|
||||
* If the key is up it holds the duration of the previous down session.
|
||||
* @property {number} duration - The number of milliseconds this key has been held down for.
|
||||
* @default
|
||||
*/
|
||||
this.duration = 0;
|
||||
/**
|
||||
* @property {integer} location - The location of the modifier key. 0 for standard (or unknown), 1 for left, 2 for right, 3 for numpad.
|
||||
* @default
|
||||
*/
|
||||
this.location = 0;
|
||||
|
||||
/**
|
||||
* @property {number} timeUp - The timestamp when the key was last released. This is based on Game.time.now.
|
||||
* @default
|
||||
*/
|
||||
this.timeUp = 0;
|
||||
/**
|
||||
* @property {number} timeDown - The timestamp when the key was last pressed down. This is based on Game.time.now.
|
||||
*/
|
||||
this.timeDown = 0;
|
||||
|
||||
/**
|
||||
* @property {number} repeats - If a key is held down this holds down the number of times the key has 'repeated'.
|
||||
* @default
|
||||
*/
|
||||
this.repeats = 0;
|
||||
/**
|
||||
* If the key is down this value holds the duration of that key press and is constantly updated.
|
||||
* If the key is up it holds the duration of the previous down session.
|
||||
* @property {number} duration - The number of milliseconds this key has been held down for.
|
||||
* @default
|
||||
*/
|
||||
this.duration = 0;
|
||||
|
||||
/**
|
||||
* @property {boolean} _justDown - True if the key has just been pressed (NOTE: requires to be reset, see justDown getter)
|
||||
* @private
|
||||
*/
|
||||
this._justDown = false;
|
||||
/**
|
||||
* @property {number} timeUp - The timestamp when the key was last released. This is based on Game.time.now.
|
||||
* @default
|
||||
*/
|
||||
this.timeUp = 0;
|
||||
|
||||
/**
|
||||
* @property {boolean} _justUp - True if the key has just been pressed (NOTE: requires to be reset, see justDown getter)
|
||||
* @private
|
||||
*/
|
||||
this._justUp = false;
|
||||
};
|
||||
/**
|
||||
* @property {number} repeats - If a key is held down this holds down the number of times the key has 'repeated'.
|
||||
* @default
|
||||
*/
|
||||
this.repeats = 0;
|
||||
|
||||
Key.prototype.constructor = Key;
|
||||
/**
|
||||
* @property {boolean} _justDown - True if the key has just been pressed (NOTE: requires to be reset, see justDown getter)
|
||||
* @private
|
||||
*/
|
||||
this._justDown = false;
|
||||
|
||||
/**
|
||||
* @property {boolean} _justUp - True if the key has just been pressed (NOTE: requires to be reset, see justDown getter)
|
||||
* @private
|
||||
*/
|
||||
this._justUp = false;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
module.exports = Key;
|
||||
|
|
|
@ -4,40 +4,43 @@ var Set = require('../structs/Set');
|
|||
var XHRSettings = require('./XHRSettings');
|
||||
var Event = require('./events/');
|
||||
var EventDispatcher = require('../events/EventDispatcher');
|
||||
var Class = require('../utils/Class');
|
||||
|
||||
var BaseLoader = function ()
|
||||
{
|
||||
// To finish the loader ...
|
||||
//
|
||||
// 3) Progress update
|
||||
// Phaser.Loader.BaseLoader
|
||||
|
||||
this.events = new EventDispatcher();
|
||||
// To finish the loader ...
|
||||
//
|
||||
// 3) Progress update
|
||||
|
||||
// Move to a 'setURL' method?
|
||||
this.baseURL = '';
|
||||
this.path = '';
|
||||
var BaseLoader = new Class({
|
||||
|
||||
// Read from Game / State Config
|
||||
this.enableParallel = true;
|
||||
this.maxParallelDownloads = 4;
|
||||
initialize:
|
||||
|
||||
// xhr specific global settings (can be overridden on a per-file basis)
|
||||
this.xhr = XHRSettings();
|
||||
function BaseLoader ()
|
||||
{
|
||||
this.events = new EventDispatcher();
|
||||
|
||||
this.crossOrigin = undefined;
|
||||
// Move to a 'setURL' method?
|
||||
this.baseURL = '';
|
||||
this.path = '';
|
||||
|
||||
this.list = new Set();
|
||||
this.inflight = new Set();
|
||||
this.failed = new Set();
|
||||
this.queue = new Set();
|
||||
this.storage = new Set();
|
||||
// Read from Game / State Config
|
||||
this.enableParallel = true;
|
||||
this.maxParallelDownloads = 4;
|
||||
|
||||
this._state = CONST.LOADER_IDLE;
|
||||
};
|
||||
// xhr specific global settings (can be overridden on a per-file basis)
|
||||
this.xhr = XHRSettings();
|
||||
|
||||
BaseLoader.prototype.contructor = BaseLoader;
|
||||
this.crossOrigin = undefined;
|
||||
|
||||
BaseLoader.prototype = {
|
||||
this.list = new Set();
|
||||
this.inflight = new Set();
|
||||
this.failed = new Set();
|
||||
this.queue = new Set();
|
||||
this.storage = new Set();
|
||||
|
||||
this._state = CONST.LOADER_IDLE;
|
||||
},
|
||||
|
||||
addFile: function (file)
|
||||
{
|
||||
|
@ -287,6 +290,6 @@ BaseLoader.prototype = {
|
|||
this._state = CONST.LOADER_DESTROYED;
|
||||
}
|
||||
|
||||
};
|
||||
});
|
||||
|
||||
module.exports = BaseLoader;
|
||||
|
|
|
@ -1,59 +1,62 @@
|
|||
var GetURL = require('./GetURL');
|
||||
var Class = require('../utils/Class');
|
||||
var CONST = require('./const');
|
||||
var GetURL = require('./GetURL');
|
||||
var MergeXHRSettings = require('./MergeXHRSettings');
|
||||
var XHRLoader = require('./XHRLoader');
|
||||
var XHRSettings = require('./XHRSettings');
|
||||
var MergeXHRSettings = require('./MergeXHRSettings');
|
||||
|
||||
var File = function (type, key, url, responseType, xhrSettings, config)
|
||||
{
|
||||
// file type (image, json, etc) for sorting within the Loader
|
||||
this.type = type;
|
||||
// Phaser.Loader.File
|
||||
|
||||
// unique cache key (unique within its file type)
|
||||
this.key = key;
|
||||
var File = new Class({
|
||||
|
||||
// The URL of the file, not including baseURL
|
||||
this.url = url;
|
||||
initialize:
|
||||
|
||||
// Set when the Loader calls 'load' on this file
|
||||
this.src = '';
|
||||
|
||||
this.xhrSettings = XHRSettings(responseType);
|
||||
|
||||
if (xhrSettings)
|
||||
function File (type, key, url, responseType, xhrSettings, config)
|
||||
{
|
||||
this.xhrSettings = MergeXHRSettings(this.xhrSettings, xhrSettings);
|
||||
}
|
||||
// file type (image, json, etc) for sorting within the Loader
|
||||
this.type = type;
|
||||
|
||||
this.xhrLoader = null;
|
||||
// unique cache key (unique within its file type)
|
||||
this.key = key;
|
||||
|
||||
this.state = CONST.FILE_PENDING;
|
||||
// The URL of the file, not including baseURL
|
||||
this.url = url;
|
||||
|
||||
// Set by onProgress (only if loading via XHR)
|
||||
this.bytesTotal = 0;
|
||||
this.bytesLoaded = -1;
|
||||
this.percentComplete = -1;
|
||||
// Set when the Loader calls 'load' on this file
|
||||
this.src = '';
|
||||
|
||||
// For CORs based loading.
|
||||
// If this is undefined then the File will check BaseLoader.crossOrigin and use that (if set)
|
||||
this.crossOrigin = undefined;
|
||||
this.xhrSettings = XHRSettings(responseType);
|
||||
|
||||
// The actual processed file data
|
||||
this.data = undefined;
|
||||
if (xhrSettings)
|
||||
{
|
||||
this.xhrSettings = MergeXHRSettings(this.xhrSettings, xhrSettings);
|
||||
}
|
||||
|
||||
// A config object that can be used by file types to store transitional data
|
||||
this.config = config || {};
|
||||
this.xhrLoader = null;
|
||||
|
||||
// Multipart file? (i.e. an atlas and its json together)
|
||||
this.linkFile = undefined;
|
||||
this.linkType = '';
|
||||
this.state = CONST.FILE_PENDING;
|
||||
|
||||
this.callback = null;
|
||||
};
|
||||
// Set by onProgress (only if loading via XHR)
|
||||
this.bytesTotal = 0;
|
||||
this.bytesLoaded = -1;
|
||||
this.percentComplete = -1;
|
||||
|
||||
File.prototype.constructor = File;
|
||||
// For CORs based loading.
|
||||
// If this is undefined then the File will check BaseLoader.crossOrigin and use that (if set)
|
||||
this.crossOrigin = undefined;
|
||||
|
||||
File.prototype = {
|
||||
// The actual processed file data
|
||||
this.data = undefined;
|
||||
|
||||
// A config object that can be used by file types to store transitional data
|
||||
this.config = config || {};
|
||||
|
||||
// Multipart file? (i.e. an atlas and its json together)
|
||||
this.linkFile = undefined;
|
||||
this.linkType = '';
|
||||
|
||||
this.callback = null;
|
||||
},
|
||||
|
||||
resetXHR: function ()
|
||||
{
|
||||
|
@ -140,6 +143,7 @@ File.prototype = {
|
|||
this.xhrLoader = XHRLoader(this, globalXHR);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
});
|
||||
|
||||
module.exports = File;
|
||||
|
|
|
@ -1,40 +1,47 @@
|
|||
|
||||
var Class = require('../../utils/Class');
|
||||
var CONST = require('../const');
|
||||
var File = require('../File');
|
||||
|
||||
var BinaryFile = function (key, url, path, xhrSettings)
|
||||
{
|
||||
if (path === undefined) { path = ''; }
|
||||
// Phaser.Loader.FileTypes.BinaryFile
|
||||
|
||||
if (!key)
|
||||
var BinaryFile = new Class({
|
||||
|
||||
Extends: File,
|
||||
|
||||
initialize:
|
||||
|
||||
function BinaryFile (key, url, path, xhrSettings)
|
||||
{
|
||||
throw new Error('Error calling \'Loader.binary\' invalid key provided.');
|
||||
if (path === undefined) { path = ''; }
|
||||
|
||||
if (!key)
|
||||
{
|
||||
throw new Error('Error calling \'Loader.binary\' invalid key provided.');
|
||||
}
|
||||
|
||||
if (!url)
|
||||
{
|
||||
url = path + key + '.bin';
|
||||
}
|
||||
else
|
||||
{
|
||||
url = path.concat(url);
|
||||
}
|
||||
|
||||
File.call(this, 'binary', key, url, 'arraybuffer', xhrSettings);
|
||||
},
|
||||
|
||||
onProcess: function (callback)
|
||||
{
|
||||
this.state = CONST.FILE_PROCESSING;
|
||||
|
||||
this.data = this.xhrLoader.response;
|
||||
|
||||
this.onComplete();
|
||||
|
||||
callback(this);
|
||||
}
|
||||
|
||||
if (!url)
|
||||
{
|
||||
url = path + key + '.bin';
|
||||
}
|
||||
else
|
||||
{
|
||||
url = path.concat(url);
|
||||
}
|
||||
|
||||
File.call(this, 'binary', key, url, 'arraybuffer', xhrSettings);
|
||||
};
|
||||
|
||||
BinaryFile.prototype = Object.create(File.prototype);
|
||||
BinaryFile.prototype.constructor = BinaryFile;
|
||||
|
||||
BinaryFile.prototype.onProcess = function (callback)
|
||||
{
|
||||
this.state = CONST.FILE_PROCESSING;
|
||||
|
||||
this.data = this.xhrLoader.response;
|
||||
|
||||
this.onComplete();
|
||||
|
||||
callback(this);
|
||||
};
|
||||
});
|
||||
|
||||
module.exports = BinaryFile;
|
||||
|
|
|
@ -1,40 +1,47 @@
|
|||
|
||||
var Class = require('../../utils/Class');
|
||||
var CONST = require('../const');
|
||||
var File = require('../File');
|
||||
|
||||
var GLSLFile = function (key, url, path, xhrSettings)
|
||||
{
|
||||
if (path === undefined) { path = ''; }
|
||||
// Phaser.Loader.FileTypes.GLSLFile
|
||||
|
||||
if (!key)
|
||||
var GLSLFile = new Class({
|
||||
|
||||
Extends: File,
|
||||
|
||||
initialize:
|
||||
|
||||
function GLSLFile (key, url, path, xhrSettings)
|
||||
{
|
||||
throw new Error('Error calling \'Loader.text\' invalid key provided.');
|
||||
if (path === undefined) { path = ''; }
|
||||
|
||||
if (!key)
|
||||
{
|
||||
throw new Error('Error calling \'Loader.glsl\' invalid key provided.');
|
||||
}
|
||||
|
||||
if (!url)
|
||||
{
|
||||
url = path + key + '.glsl';
|
||||
}
|
||||
else
|
||||
{
|
||||
url = path.concat(url);
|
||||
}
|
||||
|
||||
File.call(this, 'glsl', key, url, 'text', xhrSettings);
|
||||
},
|
||||
|
||||
onProcess: function (callback)
|
||||
{
|
||||
this.state = CONST.FILE_PROCESSING;
|
||||
|
||||
this.data = this.xhrLoader.responseText;
|
||||
|
||||
this.onComplete();
|
||||
|
||||
callback(this);
|
||||
}
|
||||
|
||||
if (!url)
|
||||
{
|
||||
url = path + key + '.glsl';
|
||||
}
|
||||
else
|
||||
{
|
||||
url = path.concat(url);
|
||||
}
|
||||
|
||||
File.call(this, 'glsl', key, url, 'text', xhrSettings);
|
||||
};
|
||||
|
||||
GLSLFile.prototype = Object.create(File.prototype);
|
||||
GLSLFile.prototype.constructor = GLSLFile;
|
||||
|
||||
GLSLFile.prototype.onProcess = function (callback)
|
||||
{
|
||||
this.state = CONST.FILE_PROCESSING;
|
||||
|
||||
this.data = this.xhrLoader.responseText;
|
||||
|
||||
this.onComplete();
|
||||
|
||||
callback(this);
|
||||
};
|
||||
});
|
||||
|
||||
module.exports = GLSLFile;
|
||||
|
|
|
@ -1,94 +1,101 @@
|
|||
|
||||
var Class = require('../../utils/Class');
|
||||
var CONST = require('../const');
|
||||
var File = require('../File');
|
||||
|
||||
var HTMLFile = function (key, url, width, height, path, xhrSettings)
|
||||
{
|
||||
if (width === undefined) { width = 512; }
|
||||
if (height === undefined) { height = 512; }
|
||||
if (path === undefined) { path = ''; }
|
||||
// Phaser.Loader.FileTypes.HTMLFile
|
||||
|
||||
if (!key)
|
||||
var HTMLFile = new Class({
|
||||
|
||||
Extends: File,
|
||||
|
||||
initialize:
|
||||
|
||||
function HTMLFile (key, url, width, height, path, xhrSettings)
|
||||
{
|
||||
throw new Error('Error calling \'Loader.html\' invalid key provided.');
|
||||
if (width === undefined) { width = 512; }
|
||||
if (height === undefined) { height = 512; }
|
||||
if (path === undefined) { path = ''; }
|
||||
|
||||
if (!key)
|
||||
{
|
||||
throw new Error('Error calling \'Loader.html\' invalid key provided.');
|
||||
}
|
||||
|
||||
if (!url)
|
||||
{
|
||||
url = path + key + '.html';
|
||||
}
|
||||
else
|
||||
{
|
||||
url = path.concat(url);
|
||||
}
|
||||
|
||||
var config = {
|
||||
width: width,
|
||||
height: height
|
||||
};
|
||||
|
||||
File.call(this, 'html', key, url, 'text', xhrSettings, config);
|
||||
},
|
||||
|
||||
onProcess: function (callback)
|
||||
{
|
||||
this.state = CONST.FILE_PROCESSING;
|
||||
|
||||
var w = this.config.width;
|
||||
var h = this.config.height;
|
||||
|
||||
var data = [];
|
||||
|
||||
data.push('<svg width="' + w + 'px" height="' + h + 'px" viewBox="0 0 ' + w + ' ' + h + '" xmlns="http://www.w3.org/2000/svg">');
|
||||
data.push('<foreignObject width="100%" height="100%">');
|
||||
data.push('<body xmlns="http://www.w3.org/1999/xhtml">');
|
||||
data.push(this.xhrLoader.responseText);
|
||||
data.push('</body>');
|
||||
data.push('</foreignObject>');
|
||||
data.push('</svg>');
|
||||
|
||||
var svg = [ data.join('\n') ];
|
||||
var _this = this;
|
||||
|
||||
try
|
||||
{
|
||||
var blob = new window.Blob(svg, { type: 'image/svg+xml;charset=utf-8' });
|
||||
}
|
||||
catch (e)
|
||||
{
|
||||
_this.state = CONST.FILE_ERRORED;
|
||||
|
||||
callback(_this);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
this.data = new Image();
|
||||
|
||||
this.data.crossOrigin = this.crossOrigin;
|
||||
|
||||
this.data.onload = function ()
|
||||
{
|
||||
URL.revokeObjectURL(_this.data.src);
|
||||
|
||||
_this.onComplete();
|
||||
|
||||
callback(_this);
|
||||
};
|
||||
|
||||
this.data.onerror = function ()
|
||||
{
|
||||
URL.revokeObjectURL(_this.data.src);
|
||||
|
||||
_this.state = CONST.FILE_ERRORED;
|
||||
|
||||
callback(_this);
|
||||
};
|
||||
|
||||
this.data.src = URL.createObjectURL(blob);
|
||||
}
|
||||
|
||||
if (!url)
|
||||
{
|
||||
url = path + key + '.html';
|
||||
}
|
||||
else
|
||||
{
|
||||
url = path.concat(url);
|
||||
}
|
||||
|
||||
var config = {
|
||||
width: width,
|
||||
height: height
|
||||
};
|
||||
|
||||
File.call(this, 'html', key, url, 'text', xhrSettings, config);
|
||||
};
|
||||
|
||||
HTMLFile.prototype = Object.create(File.prototype);
|
||||
HTMLFile.prototype.constructor = HTMLFile;
|
||||
|
||||
HTMLFile.prototype.onProcess = function (callback)
|
||||
{
|
||||
this.state = CONST.FILE_PROCESSING;
|
||||
|
||||
var w = this.config.width;
|
||||
var h = this.config.height;
|
||||
|
||||
var data = [];
|
||||
|
||||
data.push('<svg width="' + w + 'px" height="' + h + 'px" viewBox="0 0 ' + w + ' ' + h + '" xmlns="http://www.w3.org/2000/svg">');
|
||||
data.push('<foreignObject width="100%" height="100%">');
|
||||
data.push('<body xmlns="http://www.w3.org/1999/xhtml">');
|
||||
data.push(this.xhrLoader.responseText);
|
||||
data.push('</body>');
|
||||
data.push('</foreignObject>');
|
||||
data.push('</svg>');
|
||||
|
||||
var svg = [ data.join('\n') ];
|
||||
var _this = this;
|
||||
|
||||
try
|
||||
{
|
||||
var blob = new window.Blob(svg, { type: 'image/svg+xml;charset=utf-8' });
|
||||
}
|
||||
catch (e)
|
||||
{
|
||||
_this.state = CONST.FILE_ERRORED;
|
||||
|
||||
callback(_this);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
this.data = new Image();
|
||||
|
||||
this.data.crossOrigin = this.crossOrigin;
|
||||
|
||||
this.data.onload = function ()
|
||||
{
|
||||
URL.revokeObjectURL(_this.data.src);
|
||||
|
||||
_this.onComplete();
|
||||
|
||||
callback(_this);
|
||||
};
|
||||
|
||||
this.data.onerror = function ()
|
||||
{
|
||||
URL.revokeObjectURL(_this.data.src);
|
||||
|
||||
_this.state = CONST.FILE_ERRORED;
|
||||
|
||||
callback(_this);
|
||||
};
|
||||
|
||||
this.data.src = URL.createObjectURL(blob);
|
||||
};
|
||||
});
|
||||
|
||||
module.exports = HTMLFile;
|
||||
|
|
|
@ -1,60 +1,67 @@
|
|||
|
||||
var Class = require('../../utils/Class');
|
||||
var CONST = require('../const');
|
||||
var File = require('../File');
|
||||
|
||||
var ImageFile = function (key, url, path, xhrSettings, config)
|
||||
{
|
||||
if (path === undefined) { path = ''; }
|
||||
// Phaser.Loader.FileTypes.ImageFile
|
||||
|
||||
if (!key)
|
||||
var ImageFile = new Class({
|
||||
|
||||
Extends: File,
|
||||
|
||||
initialize:
|
||||
|
||||
function ImageFile (key, url, path, xhrSettings, config)
|
||||
{
|
||||
throw new Error('Error calling \'Loader.image\' invalid key provided.');
|
||||
if (path === undefined) { path = ''; }
|
||||
|
||||
if (!key)
|
||||
{
|
||||
throw new Error('Error calling \'Loader.image\' invalid key provided.');
|
||||
}
|
||||
|
||||
if (!url)
|
||||
{
|
||||
url = path + key + '.png';
|
||||
}
|
||||
else
|
||||
{
|
||||
url = path.concat(url);
|
||||
}
|
||||
|
||||
File.call(this, 'image', key, url, 'blob', xhrSettings, config);
|
||||
},
|
||||
|
||||
onProcess: function (callback)
|
||||
{
|
||||
this.state = CONST.FILE_PROCESSING;
|
||||
|
||||
this.data = new Image();
|
||||
|
||||
this.data.crossOrigin = this.crossOrigin;
|
||||
|
||||
var _this = this;
|
||||
|
||||
this.data.onload = function ()
|
||||
{
|
||||
URL.revokeObjectURL(_this.data.src);
|
||||
|
||||
_this.onComplete();
|
||||
|
||||
callback(_this);
|
||||
};
|
||||
|
||||
this.data.onerror = function ()
|
||||
{
|
||||
URL.revokeObjectURL(_this.data.src);
|
||||
|
||||
_this.state = CONST.FILE_ERRORED;
|
||||
|
||||
callback(_this);
|
||||
};
|
||||
|
||||
this.data.src = URL.createObjectURL(this.xhrLoader.response);
|
||||
}
|
||||
|
||||
if (!url)
|
||||
{
|
||||
url = path + key + '.png';
|
||||
}
|
||||
else
|
||||
{
|
||||
url = path.concat(url);
|
||||
}
|
||||
|
||||
File.call(this, 'image', key, url, 'blob', xhrSettings, config);
|
||||
};
|
||||
|
||||
ImageFile.prototype = Object.create(File.prototype);
|
||||
ImageFile.prototype.constructor = ImageFile;
|
||||
|
||||
ImageFile.prototype.onProcess = function (callback)
|
||||
{
|
||||
this.state = CONST.FILE_PROCESSING;
|
||||
|
||||
this.data = new Image();
|
||||
|
||||
this.data.crossOrigin = this.crossOrigin;
|
||||
|
||||
var _this = this;
|
||||
|
||||
this.data.onload = function ()
|
||||
{
|
||||
URL.revokeObjectURL(_this.data.src);
|
||||
|
||||
_this.onComplete();
|
||||
|
||||
callback(_this);
|
||||
};
|
||||
|
||||
this.data.onerror = function ()
|
||||
{
|
||||
URL.revokeObjectURL(_this.data.src);
|
||||
|
||||
_this.state = CONST.FILE_ERRORED;
|
||||
|
||||
callback(_this);
|
||||
};
|
||||
|
||||
this.data.src = URL.createObjectURL(this.xhrLoader.response);
|
||||
};
|
||||
});
|
||||
|
||||
module.exports = ImageFile;
|
||||
|
|
|
@ -1,40 +1,47 @@
|
|||
|
||||
var Class = require('../../utils/Class');
|
||||
var CONST = require('../const');
|
||||
var File = require('../File');
|
||||
|
||||
var JSONFile = function (key, url, path, xhrSettings)
|
||||
{
|
||||
if (path === undefined) { path = ''; }
|
||||
// Phaser.Loader.FileTypes.JSONFile
|
||||
|
||||
if (!key)
|
||||
var JSONFile = new Class({
|
||||
|
||||
Extends: File,
|
||||
|
||||
initialize:
|
||||
|
||||
function JSONFile (key, url, path, xhrSettings)
|
||||
{
|
||||
throw new Error('Error calling \'Loader.json\' invalid key provided.');
|
||||
if (path === undefined) { path = ''; }
|
||||
|
||||
if (!key)
|
||||
{
|
||||
throw new Error('Error calling \'Loader.json\' invalid key provided.');
|
||||
}
|
||||
|
||||
if (!url)
|
||||
{
|
||||
url = path + key + '.json';
|
||||
}
|
||||
else
|
||||
{
|
||||
url = path.concat(url);
|
||||
}
|
||||
|
||||
File.call(this, 'json', key, url, 'text', xhrSettings);
|
||||
},
|
||||
|
||||
onProcess: function (callback)
|
||||
{
|
||||
this.state = CONST.FILE_PROCESSING;
|
||||
|
||||
this.data = JSON.parse(this.xhrLoader.responseText);
|
||||
|
||||
this.onComplete();
|
||||
|
||||
callback(this);
|
||||
}
|
||||
|
||||
if (!url)
|
||||
{
|
||||
url = path + key + '.json';
|
||||
}
|
||||
else
|
||||
{
|
||||
url = path.concat(url);
|
||||
}
|
||||
|
||||
File.call(this, 'json', key, url, 'text', xhrSettings);
|
||||
};
|
||||
|
||||
JSONFile.prototype = Object.create(File.prototype);
|
||||
JSONFile.prototype.constructor = JSONFile;
|
||||
|
||||
JSONFile.prototype.onProcess = function (callback)
|
||||
{
|
||||
this.state = CONST.FILE_PROCESSING;
|
||||
|
||||
this.data = JSON.parse(this.xhrLoader.responseText);
|
||||
|
||||
this.onComplete();
|
||||
|
||||
callback(this);
|
||||
};
|
||||
});
|
||||
|
||||
module.exports = JSONFile;
|
||||
|
|
|
@ -1,88 +1,95 @@
|
|||
|
||||
var Class = require('../../utils/Class');
|
||||
var CONST = require('../const');
|
||||
var File = require('../File');
|
||||
|
||||
var SVGFile = function (key, url, path, xhrSettings)
|
||||
{
|
||||
if (path === undefined) { path = ''; }
|
||||
// Phaser.Loader.FileTypes.SVGFile
|
||||
|
||||
if (!key)
|
||||
var SVGFile = new Class({
|
||||
|
||||
Extends: File,
|
||||
|
||||
initialize:
|
||||
|
||||
function SVGFile (key, url, path, xhrSettings)
|
||||
{
|
||||
throw new Error('Error calling \'Loader.svg\' invalid key provided.');
|
||||
}
|
||||
if (path === undefined) { path = ''; }
|
||||
|
||||
if (!url)
|
||||
{
|
||||
url = path + key + '.svg';
|
||||
}
|
||||
else
|
||||
{
|
||||
url = path.concat(url);
|
||||
}
|
||||
|
||||
File.call(this, 'svg', key, url, 'text', xhrSettings);
|
||||
};
|
||||
|
||||
SVGFile.prototype = Object.create(File.prototype);
|
||||
SVGFile.prototype.constructor = SVGFile;
|
||||
|
||||
SVGFile.prototype.onProcess = function (callback)
|
||||
{
|
||||
this.state = CONST.FILE_PROCESSING;
|
||||
|
||||
var svg = [ this.xhrLoader.responseText ];
|
||||
var _this = this;
|
||||
|
||||
try
|
||||
{
|
||||
var blob = new window.Blob(svg, { type: 'image/svg+xml;charset=utf-8' });
|
||||
}
|
||||
catch (e)
|
||||
{
|
||||
_this.state = CONST.FILE_ERRORED;
|
||||
|
||||
callback(_this);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
this.data = new Image();
|
||||
|
||||
this.data.crossOrigin = this.crossOrigin;
|
||||
|
||||
var retry = false;
|
||||
|
||||
this.data.onload = function ()
|
||||
{
|
||||
URL.revokeObjectURL(_this.data.src);
|
||||
|
||||
_this.onComplete();
|
||||
|
||||
callback(_this);
|
||||
};
|
||||
|
||||
this.data.onerror = function ()
|
||||
{
|
||||
URL.revokeObjectURL(_this.data.src);
|
||||
|
||||
// Safari 8 re-try
|
||||
if (!retry)
|
||||
if (!key)
|
||||
{
|
||||
retry = true;
|
||||
throw new Error('Error calling \'Loader.svg\' invalid key provided.');
|
||||
}
|
||||
|
||||
var url = 'data:image/svg+xml,' + encodeURIComponent(svg.join(''));
|
||||
|
||||
_this.data.src = URL.createObjectURL(url);
|
||||
if (!url)
|
||||
{
|
||||
url = path + key + '.svg';
|
||||
}
|
||||
else
|
||||
{
|
||||
url = path.concat(url);
|
||||
}
|
||||
|
||||
File.call(this, 'svg', key, url, 'text', xhrSettings);
|
||||
},
|
||||
|
||||
onProcess: function (callback)
|
||||
{
|
||||
this.state = CONST.FILE_PROCESSING;
|
||||
|
||||
var svg = [ this.xhrLoader.responseText ];
|
||||
var _this = this;
|
||||
|
||||
try
|
||||
{
|
||||
var blob = new window.Blob(svg, { type: 'image/svg+xml;charset=utf-8' });
|
||||
}
|
||||
catch (e)
|
||||
{
|
||||
_this.state = CONST.FILE_ERRORED;
|
||||
|
||||
callback(_this);
|
||||
}
|
||||
};
|
||||
|
||||
this.data.src = URL.createObjectURL(blob);
|
||||
};
|
||||
return;
|
||||
}
|
||||
|
||||
this.data = new Image();
|
||||
|
||||
this.data.crossOrigin = this.crossOrigin;
|
||||
|
||||
var retry = false;
|
||||
|
||||
this.data.onload = function ()
|
||||
{
|
||||
URL.revokeObjectURL(_this.data.src);
|
||||
|
||||
_this.onComplete();
|
||||
|
||||
callback(_this);
|
||||
};
|
||||
|
||||
this.data.onerror = function ()
|
||||
{
|
||||
URL.revokeObjectURL(_this.data.src);
|
||||
|
||||
// Safari 8 re-try
|
||||
if (!retry)
|
||||
{
|
||||
retry = true;
|
||||
|
||||
var url = 'data:image/svg+xml,' + encodeURIComponent(svg.join(''));
|
||||
|
||||
_this.data.src = URL.createObjectURL(url);
|
||||
}
|
||||
else
|
||||
{
|
||||
_this.state = CONST.FILE_ERRORED;
|
||||
|
||||
callback(_this);
|
||||
}
|
||||
};
|
||||
|
||||
this.data.src = URL.createObjectURL(blob);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
module.exports = SVGFile;
|
||||
|
|
|
@ -1,40 +1,47 @@
|
|||
|
||||
var Class = require('../../utils/Class');
|
||||
var CONST = require('../const');
|
||||
var File = require('../File');
|
||||
|
||||
var TextFile = function (key, url, path, xhrSettings)
|
||||
{
|
||||
if (path === undefined) { path = ''; }
|
||||
// Phaser.Loader.FileTypes.TextFile
|
||||
|
||||
if (!key)
|
||||
var TextFile = new Class({
|
||||
|
||||
Extends: File,
|
||||
|
||||
initialize:
|
||||
|
||||
function TextFile (key, url, path, xhrSettings)
|
||||
{
|
||||
throw new Error('Error calling \'Loader.text\' invalid key provided.');
|
||||
if (path === undefined) { path = ''; }
|
||||
|
||||
if (!key)
|
||||
{
|
||||
throw new Error('Error calling \'Loader.txt\' invalid key provided.');
|
||||
}
|
||||
|
||||
if (!url)
|
||||
{
|
||||
url = path + key + '.txt';
|
||||
}
|
||||
else
|
||||
{
|
||||
url = path.concat(url);
|
||||
}
|
||||
|
||||
File.call(this, 'txt', key, url, 'text', xhrSettings);
|
||||
},
|
||||
|
||||
onProcess: function (callback)
|
||||
{
|
||||
this.state = CONST.FILE_PROCESSING;
|
||||
|
||||
this.data = this.xhrLoader.responseText;
|
||||
|
||||
this.onComplete();
|
||||
|
||||
callback(this);
|
||||
}
|
||||
|
||||
if (!url)
|
||||
{
|
||||
url = path + key + '.text';
|
||||
}
|
||||
else
|
||||
{
|
||||
url = path.concat(url);
|
||||
}
|
||||
|
||||
File.call(this, 'text', key, url, 'text', xhrSettings);
|
||||
};
|
||||
|
||||
TextFile.prototype = Object.create(File.prototype);
|
||||
TextFile.prototype.constructor = TextFile;
|
||||
|
||||
TextFile.prototype.onProcess = function (callback)
|
||||
{
|
||||
this.state = CONST.FILE_PROCESSING;
|
||||
|
||||
this.data = this.xhrLoader.responseText;
|
||||
|
||||
this.onComplete();
|
||||
|
||||
callback(this);
|
||||
};
|
||||
});
|
||||
|
||||
module.exports = TextFile;
|
||||
|
|
|
@ -1,46 +1,53 @@
|
|||
|
||||
var Class = require('../../utils/Class');
|
||||
var CONST = require('../const');
|
||||
var File = require('../File');
|
||||
var ParseXML = require('../../dom/ParseXML');
|
||||
|
||||
var XMLFile = function (key, url, path, xhrSettings)
|
||||
{
|
||||
if (path === undefined) { path = ''; }
|
||||
// Phaser.Loader.FileTypes.XMLFile
|
||||
|
||||
if (!key)
|
||||
var XMLFile = new Class({
|
||||
|
||||
Extends: File,
|
||||
|
||||
initialize:
|
||||
|
||||
function XMLFile (key, url, path, xhrSettings)
|
||||
{
|
||||
throw new Error('Error calling \'Loader.xml\' invalid key provided.');
|
||||
if (path === undefined) { path = ''; }
|
||||
|
||||
if (!key)
|
||||
{
|
||||
throw new Error('Error calling \'Loader.xml\' invalid key provided.');
|
||||
}
|
||||
|
||||
if (!url)
|
||||
{
|
||||
url = path + key + '.xml';
|
||||
}
|
||||
else
|
||||
{
|
||||
url = path.concat(url);
|
||||
}
|
||||
|
||||
File.call(this, 'xml', key, url, 'text', xhrSettings);
|
||||
},
|
||||
|
||||
onProcess: function (callback)
|
||||
{
|
||||
this.state = CONST.FILE_PROCESSING;
|
||||
|
||||
this.data = ParseXML(this.xhrLoader.responseText);
|
||||
|
||||
if (this.data === null)
|
||||
{
|
||||
throw new Error('XMLFile: Invalid XML');
|
||||
}
|
||||
|
||||
this.onComplete();
|
||||
|
||||
callback(this);
|
||||
}
|
||||
|
||||
if (!url)
|
||||
{
|
||||
url = path + key + '.xml';
|
||||
}
|
||||
else
|
||||
{
|
||||
url = path.concat(url);
|
||||
}
|
||||
|
||||
File.call(this, 'xml', key, url, 'text', xhrSettings);
|
||||
};
|
||||
|
||||
XMLFile.prototype = Object.create(File.prototype);
|
||||
XMLFile.prototype.constructor = XMLFile;
|
||||
|
||||
XMLFile.prototype.onProcess = function (callback)
|
||||
{
|
||||
this.state = CONST.FILE_PROCESSING;
|
||||
|
||||
this.data = ParseXML(this.xhrLoader.responseText);
|
||||
|
||||
if (this.data === null)
|
||||
{
|
||||
throw new Error('XMLFile: Invalid XML');
|
||||
}
|
||||
|
||||
this.onComplete();
|
||||
|
||||
callback(this);
|
||||
};
|
||||
});
|
||||
|
||||
module.exports = XMLFile;
|
||||
|
|
Loading…
Add table
Reference in a new issue