Merge branch 'master' into rendering-cleanup

This commit is contained in:
Felipe Alfonso 2018-01-19 18:22:48 -03:00
commit e98c6b336a
44 changed files with 1090 additions and 675 deletions

View file

@ -182,6 +182,18 @@ var Config = new Class({
this.physics = GetValue(config, 'physics', {});
this.defaultPhysicsSystem = GetValue(this.physics, 'default', false);
// Loader Defaults
this.loaderBaseURL = GetValue(config, 'loader.baseURL', '');
this.loaderPath = GetValue(config, 'loader.path', '');
this.loaderEnableParallel = GetValue(config, 'loader.enableParallel', true);
this.loaderMaxParallelDownloads = GetValue(config, 'loader.maxParallelDownloads', 4);
this.loaderCrossOrigin = GetValue(config, 'loader.crossOrigin', undefined);
this.loaderResponseType = GetValue(config, 'loader.responseType', '');
this.loaderAsync = GetValue(config, 'loader.async', true);
this.loaderUser = GetValue(config, 'loader.user', '');
this.loaderPassword = GetValue(config, 'loader.password', '');
this.loaderTimeout = GetValue(config, 'loader.timeout', 0);
// Scene Plugins
this.defaultPlugins = GetValue(config, 'plugins', DefaultScenePlugins);

View file

@ -20,7 +20,7 @@ var DebugHeader = function (game)
var renderType = (config.renderType === CONST.CANVAS) ? 'Canvas' : 'WebGL';
var audioConfig = game.config.audio;
var audioConfig = config.audio;
var deviceAudio = game.device.Audio;
var audioType;
@ -105,7 +105,7 @@ var DebugHeader = function (game)
}
// Keep this during dev build only
console.log(CHECKSUM.build);
// console.log(CHECKSUM.build);
};
module.exports = DebugHeader;

View file

@ -14,6 +14,7 @@ Point.Floor = require('./Floor');
Point.GetCentroid = require('./GetCentroid');
Point.GetMagnitude = require('./GetMagnitude');
Point.GetMagnitudeSq = require('./GetMagnitudeSq');
Point.GetRectangleFromPoints = require('./GetRectangleFromPoints');
Point.Interpolate = require('./Interpolate');
Point.Invert = require('./Invert');
Point.Multiply = require('./Multiply');

View file

