Skip to content

Commit 10be573

Browse files
committed
Updated File Types to use config object instead.
1 parent 4136ccf commit 10be573

10 files changed

Lines changed: 114 additions & 145 deletions

File tree

v3/src/checksum.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
var CHECKSUM = {
2-
build: 'dfe80200-6000-11e7-a426-abaf4c1292d1'
2+
build: '752ee830-6009-11e7-ad20-7b53f4549f8a'
33
};
44
module.exports = CHECKSUM;

v3/src/loader/File.js

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
var Class = require('../utils/Class');
2+
var GetFastValue = require('../utils/object/GetFastValue');
23
var CONST = require('./const');
34
var GetURL = require('./GetURL');
45
var MergeXHRSettings = require('./MergeXHRSettings');
@@ -11,25 +12,40 @@ var File = new Class({
1112

1213
initialize:
1314

14-
function File (type, key, url, responseType, xhrSettings, config)
15+
// old signature: type, key, url, responseType, xhrSettings, config
16+
function File (fileConfig)
1517
{
1618
// file type (image, json, etc) for sorting within the Loader
17-
this.type = type;
19+
this.type = GetFastValue(fileConfig, 'type', false);
1820

1921
// unique cache key (unique within its file type)
20-
this.key = key;
22+
this.key = GetFastValue(fileConfig, 'key', false);
23+
24+
if (!this.type || !this.key)
25+
{
26+
throw new Error('Error calling \'Loader.' + this.type + '\' invalid key provided.');
27+
}
2128

2229
// The URL of the file, not including baseURL
23-
this.url = url;
30+
this.url = GetFastValue(fileConfig, 'url', '');
31+
32+
if (this.url === '')
33+
{
34+
this.url = GetFastValue(fileConfig, 'path', '') + this.key + GetFastValue(fileConfig, 'extension', '');
35+
}
36+
else
37+
{
38+
this.url = GetFastValue(fileConfig, 'path', '').concat(this.url);
39+
}
2440

2541
// Set when the Loader calls 'load' on this file
2642
this.src = '';
2743

28-
this.xhrSettings = XHRSettings(responseType);
44+
this.xhrSettings = XHRSettings(GetFastValue(fileConfig, 'responseType', undefined));
2945

30-
if (xhrSettings)
46+
if (GetFastValue(fileConfig, 'xhrSettings', false))
3147
{
32-
this.xhrSettings = MergeXHRSettings(this.xhrSettings, xhrSettings);
48+
this.xhrSettings = MergeXHRSettings(this.xhrSettings, GetFastValue(fileConfig, 'xhrSettings', {}));
3349
}
3450

3551
this.xhrLoader = null;
@@ -49,7 +65,7 @@ var File = new Class({
4965
this.data = undefined;
5066

5167
// A config object that can be used by file types to store transitional data
52-
this.config = config || {};
68+
this.config = GetFastValue(fileConfig, 'config', {});
5369

5470
// Multipart file? (i.e. an atlas and its json together)
5571
this.linkFile = undefined;

v3/src/loader/filetypes/BinaryFile.js

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,17 @@ var BinaryFile = new Class({
1212

1313
function BinaryFile (key, url, path, xhrSettings)
1414
{
15-
if (path === undefined) { path = ''; }
16-
17-
if (!key)
18-
{
19-
throw new Error('Error calling \'Loader.binary\' invalid key provided.');
20-
}
21-
22-
if (!url)
23-
{
24-
url = path + key + '.bin';
25-
}
26-
else
27-
{
28-
url = path.concat(url);
29-
}
30-
31-
File.call(this, 'binary', key, url, 'arraybuffer', xhrSettings);
15+
var fileConfig = {
16+
type: 'binary',
17+
extension: 'bin',
18+
responseType: 'arraybuffer',
19+
key: key,
20+
url: url,
21+
path: path,
22+
xhrSettings: xhrSettings
23+
};
24+
25+
File.call(this, fileConfig);
3226
},
3327

3428
onProcess: function (callback)

v3/src/loader/filetypes/GLSLFile.js

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,17 @@ var GLSLFile = new Class({
1212

1313
function GLSLFile (key, url, path, xhrSettings)
1414
{
15-
if (path === undefined) { path = ''; }
16-
17-
if (!key)
18-
{
19-
throw new Error('Error calling \'Loader.glsl\' invalid key provided.');
20-
}
21-
22-
if (!url)
23-
{
24-
url = path + key + '.glsl';
25-
}
26-
else
27-
{
28-
url = path.concat(url);
29-
}
30-
31-
File.call(this, 'glsl', key, url, 'text', xhrSettings);
15+
var fileConfig = {
16+
type: 'glsl',
17+
extension: 'glsl',
18+
responseType: 'text',
19+
key: key,
20+
url: url,
21+
path: path,
22+
xhrSettings: xhrSettings
23+
};
24+
25+
File.call(this, fileConfig);
3226
},
3327

3428
onProcess: function (callback)

v3/src/loader/filetypes/HTMLFile.js

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,28 +14,22 @@ var HTMLFile = new Class({
1414
{
1515
if (width === undefined) { width = 512; }
1616
if (height === undefined) { height = 512; }
17-
if (path === undefined) { path = ''; }
1817

19-
if (!key)
20-
{
21-
throw new Error('Error calling \'Loader.html\' invalid key provided.');
22-
}
23-
24-
if (!url)
25-
{
26-
url = path + key + '.html';
27-
}
28-
else
29-
{
30-
url = path.concat(url);
31-
}
32-
33-
var config = {
34-
width: width,
35-
height: height
18+
var fileConfig = {
19+
type: 'html',
20+
extension: 'html',
21+
responseType: 'text',
22+
key: key,
23+
url: url,
24+
path: path,
25+
xhrSettings: xhrSettings,
26+
config: {
27+
width: width,
28+
height: height
29+
}
3630
};
3731

38-
File.call(this, 'html', key, url, 'text', xhrSettings, config);
32+
File.call(this, fileConfig);
3933
},
4034

4135
onProcess: function (callback)

v3/src/loader/filetypes/ImageFile.js

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,18 @@ var ImageFile = new Class({
1212

1313
function ImageFile (key, url, path, xhrSettings, config)
1414
{
15-
if (path === undefined) { path = ''; }
16-
17-
if (!key)
18-
{
19-
throw new Error('Error calling \'Loader.image\' invalid key provided.');
20-
}
21-
22-
if (!url)
23-
{
24-
url = path + key + '.png';
25-
}
26-
else
27-
{
28-
url = path.concat(url);
29-
}
15+
var fileConfig = {
16+
type: 'image',
17+
extension: 'png',
18+
responseType: 'blob',
19+
key: key,
20+
url: url,
21+
path: path,
22+
xhrSettings: xhrSettings,
23+
config: config
24+
};
3025

31-
File.call(this, 'image', key, url, 'blob', xhrSettings, config);
26+
File.call(this, fileConfig);
3227
},
3328

3429
onProcess: function (callback)

v3/src/loader/filetypes/JSONFile.js

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,17 @@ var JSONFile = new Class({
1212

1313
function JSONFile (key, url, path, xhrSettings)
1414
{
15-
if (path === undefined) { path = ''; }
16-
17-
if (!key)
18-
{
19-
throw new Error('Error calling \'Loader.json\' invalid key provided.');
20-
}
21-
22-
if (!url)
23-
{
24-
url = path + key + '.json';
25-
}
26-
else
27-
{
28-
url = path.concat(url);
29-
}
30-
31-
File.call(this, 'json', key, url, 'text', xhrSettings);
15+
var fileConfig = {
16+
type: 'json',
17+
extension: 'json',
18+
responseType: 'text',
19+
key: key,
20+
url: url,
21+
path: path,
22+
xhrSettings: xhrSettings
23+
};
24+
25+
File.call(this, fileConfig);
3226
},
3327

3428
onProcess: function (callback)

v3/src/loader/filetypes/SVGFile.js

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,17 @@ var SVGFile = new Class({
1212

1313
function SVGFile (key, url, path, xhrSettings)
1414
{
15-
if (path === undefined) { path = ''; }
16-
17-
if (!key)
18-
{
19-
throw new Error('Error calling \'Loader.svg\' invalid key provided.');
20-
}
21-
22-
if (!url)
23-
{
24-
url = path + key + '.svg';
25-
}
26-
else
27-
{
28-
url = path.concat(url);
29-
}
15+
var fileConfig = {
16+
type: 'svg',
17+
extension: 'svg',
18+
responseType: 'text',
19+
key: key,
20+
url: url,
21+
path: path,
22+
xhrSettings: xhrSettings
23+
};
3024

31-
File.call(this, 'svg', key, url, 'text', xhrSettings);
25+
File.call(this, fileConfig);
3226
},
3327

3428
onProcess: function (callback)

v3/src/loader/filetypes/TextFile.js

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,17 @@ var TextFile = new Class({
1212

1313
function TextFile (key, url, path, xhrSettings)
1414
{
15-
if (path === undefined) { path = ''; }
16-
17-
if (!key)
18-
{
19-
throw new Error('Error calling \'Loader.txt\' invalid key provided.');
20-
}
21-
22-
if (!url)
23-
{
24-
url = path + key + '.txt';
25-
}
26-
else
27-
{
28-
url = path.concat(url);
29-
}
30-
31-
File.call(this, 'txt', key, url, 'text', xhrSettings);
15+
var fileConfig = {
16+
type: 'text',
17+
extension: 'txt',
18+
responseType: 'text',
19+
key: key,
20+
url: url,
21+
path: path,
22+
xhrSettings: xhrSettings
23+
};
24+
25+
File.call(this, fileConfig);
3226
},
3327

3428
onProcess: function (callback)

v3/src/loader/filetypes/XMLFile.js

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,17 @@ var XMLFile = new Class({
1313

1414
function XMLFile (key, url, path, xhrSettings)
1515
{
16-
if (path === undefined) { path = ''; }
17-
18-
if (!key)
19-
{
20-
throw new Error('Error calling \'Loader.xml\' invalid key provided.');
21-
}
22-
23-
if (!url)
24-
{
25-
url = path + key + '.xml';
26-
}
27-
else
28-
{
29-
url = path.concat(url);
30-
}
31-
32-
File.call(this, 'xml', key, url, 'text', xhrSettings);
16+
var fileConfig = {
17+
type: 'xml',
18+
extension: 'xml',
19+
responseType: 'text',
20+
key: key,
21+
url: url,
22+
path: path,
23+
xhrSettings: xhrSettings
24+
};
25+
26+
File.call(this, fileConfig);
3327
},
3428

3529
onProcess: function (callback)

0 commit comments

Comments
 (0)