-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
ProgressWatcher.js
41 lines (35 loc) · 1.11 KB
/
ProgressWatcher.js
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
function ProgressWatcher(){
throw new Error('This is a static class');
}
ProgressWatcher.initialize = function(){
this.clearProgress();
ImageManager.setCreationHook(this._bitmapListener.bind(this));
AudioManager.setCreationHook(this._audioListener.bind(this));
};
ProgressWatcher._bitmapListener = function(bitmap){
this._countLoading++;
bitmap.addLoadListener(function(){
this._countLoaded++;
this._progressListener(this._countLoaded, this._countLoading);
}.bind(this));
};
ProgressWatcher._audioListener = function(audio){
this._countLoading++;
audio.addLoadListener(function(){
this._countLoaded++;
this._progressListener(this._countLoaded, this._countLoading);
}.bind(this));
};
ProgressWatcher.setProgressListener = function(progressListener){
this._progressListener = progressListener;
};
ProgressWatcher.clearProgress = function(){
this._countLoading = 0;
this._countLoaded = 0;
};
ProgressWatcher.truncateProgress = function(){
if(this._countLoaded){
this._countLoading -= this._countLoaded;
this._countLoaded = 0;
}
};