@ -48,6 +48,9 @@ var File = new Class({
this.xhrSettings = MergeXHRSettings(this.xhrSettings, GetFastValue(fileConfig, 'xhrSettings', {}));
}
// The LoaderPlugin instance that is loading this file
this.loader = null;
this.xhrLoader = null;
this.state = CONST.FILE_PENDING;
@ -70,8 +73,6 @@ var File = new Class({
// Multipart file? (i.e. an atlas and its json together)
this.linkFile = undefined;
this.linkType = '';
this.callback = null;
},
resetXHR: function ()
@ -81,20 +82,54 @@ var File = new Class({
this.xhrLoader.onprogress = undefined;
},
// Called when the Image loads
// ProgressEvent
// Called by the Loader, starts the actual file downloading.
// During the load the methods onLoad, onProgress, etc are called based on the XHR events.
load: function (loader)
{
this.loader = loader;
if (this.state === CONST.FILE_POPULATED)
{
this.onComplete();
loader.nextFile(this);
}
else
{
this.src = GetURL(this, loader.baseURL);
if (this.src.indexOf('data:') === 0)
{
console.log('Local data URI');
}
else
{
this.xhrLoader = XHRLoader(this, loader.xhr);
}
}
},
// Called when the file loads, is sent a DOM ProgressEvent
onLoad: function (event)
{
this.resetXHR();
this.callback(this, true);
if (event.target && event.target.status !== 200)
{
this.loader.nextFile(this, false);
}
else
{
this.loader.nextFile(this, true);
}
},
// Called when the file errors, is sent a DOM ProgressEvent
onError: function (event)
{
this.resetXHR();
this.callback(this, false);
this.loader.nextFile(this, false);
},
onProgress: function (event)
@ -105,11 +140,14 @@ var File = new Class({
this.bytesTotal = event.total;
this.percentComplete = Math.min((this.bytesLoaded / this.bytesTotal), 1);
}
// console.log(this.percentComplete + '% (' + this.bytesLoaded + ' bytes)');
// console.log(this.percentComplete + '% (' + this.bytesLoaded + ' bytes)');
this.loader.emit('fileprogress', this, this.percentComplete);
}
},
// Usually overriden by the FileTypes and is called by Loader.finishedLoading.
// The callback is Loader.processUpdate
onProcess: function (callback)
{
this.state = CONST.FILE_PROCESSING;
@ -139,25 +177,6 @@ var File = new Class({
{
this.state = CONST.FILE_COMPLETE;
}
},
// Called by the Loader, starts the actual file downloading
load: function (callback, baseURL, globalXHR)
{
if (baseURL === undefined) { baseURL = ''; }
this.callback = callback;
this.src = GetURL(this, baseURL);
if (this.src.indexOf('data:') === 0)
{
console.log('Local data URI');
}
else
{
this.xhrLoader = XHRLoader(this, globalXHR);
}
}
});

View file

@ -0,0 +1,27 @@
var types = {};
var FileTypesManager = {
install: function (loader)
{
for (var key in types)
{
loader[key] = types[key];
}
},
register: function (key, factoryFunction)
{
types[key] = factoryFunction;
// console.log('FileTypesManager.register', key);
},
destroy: function ()
{
types = {};
}
};
module.exports = FileTypesManager;

View file

@ -1,337 +0,0 @@
var BaseLoader = require('./BaseLoader');
var Class = require('../utils/Class');
var CONST = require('./const');
var NumberArray = require('../utils/array/NumberArray');
var PluginManager = require('../plugins/PluginManager');
var TILEMAP_FORMATS = require('../gameobjects/tilemap/Formats');
// TODO - Injection mapped
var AnimationJSONFile = require('./filetypes/AnimationJSONFile');
var AtlasJSONFile = require('./filetypes/AtlasJSONFile');
var AudioFile = require('./filetypes/AudioFile');
var BinaryFile = require('./filetypes/BinaryFile');
var BitmapFontFile = require('./filetypes/BitmapFontFile');
var GLSLFile = require('./filetypes/GLSLFile');
var HTMLFile = require('./filetypes/HTMLFile');
var ImageFile = require('./filetypes/ImageFile');
var JSONFile = require('./filetypes/JSONFile');
var PluginFile = require('./filetypes/PluginFile');
var ScriptFile = require('./filetypes/ScriptFile');
var SpriteSheet = require('./filetypes/SpriteSheet');
var SVGFile = require('./filetypes/SVGFile');
var TextFile = require('./filetypes/TextFile');
var TilemapCSVFile = require('./filetypes/TilemapCSVFile');
var TilemapJSONFile = require('./filetypes/TilemapJSONFile');
var UnityAtlasFile = require('./filetypes/UnityAtlasFile');
var WavefrontFile = require('./filetypes/WavefrontFile');
var XMLFile = require('./filetypes/XMLFile');
var Loader = new Class({
Extends: BaseLoader,
initialize:
function Loader (scene)
{
BaseLoader.call(this, scene);
this.systems = scene.sys;
if (!scene.sys.settings.isBooted)
{
scene.sys.events.once('boot', this.boot, this);
}
this._multilist = {};
},
boot: function ()
{
var eventEmitter = this.systems.events;
eventEmitter.on('shutdown', this.shutdown, this);
eventEmitter.on('destroy', this.destroy, this);
},
// key can be either a string, an object or an array of objects
image: function (key, url, xhrSettings)
{
return ImageFile.create(this, key, url, xhrSettings);
},
animation: function (key, url, xhrSettings)
{
return AnimationJSONFile.create(this, key, url, xhrSettings);
},
json: function (key, url, xhrSettings)
{
return JSONFile.create(this, key, url, xhrSettings);
},
script: function (key, url, xhrSettings)
{
return ScriptFile.create(this, key, url, xhrSettings);
},
plugin: function (key, url, xhrSettings)
{
return PluginFile.create(this, key, url, xhrSettings);
},
xml: function (key, url, xhrSettings)
{
return XMLFile.create(this, key, url, xhrSettings);
},
binary: function (key, url, xhrSettings)
{
return BinaryFile.create(this, key, url, xhrSettings);
},
text: function (key, url, xhrSettings)
{
return TextFile.create(this, key, url, xhrSettings);
},
glsl: function (key, url, xhrSettings)
{
return GLSLFile.create(this, key, url, xhrSettings);
},
html: function (key, url, width, height, xhrSettings)
{
return HTMLFile.create(this, key, url, width, height, xhrSettings);
},
svg: function (key, url, xhrSettings)
{
return SVGFile.create(this, key, url, xhrSettings);
},
obj: function (key, url, xhrSettings)
{
return WavefrontFile.create(this, key, url, xhrSettings);
},
// config can include: frameWidth, frameHeight, startFrame, endFrame, margin, spacing
spritesheet: function (key, url, config, xhrSettings)
{
return SpriteSheet.create(this, key, url, config, xhrSettings);
},
// config can include: instances
audio: function (key, urls, config, xhrSettings)
{
var audioFile = AudioFile.create(this, key, urls, config, xhrSettings);
if(audioFile)
{
this.addFile(audioFile);
}
return this;
},
tilemapCSV: function (key, url, xhrSettings)
{
return TilemapCSVFile.create(this, key, url, TILEMAP_FORMATS.CSV, xhrSettings);
},
tilemapTiledJSON: function (key, url, xhrSettings)
{
return TilemapJSONFile.create(this, key, url, TILEMAP_FORMATS.TILED_JSON, xhrSettings);
},
tilemapWeltmeister: function (key, url, xhrSettings)
{
return TilemapJSONFile.create(this, key, url, TILEMAP_FORMATS.WELTMEISTER, xhrSettings);
},
// ---------------------------------------------------
// Multi-File Loaders
// ---------------------------------------------------
audioSprite: function (key, urls, json, config, audioXhrSettings, jsonXhrSettings)
{
var audioFile = AudioFile.create(this, key, urls, config, audioXhrSettings);
if(audioFile)
{
var jsonFile;
if (typeof json === 'string')
{
jsonFile = new JSONFile(key, json, this.path, jsonXhrSettings);
this.addFile(jsonFile);
}
else
{
jsonFile = {
type: 'json',
key: key,
data: json,
state: CONST.FILE_WAITING_LINKFILE
};
}
// Link them together
audioFile.linkFile = jsonFile;
jsonFile.linkFile = audioFile;
// Set the type
audioFile.linkType = 'audioSprite';
jsonFile.linkType = 'audioSprite';
this.addFile(audioFile);
}
return this;
},
unityAtlas: function (key, textureURL, atlasURL, textureXhrSettings, atlasXhrSettings)
{
// Returns an object with two properties: 'texture' and 'data'
var files = new UnityAtlasFile(key, textureURL, atlasURL, this.path, textureXhrSettings, atlasXhrSettings);
this.addFile(files.texture);
this.addFile(files.data);
return this;
},
atlas: function (key, textureURL, atlasURL, textureXhrSettings, atlasXhrSettings)
{
// Returns an object with two properties: 'texture' and 'data'
var files = new AtlasJSONFile(key, textureURL, atlasURL, this.path, textureXhrSettings, atlasXhrSettings);
this.addFile(files.texture);
this.addFile(files.data);
return this;
},
bitmapFont: function (key, textureURL, xmlURL, textureXhrSettings, xmlXhrSettings)
{
// Returns an object with two properties: 'texture' and 'data'
var files = new BitmapFontFile(key, textureURL, xmlURL, this.path, textureXhrSettings, xmlXhrSettings);
this.addFile(files.texture);
this.addFile(files.data);
return this;
},
multiatlas: function (key, textureURLs, atlasURLs, textureXhrSettings, atlasXhrSettings)
{
if (typeof textureURLs === 'number')
{
var total = textureURLs;
var suffix = (atlasURLs === undefined) ? '' : atlasURLs;
textureURLs = NumberArray(0, total, key + suffix, '.png');
atlasURLs = NumberArray(0, total, key + suffix, '.json');
}
else
{
if (!Array.isArray(textureURLs))
{
textureURLs = [ textureURLs ];
}
if (!Array.isArray(atlasURLs))
{
atlasURLs = [ atlasURLs ];
}
}
var file;
var i = 0;
var multiKey;
this._multilist[key] = [];
for (i = 0; i < textureURLs.length; i++)
{
multiKey = '_MA_IMG_' + key + '_' + i.toString();
file = new ImageFile(multiKey, textureURLs[i], this.path, textureXhrSettings);
this.addFile(file);
this._multilist[key].push(multiKey);
}
for (i = 0; i < atlasURLs.length; i++)
{
multiKey = '_MA_JSON_' + key + '_' + i.toString();
file = new JSONFile(multiKey, atlasURLs[i], this.path, atlasXhrSettings);
this.addFile(file);
this._multilist[key].push(multiKey);
}
},
loadArray: function (files)
{
if (Array.isArray(files))
{
for (var i = 0; i < files.length; i++)
{
this.file(files[i]);
}
}
return (this.list.size > 0);
},
file: function (file)
{
var entry;
switch (file.type)
{
case 'spritesheet':
entry = this.spritesheet(file.key, file.url, file.config, file.xhrSettings);
break;
case 'atlas':
entry = this.atlas(file.key, file.textureURL, file.atlasURL, file.textureXhrSettings, file.atlasXhrSettings);
break;
case 'bitmapFont':
entry = this.bitmapFont(file.key, file.textureURL, file.xmlURL, file.textureXhrSettings, file.xmlXhrSettings);
break;
case 'multiatlas':
entry = this.multiatlas(file.key, file.textureURLs, file.atlasURLs, file.textureXhrSettings, file.atlasXhrSettings);
break;
case 'audioSprite':
entry = this.audioSprite(file.key, file.urls, file.json, file.config, file.audioXhrSettings, file.jsonXhrSettings);
break;
// image, json, xml, binary, text, glsl, svg, obj
default:
entry = this[file.type](file.key, file.url, file.xhrSettings);
break;
}
return entry;
},
shutdown: function ()
{
// TODO
}
});
PluginManager.register('Loader', Loader, 'load');
module.exports = Loader;

View file

@ -2,39 +2,63 @@ var Class = require('../utils/Class');
var CONST = require('./const');
var CustomSet = require('../structs/Set');
var EventEmitter = require('eventemitter3');
var FileTypesManager = require('./FileTypesManager');
var GetFastValue = require('../utils/object/GetFastValue');
var ParseXMLBitmapFont = require('../gameobjects/bitmaptext/ParseXMLBitmapFont');
var PluginManager = require('../plugins/PluginManager');
var XHRSettings = require('./XHRSettings');
// Phaser.Loader.BaseLoader
// Phaser.Loader.LoaderPlugin
// To finish the loader ...
//
// 3) Progress update
var BaseLoader = new Class({
var LoaderPlugin = new Class({
Extends: EventEmitter,
initialize:
function BaseLoader (scene)
function LoaderPlugin (scene)
{
EventEmitter.call(this);
this.scene = scene;
// Move to a 'setURL' method?
this.baseURL = '';
this.path = '';
this.systems = scene.sys;
// Read from Game / Scene Config
this.enableParallel = true;
this.maxParallelDownloads = 4;
if (!scene.sys.settings.isBooted)
{
scene.sys.events.once('boot', this.boot, this);
}
this._multilist = {};
// Inject the available filetypes into the Loader
FileTypesManager.install(this);
var gameConfig = this.systems.game.config;
var sceneConfig = this.systems.settings.loader;
this.path = '';
this.baseURL = '';
this.setBaseURL(GetFastValue(sceneConfig, 'baseURL', gameConfig.loaderBaseURL));
this.setPath(GetFastValue(sceneConfig, 'path', gameConfig.loaderPath));
this.enableParallel = GetFastValue(sceneConfig, 'enableParallel', gameConfig.loaderEnableParallel);
this.maxParallelDownloads = GetFastValue(sceneConfig, 'maxParallelDownloads', gameConfig.loaderMaxParallelDownloads);
// xhr specific global settings (can be overridden on a per-file basis)
this.xhr = XHRSettings();
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)
);
this.crossOrigin = undefined;
this.crossOrigin = GetFastValue(sceneConfig, 'crossOrigin', gameConfig.loaderCrossOrigin);
this.totalToLoad = 0;
this.progress = 0;
this.list = new CustomSet();
this.inflight = new CustomSet();
@ -45,9 +69,29 @@ var BaseLoader = new Class({
this.state = CONST.LOADER_IDLE;
},
boot: function ()
{
var eventEmitter = this.systems.events;
eventEmitter.on('shutdown', this.shutdown, this);
eventEmitter.on('destroy', this.destroy, this);
},
setBaseURL: function (url)
{
if (url !== '' && url.substr(-1) !== '/')
{
url = url.concat('/');
}
this.baseURL = url;
return this;
},
setPath: function (path)
{
if (path.substr(-1) !== '/')
if (path !== '' && path.substr(-1) !== '/')
{
path = path.concat('/');
}
@ -85,13 +129,16 @@ var BaseLoader = new Class({
start: function ()
{
console.log(this.scene.sys.settings.key, '- BaseLoader start. Files to load:', this.list.size);
// console.log(this.scene.sys.settings.key, '- Loader start. Files to load:', this.list.size);
if (!this.isReady())
{
return;
}
this.progress = 0;
this.totalToLoad = this.list.size;
this.emit('start', this);
if (this.list.size === 0)
@ -116,18 +163,22 @@ var BaseLoader = new Class({
updateProgress: function ()
{
this.progress = 1 - (this.list.size / this.totalToLoad);
// console.log(this.progress);
this.emit('progress', this.progress);
},
processLoadQueue: function ()
{
// console.log('======== BaseLoader processLoadQueue');
// console.log('======== LoaderPlugin processLoadQueue');
// console.log('List size', this.list.size);
// console.log(this.inflight.size, 'items still in flight. Can load another', (this.maxParallelDownloads - this.inflight.size));
this.list.each(function (file)
{
if (file.state === CONST.FILE_PENDING && this.inflight.size < this.maxParallelDownloads)
if (file.state === CONST.FILE_POPULATED || (file.state === CONST.FILE_PENDING && this.inflight.size < this.maxParallelDownloads))
{
this.inflight.set(file);
@ -157,7 +208,7 @@ var BaseLoader = new Class({
file.crossOrigin = this.crossOrigin;
}
file.load(this.nextFile.bind(this), this.baseURL);
file.load(this);
},
nextFile: function (previousFile, success)
@ -168,15 +219,19 @@ var BaseLoader = new Class({
if (success)
{
this.emit('load', previousFile);
this.queue.set(previousFile);
}
else
{
this.emit('loaderror', previousFile);
this.failed.set(previousFile);
}
this.inflight.delete(previousFile);
this.updateProgress();
if (this.list.size > 0)
{
// console.log('nextFile - still something in the list');
@ -191,23 +246,32 @@ var BaseLoader = new Class({
finishedLoading: function ()
{
// console.log('---> BaseLoader.finishedLoading PROCESSING', this.queue.size, 'files');
// console.log('---> LoaderPlugin.finishedLoading PROCESSING', this.queue.size, 'files');
if(this.state === CONST.LOADER_PROCESSING)
if (this.state === CONST.LOADER_PROCESSING)
{
return;
}
this.progress = 1;
this.state = CONST.LOADER_PROCESSING;
this.storage.clear();
this.queue.each(function (file)
if (this.queue.size === 0)
{
// console.log('%c Calling process on ' + file.key, 'color: #000000; background: #ffff00;');
file.onProcess(this.processUpdate.bind(this));
}, this);
// Everything failed, so nothing to process
this.processComplete();
}
else
{
this.queue.each(function (file)
{
// console.log('%c Calling process on ' + file.key, 'color: #000000; background: #ffff00;');
file.onProcess(this.processUpdate.bind(this));
}, this);
}
},
// Called automatically by the File when it has finished processing
@ -266,7 +330,7 @@ var BaseLoader = new Class({
processComplete: function ()
{
console.log(this.scene.sys.settings.key, '- Loader Complete. Loaded:', this.storage.size, 'Failed:', this.failed.size);
// console.log(this.scene.sys.settings.key, '- Loader Complete. Loaded:', this.storage.size, 'Failed:', this.failed.size);
this.list.clear();
this.inflight.clear();
@ -474,7 +538,7 @@ var BaseLoader = new Class({
if (filename === undefined) { filename = 'file.json'; }
if (filetype === undefined) { filetype = 'application/json'; }
var blob = new Blob([data], { type: filetype });
var blob = new Blob([ data ], { type: filetype });
var url = URL.createObjectURL(blob);
@ -497,15 +561,74 @@ var BaseLoader = new Class({
this.storage.clear();
this.removeAllListeners('start');
this.removeAllListeners('load');
this.removeAllListeners('loaderror');
this.removeAllListeners('complete');
this.tag = '';
this.path = '';
this.baseURL = '';
var gameConfig = this.systems.game.config;
var sceneConfig = this.systems.settings.loader;
this.setBaseURL(GetFastValue(sceneConfig, 'baseURL', gameConfig.loaderBaseURL));
this.setPath(GetFastValue(sceneConfig, 'path', gameConfig.loaderPath));
this.state = CONST.LOADER_IDLE;
},
loadArray: function (files)
{
if (Array.isArray(files))
{
for (var i = 0; i < files.length; i++)
{
this.file(files[i]);
}
}
return (this.list.size > 0);
},
file: function (file)
{
var entry;
var key = file.key;
switch (file.type)
{
case 'spritesheet':
entry = this.spritesheet(key, file.url, file.config, file.xhrSettings);
break;
case 'atlas':
entry = this.atlas(key, file.textureURL, file.atlasURL, file.textureXhrSettings, file.atlasXhrSettings);
break;
case 'bitmapFont':
entry = this.bitmapFont(key, file.textureURL, file.xmlURL, file.textureXhrSettings, file.xmlXhrSettings);
break;
case 'multiatlas':
entry = this.multiatlas(key, file.textureURLs, file.atlasURLs, file.textureXhrSettings, file.atlasXhrSettings);
break;
case 'audioSprite':
entry = this.audioSprite(key, file.urls, file.json, file.config, file.audioXhrSettings, file.jsonXhrSettings);
break;
// image, json, xml, binary, text, glsl, svg, obj
default:
entry = this[file.type](key, file.url, file.xhrSettings);
break;
}
return entry;
},
shutdown: function ()
{
this.reset();
this.state = CONST.LOADER_SHUTDOWN;
},
destroy: function ()
{
this.reset();
@ -514,4 +637,6 @@ var BaseLoader = new Class({
});
module.exports = BaseLoader;
PluginManager.register('Loader', LoaderPlugin, 'load');
module.exports = LoaderPlugin;

View file

@ -4,17 +4,38 @@ var FILE_CONST = {
LOADER_LOADING: 1,
LOADER_PROCESSING: 2,
LOADER_COMPLETE: 3,
LOADER_DESTROYED: 4,
LOADER_SHUTDOWN: 4,
LOADER_DESTROYED: 5,
FILE_PENDING: 5, // file is in the load queue but not yet started
FILE_LOADING: 6, // file has been started to load by the loader (onLoad called)
FILE_LOADED: 7, // file has loaded successfully, awaiting processing
FILE_FAILED: 8, // file failed to load
FILE_PROCESSING: 9, // file is being processed (onProcess callback)
FILE_WAITING_LINKFILE: 10, // file is being processed (onProcess callback)
FILE_ERRORED: 11, // file is being processed (onProcess callback)
FILE_COMPLETE: 12, // file has finished processing
FILE_DESTROYED: 13, // file has been destroyed
// File is in the load queue but not yet started
FILE_PENDING: 10,
// File has been started to load by the loader (onLoad called)
FILE_LOADING: 11,
// File has loaded successfully, awaiting processing
FILE_LOADED: 12,
// File failed to load
FILE_FAILED: 13,
// File is being processed (onProcess callback)
FILE_PROCESSING: 14,
// File is being processed (onProcess callback)
FILE_WAITING_LINKFILE: 15,
// File is being processed (onProcess callback)
FILE_ERRORED: 16,
// File has finished processing
FILE_COMPLETE: 17,
// File has been destroyed
FILE_DESTROYED: 18,
// File was populated from local data and doesn't need an HTTP request
FILE_POPULATED: 19,
TEXTURE_ATLAS_JSON_ARRAY: 20,
TEXTURE_ATLAS_JSON_HASH: 21

View file

@ -1,5 +1,8 @@
var FileTypesManager = require('../FileTypesManager');
var JSONFile = require('./JSONFile.js');
// Phaser.Loader.FileTypes.AnimationJSONFile
var AnimationJSONFile = function (key, url, path, xhrSettings)
{
var json = new JSONFile(key, url, path, xhrSettings);
@ -10,23 +13,29 @@ var AnimationJSONFile = function (key, url, path, xhrSettings)
return json;
};
AnimationJSONFile.create = function (loader, key, url, xhrSettings)
// When registering a factory function 'this' refers to the Loader context.
//
// There are several properties available to use:
//
// this.scene - a reference to the Scene that owns the GameObjectFactory
FileTypesManager.register('animation', function (key, url, xhrSettings)
{
if (Array.isArray(key))
{
for (var i = 0; i < key.length; i++)
{
// If it's an array it has to be an array of Objects, so we get everything out of the 'key' object
loader.addFile(new AnimationJSONFile(key[i], url, loader.path, xhrSettings));
this.addFile(new AnimationJSONFile(key[i], url, this.path, xhrSettings));
}
}
else
{
loader.addFile(new AnimationJSONFile(key, url, loader.path, xhrSettings));
this.addFile(new AnimationJSONFile(key, url, this.path, xhrSettings));
}
// For method chaining
return loader;
};
return this;
});
module.exports = AnimationJSONFile;

View file

@ -1,6 +1,9 @@
var FileTypesManager = require('../FileTypesManager');
var ImageFile = require('./ImageFile.js');
var JSONFile = require('./JSONFile.js');
// Phaser.Loader.FileTypes.AtlasJSONFile
var AtlasJSONFile = function (key, textureURL, atlasURL, path, textureXhrSettings, atlasXhrSettings)
{
var image = new ImageFile(key, textureURL, path, textureXhrSettings);
@ -17,4 +20,15 @@ var AtlasJSONFile = function (key, textureURL, atlasURL, path, textureXhrSetting
return { texture: image, data: data };
};
FileTypesManager.register('atlas', function (key, textureURL, atlasURL, textureXhrSettings, atlasXhrSettings)
{
// Returns an object with two properties: 'texture' and 'data'
var files = new AtlasJSONFile(key, textureURL, atlasURL, this.path, textureXhrSettings, atlasXhrSettings);
this.addFile(files.texture);
this.addFile(files.data);
return this;
});
module.exports = AtlasJSONFile;

View file

@ -1,5 +1,6 @@
var Class = require('../../utils/Class');
var File = require('../File');
var FileTypesManager = require('../FileTypesManager');
var GetFastValue = require('../../utils/object/GetFastValue');
var CONST = require('../../const');
var HTML5AudioFile = require('./HTML5AudioFile');
@ -60,7 +61,7 @@ var AudioFile = new Class({
AudioFile.create = function (loader, key, urls, config, xhrSettings)
{
var game = loader.scene.game;
var game = loader.systems.game;
var audioConfig = game.config.audio;
var deviceAudio = game.device.Audio;
@ -78,13 +79,33 @@ AudioFile.create = function (loader, key, urls, config, xhrSettings)
return null;
}
if(deviceAudio.webAudio && !(audioConfig && audioConfig.disableWebAudio))
if (deviceAudio.webAudio && !(audioConfig && audioConfig.disableWebAudio))
{
return new AudioFile(key, url, loader.path, xhrSettings, game.sound.context);
return new AudioFile(key, url, this.path, xhrSettings, game.sound.context);
}
else
{
return new HTML5AudioFile(key, url, this.path, config, game.sound.locked);
}
};
// When registering a factory function 'this' refers to the Loader context.
//
// There are several properties available to use:
//
// this.scene - a reference to the Scene that owns the GameObjectFactory
FileTypesManager.register('audio', function (key, urls, config, xhrSettings)
{
var audioFile = AudioFile.create(this, key, urls, config, xhrSettings);
if (audioFile)
{
this.addFile(audioFile);
}
return new HTML5AudioFile(key, url, loader.path, config);
};
return this;
});
// this.load.audio('sound', 'assets/audio/booom.ogg', config, xhrSettings);
//
@ -129,6 +150,7 @@ AudioFile.create = function (loader, key, urls, config, xhrSettings)
// }
// ],
// config, xhrSettings);
AudioFile.findAudioURL = function (game, urls)
{
if (urls.constructor !== Array)

View file

@ -0,0 +1,44 @@
var AudioFile = require('./AudioFile.js');
var CONST = require('../const');
var FileTypesManager = require('../FileTypesManager');
var JSONFile = require('./JSONFile.js');
// Phaser.Loader.FileTypes.AudioSprite
FileTypesManager.register('audioSprite', function (key, urls, json, config, audioXhrSettings, jsonXhrSettings)
{
var audioFile = AudioFile.create(this, key, urls, config, audioXhrSettings);
if (audioFile)
{
var jsonFile;
if (typeof json === 'string')
{
jsonFile = new JSONFile(key, json, this.path, jsonXhrSettings);
this.addFile(jsonFile);
}
else
{
jsonFile = {
type: 'json',
key: key,
data: json,
state: CONST.FILE_WAITING_LINKFILE
};
}
// Link them together
audioFile.linkFile = jsonFile;
jsonFile.linkFile = audioFile;
// Set the type
audioFile.linkType = 'audioSprite';
jsonFile.linkType = 'audioSprite';
this.addFile(audioFile);
}
return this;
});

View file

@ -1,6 +1,7 @@
var Class = require('../../utils/Class');
var CONST = require('../const');
var File = require('../File');
var FileTypesManager = require('../FileTypesManager');
var GetFastValue = require('../../utils/object/GetFastValue');
// Phaser.Loader.FileTypes.BinaryFile
@ -41,23 +42,29 @@ var BinaryFile = new Class({
});
BinaryFile.create = function (loader, key, url, xhrSettings)
// When registering a factory function 'this' refers to the Loader context.
//
// There are several properties available to use:
//
// this.scene - a reference to the Scene that owns the GameObjectFactory
FileTypesManager.register('binary', function (key, url, xhrSettings)
{
if (Array.isArray(key))
{
for (var i = 0; i < key.length; i++)
{
// If it's an array it has to be an array of Objects, so we get everything out of the 'key' object
loader.addFile(new BinaryFile(key[i], url, loader.path, xhrSettings));
this.addFile(new BinaryFile(key[i], url, this.path, xhrSettings));
}
}
else
{
loader.addFile(new BinaryFile(key, url, loader.path, xhrSettings));
this.addFile(new BinaryFile(key, url, this.path, xhrSettings));
}
// For method chaining
return loader;
};
return this;
});
module.exports = BinaryFile;

View file

@ -1,3 +1,4 @@
var FileTypesManager = require('../FileTypesManager');
var ImageFile = require('./ImageFile.js');
var XMLFile = require('./XMLFile.js');
@ -17,4 +18,21 @@ var BitmapFontFile = function (key, textureURL, xmlURL, path, textureXhrSettings
return { texture: image, data: data };
};
// When registering a factory function 'this' refers to the Loader context.
//
// There are several properties available to use:
//
// this.scene - a reference to the Scene that owns the GameObjectFactory
FileTypesManager.register('bitmapFont', function (key, textureURL, xmlURL, textureXhrSettings, xmlXhrSettings)
{
// Returns an object with two properties: 'texture' and 'data'
var files = new BitmapFontFile(key, textureURL, xmlURL, this.path, textureXhrSettings, xmlXhrSettings);
this.addFile(files.texture);
this.addFile(files.data);
return this;
});
module.exports = BitmapFontFile;

View file

@ -1,6 +1,7 @@
var Class = require('../../utils/Class');
var CONST = require('../const');
var File = require('../File');
var FileTypesManager = require('../FileTypesManager');
var GetFastValue = require('../../utils/object/GetFastValue');
// Phaser.Loader.FileTypes.GLSLFile
@ -41,23 +42,29 @@ var GLSLFile = new Class({
});
GLSLFile.create = function (loader, key, url, xhrSettings)
// When registering a factory function 'this' refers to the Loader context.
//
// There are several properties available to use:
//
// this.scene - a reference to the Scene that owns the GameObjectFactory
FileTypesManager.register('glsl', function (key, url, xhrSettings)
{
if (Array.isArray(key))
{
for (var i = 0; i < key.length; i++)
{
// If it's an array it has to be an array of Objects, so we get everything out of the 'key' object
loader.addFile(new GLSLFile(key[i], url, loader.path, xhrSettings));
this.addFile(new GLSLFile(key[i], url, this.path, xhrSettings));
}
}
else
{
loader.addFile(new GLSLFile(key, url, loader.path, xhrSettings));
this.addFile(new GLSLFile(key, url, this.path, xhrSettings));
}
// For method chaining
return loader;
};
return this;
});
module.exports = GLSLFile;

View file

@ -11,8 +11,10 @@ var HTML5AudioFile = new Class({
initialize:
function HTML5AudioFile (key, url, path, config)
function HTML5AudioFile (key, url, path, config, locked)
{
this.locked = locked;
var fileConfig = {
type: 'audio',
extension: GetFastValue(url, 'type', ''),
@ -72,14 +74,15 @@ var HTML5AudioFile = new Class({
for(var i = 0; i < instances; i++)
{
var audio = new Audio();
audio.name = this.key + ('0' + i).slice(-2); // Useful for debugging
audio.dataset.name = this.key + ('0' + i).slice(-2); // Useful for debugging
audio.dataset.used = 'false';
audio.preload = 'auto';
// TODO check if ios is locked
audio.oncanplaythrough = this.onProgress.bind(this);
audio.onerror = this.onError.bind(this);
if (!this.locked)
{
audio.preload = 'auto';
audio.oncanplaythrough = this.onProgress.bind(this);
audio.onerror = this.onError.bind(this);
}
this.data.push(audio);
}
@ -88,7 +91,22 @@ var HTML5AudioFile = new Class({
{
audio = this.data[i];
audio.src = GetURL(this, baseURL || '');
audio.load();
if (!this.locked)
{
audio.load();
}
}
if (this.locked)
{
setTimeout(function ()
{
this.filesLoaded = this.filesTotal;
this.percentComplete = 1;
this.onLoad();
}.bind(this));
}
}

View file

@ -1,6 +1,7 @@
var Class = require('../../utils/Class');
var CONST = require('../const');
var File = require('../File');
var FileTypesManager = require('../FileTypesManager');
var GetFastValue = require('../../utils/object/GetFastValue');
// Phaser.Loader.FileTypes.HTMLFile
@ -95,23 +96,29 @@ var HTMLFile = new Class({
});
HTMLFile.create = function (loader, key, url, width, height, xhrSettings)
// When registering a factory function 'this' refers to the Loader context.
//
// There are several properties available to use:
//
// this.scene - a reference to the Scene that owns the GameObjectFactory
FileTypesManager.register('html', function (key, url, width, height, xhrSettings)
{
if (Array.isArray(key))
{
for (var i = 0; i < key.length; i++)
{
// If it's an array it has to be an array of Objects, so we get everything out of the 'key' object
loader.addFile(new HTMLFile(key[i], url, width, height, loader.path, xhrSettings));
this.addFile(new HTMLFile(key[i], url, width, height, this.path, xhrSettings));
}
}
else
{
loader.addFile(new HTMLFile(key, url, width, height, loader.path, xhrSettings));
this.addFile(new HTMLFile(key, url, width, height, this.path, xhrSettings));
}
// For method chaining
return loader;
};
return this;
});
module.exports = HTMLFile;

View file

@ -1,6 +1,7 @@
var Class = require('../../utils/Class');
var CONST = require('../const');
var File = require('../File');
var FileTypesManager = require('../FileTypesManager');
var GetFastValue = require('../../utils/object/GetFastValue');
// Phaser.Loader.FileTypes.ImageFile
@ -26,6 +27,7 @@ var ImageFile = new Class({
// });
// this.load.image({ key: 'bunny' });
// this.load.image({ key: 'bunny', extension: 'jpg' });
function ImageFile (key, url, path, xhrSettings, config)
{
var fileKey = (typeof key === 'string') ? key : GetFastValue(key, 'key', '');
@ -73,28 +75,33 @@ var ImageFile = new Class({
};
File.createObjectURL(this.data, this.xhrLoader.response, 'image/png');
}
});
ImageFile.create = function (loader, key, url, xhrSettings)
// When registering a factory function 'this' refers to the Loader context.
//
// There are several properties available to use:
//
// this.scene - a reference to the Scene that owns the GameObjectFactory
FileTypesManager.register('image', function (key, url, xhrSettings)
{
if (Array.isArray(key))
{
for (var i = 0; i < key.length; i++)
{
// If it's an array it has to be an array of Objects, so we get everything out of the 'key' object
loader.addFile(new ImageFile(key[i], url, loader.path, xhrSettings));
this.addFile(new ImageFile(key[i], url, this.path, xhrSettings));
}
}
else
{
loader.addFile(new ImageFile(key, url, loader.path, xhrSettings));
this.addFile(new ImageFile(key, url, this.path, xhrSettings));
}
// For method chaining
return loader;
};
return this;
});
module.exports = ImageFile;

View file

@ -1,6 +1,7 @@
var Class = require('../../utils/Class');
var CONST = require('../const');
var File = require('../File');
var FileTypesManager = require('../FileTypesManager');
var GetFastValue = require('../../utils/object/GetFastValue');
// Phaser.Loader.FileTypes.JSONFile
@ -11,6 +12,8 @@ var JSONFile = new Class({
initialize:
// url can either be a string, in which case it is treated like a proper url, or an object, in which case it is treated as a ready-made JS Object
function JSONFile (key, url, path, xhrSettings)
{
var fileKey = (typeof key === 'string') ? key : GetFastValue(key, 'key', '');
@ -26,6 +29,14 @@ var JSONFile = new Class({
};
File.call(this, fileConfig);
if (typeof fileConfig.url === 'object')
{
// Object provided instead of a URL, so no need to actually load it (populate data with value)
this.data = fileConfig.url;
this.state = CONST.FILE_POPULATED;
}
},
onProcess: function (callback)
@ -41,23 +52,29 @@ var JSONFile = new Class({
});
JSONFile.create = function (loader, key, url, xhrSettings)
// When registering a factory function 'this' refers to the Loader context.
//
// There are several properties available to use:
//
// this.scene - a reference to the Scene that owns the GameObjectFactory
FileTypesManager.register('json', function (key, url, xhrSettings)
{
if (Array.isArray(key))
{
for (var i = 0; i < key.length; i++)
{
// If it's an array it has to be an array of Objects, so we get everything out of the 'key' object
loader.addFile(new JSONFile(key[i], url, loader.path, xhrSettings));
this.addFile(new JSONFile(key[i], url, this.path, xhrSettings));
}
}
else
{
loader.addFile(new JSONFile(key, url, loader.path, xhrSettings));
this.addFile(new JSONFile(key, url, this.path, xhrSettings));
}
// For method chaining
return loader;
};
return this;
});
module.exports = JSONFile;

View file

@ -0,0 +1,60 @@
var FileTypesManager = require('../FileTypesManager');
var ImageFile = require('./ImageFile.js');
var JSONFile = require('./JSONFile.js');
var NumberArray = require('../../utils/array/NumberArray');
// Phaser.Loader.FileTypes.MultiAtlas
FileTypesManager.register('multiatlas', function (key, textureURLs, atlasURLs, textureXhrSettings, atlasXhrSettings)
{
if (typeof textureURLs === 'number')
{
var total = textureURLs;
var suffix = (atlasURLs === undefined) ? '' : atlasURLs;
textureURLs = NumberArray(0, total, key + suffix, '.png');
atlasURLs = NumberArray(0, total, key + suffix, '.json');
}
else
{
if (!Array.isArray(textureURLs))
{
textureURLs = [ textureURLs ];
}
if (!Array.isArray(atlasURLs))
{
atlasURLs = [ atlasURLs ];
}
}
var file;
var i = 0;
var multiKey;
this._multilist[key] = [];
for (i = 0; i < textureURLs.length; i++)
{
multiKey = '_MA_IMG_' + key + '_' + i.toString();
file = new ImageFile(multiKey, textureURLs[i], this.path, textureXhrSettings);
this.addFile(file);
this._multilist[key].push(multiKey);
}
for (i = 0; i < atlasURLs.length; i++)
{
multiKey = '_MA_JSON_' + key + '_' + i.toString();
file = new JSONFile(multiKey, atlasURLs[i], this.path, atlasXhrSettings);
this.addFile(file);
this._multilist[key].push(multiKey);
}
return this;
});

View file

@ -1,6 +1,7 @@
var Class = require('../../utils/Class');
var CONST = require('../const');
var File = require('../File');
var FileTypesManager = require('../FileTypesManager');
var GetFastValue = require('../../utils/object/GetFastValue');
var PluginManager = require('../../plugins/PluginManager');
@ -51,23 +52,29 @@ var PluginFile = new Class({
});
PluginFile.create = function (loader, key, url, xhrSettings)
// When registering a factory function 'this' refers to the Loader context.
//
// There are several properties available to use:
//
// this.scene - a reference to the Scene that owns the GameObjectFactory
FileTypesManager.register('plugin', function (key, url, xhrSettings)
{
if (Array.isArray(key))
{
for (var i = 0; i < key.length; i++)
{
// If it's an array it has to be an array of Objects, so we get everything out of the 'key' object
loader.addFile(new PluginFile(key[i], url, loader.path, xhrSettings));
this.addFile(new PluginFile(key[i], url, this.path, xhrSettings));
}
}
else
{
loader.addFile(new PluginFile(key, url, loader.path, xhrSettings));
this.addFile(new PluginFile(key, url, this.path, xhrSettings));
}
// For method chaining
return loader;
};
return this;
});
module.exports = PluginFile;

View file

@ -1,6 +1,7 @@
var Class = require('../../utils/Class');
var CONST = require('../const');
var File = require('../File');
var FileTypesManager = require('../FileTypesManager');
var GetFastValue = require('../../utils/object/GetFastValue');
// Phaser.Loader.FileTypes.SVGFile
@ -90,23 +91,29 @@ var SVGFile = new Class({
});
SVGFile.create = function (loader, key, url, xhrSettings)
// When registering a factory function 'this' refers to the Loader context.
//
// There are several properties available to use:
//
// this.scene - a reference to the Scene that owns the GameObjectFactory
FileTypesManager.register('svg', function (key, url, xhrSettings)
{
if (Array.isArray(key))
{
for (var i = 0; i < key.length; i++)
{
// If it's an array it has to be an array of Objects, so we get everything out of the 'key' object
loader.addFile(new SVGFile(key[i], url, loader.path, xhrSettings));
this.addFile(new SVGFile(key[i], url, this.path, xhrSettings));
}
}
else
{
loader.addFile(new SVGFile(key, url, loader.path, xhrSettings));
this.addFile(new SVGFile(key, url, this.path, xhrSettings));
}
// For method chaining
return loader;
};
return this;
});
module.exports = SVGFile;

View file

@ -1,6 +1,7 @@
var Class = require('../../utils/Class');
var CONST = require('../const');
var File = require('../File');
var FileTypesManager = require('../FileTypesManager');
var GetFastValue = require('../../utils/object/GetFastValue');
// Phaser.Loader.FileTypes.ScriptFile
@ -47,23 +48,29 @@ var ScriptFile = new Class({
});
ScriptFile.create = function (loader, key, url, xhrSettings)
// When registering a factory function 'this' refers to the Loader context.
//
// There are several properties available to use:
//
// this.scene - a reference to the Scene that owns the GameObjectFactory
FileTypesManager.register('script', function (key, url, xhrSettings)
{
if (Array.isArray(key))
{
for (var i = 0; i < key.length; i++)
{
// If it's an array it has to be an array of Objects, so we get everything out of the 'key' object
loader.addFile(new ScriptFile(key[i], url, loader.path, xhrSettings));
this.addFile(new ScriptFile(key[i], url, this.path, xhrSettings));
}
}
else
{
loader.addFile(new ScriptFile(key, url, loader.path, xhrSettings));
this.addFile(new ScriptFile(key, url, this.path, xhrSettings));
}
// For method chaining
return loader;
};
return this;
});
module.exports = ScriptFile;

View file

@ -1,3 +1,4 @@
var FileTypesManager = require('../FileTypesManager');
var ImageFile = require('./ImageFile.js');
// config can include: frameWidth, frameHeight, startFrame, endFrame, margin, spacing
@ -12,23 +13,30 @@ var SpriteSheet = function (key, url, config, path, xhrSettings)
return image;
};
SpriteSheet.create = function (loader, key, url, config, xhrSettings)
// When registering a factory function 'this' refers to the Loader context.
//
// There are several properties available to use:
//
// this.scene - a reference to the Scene that owns the GameObjectFactory
// config can include: frameWidth, frameHeight, startFrame, endFrame, margin, spacing
FileTypesManager.register('spritesheet', function (key, url, config, xhrSettings)
{
if (Array.isArray(key))
{
for (var i = 0; i < key.length; i++)
{
// If it's an array it has to be an array of Objects, so we get everything out of the 'key' object
loader.addFile(new SpriteSheet(key[i], url, null, loader.path, xhrSettings));
this.addFile(new SpriteSheet(key[i], url, null, this.path, xhrSettings));
}
}
else
{
loader.addFile(new SpriteSheet(key, url, config, loader.path, xhrSettings));
this.addFile(new SpriteSheet(key, url, config, this.path, xhrSettings));
}
// For method chaining
return loader;
};
return this;
});
module.exports = SpriteSheet;

View file

@ -1,6 +1,7 @@
var Class = require('../../utils/Class');
var CONST = require('../const');
var File = require('../File');
var FileTypesManager = require('../FileTypesManager');
// Phaser.Loader.FileTypes.TextFile
@ -38,23 +39,29 @@ var TextFile = new Class({
});
TextFile.create = function (loader, key, url, xhrSettings)
// When registering a factory function 'this' refers to the Loader context.
//
// There are several properties available to use:
//
// this.scene - a reference to the Scene that owns the GameObjectFactory
FileTypesManager.register('text', function (key, url, xhrSettings)
{
if (Array.isArray(key))
{
for (var i = 0; i < key.length; i++)
{
// If it's an array it has to be an array of Objects, so we get everything out of the 'key' object
loader.addFile(new TextFile(key[i], url, loader.path, xhrSettings));
this.addFile(new TextFile(key[i], url, this.path, xhrSettings));
}
}
else
{
loader.addFile(new TextFile(key, url, loader.path, xhrSettings));
this.addFile(new TextFile(key, url, this.path, xhrSettings));
}
// For method chaining
return loader;
};
return this;
});
module.exports = TextFile;

View file

@ -1,6 +1,8 @@
var Class = require('../../utils/Class');
var CONST = require('../const');
var File = require('../File');
var FileTypesManager = require('../FileTypesManager');
var TILEMAP_FORMATS = require('../../gameobjects/tilemap/Formats');
// Phaser.Loader.FileTypes.TilemapCSVFile
@ -10,7 +12,7 @@ var TilemapCSVFile = new Class({
initialize:
function TextFile (key, url, path, format, xhrSettings)
function TilemapCSVFile (key, url, path, format, xhrSettings)
{
var fileConfig = {
type: 'tilemapCSV',
@ -40,23 +42,29 @@ var TilemapCSVFile = new Class({
});
TilemapCSVFile.create = function (loader, key, url, format, xhrSettings)
// When registering a factory function 'this' refers to the Loader context.
//
// There are several properties available to use:
//
// this.scene - a reference to the Scene that owns the GameObjectFactory
FileTypesManager.register('tilemapCSV', function (key, url, xhrSettings)
{
if (Array.isArray(key))
{
for (var i = 0; i < key.length; i++)
{
// If it's an array it has to be an array of Objects, so we get everything out of the 'key' object
loader.addFile(new TilemapCSVFile(key[i], url, loader.path, format, xhrSettings));
this.addFile(new TilemapCSVFile(key[i], url, this.path, TILEMAP_FORMATS.CSV, xhrSettings));
}
}
else
{
loader.addFile(new TilemapCSVFile(key, url, loader.path, format, xhrSettings));
this.addFile(new TilemapCSVFile(key, url, this.path, TILEMAP_FORMATS.CSV, xhrSettings));
}
// For method chaining
return loader;
};
return this;
});
module.exports = TilemapCSVFile;

View file

@ -1,4 +1,8 @@
var FileTypesManager = require('../FileTypesManager');
var JSONFile = require('./JSONFile.js');
var TILEMAP_FORMATS = require('../../gameobjects/tilemap/Formats');
// Phaser.Loader.FileTypes.TilemapJSONFile
var TilemapJSONFile = function (key, url, path, format, xhrSettings)
{
@ -12,23 +16,48 @@ var TilemapJSONFile = function (key, url, path, format, xhrSettings)
return json;
};
TilemapJSONFile.create = function (loader, key, url, format, xhrSettings)
// When registering a factory function 'this' refers to the Loader context.
//
// There are several properties available to use:
//
// this.scene - a reference to the Scene that owns the GameObjectFactory
FileTypesManager.register('tilemapTiledJSON', function (key, url, xhrSettings)
{
if (Array.isArray(key))
{
for (var i = 0; i < key.length; i++)
{
// If it's an array it has to be an array of Objects, so we get everything out of the 'key' object
loader.addFile(TilemapJSONFile(key[i], url, loader.path, format, xhrSettings));
this.addFile(TilemapJSONFile(key[i], url, this.path, TILEMAP_FORMATS.TILED_JSON, xhrSettings));
}
}
else
{
loader.addFile(TilemapJSONFile(key, url, loader.path, format, xhrSettings));
this.addFile(TilemapJSONFile(key, url, this.path, TILEMAP_FORMATS.TILED_JSON, xhrSettings));
}
// For method chaining
return loader;
};
return this;
});
FileTypesManager.register('tilemapWeltmeister', function (key, url, xhrSettings)
{
if (Array.isArray(key))
{
for (var i = 0; i < key.length; i++)
{
// If it's an array it has to be an array of Objects, so we get everything out of the 'key' object
this.addFile(TilemapJSONFile(key[i], url, this.path, TILEMAP_FORMATS.WELTMEISTER.TILED_JSON, xhrSettings));
}
}
else
{
this.addFile(TilemapJSONFile(key, url, this.path, TILEMAP_FORMATS.WELTMEISTER.TILED_JSON, xhrSettings));
}
// For method chaining
return this;
});
module.exports = TilemapJSONFile;

View file

@ -1,3 +1,4 @@
var FileTypesManager = require('../FileTypesManager');
var ImageFile = require('./ImageFile.js');
var TextFile = require('./TextFile.js');
@ -17,4 +18,22 @@ var UnityAtlasFile = function (key, textureURL, atlasURL, path, textureXhrSettin
return { texture: image, data: data };
};
// When registering a factory function 'this' refers to the Loader context.
//
// There are several properties available to use:
//
// this.scene - a reference to the Scene that owns the GameObjectFactory
FileTypesManager.register('unityAtlas', function (key, textureURL, atlasURL, textureXhrSettings, atlasXhrSettings)
{
// Returns an object with two properties: 'texture' and 'data'
var files = new UnityAtlasFile(key, textureURL, atlasURL, this.path, textureXhrSettings, atlasXhrSettings);
this.addFile(files.texture);
this.addFile(files.data);
return this;
});
module.exports = UnityAtlasFile;

View file

@ -1,6 +1,7 @@
var Class = require('../../utils/Class');
var CONST = require('../const');
var File = require('../File');
var FileTypesManager = require('../FileTypesManager');
var GetFastValue = require('../../utils/object/GetFastValue');
var ParseOBJ = require('../../geom/mesh/ParseOBJ');
@ -42,23 +43,29 @@ var WavefrontFile = new Class({
});
WavefrontFile.create = function (loader, key, url, xhrSettings)
// When registering a factory function 'this' refers to the Loader context.
//
// There are several properties available to use:
//
// this.scene - a reference to the Scene that owns the GameObjectFactory
FileTypesManager.register('obj', function (key, url, xhrSettings)
{
if (Array.isArray(key))
{
for (var i = 0; i < key.length; i++)
{
// If it's an array it has to be an array of Objects, so we get everything out of the 'key' object
loader.addFile(new WavefrontFile(key[i], url, loader.path, xhrSettings));
this.addFile(new WavefrontFile(key[i], url, this.path, xhrSettings));
}
}
else
{
loader.addFile(new WavefrontFile(key, url, loader.path, xhrSettings));
this.addFile(new WavefrontFile(key, url, this.path, xhrSettings));
}
// For method chaining
return loader;
};
return this;
});
module.exports = WavefrontFile;

View file

@ -1,6 +1,7 @@
var Class = require('../../utils/Class');
var CONST = require('../const');
var File = require('../File');
var FileTypesManager = require('../FileTypesManager');
var GetFastValue = require('../../utils/object/GetFastValue');
var ParseXML = require('../../dom/ParseXML');
@ -47,23 +48,29 @@ var XMLFile = new Class({
});
XMLFile.create = function (loader, key, url, xhrSettings)
// When registering a factory function 'this' refers to the Loader context.
//
// There are several properties available to use:
//
// this.scene - a reference to the Scene that owns the GameObjectFactory
FileTypesManager.register('xml', function (key, url, xhrSettings)
{
if (Array.isArray(key))
{
for (var i = 0; i < key.length; i++)
{
// If it's an array it has to be an array of Objects, so we get everything out of the 'key' object
loader.addFile(new XMLFile(key[i], url, loader.path, xhrSettings));
this.addFile(new XMLFile(key[i], url, this.path, xhrSettings));
}
}
else
{
loader.addFile(new XMLFile(key, url, loader.path, xhrSettings));
this.addFile(new XMLFile(key, url, this.path, xhrSettings));
}
// For method chaining
return loader;
};
return this;
});
module.exports = XMLFile;

View file

@ -2,8 +2,32 @@
module.exports = {
BaseLoader: require('./BaseLoader'),
LoaderPlugin: require('./LoaderPlugin'),
File: require('./File'),
LoaderPlugin: require('./Loader')
FileTypesManager: require('./FileTypesManager'),
FileTypes: {
AnimationJSONFile: require('./filetypes/AnimationJSONFile'),
AtlasJSONFile: require('./filetypes/AtlasJSONFile'),
AudioFile: require('./filetypes/AudioFile'),
AudioSprite: require('./filetypes/AudioSprite'),
BinaryFile: require('./filetypes/BinaryFile'),
BitmapFontFile: require('./filetypes/BitmapFontFile'),
GLSLFile: require('./filetypes/GLSLFile'),
HTMLFile: require('./filetypes/HTMLFile'),
ImageFile: require('./filetypes/ImageFile'),
JSONFile: require('./filetypes/JSONFile'),
MultiAtlas: require('./filetypes/MultiAtlas'),
PluginFile: require('./filetypes/PluginFile'),
ScriptFile: require('./filetypes/ScriptFile'),
SpriteSheet: require('./filetypes/SpriteSheet'),
SVGFile: require('./filetypes/SVGFile'),
TextFile: require('./filetypes/TextFile'),
TilemapCSVFile: require('./filetypes/TilemapCSVFile'),
TilemapJSONFile: require('./filetypes/TilemapJSONFile'),
UnityAtlasFile: require('./filetypes/UnityAtlasFile'),
WavefrontFile: require('./filetypes/WavefrontFile'),
XMLFile: require('./filetypes/XMLFile')
}
};

View file

@ -23,14 +23,14 @@ var CollideSpriteVsTilemapLayer = function (sprite, tilemapLayer, collideCallbac
if (layerData.tileWidth > layerData.baseTileWidth)
{
// The x origin of a tile is the left side, so x and width need to be adjusted.
let xDiff = (layerData.tileWidth - layerData.baseTileWidth) * tilemapLayer.scaleX;
var xDiff = (layerData.tileWidth - layerData.baseTileWidth) * tilemapLayer.scaleX;
x -= xDiff;
w += xDiff;
}
if (layerData.tileHeight > layerData.baseTileHeight)
{
// The y origin of a tile is the bottom side, so just the height needs to be adjusted.
let yDiff = (layerData.tileHeight - layerData.baseTileHeight) * tilemapLayer.scaleY;
var yDiff = (layerData.tileHeight - layerData.baseTileHeight) * tilemapLayer.scaleY;
h += yDiff;
}

View file

@ -1,42 +0,0 @@
var Class = require('../utils/Class');
var PluginManager = require('../plugins/PluginManager');
var TestPlugin = new Class({
initialize:
function TestPlugin (scene)
{
this.scene = scene;
this.systems = scene.sys;
this.mapping = 'test';
console.log('TestPlugin is alive');
if (!scene.sys.settings.isBooted)
{
scene.sys.events.once('boot', this.boot, this);
}
},
boot: function ()
{
console.log('TestPlugin has booted');
this.scene[this.mapping] = this;
},
fire: function (img)
{
console.log('Hello!');
this.systems.add.image(400, 300, img);
}
});
PluginManager.register('test', TestPlugin);
module.exports = TestPlugin;

View file

@ -105,6 +105,14 @@ var SceneManager = new Class({
scene.init.call(scene, scene.sys.settings.data);
}
// Insert at the correct index, or it just all goes wrong :)
var i = this.getSceneIndex(scene);
this.active.push({ index: i, scene: scene });
// Sort the 'active' array based on the index property
this.active.sort(this.sortScenes);
var loader;
if (scene.sys.load)
@ -126,7 +134,6 @@ var SceneManager = new Class({
else
{
// Start the loader going as we have something in the queue
loader.once('complete', this.loadComplete, this);
loader.start();
@ -260,15 +267,6 @@ var SceneManager = new Class({
*/
create: function (scene)
{
// Insert at the correct index, or it just all goes wrong :)
var i = this.getSceneIndex(scene);
this.active.push({ index: i, scene: scene });
// Sort the 'active' array based on the index property
this.active.sort(this.sortScenes);
if (scene.create)
{
scene.create.call(scene, scene.sys.settings.data);
@ -354,42 +352,11 @@ var SceneManager = new Class({
this.createSceneDisplay(newScene);
// Default required functions
/*
if (!newScene.init)
{
newScene.init = NOOP;
}
if (!newScene.preload)
{
newScene.preload = NOOP;
}
if (!newScene.create)
{
newScene.create = NOOP;
}
if (!newScene.shutdown)
{
newScene.shutdown = NOOP;
}
*/
if (!newScene.update)
{
newScene.update = NOOP;
}
/*
if (!newScene.render)
{
newScene.render = NOOP;
}
*/
return newScene;
}
},
@ -455,21 +422,27 @@ var SceneManager = new Class({
this.createSceneDisplay(newScene);
// Extract callbacks or set NOOP
// Extract callbacks
var defaults = [ 'init', 'preload', 'create', 'update', 'render' ];
var defaults = [ 'init', 'preload', 'create', 'update', 'render', 'shutdown', 'destroy' ];
for (var i = 0; i < defaults.length; i++)
{
var sceneCallback = GetValue(sceneConfig, defaults[i], null);
// Must always have an update function, no matter what (the rest are optional)
if (defaults[i] === 'update' && !sceneCallback)
{
sceneCallback = NOOP;
}
if (sceneCallback)
{
newScene[defaults[i]] = sceneCallback;
}
}
// Now let's move across any other functions or properties that may exist
// Now let's move across any other functions or properties that may exist in the extend object:
/*
scene: {
@ -487,10 +460,7 @@ var SceneManager = new Class({
{
for (var propertyKey in sceneConfig.extend)
{
if (defaults.indexOf(propertyKey) === -1)
{
newScene[propertyKey] = sceneConfig.extend[propertyKey];
}
newScene[propertyKey] = sceneConfig.extend[propertyKey];
}
}
@ -807,11 +777,9 @@ var SceneManager = new Class({
*
* @param {object} event - [description]
*/
payloadComplete: function (event)
payloadComplete: function (loader)
{
var scene = event.loader.scene;
this.bootScene(scene);
this.bootScene(loader.scene);
},
/**

View file

@ -47,6 +47,10 @@ var Settings = {
physics: GetValue(config, 'physics', {}),
// Loader
loader: GetValue(config, 'loader', {}),
// Plugins
plugins: GetValue(config, 'plugins', false),

View file

@ -98,6 +98,27 @@ var BaseSoundManager = new Class({
* @default 0
*/
this._detune = 0;
/**
* Mobile devices require sounds to be triggered from an explicit user action,
* such as a tap, before any sound can be loaded/played on a web page.
* Set to true if the audio system is currently locked awaiting user interaction.
*
* @readonly
* @property {boolean} locked
*/
this.locked = this.locked || false;
/**
* Flag used internally for handling when the audio system
* has been unlocked, if there ever was a need for it.
*
* @private
* @property {boolean} unlocked
* @default false
*/
this.unlocked = false;
if (this.locked) {
this.unlock();
}
},
/**
* Adds a new sound into the sound manager.
@ -248,6 +269,17 @@ var BaseSoundManager = new Class({
});
this.emit('stopall', this);
},
/**
* Method used internally for unlocking audio playback on devices that
* require user interaction before any sound can be played on a web page.
*
* Read more about how this issue is handled here in [this article](TODO add link).
*
* @override
* @protected
* @method Phaser.Sound.BaseSoundManager#unlock
*/
unlock: NOOP,
/**
* Method used internally for pausing sound manager if
* Phaser.Sound.BaseSoundManager#pauseOnBlur is set to true.
@ -276,6 +308,11 @@ var BaseSoundManager = new Class({
* @param {number} delta - The delta time elapsed since the last frame.
*/
update: function (time, delta) {
if (this.unlocked) {
this.unlocked = false;
this.locked = false;
this.emit('unlocked', this);
}
for (var i = this.sounds.length - 1; i >= 0; i--) {
if (this.sounds[i].pendingRemove) {
this.sounds.splice(i, 1);

View file

@ -49,6 +49,9 @@ var HTML5AudioSound = new Class({
BaseSound.call(this, manager, key, config);
},
play: function (markerName, config) {
if (this.manager.isLocked(this, 'play', [markerName, config])) {
return false;
}
if (!BaseSound.prototype.play.call(this, markerName, config)) {
return false;
}
@ -60,6 +63,9 @@ var HTML5AudioSound = new Class({
return true;
},
pause: function () {
if (this.manager.isLocked(this, 'pause')) {
return false;
}
if (this.startTime > 0) {
return false;
}
@ -74,6 +80,9 @@ var HTML5AudioSound = new Class({
return true;
},
resume: function () {
if (this.manager.isLocked(this, 'resume')) {
return false;
}
if (this.startTime > 0) {
return false;
}
@ -88,6 +97,9 @@ var HTML5AudioSound = new Class({
return true;
},
stop: function () {
if (this.manager.isLocked(this, 'stop')) {
return false;
}
if (!BaseSound.prototype.stop.call(this)) {
return false;
}
@ -110,7 +122,7 @@ var HTML5AudioSound = new Class({
if (delay === 0) {
this.startTime = 0;
if (this.audio.paused) {
this.audio.play();
this.playCatchPromise();
}
}
else {
@ -123,40 +135,47 @@ var HTML5AudioSound = new Class({
return true;
},
pickAudioTag: function () {
if (!this.audio) {
for (var i = 0; i < this.tags.length; i++) {
var audio = this.tags[i];
if (audio.dataset.used === 'false') {
audio.dataset.used = 'true';
this.audio = audio;
return true;
}
}
if (!this.manager.override) {
return false;
}
var otherSounds_1 = [];
this.manager.forEachActiveSound(function (sound) {
if (sound.key === this.key && sound.audio) {
otherSounds_1.push(sound);
}
}, this);
otherSounds_1.sort(function (a1, a2) {
if (a1.loop === a2.loop) {
// sort by progress
return (a2.seek / a2.duration) - (a1.seek / a1.duration);
}
return a1.loop ? 1 : -1;
});
var selectedSound = otherSounds_1[0];
this.audio = selectedSound.audio;
selectedSound.reset();
selectedSound.audio = null;
selectedSound.startTime = 0;
selectedSound.previousTime = 0;
if (this.audio) {
return true;
}
for (var i = 0; i < this.tags.length; i++) {
var audio = this.tags[i];
if (audio.dataset.used === 'false') {
audio.dataset.used = 'true';
this.audio = audio;
return true;
}
}
if (!this.manager.override) {
return false;
}
var otherSounds = [];
this.manager.forEachActiveSound(function (sound) {
if (sound.key === this.key && sound.audio) {
otherSounds.push(sound);
}
}, this);
otherSounds.sort(function (a1, a2) {
if (a1.loop === a2.loop) {
// sort by progress
return (a2.seek / a2.duration) - (a1.seek / a1.duration);
}
return a1.loop ? 1 : -1;
});
var selectedSound = otherSounds[0];
this.audio = selectedSound.audio;
selectedSound.reset();
selectedSound.audio = null;
selectedSound.startTime = 0;
selectedSound.previousTime = 0;
return true;
},
playCatchPromise: function () {
var playPromise = this.audio.play();
if (playPromise) {
playPromise.catch(function (reason) { });
}
},
stopAndReleaseAudioTag: function () {
this.audio.pause();
this.audio.dataset.used = 'false';
@ -181,42 +200,43 @@ var HTML5AudioSound = new Class({
this.pickAndPlayAudioTag();
},
update: function (time, delta) {
if (this.isPlaying) {
// handling delayed playback
if (this.startTime > 0) {
if (this.startTime < time - this.manager.audioPlayDelay) {
this.audio.currentTime += Math.max(0, time - this.startTime) / 1000;
this.startTime = 0;
this.previousTime = this.audio.currentTime;
this.audio.play();
}
return;
}
// handle looping and ending
var startTime = this.currentMarker ? this.currentMarker.start : 0;
var endTime = startTime + this.duration;
var currentTime = this.audio.currentTime;
if (this.currentConfig.loop) {
if (currentTime >= endTime - this.manager.loopEndOffset) {
this.audio.currentTime = startTime + Math.max(0, currentTime - endTime);
currentTime = this.audio.currentTime;
}
else if (currentTime < startTime) {
this.audio.currentTime += startTime;
currentTime = this.audio.currentTime;
}
if (currentTime < this.previousTime) {
this.emit('looped', this);
}
}
else if (currentTime >= endTime) {
this.reset();
this.stopAndReleaseAudioTag();
this.emit('ended', this);
return;
}
this.previousTime = currentTime;
if (!this.isPlaying) {
return;
}
// handling delayed playback
if (this.startTime > 0) {
if (this.startTime < time - this.manager.audioPlayDelay) {
this.audio.currentTime += Math.max(0, time - this.startTime) / 1000;
this.startTime = 0;
this.previousTime = this.audio.currentTime;
this.playCatchPromise();
}
return;
}
// handle looping and ending
var startTime = this.currentMarker ? this.currentMarker.start : 0;
var endTime = startTime + this.duration;
var currentTime = this.audio.currentTime;
if (this.currentConfig.loop) {
if (currentTime >= endTime - this.manager.loopEndOffset) {
this.audio.currentTime = startTime + Math.max(0, currentTime - endTime);
currentTime = this.audio.currentTime;
}
else if (currentTime < startTime) {
this.audio.currentTime += startTime;
currentTime = this.audio.currentTime;
}
if (currentTime < this.previousTime) {
this.emit('looped', this);
}
}
else if (currentTime >= endTime) {
this.reset();
this.stopAndReleaseAudioTag();
this.emit('ended', this);
return;
}
this.previousTime = currentTime;
},
destroy: function () {
BaseSound.prototype.destroy.call(this);
@ -254,6 +274,9 @@ Object.defineProperty(HTML5AudioSound.prototype, 'mute', {
},
set: function (value) {
this.currentConfig.mute = value;
if (this.manager.isLocked(this, 'mute', value)) {
return;
}
this.setMute();
this.emit('mute', this, value);
}
@ -270,10 +293,49 @@ Object.defineProperty(HTML5AudioSound.prototype, 'volume', {
},
set: function (value) {
this.currentConfig.volume = value;
if (this.manager.isLocked(this, 'volume', value)) {
return;
}
this.setVolume();
this.emit('volume', this, value);
}
});
/**
* Playback rate.
*
* @name Phaser.Sound.HTML5AudioSound#rate
* @property {number} rate
*/
Object.defineProperty(HTML5AudioSound.prototype, 'rate', {
get: function () {
return Object.getOwnPropertyDescriptor(BaseSound.prototype, 'rate').get.call(this);
},
set: function (value) {
this.currentConfig.rate = value;
if (this.manager.isLocked(this, 'rate', value)) {
return;
}
Object.getOwnPropertyDescriptor(BaseSound.prototype, 'rate').set.call(this, value);
}
});
/**
* Detuning of sound.
*
* @name Phaser.Sound.HTML5AudioSound#detune
* @property {number} detune
*/
Object.defineProperty(HTML5AudioSound.prototype, 'detune', {
get: function () {
return Object.getOwnPropertyDescriptor(BaseSound.prototype, 'detune').get.call(this);
},
set: function (value) {
this.currentConfig.detune = value;
if (this.manager.isLocked(this, 'detune', value)) {
return;
}
Object.getOwnPropertyDescriptor(BaseSound.prototype, 'detune').set.call(this, value);
}
});
/**
* Current position of playing sound.
*
@ -294,6 +356,9 @@ Object.defineProperty(HTML5AudioSound.prototype, 'seek', {
}
},
set: function (value) {
if (this.manager.isLocked(this, 'seek', value)) {
return;
}
if (this.startTime > 0) {
return;
}
@ -323,6 +388,9 @@ Object.defineProperty(HTML5AudioSound.prototype, 'loop', {
},
set: function (value) {
this.currentConfig.loop = value;
if (this.manager.isLocked(this, 'loop', value)) {
return;
}
if (this.audio) {
this.audio.loop = value;
}

View file

@ -46,6 +46,20 @@ var HTML5AudioSoundManager = new Class({
* @default []
*/
this.onBlurPausedSounds = [];
this.locked = 'ontouchstart' in window;
/**
* A queue of all actions performed on sound objects while audio was locked.
* Once the audio gets unlocked, after an explicit user interaction,
* all actions will be performed in chronological order.
*
* @private
* @property {{
* sound: Phaser.Sound.HTML5AudioSound,
* name: string,
* value?: any,
* }[]} lockedActionsQueue
*/
this.lockedActionsQueue = this.locked ? [] : null;
/**
* Property that actually holds the value of global mute
* for HTML5 Audio sound manager implementation.
@ -71,6 +85,54 @@ var HTML5AudioSoundManager = new Class({
this.sounds.push(sound);
return sound;
},
unlock: function () {
var _this = this;
var moved = false;
var detectMove = function () {
moved = true;
};
var unlock = function () {
if (moved) {
moved = false;
return;
}
document.body.removeEventListener('touchmove', detectMove);
document.body.removeEventListener('touchend', unlock);
var allTags = [];
_this.game.cache.audio.entries.each(function (key, tags) {
for (var i = 0; i < tags.length; i++) {
allTags.push(tags[i]);
}
return true;
});
var lastTag = allTags[allTags.length - 1];
lastTag.oncanplaythrough = function () {
lastTag.oncanplaythrough = null;
_this.unlocked = true;
};
allTags.forEach(function (tag) {
tag.load();
});
};
this.once('unlocked', function () {
_this.forEachActiveSound(function (sound) {
sound.duration = sound.tags[0].duration;
sound.totalDuration = sound.tags[0].duration;
});
_this.lockedActionsQueue.forEach(function (lockedAction) {
if (lockedAction.sound[lockedAction.prop].apply) {
lockedAction.sound[lockedAction.prop].apply(lockedAction.sound, lockedAction.value || []);
}
else {
lockedAction.sound[lockedAction.prop] = lockedAction.value;
}
});
_this.lockedActionsQueue.length = 0;
_this.lockedActionsQueue = null;
});
document.body.addEventListener('touchmove', detectMove, false);
document.body.addEventListener('touchend', unlock, false);
},
onBlur: function () {
this.forEachActiveSound(function (sound) {
if (sound.isPlaying) {
@ -89,6 +151,17 @@ var HTML5AudioSoundManager = new Class({
BaseSoundManager.prototype.destroy.call(this);
this.onBlurPausedSounds.length = 0;
this.onBlurPausedSounds = null;
},
isLocked: function (sound, prop, value) {
if (this.locked) {
this.lockedActionsQueue.push({
sound: sound,
prop: prop,
value: value
});
return true;
}
return false;
}
});
/**

View file

@ -44,7 +44,7 @@ var WebAudioSoundManager = new Class({
* @property {AudioNode} destination
*/
this.destination = this.masterMuteNode;
this.unlock();
this.locked = this.context.state === 'suspended' && 'ontouchstart' in window;
BaseSoundManager.call(this, game);
},
/**
@ -81,6 +81,7 @@ var WebAudioSoundManager = new Class({
},
/**
* Unlocks Web Audio API on iOS devices on the initial touch event.
*
* Read more about how this issue is handled here in [this article](TODO add link).
*
* @private
@ -88,16 +89,15 @@ var WebAudioSoundManager = new Class({
*/
unlock: function () {
var _this = this;
if (this.context.state === 'suspended' && 'ontouchstart' in window) {
var unlock_1 = function () {
_this.context.resume().then(function () {
document.body.removeEventListener('touchstart', unlock_1);
document.body.removeEventListener('touchend', unlock_1);
});
};
document.body.addEventListener('touchstart', unlock_1, false);
document.body.addEventListener('touchend', unlock_1, false);
}
var unlock = function () {
_this.context.resume().then(function () {
document.body.removeEventListener('touchstart', unlock);
document.body.removeEventListener('touchend', unlock);
_this.unlocked = true;
});
};
document.body.addEventListener('touchstart', unlock, false);
document.body.addEventListener('touchend', unlock, false);
},
/**
* Method used internally for pausing sound manager if

View file

@ -80,6 +80,16 @@ var Frame = new Class({
*/
this.centerY = Math.floor(height / 2);
/**
* @property {number} pivotX - The horizontal pivot point of this Frame.
*/
this.pivotX = 0;
/**
* @property {number} height - The vertical pivot point of this Frame.
*/
this.pivotY = 0;
/**
* Is this frame is rotated or not in the Texture?
* Rotation allows you to use rotated frames in texture atlas packing.
@ -93,6 +103,9 @@ var Frame = new Class({
// Over-rides the Renderer setting? -1 = use Renderer Setting, 0 = No rounding, 1 = Round
this.autoRound = -1;
// Any Frame specific custom data can be stored here
this.customData = {};
/**
* The un-modified source frame, trim and UV data.
*

View file

@ -36,6 +36,9 @@ var Texture = new Class({
this.frames = {};
// Any additional data that was set in the source JSON (if any), or any extra data you'd like to store relating to this texture
this.customData = {};
this.firstFrame = '__BASE';
this.frameTotal = 0;

View file

@ -323,6 +323,21 @@ var TextureManager = new Class({
}
},
getTextureKeys: function ()
{
var output = [];
for (var key in this.list)
{
if (key !== '__DEFAULT' && key !== '__MISSING')
{
output.push(key);
}
}
return output;
},
getPixel: function (x, y, key, frame)
{
var textureFrame = this.getFrame(key, frame);

View file

@ -1,3 +1,5 @@
var Clone = require('../../utils/object/Clone');
var JSONArray = function (texture, sourceIndex, json)
{
// Malformed?
@ -9,6 +11,7 @@ var JSONArray = function (texture, sourceIndex, json)
// Add in a __BASE entry (for the entire atlas)
var source = texture.source[sourceIndex];
texture.add('__BASE', sourceIndex, 0, 0, source.width, source.height);
// By this stage frames is a fully parsed array
@ -40,6 +43,27 @@ var JSONArray = function (texture, sourceIndex, json)
newFrame.rotated = true;
newFrame.updateUVsInverted();
}
// Copy over any extra data
newFrame.customData = Clone(src);
}
// Copy over any additional data that was in the JSON to Texture.customData
for (var dataKey in json)
{
if (dataKey === 'frames')
{
continue;
}
if (Array.isArray(json[dataKey]))
{
texture.customData[dataKey] = json[dataKey].slice(0);
}
else
{
texture.customData[dataKey] = json[dataKey];
}
}
return texture;

View file

@ -1,3 +1,5 @@
var Clone = require('../../utils/object/Clone');
var JSONHash = function (texture, sourceIndex, json)
{
// Malformed?
@ -9,6 +11,7 @@ var JSONHash = function (texture, sourceIndex, json)
// Add in a __BASE entry (for the entire atlas)
var source = texture.source[sourceIndex];
texture.add('__BASE', sourceIndex, 0, 0, source.width, source.height);
// By this stage frames is a fully parsed Object
@ -40,6 +43,27 @@ var JSONHash = function (texture, sourceIndex, json)
newFrame.rotated = true;
newFrame.updateUVsInverted();
}
// Copy over any extra data
newFrame.customData = Clone(src);
}
// Copy over any additional data that was in the JSON to Texture.customData
for (var dataKey in json)
{
if (dataKey === 'frames')
{
continue;
}
if (Array.isArray(json[dataKey]))
{
texture.customData[dataKey] = json[dataKey].slice(0);
}
else
{
texture.customData[dataKey] = json[dataKey];
}
}
return texture;