-
Notifications
You must be signed in to change notification settings - Fork 193
/
Copy pathsrc_file_Loader.ts.html
1785 lines (1372 loc) · 55.2 KB
/
src_file_Loader.ts.html
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>src\file\Loader.ts - Kiwi.js</title>
<link rel="stylesheet" href="http://yui.yahooapis.com/3.9.1/build/cssgrids/cssgrids-min.css">
<link rel="stylesheet" href="../assets/vendor/prettify/prettify-min.css">
<link rel="stylesheet" href="../assets/css/main.css" id="site_styles">
<link rel="shortcut icon" type="image/png" href="../assets/favicon.png">
<script src="http://yui.yahooapis.com/combo?3.9.1/build/yui/yui-min.js"></script>
</head>
<body class="yui3-skin-sam">
<div id="doc">
<div id="hd" class="yui3-g header">
<div class="yui3-u-3-4">
<h1><img src="../assets/css/logo.png" title="Kiwi.js"></h1>
</div>
<div class="yui3-u-1-4 version">
<em>API Docs for: 1.4.0</em>
</div>
</div>
<div id="bd" class="yui3-g">
<div class="yui3-u-1-4">
<div id="docs-sidebar" class="sidebar apidocs">
<div id="api-list">
<h2 class="off-left">APIs</h2>
<div id="api-tabview" class="tabview">
<ul class="tabs">
<li><a href="#api-classes">Classes</a></li>
<li><a href="#api-modules">Modules</a></li>
</ul>
<div id="api-tabview-filter">
<input type="search" id="api-filter" placeholder="Type to filter APIs">
</div>
<div id="api-tabview-panel">
<ul id="api-classes" class="apis classes">
<li><a href="../classes/Kiwi.Animations.Animation.html">Kiwi.Animations.Animation</a></li>
<li><a href="../classes/Kiwi.Animations.Sequence.html">Kiwi.Animations.Sequence</a></li>
<li><a href="../classes/Kiwi.Animations.Tween.html">Kiwi.Animations.Tween</a></li>
<li><a href="../classes/Kiwi.Animations.Tweens.Easing.Back.html">Kiwi.Animations.Tweens.Easing.Back</a></li>
<li><a href="../classes/Kiwi.Animations.Tweens.Easing.Bounce.html">Kiwi.Animations.Tweens.Easing.Bounce</a></li>
<li><a href="../classes/Kiwi.Animations.Tweens.Easing.Circular.html">Kiwi.Animations.Tweens.Easing.Circular</a></li>
<li><a href="../classes/Kiwi.Animations.Tweens.Easing.Cubic.html">Kiwi.Animations.Tweens.Easing.Cubic</a></li>
<li><a href="../classes/Kiwi.Animations.Tweens.Easing.Elastic.html">Kiwi.Animations.Tweens.Easing.Elastic</a></li>
<li><a href="../classes/Kiwi.Animations.Tweens.Easing.Exponential.html">Kiwi.Animations.Tweens.Easing.Exponential</a></li>
<li><a href="../classes/Kiwi.Animations.Tweens.Easing.Linear.html">Kiwi.Animations.Tweens.Easing.Linear</a></li>
<li><a href="../classes/Kiwi.Animations.Tweens.Easing.Quadratic.html">Kiwi.Animations.Tweens.Easing.Quadratic</a></li>
<li><a href="../classes/Kiwi.Animations.Tweens.Easing.Quartic.html">Kiwi.Animations.Tweens.Easing.Quartic</a></li>
<li><a href="../classes/Kiwi.Animations.Tweens.Easing.Quintic.html">Kiwi.Animations.Tweens.Easing.Quintic</a></li>
<li><a href="../classes/Kiwi.Animations.Tweens.Easing.Sinusoidal.html">Kiwi.Animations.Tweens.Easing.Sinusoidal</a></li>
<li><a href="../classes/Kiwi.Animations.Tweens.TweenManager.html">Kiwi.Animations.Tweens.TweenManager</a></li>
<li><a href="../classes/Kiwi.Camera.html">Kiwi.Camera</a></li>
<li><a href="../classes/Kiwi.CameraManager.html">Kiwi.CameraManager</a></li>
<li><a href="../classes/Kiwi.Component.html">Kiwi.Component</a></li>
<li><a href="../classes/Kiwi.ComponentManager.html">Kiwi.ComponentManager</a></li>
<li><a href="../classes/Kiwi.Components.AnimationManager.html">Kiwi.Components.AnimationManager</a></li>
<li><a href="../classes/Kiwi.Components.ArcadePhysics.html">Kiwi.Components.ArcadePhysics</a></li>
<li><a href="../classes/Kiwi.Components.Box.html">Kiwi.Components.Box</a></li>
<li><a href="../classes/Kiwi.Components.Input.html">Kiwi.Components.Input</a></li>
<li><a href="../classes/Kiwi.Components.Sound.html">Kiwi.Components.Sound</a></li>
<li><a href="../classes/Kiwi.Entity.html">Kiwi.Entity</a></li>
<li><a href="../classes/Kiwi.Files.AudioFile.html">Kiwi.Files.AudioFile</a></li>
<li><a href="../classes/Kiwi.Files.DataFile.html">Kiwi.Files.DataFile</a></li>
<li><a href="../classes/Kiwi.Files.DataLibrary.html">Kiwi.Files.DataLibrary</a></li>
<li><a href="../classes/Kiwi.Files.File.html">Kiwi.Files.File</a></li>
<li><a href="../classes/Kiwi.Files.FileStore.html">Kiwi.Files.FileStore</a></li>
<li><a href="../classes/Kiwi.Files.Loader.html">Kiwi.Files.Loader</a></li>
<li><a href="../classes/Kiwi.Files.TextureFile.html">Kiwi.Files.TextureFile</a></li>
<li><a href="../classes/Kiwi.Game.html">Kiwi.Game</a></li>
<li><a href="../classes/Kiwi.GameManager.html">Kiwi.GameManager</a></li>
<li><a href="../classes/Kiwi.GameObjects.Sprite.html">Kiwi.GameObjects.Sprite</a></li>
<li><a href="../classes/Kiwi.GameObjects.StaticImage.html">Kiwi.GameObjects.StaticImage</a></li>
<li><a href="../classes/Kiwi.GameObjects.TextField.html">Kiwi.GameObjects.TextField</a></li>
<li><a href="../classes/Kiwi.GameObjects.Tilemap.TileMap.html">Kiwi.GameObjects.Tilemap.TileMap</a></li>
<li><a href="../classes/Kiwi.GameObjects.Tilemap.TileMapLayer.html">Kiwi.GameObjects.Tilemap.TileMapLayer</a></li>
<li><a href="../classes/Kiwi.GameObjects.Tilemap.TileMapLayerIsometric.html">Kiwi.GameObjects.Tilemap.TileMapLayerIsometric</a></li>
<li><a href="../classes/Kiwi.GameObjects.Tilemap.TileMapLayerOrthogonal.html">Kiwi.GameObjects.Tilemap.TileMapLayerOrthogonal</a></li>
<li><a href="../classes/Kiwi.GameObjects.Tilemap.TileType.html">Kiwi.GameObjects.Tilemap.TileType</a></li>
<li><a href="../classes/Kiwi.Geom.AABB.html">Kiwi.Geom.AABB</a></li>
<li><a href="../classes/Kiwi.Geom.Circle.html">Kiwi.Geom.Circle</a></li>
<li><a href="../classes/Kiwi.Geom.Intersect.html">Kiwi.Geom.Intersect</a></li>
<li><a href="../classes/Kiwi.Geom.IntersectResult.html">Kiwi.Geom.IntersectResult</a></li>
<li><a href="../classes/Kiwi.Geom.Line.html">Kiwi.Geom.Line</a></li>
<li><a href="../classes/Kiwi.Geom.Matrix.html">Kiwi.Geom.Matrix</a></li>
<li><a href="../classes/Kiwi.Geom.Point.html">Kiwi.Geom.Point</a></li>
<li><a href="../classes/Kiwi.Geom.Ray.html">Kiwi.Geom.Ray</a></li>
<li><a href="../classes/Kiwi.Geom.Rectangle.html">Kiwi.Geom.Rectangle</a></li>
<li><a href="../classes/Kiwi.Geom.Transform.html">Kiwi.Geom.Transform</a></li>
<li><a href="../classes/Kiwi.Geom.Vector2.html">Kiwi.Geom.Vector2</a></li>
<li><a href="../classes/Kiwi.Group.html">Kiwi.Group</a></li>
<li><a href="../classes/Kiwi.HUD.HUDComponents.Counter.html">Kiwi.HUD.HUDComponents.Counter</a></li>
<li><a href="../classes/Kiwi.HUD.HUDComponents.Time.html">Kiwi.HUD.HUDComponents.Time</a></li>
<li><a href="../classes/Kiwi.HUD.HUDComponents.WidgetInput.html">Kiwi.HUD.HUDComponents.WidgetInput</a></li>
<li><a href="../classes/Kiwi.HUD.HUDDisplay.html">Kiwi.HUD.HUDDisplay</a></li>
<li><a href="../classes/Kiwi.HUD.HUDManager.html">Kiwi.HUD.HUDManager</a></li>
<li><a href="../classes/Kiwi.HUD.HUDWidget.html">Kiwi.HUD.HUDWidget</a></li>
<li><a href="../classes/Kiwi.HUD.Widget.Bar.html">Kiwi.HUD.Widget.Bar</a></li>
<li><a href="../classes/Kiwi.HUD.Widget.BasicScore.html">Kiwi.HUD.Widget.BasicScore</a></li>
<li><a href="../classes/Kiwi.HUD.Widget.Button.html">Kiwi.HUD.Widget.Button</a></li>
<li><a href="../classes/Kiwi.HUD.Widget.Icon.html">Kiwi.HUD.Widget.Icon</a></li>
<li><a href="../classes/Kiwi.HUD.Widget.IconBar.html">Kiwi.HUD.Widget.IconBar</a></li>
<li><a href="../classes/Kiwi.HUD.Widget.Menu.html">Kiwi.HUD.Widget.Menu</a></li>
<li><a href="../classes/Kiwi.HUD.Widget.MenuItem.html">Kiwi.HUD.Widget.MenuItem</a></li>
<li><a href="../classes/Kiwi.HUD.Widget.TextField.html">Kiwi.HUD.Widget.TextField</a></li>
<li><a href="../classes/Kiwi.HUD.Widget.Time.html">Kiwi.HUD.Widget.Time</a></li>
<li><a href="../classes/Kiwi.IChild.html">Kiwi.IChild</a></li>
<li><a href="../classes/Kiwi.Input.Finger.html">Kiwi.Input.Finger</a></li>
<li><a href="../classes/Kiwi.Input.InputManager.html">Kiwi.Input.InputManager</a></li>
<li><a href="../classes/Kiwi.Input.Key.html">Kiwi.Input.Key</a></li>
<li><a href="../classes/Kiwi.Input.Keyboard.html">Kiwi.Input.Keyboard</a></li>
<li><a href="../classes/Kiwi.Input.Keycodes.html">Kiwi.Input.Keycodes</a></li>
<li><a href="../classes/Kiwi.Input.Mouse.html">Kiwi.Input.Mouse</a></li>
<li><a href="../classes/Kiwi.Input.MouseCursor.html">Kiwi.Input.MouseCursor</a></li>
<li><a href="../classes/Kiwi.Input.Pointer.html">Kiwi.Input.Pointer</a></li>
<li><a href="../classes/Kiwi.Input.Touch.html">Kiwi.Input.Touch</a></li>
<li><a href="../classes/Kiwi.PluginManager.html">Kiwi.PluginManager</a></li>
<li><a href="../classes/Kiwi.Renderers.CanvasRenderer.html">Kiwi.Renderers.CanvasRenderer</a></li>
<li><a href="../classes/Kiwi.Renderers.GLArrayBuffer.html">Kiwi.Renderers.GLArrayBuffer</a></li>
<li><a href="../classes/Kiwi.Renderers.GLBlendMode.html">Kiwi.Renderers.GLBlendMode</a></li>
<li><a href="../classes/Kiwi.Renderers.GLElementArrayBuffer.html">Kiwi.Renderers.GLElementArrayBuffer</a></li>
<li><a href="../classes/Kiwi.Renderers.GLRenderManager.html">Kiwi.Renderers.GLRenderManager</a></li>
<li><a href="../classes/Kiwi.Renderers.GLTextureManager.html">Kiwi.Renderers.GLTextureManager</a></li>
<li><a href="../classes/Kiwi.Renderers.GLTextureWrapper.html">Kiwi.Renderers.GLTextureWrapper</a></li>
<li><a href="../classes/Kiwi.Renderers.Renderer.html">Kiwi.Renderers.Renderer</a></li>
<li><a href="../classes/Kiwi.Renderers.TextureAtlasRenderer.html">Kiwi.Renderers.TextureAtlasRenderer</a></li>
<li><a href="../classes/Kiwi.Shaders.ShaderManager.html">Kiwi.Shaders.ShaderManager</a></li>
<li><a href="../classes/Kiwi.Shaders.ShaderPair.html">Kiwi.Shaders.ShaderPair</a></li>
<li><a href="../classes/Kiwi.Shaders.TextureAtlasShader.html">Kiwi.Shaders.TextureAtlasShader</a></li>
<li><a href="../classes/Kiwi.Signal.html">Kiwi.Signal</a></li>
<li><a href="../classes/Kiwi.SignalBinding.html">Kiwi.SignalBinding</a></li>
<li><a href="../classes/Kiwi.Sound.Audio.html">Kiwi.Sound.Audio</a></li>
<li><a href="../classes/Kiwi.Sound.AudioLibrary.html">Kiwi.Sound.AudioLibrary</a></li>
<li><a href="../classes/Kiwi.Sound.AudioManager.html">Kiwi.Sound.AudioManager</a></li>
<li><a href="../classes/Kiwi.Stage.html">Kiwi.Stage</a></li>
<li><a href="../classes/Kiwi.State.html">Kiwi.State</a></li>
<li><a href="../classes/Kiwi.StateConfig.html">Kiwi.StateConfig</a></li>
<li><a href="../classes/Kiwi.StateManager.html">Kiwi.StateManager</a></li>
<li><a href="../classes/Kiwi.System.Bootstrap.html">Kiwi.System.Bootstrap</a></li>
<li><a href="../classes/Kiwi.System.Device.html">Kiwi.System.Device</a></li>
<li><a href="../classes/Kiwi.Textures.SingleImage.html">Kiwi.Textures.SingleImage</a></li>
<li><a href="../classes/Kiwi.Textures.SpriteSheet.html">Kiwi.Textures.SpriteSheet</a></li>
<li><a href="../classes/Kiwi.Textures.TextureAtlas.html">Kiwi.Textures.TextureAtlas</a></li>
<li><a href="../classes/Kiwi.Textures.TextureLibrary.html">Kiwi.Textures.TextureLibrary</a></li>
<li><a href="../classes/Kiwi.Time.Clock.html">Kiwi.Time.Clock</a></li>
<li><a href="../classes/Kiwi.Time.ClockManager.html">Kiwi.Time.ClockManager</a></li>
<li><a href="../classes/Kiwi.Time.MasterClock.html">Kiwi.Time.MasterClock</a></li>
<li><a href="../classes/Kiwi.Time.Timer.html">Kiwi.Time.Timer</a></li>
<li><a href="../classes/Kiwi.Time.TimerEvent.html">Kiwi.Time.TimerEvent</a></li>
<li><a href="../classes/Kiwi.Utils.Canvas.html">Kiwi.Utils.Canvas</a></li>
<li><a href="../classes/Kiwi.Utils.Color.html">Kiwi.Utils.Color</a></li>
<li><a href="../classes/Kiwi.Utils.Common.html">Kiwi.Utils.Common</a></li>
<li><a href="../classes/Kiwi.Utils.GameMath.html">Kiwi.Utils.GameMath</a></li>
<li><a href="../classes/Kiwi.Utils.Log.html">Kiwi.Utils.Log</a></li>
<li><a href="../classes/Kiwi.Utils.RandomDataGenerator.html">Kiwi.Utils.RandomDataGenerator</a></li>
<li><a href="../classes/Kiwi.Utils.RequestAnimationFrame.html">Kiwi.Utils.RequestAnimationFrame</a></li>
<li><a href="../classes/Kiwi.Utils.Version.html">Kiwi.Utils.Version</a></li>
</ul>
<ul id="api-modules" class="apis modules">
<li><a href="../modules/Animations.html">Animations</a></li>
<li><a href="../modules/Components.html">Components</a></li>
<li><a href="../modules/Easing.html">Easing</a></li>
<li><a href="../modules/Files.html">Files</a></li>
<li><a href="../modules/GameObjects.html">GameObjects</a></li>
<li><a href="../modules/Geom.html">Geom</a></li>
<li><a href="../modules/HUD.html">HUD</a></li>
<li><a href="../modules/HUDComponents.html">HUDComponents</a></li>
<li><a href="../modules/Input.html">Input</a></li>
<li><a href="../modules/Kiwi.html">Kiwi</a></li>
<li><a href="../modules/Renderers.html">Renderers</a></li>
<li><a href="../modules/Shaders.html">Shaders</a></li>
<li><a href="../modules/Sound.html">Sound</a></li>
<li><a href="../modules/System.html">System</a></li>
<li><a href="../modules/Textures.html">Textures</a></li>
<li><a href="../modules/Tilemap.html">Tilemap</a></li>
<li><a href="../modules/Time.html">Time</a></li>
<li><a href="../modules/Tweens.html">Tweens</a></li>
<li><a href="../modules/Utils.html">Utils</a></li>
<li><a href="../modules/Utils..html">Utils.</a></li>
<li><a href="../modules/Widget.html">Widget</a></li>
</ul>
</div>
</div>
</div>
</div>
</div>
<div class="yui3-u-3-4">
<div id="api-options">
Show:
<label for="api-show-inherited">
<input type="checkbox" id="api-show-inherited" checked>
Inherited
</label>
<label for="api-show-protected">
<input type="checkbox" id="api-show-protected">
Protected
</label>
<label for="api-show-private">
<input type="checkbox" id="api-show-private">
Private
</label>
<label for="api-show-deprecated">
<input type="checkbox" id="api-show-deprecated">
Deprecated
</label>
</div>
<div class="apidocs">
<div id="docs-main">
<div class="content">
<h1 class="file-heading">File: src\file\Loader.ts</h1>
<div class="file">
<pre class="code prettyprint linenums">
/**
*
* @module Kiwi
* @submodule Files
*
*/
module Kiwi.Files {
/**
* Used for the loading of files and game assets. This usually happens when a State is at the 'loading' stage (executing the 'preload' method).
*
* @class Loader
* @namespace Kiwi.Files
* @constructor
* @param game {Kiwi.Game} The game that this loader belongs to.
* @return {Kiwi.Files.Loader} This Object
*
*/
export class Loader {
constructor(game: Kiwi.Game) {
this.game = game;
}
/**
* The type of object this is.
* @method objType
* @return {String} "Loader"
* @public
*/
public objType() {
return "Loader";
}
/**
* The game this loader is attached to.
* @property game
* @type Kiwi.Game
* @public
*/
public game: Kiwi.Game;
/**
* A list of files that can be loaded in parallel to one another.
* This list of files are currently being loaded.
*
* @property _loadingParallel
* @type Array
* @since 1.2.0
* @private
*/
private _loadingParallel: Kiwi.Files.File[];
/**
* List of files that cannot load in parallel to one another
* and so need to wait for previous files to load first.
* Generally files loaded via XHR.
*
* @property _loadingQueue
* @type Array
* @since 1.2.0
* @private
*/
private _loadingQueue: Kiwi.Files.File[];
/**
* List of files that are to be loaded.
* These files will be placed in the '_loadingQueue' or '_loadingParallel'
* lists when the queue is told to 'start' loading.
*
* @property _loadingList
* @type Array
* @since 1.2.0
* @private
*/
private _loadingList: Kiwi.Files.File[];
/**
* A Signal which dispatches callbacks when all files in the 'loadingList' have been loaded.
* When adding callbacks make sure to 'remove' them (or to use the 'addOnce' method)
* otherwise will fire when other sections use the loader.
*
* @method onQueueComplete
* @type Kiwi.Signal
* @since 1.2.0
* @public
*/
public onQueueComplete: Kiwi.Signal;
/**
* A Signal which dispatches callbacks each time a file in the 'loadingList' have been loaded.
* Callbacks dispatched are passed the following arguments in order.
* 1. percent - The percentage of files loaded. A number from 0 - 100
* 2. bytesLoaded - The number of bytes loaded
* 3. file - The latest file that was loaded. First call will be null.
*
* When adding callbacks make sure to 'remove' them (or to use the 'addOnce' method)
* otherwise will fire when other sections use the loader.
*
* @method onQueueProgress
* @type Kiwi.Signal
* @since 1.2.0
* @public
*/
public onQueueProgress: Kiwi.Signal;
/**
* A flag indicating if the files inside the file queue are loading or not.
*
* @property _fileQueueLoading
* @type Boolean
* @default false
* @since 1.2.0
* @private
*/
private _queueLoading: boolean = false;
/**
* READ ONLY: A flag indicating if the files inside the file queue are loading or not.
*
* @property fileQueueLoading
* @type Boolean
* @default false
* @readOnly
* @since 1.2.0
* @public
*/
public get queueLoading(): boolean {
return this._queueLoading;
}
/**
* When 'calculateBytes' is true the percentLoaded will be the `bytesLoaded / bytesTotal`.
* Otherwise it is based on the `filesLoaded / numberOfFilesToLoad`.
*
* @property percentLoaded
* @type Number
* @since 1.2.0
* @readOnly
* @public
*/
public percentLoaded: number = 0;
/**
* When enabled, files which can be loaded in parallel (those which are loaded via tags)
* will be loaded at the same time.
*
* The default behaviour is to have the files loading in a queued fashion instead of one after another.
*
* @property enableParallelLoading
* @type Boolean
* @default false
* @since 1.2.0
* @public
*/
public enableParallelLoading: boolean = false;
/**
* The boot method is executed when the DOM has successfully loaded and we can now start the game.
* @method boot
* @public
*/
public boot() {
this._loadingList = [];
this._loadingParallel = [];
this._loadingQueue = [];
this.onQueueComplete = new Kiwi.Signal();
this.onQueueProgress = new Kiwi.Signal();
}
/**
* Starts loading all the files which are in the file queue.
*
* To accurately use the bytesLoaded or bytesTotal properties you will need to set the 'calculateBytes' boolean to true.
* This may increase load times, as each file in the queue will firstly make XHR HEAD requests for information.
*
* When 'calculateBytes' is true the percentLoaded will be the `bytesLoaded / bytesTotal`.
* Otherwise it is based on the `filesLoaded / numberOfFilesToLoad`.
*
* @method start
* @param [calculateBytes] {Boolean} Setter for the 'calculateBytes' property.
* @since 1.2.0
* @public
*/
public start(calculateBytes: boolean = null) {
if (calculateBytes !== null) {
this._calculateBytes = calculateBytes;
}
if (this._queueLoading) {
Kiwi.Log.warn('Kiwi.Files.Loader: Files in the queue are already being loaded');
return;
}
//Reset the number of bytes laoded
this._bytesLoaded = 0;
this._bytesTotal = 0;
this.percentLoaded = 0;
if (this._calculateBytes) {
this.calculateQueuedSize(this._startLoading, this);
} else {
this._startLoading();
}
}
/**
* Loops through the file queue and starts the loading process.
*
* @method _startLoading
* @private
*/
private _startLoading() {
//Any files to load?
if (this._loadingList.length <= 0) {
Kiwi.Log.log('Kiwi.Files.Loader: No files are to load have been found.', '#loading');
this.onQueueProgress.dispatch(100, 0, null);
this.onQueueComplete.dispatch();
return;
}
//There are files to load
var i = 0,
file: Kiwi.Files.File;
while (i < this._loadingList.length) {
if (this._calculateBytes) {
this._loadingList[i].onProgress.add(this._updateFileListInformation, this);
}
this._sortFile(this._loadingList[i]);
this._loadingList[i].onComplete.addOnce(this._fileQueueUpdate, this);
i++;
}
this._queueLoading = true;
this._bytesLoaded = 0;
this._startLoadingQueue();
this._startLoadingAllParallel();
this._fileQueueUpdate(null, true);
}
/**
* Adds a file to the queue of files to be loaded.
* Files cannot be added whilst the queue is currently loading,
* the file to add is currently loading, or has been loaded before.
*
* @method addFileToQueue
* @param file {Kiwi.Files.File} The file to add.
* @return {Boolean} If the file was added to the queue or not.
* @since 1.2.0
* @public
*/
public addFileToQueue(file: Kiwi.Files.File) {
if (this._queueLoading) {
Kiwi.Log.warn('Kiwi.Files.Loader: File cannot be added to the queue whilst the queue is currently loading.', '#loading', '#filequeue');
return false;
}
if (file.loading || file.complete) {
Kiwi.Log.warn('Kiwi.Files.Loader: File could not be added as it is currently loading or has already loaded.', '#loading', '#filequeue');
return false;
}
this._loadingList.push(file);
return true;
}
/**
* Removes a file from the file queue.
* Files cannot be removed whilst the queue is loading.
*
* @method removeFileFromQueue
* @param file {Kiwi.Files.File} The file to remove.
* @return {Boolean} If the file was added to the queue or not.
* @since 1.2.0
* @public
*/
public removeFileFromQueue(file: Kiwi.Files.File): boolean {
if (this._queueLoading) {
Kiwi.Log.warn('Kiwi.Files.Loader: File cannot be remove from the queue whilst the queue is currently loading.', '#loading', '#filequeue');
return false;
}
var index = this._loadingList.indexOf(file);
if (index === -1) {
return false;
}
if (file.loading) {
Kiwi.Log.warn('Kiwi.Files.Loader: Cannot remove the file from the list as it is currently loading.', '#loading', '#filequeue');
return false;
}
this._loadingList.splice(index, 1);
return true;
}
/**
* Clears the file queue of all files.
*
* @method clearQueue
* @since 1.2.0
* @public
*/
public clearQueue() {
if (!this._queueLoading) {
this._loadingList.length = 0;
} else {
Kiwi.Log.error('Kiwi.Files.Loader: Cannot clear the file queue whilst the files are being loaded.', '#loading', '#filequeue');
}
}
/**
* Starts the process of loading a file outside of the regular queue loading process.
* Callbacks for load completion need to be added onto the file via 'onComplete' Signal.
*
* @method loadFile
* @public
*/
public loadFile(file: Kiwi.Files.File) {
if ( file.loading || file.complete ) {
Kiwi.Log.error('Kiwi.Files.Loader: Could not add file. File is already loading or has completed loading.');
return;
}
this._sortFile(file, true);
}
/**
* Sorts a file and places it into either the 'loadingParallel' or 'loadingQueue'
* depending on the method of loading it is using.
*
* @method _sortFile
* @param file {Kiwi.Files.File}
* @since 1.2.0
* @private
*/
private _sortFile(file: Kiwi.Files.File, startLoading: boolean = false) {
if (this.enableParallelLoading && file.loadInParallel) {
//Push into the tag loader queue
this._loadingParallel.push(file);
if (startLoading) {
this._startLoadingParallel(file);
}
} else {
//Push into the xhr queue
this._loadingQueue.push(file);
if (startLoading) {
this._startLoadingQueue();
}
}
}
/**
* The number of files in the file queue that have been updated.
*
* @property _completeFiles
* @type number
* @default 0
* @private
*/
private _completedFiles: number = 0;
/**
* Called each time a file has processed whilst loading, or has just completed loading.
*
* Calculates the new number of bytes loaded and
* the percentage of loading done by looping through all of the files.
*
* @method _updateFileListInformation
* @private
*/
private _updateFileListInformation() {
var i = 0;
this._completedFiles = 0;
this._bytesLoaded = 0;
while (i < this._loadingList.length) {
//Was the file loaded, but we have no bytes (must have used the tag loader) and we have their details?
if (this._loadingList[i].bytesLoaded === 0 && this._loadingList[i].success && this._loadingList[i].detailsReceived) {
this._bytesLoaded += this._loadingList[i].size;
} else {
//Add the bytes loaded to the list
this._bytesLoaded += this._loadingList[i].bytesLoaded;
}
//Calculate percentage
if (this._loadingList[i].complete) {
this._completedFiles++;
}
i++;
}
//Calculate the percentage depending on how accurate we can be.
if (this._calculateBytes) {
this.percentLoaded = (this._bytesLoaded / this._bytesTotal) * 100;
} else {
this.percentLoaded = (this._completedFiles / this._loadingList.length) * 100;
}
}
/**
* Executed by files when they have successfully been loaded.
* This method checks to see if the files are in the file queue, and dispatches the appropriate events.
*
* @method _fileQueueUpdate
* @param file {Kiwi.Files.File} The file which has been recently loaded.
* @param [forceProgressCheck=false] {Boolean} If the progress of file loading should be checked, regardless of the file being in the queue or not.
* @since 1.2.0
* @private
*/
private _fileQueueUpdate(file: Kiwi.Files.File, forceProgressCheck: boolean = false) {
//If the file loaded is in the loadingList
if (!forceProgressCheck && this._loadingList.indexOf(file) === -1) {
return;
}
//Update the file information.
this._updateFileListInformation();
//Dispatch progress event.
this.onQueueProgress.dispatch(this.percentLoaded, this.bytesLoaded, file);
if (this._completedFiles >= this._loadingList.length) {
//Clear the file queue and dispatch the loaded event
this._queueLoading = false;
this.clearQueue();
this.onQueueComplete.dispatch();
}
}
/**
* Starts the loading process in the loadingQueue.
* @method _startLoadingQueue
* @return {Boolean}
* @private
* @since 1.2.0
* @return {boolean} Whether the first file is loading
*/
private _startLoadingQueue(): boolean {
//Any files to load?
if (this._loadingQueue.length <= 0) {
Kiwi.Log.log('Kiwi.Files.Loader: No queued files to load.', '#loading');
return false;
}
//Is the first file currently loading?
if (this._loadingQueue[0].loading) {
return false;
}
//Attempt to load the file!
this._loadingQueue[0].onComplete.addOnce(this._queueFileComplete, this, 1);
this._loadingQueue[0].load();
return true;
}
/**
* Executed when a file in the 'loadingQueue' has been successfully loaded.
* Removes the file from the loadingQueue and executes the '_startLoadingQueue' to start loading the next file.
*
* @method _queueFileComplete
* @param file {Kiwi.Files.File}
* @since 1.2.0
* @private
*/
private _queueFileComplete(file: Kiwi.Files.File) {
//Remove from the loadingQueue
var index = this._loadingQueue.indexOf(file);
if (index === -1) {
Kiwi.Log.warn("Something has gone wrong? The file which executed this method doesn't exist in the loadingQueue.", '#loading', '#error');
return;
}
this._loadingQueue.splice(index, 1);
//Start loading the next file
this._startLoadingQueue();
}
/**
* Starts loading a file which can be loaded in parallel.
* @method _startLoadingParallel
* @param params file {Kiwi.Files.File}
* @since 1.2.0
* @private
*/
private _startLoadingParallel( file: Kiwi.Files.File) {
if (!file.loading) {
file.onComplete.add(this._parallelFileComplete, this, 1);
file.load();
}
}
/**
* Starts loading all files which can be loaded in parallel.
* @method _startLoadingAllParallel
* @since 1.2.0
* @private
*/
private _startLoadingAllParallel() {
var i = this._loadingParallel.length,
file: Kiwi.Files.File;
while( i-- ) {
this._startLoadingParallel( this._loadingParallel[ i ] );
}
}
/**
* Executed when a file in the 'loadingParallel' lsit has been successfully loaded.
* Removes the file from the list and get the fileQueue to check its progress.
*
* @method _parallelFileComplete
* @param file {Kiwi.Files.File}
* @since 1.2.0
* @private
*/
private _parallelFileComplete(file: Kiwi.Files.File) {
var index = this._loadingParallel.indexOf(file);
if (index === -1) {
Kiwi.Log.warn("Something has gone wrong? The file which executed this method doesn't exist in the loadingParallel.", '#loading', '#error');
return;
}
this._loadingParallel.splice(index, 1);
}
/**
* -----------------------------
* Bytes Loaded Methods
* -----------------------------
**/
/**
* If the number of bytes for each file should be calculated before the queue starts loading.
* If true each file in the queue makes a XHR HEAD request first to get the total values.
*
* @property _calculateBytes
* @type Boolean
* @private
*/
private _calculateBytes: boolean = false;
/**
* Callback for when the total number of bytes of the files in the file list has been calculated.
*
* @property onQueueSizeCalculate
* @type any
* @private
*/
private onSizeCallback: any;
/**
* Context that the onSizeCallback should be executed in.
*
* @property onSizeContext
* @type any
* @private
*/
private onSizeContext: any;
/**
* The index of the current file in the filelist thats size is being retrieved.
* @property _currentFileIndex
* @type number
* @private
*/
private _currentFileIndex: number = 0;
/**
* Total file size (in bytes) of all files in the queue to be loaded.
*
* @property _bytesTotal
* @type Number
* @private
*/
private _bytesTotal: number = 0;
/**
* READ ONLY: Returns the total number of bytes for the files in the file queue.
* Only contains a value if you use the 'calculateBytes' and are loading files
* OR if you use the 'calculateQueuedSize' method.