Skip to content

Commit 727383d

Browse files
committed
Loader.MultiFile will now parse the given files array and only add valid entries into the file list, allowing multifiles to now have optional file entries.
1 parent 5bb73b5 commit 727383d

1 file changed

Lines changed: 16 additions & 5 deletions

File tree

src/loader/MultiFile.js

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ var Class = require('../utils/Class');
1010
* @classdesc
1111
* A MultiFile is a special kind of parent that contains two, or more, Files as children and looks after
1212
* the loading and processing of them all. It is commonly extended and used as a base class for file types such as AtlasJSON or BitmapFont.
13-
*
13+
*
1414
* You shouldn't create an instance of a MultiFile directly, but should extend it with your own class, setting a custom type and processing methods.
1515
*
1616
* @class MultiFile
@@ -29,6 +29,17 @@ var MultiFile = new Class({
2929

3030
function MultiFile (loader, type, key, files)
3131
{
32+
var finalFiles = [];
33+
34+
// Clean out any potential 'null' or 'undefined' file entries
35+
files.forEach(function (file)
36+
{
37+
if (file)
38+
{
39+
finalFiles.push(file);
40+
}
41+
});
42+
3243
/**
3344
* A reference to the Loader that is going to load this file.
3445
*
@@ -73,7 +84,7 @@ var MultiFile = new Class({
7384
* @type {Phaser.Loader.File[]}
7485
* @since 3.7.0
7586
*/
76-
this.files = files;
87+
this.files = finalFiles;
7788

7889
/**
7990
* The completion status of this MultiFile.
@@ -93,7 +104,7 @@ var MultiFile = new Class({
93104
* @since 3.7.0
94105
*/
95106

96-
this.pending = files.length;
107+
this.pending = finalFiles.length;
97108

98109
/**
99110
* The number of files that failed to load.
@@ -145,9 +156,9 @@ var MultiFile = new Class({
145156
this.prefix = loader.prefix;
146157

147158
// Link the files
148-
for (var i = 0; i < files.length; i++)
159+
for (var i = 0; i < finalFiles.length; i++)
149160
{
150-
files[i].multiFile = this;
161+
finalFiles[i].multiFile = this;
151162
}
152163
},
153164

0 commit comments

Comments
 (0)