mirror of
https://github.com/photonstorm/phaser
synced 2025-03-01 05:47:28 +00:00
Merge remote-tracking branch 'origin/master'
# Conflicts: # src/loader/filetypes/AudioFile.js
This commit is contained in:
commit
d50c04e9f8
29 changed files with 512 additions and 487 deletions
|
@ -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');
|
||||
|
|
27
src/loader/FileTypesManager.js
Normal file
27
src/loader/FileTypesManager.js
Normal 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;
|
|
@ -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;
|
|
@ -2,27 +2,37 @@ var Class = require('../utils/Class');
|
|||
var CONST = require('./const');
|
||||
var CustomSet = require('../structs/Set');
|
||||
var EventEmitter = require('eventemitter3');
|
||||
var FileTypesManager = require('./FileTypesManager');
|
||||
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;
|
||||
|
||||
this.systems = scene.sys;
|
||||
|
||||
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);
|
||||
|
||||
// Move to a 'setURL' method?
|
||||
this.baseURL = '';
|
||||
this.path = '';
|
||||
|
@ -45,6 +55,14 @@ 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);
|
||||
},
|
||||
|
||||
setPath: function (path)
|
||||
{
|
||||
if (path.substr(-1) !== '/')
|
||||
|
@ -85,7 +103,7 @@ 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, '- LoaderPlugin start. Files to load:', this.list.size);
|
||||
|
||||
if (!this.isReady())
|
||||
{
|
||||
|
@ -121,7 +139,7 @@ var BaseLoader = new Class({
|
|||
|
||||
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));
|
||||
|
||||
|
@ -191,7 +209,7 @@ 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)
|
||||
{
|
||||
|
@ -474,7 +492,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);
|
||||
|
||||
|
@ -506,6 +524,12 @@ var BaseLoader = new Class({
|
|||
this.state = CONST.LOADER_IDLE;
|
||||
},
|
||||
|
||||
shutdown: function ()
|
||||
{
|
||||
this.reset();
|
||||
this.state = CONST.LOADER_SHUTDOWN;
|
||||
},
|
||||
|
||||
destroy: function ()
|
||||
{
|
||||
this.reset();
|
||||
|
@ -514,4 +538,6 @@ var BaseLoader = new Class({
|
|||
|
||||
});
|
||||
|
||||
module.exports = BaseLoader;
|
||||
PluginManager.register('Loader', LoaderPlugin, 'load');
|
||||
|
||||
module.exports = LoaderPlugin;
|
|
@ -4,17 +4,35 @@ 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,
|
||||
|
||||
TEXTURE_ATLAS_JSON_ARRAY: 20,
|
||||
TEXTURE_ATLAS_JSON_HASH: 21
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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.sys.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, game.sound.locked);
|
||||
};
|
||||
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)
|
||||
|
|
44
src/loader/filetypes/AudioSprite.js
Normal file
44
src/loader/filetypes/AudioSprite.js
Normal 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;
|
||||
});
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
|
@ -41,23 +42,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;
|
||||
|
|
60
src/loader/filetypes/MultiAtlas.js
Normal file
60
src/loader/filetypes/MultiAtlas.js
Normal 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;
|
||||
});
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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')
|
||||
}
|
||||
|
||||
};
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
Loading…
Add table
Reference in a new issue