Skip to content

Commit 822b3a9

Browse files
committed
Updated Loader so you can pass in your own XHRSettings object with any file, and have that override the XHR defaults for the specific file.
1 parent 65828df commit 822b3a9

10 files changed

Lines changed: 56 additions & 70 deletions

File tree

v3/src/loader/BaseLoader.js

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -50,24 +50,9 @@ BaseLoader.prototype = {
5050
return -1;
5151
}
5252

53-
// Multipart file?
54-
if (file.linkFile)
55-
{
56-
var fileA = file;
57-
var fileB = file.linkFile;
58-
59-
fileA.path = this.path;
60-
fileB.path = this.path;
61-
62-
this.list.add(fileA);
63-
this.list.add(fileB);
64-
}
65-
else
66-
{
67-
file.path = this.path;
53+
file.path = this.path;
6854

69-
this.list.add(file);
70-
}
55+
this.list.add(file);
7156

7257
return this;
7358
},

v3/src/loader/File.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ var GetURL = require('./GetURL');
22
var CONST = require('./const');
33
var XHRLoader = require('./XHRLoader');
44
var XHRSettings = require('./XHRSettings');
5+
var MergeXHRSettings = require('./MergeXHRSettings');
56

6-
var File = function (type, key, url, responseType)
7+
var File = function (type, key, url, responseType, xhrSettings)
78
{
89
// file type (image, json, etc) for sorting within the Loader
910
this.type = type;
@@ -19,6 +20,11 @@ var File = function (type, key, url, responseType)
1920

2021
this.xhrSettings = XHRSettings(responseType);
2122

23+
if (xhrSettings)
24+
{
25+
this.xhrSettings = MergeXHRSettings(this.xhrSettings, xhrSettings);
26+
}
27+
2228
this.xhrLoader = null;
2329

2430
this.state = CONST.FILE_PENDING;
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
var ImageFile = require('./ImageFile.js');
22
var JSONFile = require('./JSONFile.js');
33

4-
var AtlasJSONFile = function (key, textureURL, atlasURL, path)
4+
var AtlasJSONFile = function (key, textureURL, atlasURL, path, textureXhrSettings, atlasXhrSettings)
55
{
6-
var image = new ImageFile(key, textureURL, path);
7-
var data = new JSONFile(key, atlasURL, path);
6+
var image = new ImageFile(key, textureURL, path, textureXhrSettings);
7+
var data = new JSONFile(key, atlasURL, path, atlasXhrSettings);
88

99
// Link them together
1010
image.linkFile = data;
@@ -14,7 +14,7 @@ var AtlasJSONFile = function (key, textureURL, atlasURL, path)
1414
image.linkType = 'atlasjson';
1515
data.linkType = 'atlasjson';
1616

17-
return image;
17+
return { texture: image, data: data };
1818
};
1919

2020
module.exports = AtlasJSONFile;

v3/src/loader/filetypes/BinaryFile.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
var CONST = require('../const');
33
var File = require('../File');
44

5-
var BinaryFile = function (key, url, path)
5+
var BinaryFile = function (key, url, path, xhrSettings)
66
{
77
if (path === undefined) { path = ''; }
88

@@ -20,7 +20,7 @@ var BinaryFile = function (key, url, path)
2020
url = path.concat(url);
2121
}
2222

23-
File.call(this, 'binary', key, url, 'arraybuffer');
23+
File.call(this, 'binary', key, url, 'arraybuffer', xhrSettings);
2424
};
2525

2626
BinaryFile.prototype = Object.create(File.prototype);

v3/src/loader/filetypes/GLSLFile.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
var CONST = require('../const');
33
var File = require('../File');
44

5-
var GLSLFile = function (key, url, path)
5+
var GLSLFile = function (key, url, path, xhrSettings)
66
{
77
if (path === undefined) { path = ''; }
88

@@ -20,7 +20,7 @@ var GLSLFile = function (key, url, path)
2020
url = path.concat(url);
2121
}
2222

23-
File.call(this, 'glsl', key, url, 'text');
23+
File.call(this, 'glsl', key, url, 'text', xhrSettings);
2424
};
2525

2626
GLSLFile.prototype = Object.create(File.prototype);

v3/src/loader/filetypes/ImageFile.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
var CONST = require('../const');
33
var File = require('../File');
44

5-
var ImageFile = function (key, url, path)
5+
var ImageFile = function (key, url, path, xhrSettings)
66
{
77
if (path === undefined) { path = ''; }
88

@@ -20,7 +20,7 @@ var ImageFile = function (key, url, path)
2020
url = path.concat(url);
2121
}
2222

23-
File.call(this, 'image', key, url, 'blob');
23+
File.call(this, 'image', key, url, 'blob', xhrSettings);
2424
};
2525

2626
ImageFile.prototype = Object.create(File.prototype);

v3/src/loader/filetypes/JSONFile.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
var CONST = require('../const');
33
var File = require('../File');
44

5-
var JSONFile = function (key, url, path)
5+
var JSONFile = function (key, url, path, xhrSettings)
66
{
77
if (path === undefined) { path = ''; }
88

@@ -20,7 +20,7 @@ var JSONFile = function (key, url, path)
2020
url = path.concat(url);
2121
}
2222

23-
File.call(this, 'json', key, url, 'text');
23+
File.call(this, 'json', key, url, 'text', xhrSettings);
2424
};
2525

2626
JSONFile.prototype = Object.create(File.prototype);

v3/src/loader/filetypes/TextFile.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
var CONST = require('../const');
33
var File = require('../File');
44

5-
var TextFile = function (key, url, path)
5+
var TextFile = function (key, url, path, xhrSettings)
66
{
77
if (path === undefined) { path = ''; }
88

@@ -20,7 +20,7 @@ var TextFile = function (key, url, path)
2020
url = path.concat(url);
2121
}
2222

