Skip to content

Commit 83a1965

Browse files
committed
Files types updated to support new cache config value
1 parent 75a49d2 commit 83a1965

16 files changed

Lines changed: 144 additions & 90 deletions

src/loader/filetypes/AnimationJSONFile.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ var JSONFile = require('./JSONFile.js');
2020
*
2121
* @return {Phaser.Loader.FileTypes.JSONFile} A File instance to be added to the Loader.
2222
*/
23-
var AnimationJSONFile = function (key, url, path, xhrSettings)
23+
var AnimationJSONFile = function (loader, key, url, xhrSettings)
2424
{
25-
var json = new JSONFile(key, url, path, xhrSettings);
25+
var json = new JSONFile(loader, key, url, xhrSettings);
2626

2727
// Override the File type
2828
json.type = 'animationJSON';
@@ -55,12 +55,12 @@ FileTypesManager.register('animation', function (key, url, xhrSettings)
5555
for (var i = 0; i < key.length; i++)
5656
{
5757
// If it's an array it has to be an array of Objects, so we get everything out of the 'key' object
58-
this.addFile(new AnimationJSONFile(key[i], url, this.path, xhrSettings));
58+
this.addFile(new AnimationJSONFile(this, key[i], url, xhrSettings));
5959
}
6060
}
6161
else
6262
{
63-
this.addFile(new AnimationJSONFile(key, url, this.path, xhrSettings));
63+
this.addFile(new AnimationJSONFile(this, key, url, xhrSettings));
6464
}
6565

6666
// For method chaining

src/loader/filetypes/AtlasJSONFile.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ var JSONFile = require('./JSONFile.js');
2323
*
2424
* @return {object} An object containing two File objects to be added to the loader.
2525
*/
26-
var AtlasJSONFile = function (key, textureURL, atlasURL, path, textureXhrSettings, atlasXhrSettings)
26+
var AtlasJSONFile = function (loader, key, textureURL, atlasURL, textureXhrSettings, atlasXhrSettings)
2727
{
28-
var image = new ImageFile(key, textureURL, path, textureXhrSettings);
29-
var data = new JSONFile(key, atlasURL, path, atlasXhrSettings);
28+
var image = new ImageFile(loader, key, textureURL, textureXhrSettings);
29+
var data = new JSONFile(loader, key, atlasURL, atlasXhrSettings);
3030

3131
// Link them together
3232
image.linkFile = data;
@@ -60,20 +60,19 @@ var AtlasJSONFile = function (key, textureURL, atlasURL, path, textureXhrSetting
6060
*/
6161
FileTypesManager.register('atlas', function (key, textureURL, atlasURL, textureXhrSettings, atlasXhrSettings)
6262
{
63-
6463
var files;
6564

6665
// If param key is an object, use object based loading method
6766
if ((typeof key === 'object') && (key !== null))
6867
{
69-
files = new AtlasJSONFile(key.key, key.texture, key.data, this.path, textureXhrSettings, atlasXhrSettings);
68+
files = new AtlasJSONFile(this, key.key, key.texture, key.data, textureXhrSettings, atlasXhrSettings);
7069
}
7170

7271
// Else just use the parameters like normal
7372
else
7473
{
7574
// Returns an object with two properties: 'texture' and 'data'
76-
files = new AtlasJSONFile(key, textureURL, atlasURL, this.path, textureXhrSettings, atlasXhrSettings);
75+
files = new AtlasJSONFile(this, key, textureURL, atlasURL, textureXhrSettings, atlasXhrSettings);
7776
}
7877

7978
this.addFile(files.texture);

src/loader/filetypes/AudioFile.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ var AudioFile = new Class({
3333

3434
initialize:
3535

36-
function AudioFile (key, url, path, xhrSettings, audioContext)
36+
function AudioFile (loader, key, url, xhrSettings, audioContext)
3737
{
3838
/**
3939
* [description]
@@ -46,15 +46,16 @@ var AudioFile = new Class({
4646

4747
var fileConfig = {
4848
type: 'audio',
49+
cache: loader.cacheManager.audio,
4950
extension: GetFastValue(url, 'type', ''),
5051
responseType: 'arraybuffer',
5152
key: key,
5253
url: GetFastValue(url, 'uri', url),
53-
path: path,
54+
path: loader.path,
5455
xhrSettings: xhrSettings
5556
};
5657

57-
File.call(this, fileConfig);
58+
File.call(this, loader, fileConfig);
5859
},
5960

6061
/**
@@ -119,11 +120,11 @@ AudioFile.create = function (loader, key, urls, config, xhrSettings)
119120

120121
if (deviceAudio.webAudio && !(audioConfig && audioConfig.disableWebAudio))
121122
{
122-
return new AudioFile(key, url, loader.path, xhrSettings, game.sound.context);
123+
return new AudioFile(loader, key, url, xhrSettings, game.sound.context);
123124
}
124125
else
125126
{
126-
return new HTML5AudioFile(key, url, loader.path, config);
127+
return new HTML5AudioFile(loader, key, url, config);
127128
}
128129
};
129130

src/loader/filetypes/BinaryFile.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,21 +31,22 @@ var BinaryFile = new Class({
3131

3232
initialize:
3333

34-
function BinaryFile (key, url, path, xhrSettings)
34+
function BinaryFile (loader, key, url, xhrSettings)
3535
{
3636
var fileKey = (typeof key === 'string') ? key : GetFastValue(key, 'key', '');
3737

3838
var fileConfig = {
3939
type: 'binary',
40+
cache: loader.cacheManager.binary,
4041
extension: GetFastValue(key, 'extension', 'bin'),
4142
responseType: 'arraybuffer',
4243
key: fileKey,
4344
url: GetFastValue(key, 'file', url),
44-
path: path,
45+
path: loader.path,
4546
xhrSettings: GetFastValue(key, 'xhr', xhrSettings)
4647
};
4748

48-
File.call(this, fileConfig);
49+
File.call(this, loader, fileConfig);
4950
},
5051

5152
onProcess: function (callback)
@@ -85,12 +86,12 @@ FileTypesManager.register('binary', function (key, url, xhrSettings)
8586
for (var i = 0; i < key.length; i++)
8687
{
8788
// If it's an array it has to be an array of Objects, so we get everything out of the 'key' object
88-
this.addFile(new BinaryFile(key[i], url, this.path, xhrSettings));
89+
this.addFile(new BinaryFile(this, key[i], url, xhrSettings));
8990
}
9091
}
9192
else
9293
{
93-
this.addFile(new BinaryFile(key, url, this.path, xhrSettings));
94+
this.addFile(new BinaryFile(this, key, url, xhrSettings));
9495
}
9596

9697
// For method chaining

src/loader/filetypes/GLSLFile.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,21 +31,22 @@ var GLSLFile = new Class({
3131

3232
initialize:
3333

34-
function GLSLFile (key, url, path, xhrSettings)
34+
function GLSLFile (loader, key, url, xhrSettings)
3535
{
3636
var fileKey = (typeof key === 'string') ? key : GetFastValue(key, 'key', '');
3737

3838
var fileConfig = {
3939
type: 'glsl',
40+
cache: loader.cacheManager.shader,
4041
extension: GetFastValue(key, 'extension', 'glsl'),
4142
responseType: 'text',
4243
key: fileKey,
4344
url: GetFastValue(key, 'file', url),
44-
path: path,
45+
path: loader.path,
4546
xhrSettings: GetFastValue(key, 'xhr', xhrSettings)
4647
};
4748

48-
File.call(this, fileConfig);
49+
File.call(this, loader, fileConfig);
4950
},
5051

5152
onProcess: function (callback)
@@ -85,12 +86,12 @@ FileTypesManager.register('glsl', function (key, url, xhrSettings)
8586
for (var i = 0; i < key.length; i++)
8687
{
8788
// If it's an array it has to be an array of Objects, so we get everything out of the 'key' object
88-
this.addFile(new GLSLFile(key[i], url, this.path, xhrSettings));
89+
this.addFile(new GLSLFile(this, key[i], url, xhrSettings));
8990
}
9091
}
9192
else
9293
{
93-
this.addFile(new GLSLFile(key, url, this.path, xhrSettings));
94+
this.addFile(new GLSLFile(this, key, url, xhrSettings));
9495
}
9596

9697
// For method chaining

src/loader/filetypes/HTML5AudioFile.js

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,23 +30,24 @@ var HTML5AudioFile = new Class({
3030

3131
initialize:
3232

33-
function HTML5AudioFile (key, url, path, config)
34-
{
35-
this.locked = 'ontouchstart' in window;
33+
function HTML5AudioFile (loader, key, url, config)
34+
{
35+
this.locked = 'ontouchstart' in window;
3636

37-
this.loaded = false;
37+
this.loaded = false;
3838

39-
var fileConfig = {
40-
type: 'audio',
41-
extension: GetFastValue(url, 'type', ''),
42-
key: key,
43-
url: GetFastValue(url, 'uri', url),
44-
path: path,
45-
config: config
46-
};
39+
var fileConfig = {
40+
type: 'audio',
41+
cache: loader.cacheManager.audio,
42+
extension: GetFastValue(url, 'type', ''),
43+
key: key,
44+
url: GetFastValue(url, 'uri', url),
45+
path: loader.path,
46+
config: config
47+
};
4748

48-
File.call(this, fileConfig);
49-
},
49+
File.call(this, loader, fileConfig);
50+
},
5051

5152
onLoad: function ()
5253
{

src/loader/filetypes/HTMLFile.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ var HTMLFile = new Class({
3333

3434
initialize:
3535

36-
function HTMLFile (key, url, width, height, path, xhrSettings)
36+
function HTMLFile (loader, key, url, width, height, xhrSettings)
3737
{
3838
if (width === undefined) { width = 512; }
3939
if (height === undefined) { height = 512; }
@@ -42,19 +42,20 @@ var HTMLFile = new Class({
4242

4343
var fileConfig = {
4444
type: 'html',
45+
cache: loader.textureManager,
4546
extension: GetFastValue(key, 'extension', 'html'),
4647
responseType: 'text',
4748
key: fileKey,
4849
url: GetFastValue(key, 'file', url),
49-
path: path,
50+
path: loader.path,
5051
xhrSettings: GetFastValue(key, 'xhr', xhrSettings),
5152
config: {
5253
width: width,
5354
height: height
5455
}
5556
};
5657

57-
File.call(this, fileConfig);
58+
File.call(this, loader, fileConfig);
5859
},
5960

6061
onProcess: function (callback)
@@ -113,6 +114,13 @@ var HTMLFile = new Class({
113114
};
114115

115116
File.createObjectURL(this.data, blob, 'image/svg+xml');
117+
},
118+
119+
addToCache: function ()
120+
{
121+
this.cache.addImage(this.key, this.data);
122+
123+
this.loader.emit('filecomplete', this.key, this);
116124
}
117125

118126
});
@@ -143,12 +151,12 @@ FileTypesManager.register('html', function (key, url, width, height, xhrSettings
143151
for (var i = 0; i < key.length; i++)
144152
{
145153
// If it's an array it has to be an array of Objects, so we get everything out of the 'key' object
146-
this.addFile(new HTMLFile(key[i], url, width, height, this.path, xhrSettings));
154+
this.addFile(new HTMLFile(this, key[i], url, width, height, xhrSettings));
147155
}
148156
}
149157
else
150158
{
151-
this.addFile(new HTMLFile(key, url, width, height, this.path, xhrSettings));
159+
this.addFile(new HTMLFile(this, key, url, width, height, xhrSettings));
152160
}
153161

154162
// For method chaining

src/loader/filetypes/ImageFile.js

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,22 +48,23 @@ var ImageFile = new Class({
4848
// this.load.image({ key: 'bunny' });
4949
// this.load.image({ key: 'bunny', extension: 'jpg' });
5050

51-
function ImageFile (key, url, path, xhrSettings, config)
51+
function ImageFile (loader, key, url, xhrSettings, config)
5252
{
5353
var fileKey = (typeof key === 'string') ? key : GetFastValue(key, 'key', '');
5454

5555
var fileConfig = {
5656
type: 'image',
57+
cache: loader.textureManager,
5758
extension: GetFastValue(key, 'extension', 'png'),
5859
responseType: 'blob',
5960
key: fileKey,
6061
url: GetFastValue(key, 'file', url),
61-
path: path,
62+
path: loader.path,
6263
xhrSettings: GetFastValue(key, 'xhr', xhrSettings),
6364
config: GetFastValue(key, 'config', config)
6465
};
6566

66-
File.call(this, fileConfig);
67+
File.call(this, loader, fileConfig);
6768
},
6869

6970
onProcess: function (callback)
@@ -95,6 +96,13 @@ var ImageFile = new Class({
9596
};
9697

9798
File.createObjectURL(this.data, this.xhrLoader.response, 'image/png');
99+
},
100+
101+
addToCache: function ()
102+
{
103+
this.cache.addImage(this.key, this.data);
104+
105+
this.loader.emit('filecomplete', this.key, this);
98106
}
99107

100108
});
@@ -131,14 +139,14 @@ FileTypesManager.register('image', function (key, url, xhrSettings)
131139

132140
if (Array.isArray(urls) && urls.length === 2)
133141
{
134-
fileA = this.addFile(new ImageFile(key[i], urls[0], this.path, xhrSettings));
135-
fileB = this.addFile(new ImageFile(key[i], urls[1], this.path, xhrSettings));
142+
fileA = this.addFile(new ImageFile(this, key[i], urls[0], xhrSettings));
143+
fileB = this.addFile(new ImageFile(this, key[i], urls[1], xhrSettings));
136144

137145
fileA.setLinkFile(fileB, 'dataimage');
138146
}
139147
else
140148
{
141-
this.addFile(new ImageFile(key[i], url, this.path, xhrSettings));
149+
this.addFile(new ImageFile(this, key[i], url, xhrSettings));
142150
}
143151
}
144152
}
@@ -148,14 +156,14 @@ FileTypesManager.register('image', function (key, url, xhrSettings)
148156

149157
if (Array.isArray(urls) && urls.length === 2)
150158
{
151-
fileA = this.addFile(new ImageFile(key, urls[0], this.path, xhrSettings));
152-
fileB = this.addFile(new ImageFile(key, urls[1], this.path, xhrSettings));
159+
fileA = this.addFile(new ImageFile(this, key, urls[0], xhrSettings));
160+
fileB = this.addFile(new ImageFile(this, key, urls[1], xhrSettings));
153161

154162
fileA.setLinkFile(fileB, 'dataimage');
155163
}
156164
else
157165
{
158-
this.addFile(new ImageFile(key, url, this.path, xhrSettings));
166+
this.addFile(new ImageFile(this, key, url, xhrSettings));
159167
}
160168
}
161169

src/loader/filetypes/JSONFile.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,21 +33,22 @@ var JSONFile = new Class({
3333

3434
// 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
3535

36-
function JSONFile (key, url, path, xhrSettings)
36+
function JSONFile (loader, key, url, xhrSettings)
3737
{
3838
var fileKey = (typeof key === 'string') ? key : GetFastValue(key, 'key', '');
3939

4040
var fileConfig = {
4141
type: 'json',
42+
cache: loader.cacheManager.json,
4243
extension: GetFastValue(key, 'extension', 'json'),
4344
responseType: 'text',
4445
key: fileKey,
4546
url: GetFastValue(key, 'file', url),
46-
path: path,
47+
path: loader.path,
4748
xhrSettings: GetFastValue(key, 'xhr', xhrSettings)
4849
};
4950

50-
File.call(this, fileConfig);
51+
File.call(this, loader, fileConfig);
5152

5253
if (typeof fileConfig.url === 'object')
5354
{

0 commit comments

Comments
 (0)