forked from phaserjs/phaser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUnityAtlasFile.js
More file actions
73 lines (63 loc) · 2.63 KB
/
UnityAtlasFile.js
File metadata and controls
73 lines (63 loc) · 2.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/**
* @author Richard Davey <rich@photonstorm.com>
* @copyright 2018 Photon Storm Ltd.
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
*/
var FileTypesManager = require('../FileTypesManager');
var ImageFile = require('./ImageFile.js');
var TextFile = require('./TextFile.js');
/**
* An Atlas JSON File.
*
* @function Phaser.Loader.Filetypes.UnityAtlasFile
* @since 3.0.0
*
* @param {string} key - The key of the file within the loader.
* @param {string} textureURL - The url to load the texture file from.
* @param {string} atlasURL - The url to load the atlas file from.
* @param {string} path - The path of the file.
* @param {object} textureXhrSettings - Optional texture file specific XHR settings.
* @param {object} atlasXhrSettings - Optional atlas file specific XHR settings.
*
* @return {object} An object containing two File objects to be added to the loader.
*/
var UnityAtlasFile = function (key, textureURL, atlasURL, path, textureXhrSettings, atlasXhrSettings)
{
var image = new ImageFile(key, textureURL, path, textureXhrSettings);
var data = new TextFile(key, atlasURL, path, atlasXhrSettings);
// Link them together
image.linkFile = data;
data.linkFile = image;
// Set the type
image.linkType = 'unityatlas';
data.linkType = 'unityatlas';
return { texture: image, data: data };
};
/**
* Adds a Unity Texture Atlas file to the current load queue.
*
* Note: This method will only be available if the Unity Atlas File type has been built into Phaser.
*
* The file is **not** loaded immediately after calling this method.
* Instead, the file is added to a queue within the Loader, which is processed automatically when the Loader starts.
*
* @method Phaser.Loader.LoaderPlugin#unityAtlas
* @since 3.0.0
*
* @param {string} key - The key of the file within the loader.
* @param {string} textureURL - The url to load the texture file from.
* @param {string} atlasURL - The url to load the atlas file from.
* @param {object} textureXhrSettings - Optional texture file specific XHR settings.
* @param {object} atlasXhrSettings - Optional atlas file specific XHR settings.
*
* @return {Phaser.Loader.LoaderPlugin} The Loader.
*/
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;