23-
File.call(this, 'text', key, url, 'text');
23+
File.call(this, 'text', key, url, 'text', xhrSettings);
2424
};
2525

2626
TextFile.prototype = Object.create(File.prototype);

v3/src/loader/filetypes/XMLFile.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ var CONST = require('../const');
33
var File = require('../File');
44
var ParseXML = require('../../dom/ParseXML');
55

6-
var XMLFile = function (key, url, path)
6+
var XMLFile = function (key, url, path, xhrSettings)
77
{
88
if (path === undefined) { path = ''; }
99

@@ -21,7 +21,7 @@ var XMLFile = function (key, url, path)
2121
url = path.concat(url);
2222
}
2323

24-
File.call(this, 'xml', key, url, 'text');
24+
File.call(this, 'xml', key, url, 'text', xhrSettings);
2525
};
2626

2727
XMLFile.prototype = Object.create(File.prototype);

v3/src/state/systems/Loader.js

Lines changed: 31 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -26,70 +26,60 @@ var Loader = function (state)
2626
Loader.prototype = Object.create(BaseLoader.prototype);
2727
Loader.prototype.constructor = Loader;
2828

29-
Loader.prototype.image = function (key, url)
29+
Loader.prototype.image = function (key, url, xhrSettings)
3030
{
31-
var file = new ImageFile(key, url, this.path);
31+
var file = new ImageFile(key, url, this.path, xhrSettings);
3232

33-
this.addFile(file);
34-
35-
return this;
33+
return this.addFile(file);
3634
};
3735

38-
Loader.prototype.json = function (key, url)
36+
Loader.prototype.json = function (key, url, xhrSettings)
3937
{
40-
var file = new JSONFile(key, url, this.path);
38+
var file = new JSONFile(key, url, this.path, xhrSettings);
4139

42-
this.addFile(file);
43-
44-
return this;
40+
return this.addFile(file);
4541
};
4642

47-
Loader.prototype.xml = function (key, url)
43+
Loader.prototype.xml = function (key, url, xhrSettings)
4844
{
49-
var file = new XMLFile(key, url, this.path);
45+
var file = new XMLFile(key, url, this.path, xhrSettings);
5046

51-
this.addFile(file);
52-
53-
return this;
47+
return this.addFile(file);
5448
};
5549

56-
Loader.prototype.binary = function (key, url)
50+
Loader.prototype.binary = function (key, url, xhrSettings)
5751
{
58-
var file = new BinaryFile(key, url, this.path);
52+
var file = new BinaryFile(key, url, this.path, xhrSettings);
5953

60-
this.addFile(file);
61-
62-
return this;
54+
return this.addFile(file);
6355
};
6456

65-
Loader.prototype.text = function (key, url)
57+
Loader.prototype.text = function (key, url, xhrSettings)
6658
{
67-
var file = new TextFile(key, url, this.path);
59+
var file = new TextFile(key, url, this.path, xhrSettings);
6860

69-
this.addFile(file);
70-
71-
return this;
61+
return this.addFile(file);
7262
};
7363

74-
Loader.prototype.glsl = function (key, url)
64+
Loader.prototype.glsl = function (key, url, xhrSettings)
7565
{
76-
var file = new GLSLFile(key, url, this.path);
66+
var file = new GLSLFile(key, url, this.path, xhrSettings);
7767

78-
this.addFile(file);
79-
80-
return this;
68+
return this.addFile(file);
8169
};
8270

83-
Loader.prototype.atlas = function (key, textureURL, atlasURL)
71+
Loader.prototype.atlas = function (key, textureURL, atlasURL, textureXhrSettings, atlasXhrSettings)
8472
{
85-
var file = new AtlasJSONFile(key, textureURL, atlasURL, this.path);
73+
// Returns an object with two properties: 'texture' and 'data'
74+
var files = new AtlasJSONFile(key, textureURL, atlasURL, this.path, textureXhrSettings, atlasXhrSettings);
8675

87-
this.addFile(file);
76+
this.addFile(files.texture);
77+
this.addFile(files.data);
8878

8979
return this;
9080
};
9181

92-
Loader.prototype.multiatlas = function (key, textureURLs, atlasURLs)
82+
Loader.prototype.multiatlas = function (key, textureURLs, atlasURLs, textureXhrSettings, atlasXhrSettings)
9383
{
9484
if (typeof textureURLs === 'number')
9585
{
@@ -111,6 +101,7 @@ Loader.prototype.multiatlas = function (key, textureURLs, atlasURLs)
111101
}
112102
}
113103

104+
var file;
114105
var i = 0;
115106
var multiKey;
116107

@@ -120,7 +111,9 @@ Loader.prototype.multiatlas = function (key, textureURLs, atlasURLs)
120111
{
121112
multiKey = '_MA_IMG_' + key + '_' + i.toString();
122113

123-
this.addFile(new ImageFile(multiKey, textureURLs[i], this.path));
114+
file = new ImageFile(multiKey, textureURLs[i], this.path, textureXhrSettings);
115+
116+
this.addFile(file);
124117

125118
this._multilist[key].push(multiKey);
126119
}
@@ -129,7 +122,9 @@ Loader.prototype.multiatlas = function (key, textureURLs, atlasURLs)
129122
{
130123
multiKey = '_MA_JSON_' + key + '_' + i.toString();
131124

132-
this.addFile(new JSONFile(multiKey, atlasURLs[i], this.path));
125+
file = new JSONFile(multiKey, atlasURLs[i], this.path, atlasXhrSettings);
126+
127+
this.addFile(file);
133128

134129
this._multilist[key].push(multiKey);
135130
}

0 commit comments

Comments
 (0)