forked from phaserjs/phaser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMultiFile.js
More file actions
159 lines (134 loc) · 3.61 KB
/
Copy pathMultiFile.js
File metadata and controls
159 lines (134 loc) · 3.61 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
/**
* @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 Class = require('../utils/Class');
/**
* @classdesc
* [description]
*
* @class MultiFile
* @memberOf Phaser.Loader
* @constructor
* @since 3.7.0
*
* @param {Phaser.Loader.LoaderPlugin} loader - The Loader that is going to load this File.
* @param {string} type - The file type string for sorting within the Loader.
* @param {string} key - The key of the file within the loader.
* @param {Phaser.Loader.File[]} files - An array of Files that make-up this MultiFile.
*/
var MultiFile = new Class({
initialize:
function MultiFile (loader, type, key, files)
{
/**
* A reference to the Loader that is going to load this file.
*
* @name Phaser.Loader.MultiFile#loader
* @type {Phaser.Loader.LoaderPlugin}
* @since 3.7.0
*/
this.loader = loader;
/**
* The file type string for sorting within the Loader.
*
* @name Phaser.Loader.MultiFile#type
* @type {string}
* @since 3.7.0
*/
this.type = type;
/**
* Unique cache key (unique within its file type)
*
* @name Phaser.Loader.MultiFile#key
* @type {string}
* @since 3.7.0
*/
this.key = key;
/**
* Array of files that make up this MultiFile.
*
* @name Phaser.Loader.MultiFile#files
* @type {Phaser.Loader.File[]}
* @since 3.7.0
*/
this.files = files;
/**
* The completion status of this MultiFile.
*
* @name Phaser.Loader.MultiFile#complete
* @type {boolean}
* @since 3.7.0
*/
this.complete = false;
/**
* The number of files to load.
*
* @name Phaser.Loader.MultiFile#pending
* @type {integer}
* @since 3.7.0
*/
this.pending = files.length;
/**
* The number of files that failed to load.
*
* @name Phaser.Loader.MultiFile#failed
* @type {integer}
* @default 0
* @since 3.7.0
*/
this.failed = 0;
this.config = {};
// Link the files
for (var i = 0; i < files.length; i++)
{
files[i].multiFile = this;
}
},
isReadyToProcess: function ()
{
return (this.pending === 0 && this.failed === 0 && !this.complete);
},
addToMultiFile: function (file)
{
this.files.push(file);
file.multiFile = this;
this.pending++;
this.complete = false;
return this;
},
/**
* Called by each File when it finishes loading.
*
* @method Phaser.Loader.MultiFile#onFileComplete
* @since 3.7.0
*
* @param {Phaser.Loader.File} file - The File that has completed processing.
*/
onFileComplete: function (file)
{
var index = this.files.indexOf(file);
if (index !== -1)
{
this.pending--;
}
},
/**
* Called by each File that fails to load.
*
* @method Phaser.Loader.MultiFile#onFileFailed
* @since 3.7.0
*
* @param {Phaser.Loader.File} file - The File that has failed to load.
*/
onFileFailed: function (file)
{
var index = this.files.indexOf(file);
if (index !== -1)
{
this.failed++;
}
}
});
module.exports = MultiFile;