Moving to unified 'add' structure and removing multiatlas

This commit is contained in:
Richard Davey 2018-04-28 12:32:03 +01:00
parent 9a974514ff
commit 0390af16e9
6 changed files with 116 additions and 78 deletions

View file

@ -110,7 +110,7 @@ var LoaderPlugin = new Class({
* @default {}
* @since 3.0.0
*/
this._multilist = {};
// this._multilist = {};
// Inject the available filetypes into the Loader
FileTypesManager.install(this);
@ -362,7 +362,7 @@ var LoaderPlugin = new Class({
{
if (!this.isReady())
{
return -1;
return;
}
if (Array.isArray(file))
@ -666,6 +666,7 @@ var LoaderPlugin = new Class({
return;
}
/*
// The global Texture Manager
var cache = this.scene.sys.cache;
var textures = this.scene.sys.textures;
@ -717,6 +718,7 @@ var LoaderPlugin = new Class({
}
}
}
*/
// Process all of the files
@ -843,14 +845,15 @@ var LoaderPlugin = new Class({
},
/**
* [description]
* Called by the Scene Manager if you specify a files payload for a pre-Scene Boot.
* Takes an array of file objects.
*
* @method Phaser.Loader.LoaderPlugin#loadArray
* @since 3.0.0
*
* @param {LoaderFileObject[]} files - [description]
* @param {LoaderFileObject[]} files - An array of files to load.
*
* @return {boolean} [description]
* @return {boolean} `true` if any files were successfully added to the list, otherwise `false`.
*/
loadArray: function (files)
{
@ -858,59 +861,16 @@ var LoaderPlugin = new Class({
{
for (var i = 0; i < files.length; i++)
{
this.file(files[i]);
var file = files[i];
// Calls file-type methods like `atlas` or `image`
this[file.type](file);
}
}
return (this.list.size > 0);
},
/**
* [description]
*
* @method Phaser.Loader.LoaderPlugin#file
* @since 3.0.0
*
* @param {LoaderFileObject} file - [description]
*
* @return {Phaser.Loader.File} [description]
*/
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;
},
/**
* The Scene that owns this plugin is shutting down.
* We need to kill and reset all internal properties as well as stop listening to Scene events.

View file

@ -6,6 +6,7 @@
var Class = require('../../utils/Class');
var FileTypesManager = require('../FileTypesManager');
var GetFastValue = require('../../utils/object/GetFastValue');
var JSONFile = require('./JSONFile.js');
/**
@ -73,20 +74,28 @@ var AnimationJSONFile = new Class({
*/
FileTypesManager.register('animation', function (key, url, xhrSettings)
{
var file;
// Supports an Object file definition in the key argument
// Or an array of objects in the key argument
// Or a single entry where all arguments have been defined
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(new AnimationJSONFile(this, key[i], url, xhrSettings));
file = new AnimationJSONFile(this, key[i]);
this.addFile(file);
}
}
else
{
this.addFile(new AnimationJSONFile(this, key, url, xhrSettings));
file = this.addFile(new AnimationJSONFile(this, key, url, xhrSettings));
this.addFile(file);
}
// For method chaining
return this;
});

View file

@ -6,7 +6,9 @@
var Class = require('../../utils/Class');
var FileTypesManager = require('../FileTypesManager');
var GetFastValue = require('../../utils/object/GetFastValue');
var ImageFile = require('./ImageFile.js');
var IsPlainObject = require('../../utils/object/IsPlainObject');
var JSONFile = require('./JSONFile.js');
var LinkFile = require('../LinkFile.js');
@ -35,6 +37,17 @@ var AtlasJSONFile = new Class({
function AtlasJSONFile (loader, key, textureURL, atlasURL, textureXhrSettings, atlasXhrSettings)
{
if (IsPlainObject(key))
{
var config = key;
key = GetFastValue(config, 'key');
textureURL = GetFastValue(config, 'textureURL');
atlasURL = GetFastValue(config, 'atlasURL');
textureXhrSettings = GetFastValue(config, 'textureXhrSettings');
atlasXhrSettings = GetFastValue(config, 'atlasXhrSettings');
}
var image = new ImageFile(loader, key, textureURL, textureXhrSettings);
var data = new JSONFile(loader, key, atlasURL, atlasXhrSettings);
@ -88,18 +101,25 @@ FileTypesManager.register('atlas', function (key, textureURL, atlasURL, textureX
{
var linkfile;
if ((typeof key === 'object') && (key !== null))
// Supports an Object file definition in the key argument
// Or an array of objects in the key argument
// Or a single entry where all arguments have been defined
if (Array.isArray(key))
{
// If param key is an object, use object based loading method
linkfile = new AtlasJSONFile(this, key.key, key.texture, key.data, textureXhrSettings, atlasXhrSettings);
for (var i = 0; i < key.length; i++)
{
linkfile = new AtlasJSONFile(this, key[i]);
this.addFile(linkfile.files);
}
}
else
{
// else just use the parameters like normal
linkfile = new AtlasJSONFile(this, key, textureURL, atlasURL, textureXhrSettings, atlasXhrSettings);
}
this.addFile(linkfile.files);
}
return this;
});

View file

@ -9,6 +9,7 @@ var CONST = require('../const');
var File = require('../File');
var FileTypesManager = require('../FileTypesManager');
var GetFastValue = require('../../utils/object/GetFastValue');
var IsPlainObject = require('../../utils/object/IsPlainObject');
/**
* @classdesc
@ -33,17 +34,27 @@ var BinaryFile = new Class({
function BinaryFile (loader, key, url, xhrSettings)
{
var fileKey = (typeof key === 'string') ? key : GetFastValue(key, 'key', '');
var extension = 'bin';
if (IsPlainObject(key))
{
var config = key;
key = GetFastValue(config, 'key');
url = GetFastValue(config, 'url');
xhrSettings = GetFastValue(config, 'xhrSettings');
extension = GetFastValue(config, 'extension', extension);
}
var fileConfig = {
type: 'binary',
cache: loader.cacheManager.binary,
extension: GetFastValue(key, 'extension', 'bin'),
extension: extension,
responseType: 'arraybuffer',
key: fileKey,
url: GetFastValue(key, 'file', url),
key: key,
url: url,
path: loader.path,
xhrSettings: GetFastValue(key, 'xhr', xhrSettings)
xhrSettings: xhrSettings
};
File.call(this, loader, fileConfig);

View file

@ -7,6 +7,7 @@
var Class = require('../../utils/Class');
var FileTypesManager = require('../FileTypesManager');
var ImageFile = require('./ImageFile.js');
var IsPlainObject = require('../../utils/object/IsPlainObject');
var LinkFile = require('../LinkFile.js');
var ParseXMLBitmapFont = require('../../gameobjects/bitmaptext/ParseXMLBitmapFont.js');
var XMLFile = require('./XMLFile.js');
@ -34,10 +35,21 @@ var BitmapFontFile = new Class({
initialize:
function BitmapFontFile (loader, key, textureURL, atlasURL, textureXhrSettings, atlasXhrSettings)
function BitmapFontFile (loader, key, textureURL, xmlURL, textureXhrSettings, xmlXhrSettings)
{
if (IsPlainObject(key))
{
var config = key;
key = GetFastValue(config, 'key');
textureURL = GetFastValue(config, 'textureURL');
xmlURL = GetFastValue(config, 'xmlURL');
textureXhrSettings = GetFastValue(config, 'textureXhrSettings');
xmlXhrSettings = GetFastValue(config, 'xmlXhrSettings');
}
var image = new ImageFile(loader, key, textureURL, textureXhrSettings);
var data = new XMLFile(loader, key, atlasURL, atlasXhrSettings);
var data = new XMLFile(loader, key, xmlURL, xmlXhrSettings);
LinkFile.call(this, loader, 'bitmapfont', key, [ image, data ]);
},
@ -95,10 +107,27 @@ var BitmapFontFile = new Class({
*/
FileTypesManager.register('bitmapFont', function (key, textureURL, xmlURL, textureXhrSettings, xmlXhrSettings)
{
// Returns an object with two properties: 'texture' and 'data'
var linkfile = new BitmapFontFile(this, key, textureURL, xmlURL, textureXhrSettings, xmlXhrSettings);
var linkfile;
// Supports an Object file definition in the key argument
// Or an array of objects in the key argument
// Or a single entry where all arguments have been defined
if (Array.isArray(key))
{
for (var i = 0; i < key.length; i++)
{
linkfile = new BitmapFontFile(this, key[i]);
this.addFile(linkfile.files);
}
}
else
{
linkfile = new BitmapFontFile(this, key, textureURL, xmlURL, textureXhrSettings, xmlXhrSettings);
this.addFile(linkfile.files);
}
return this;
});

View file

@ -33,17 +33,27 @@ var GLSLFile = new Class({
function GLSLFile (loader, key, url, xhrSettings)
{
var fileKey = (typeof key === 'string') ? key : GetFastValue(key, 'key', '');
var extension = 'glsl';
if (IsPlainObject(key))
{
var config = key;
key = GetFastValue(config, 'key');
url = GetFastValue(config, 'url');
xhrSettings = GetFastValue(config, 'xhrSettings');
extension = GetFastValue(config, 'extension', extension);
}
var fileConfig = {
type: 'glsl',
cache: loader.cacheManager.shader,
extension: GetFastValue(key, 'extension', 'glsl'),
extension: extension,
responseType: 'text',
key: fileKey,
url: GetFastValue(key, 'file', url),
key: key,
url: url,
path: loader.path,
xhrSettings: GetFastValue(key, 'xhr', xhrSettings)
xhrSettings: xhrSettings
};
File.call(this, loader, fileConfig);
@ -94,7 +104,6 @@ FileTypesManager.register('glsl', function (key, url, xhrSettings)
this.addFile(new GLSLFile(this, key, url, xhrSettings));
}
// For method chaining
return this;
});