-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstudio-compiled.js
4483 lines (3972 loc) · 119 KB
/
studio-compiled.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
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
'use strict';
// These are used to enable compatablity with older browsers.
// The canvas rendering engine will even work on an original iPhone running iOS 3.1 (13 sprites / 24 fps)
//
if (!window.console) {
var console = {
log: function() {},
warn: function() {},
}
}
if ('Float32Array' in window ) {
}else{
console.log('no float32')
window.Float32Array = window.Array;
}
// From https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/keys
if (!Object.keys) {
console.warn('This browser does not support Object.keys() . Using polyfill instead.')
Object.keys = (function() {
var hasOwnProperty = Object.prototype.hasOwnProperty,
hasDontEnumBug = !({toString: null}).propertyIsEnumerable('toString'),
dontEnums = [
'toString',
'toLocaleString',
'valueOf',
'hasOwnProperty',
'isPrototypeOf',
'propertyIsEnumerable',
'constructor'
],
dontEnumsLength = dontEnums.length
return function(obj) {
if (typeof obj !== 'object' && (typeof obj !== 'function' || obj === null)) {
throw new TypeError('Object.keys called on non-object')
}
var result = [], prop, i
for (prop in obj) {
if (hasOwnProperty.call(obj, prop)) {
result.push(prop)
}
}
if (hasDontEnumBug) {
for (i = 0; i < dontEnumsLength; i++) {
if (hasOwnProperty.call(obj, dontEnums[i])) {
result.push(dontEnums[i])
}
}
}
return result
}
}())
}
if (typeof Object.create !== 'function') {
console.warn('This browser does not support Object.create() . Using polyfill instead.')
Object.create = (function() {
var Temp = function() {}
return function(prototype) {
if (arguments.length > 1) {
throw Error('Second argument not supported')
}
if (typeof prototype !== 'object') {
throw new TypeError('Argument must be an object')
}
Temp.prototype = prototype
var result = new Temp()
Temp.prototype = null
return result
}
})()
}
(function() {
var vendors = ['ms', 'moz', 'webkit', 'o']
for (var x = 0; x < vendors.length && !window.requestAnimationFrame; ++x) {
window.requestAnimationFrame = window[vendors[x] + 'RequestAnimationFrame']
window.cancelAnimationFrame = window[vendors[x] + 'CancelAnimationFrame'] || window[vendors[x] + 'CancelRequestAnimationFrame']
}
if (!window.requestAnimationFrame) {
console.warn('This browser does not support requestAnimationFrame() . Using setTimeout() instead.')
window.requestAnimationFrame = function(callback) {
var id = window.setTimeout(function() {
callback(Date.now())
}, 1000 / 60)
return id
}
}
if (!window.cancelAnimationFrame) {
window.cancelAnimationFrame = function(id) {
clearTimeout(id)
}
}
}())
// @codekit-prepend "Studio/Requirements.js"
// @codekit-append "Studio/Components/Box.js"
// @codekit-append "Studio/Components/Color.js"
// @codekit-append "Studio/Components/DisplayProperty.js"
// @codekit-append "Studio/Components/Messenger.js"
// @codekit-append "Studio/Components/LinkedList.js"
// @codekit-append "Studio/Components/Plugin.js"
// @codekit-append "Studio/Components/Image.js"
// @codekit-append "Studio/Components/Cache.js"
// @codekit-append "Studio/Components/Ease.js"
// @codekit-append "Studio/Components/Pool.js"
// @codekit-append "Studio/DisplayObjects/DisplayObject.js"
// @codekit-append "Studio/DisplayObjects/DisplayList.js"
// @codekit-append "Studio/DisplayObjects/Rect.js"
// @codekit-append "Studio/DisplayObjects/Clip.js"
// @codekit-append "Studio/DisplayObjects/CircleClip.js"
// @codekit-append "Studio/DisplayObjects/Restore.js"
// @codekit-append "Studio/DisplayObjects/Circle.js"
// @codekit-append "Studio/DisplayObjects/Sprite.js"
// @codekit-append "Studio/DisplayObjects/Camera.js"
// @codekit-append "Studio/DisplayObjects/Scene.js"
// @codekit-append "Studio/DisplayObjects/Stage.js"
// @codekit-append "Studio/DisplayObjects/TextBox.js"
// @codekit-append "Studio/DisplayObjects/Tween.js"
// @codekit-append "Studio/DisplayObjects/Pattern.js"
// @codekit-append "Studio/DisplayObjects/TileMap.js"
// @codekit-append "Studio/Effects/Standards.js"
// @codekit-append "Studio/engines/TimeStep.js"
// @codekit-append "Studio/engines/WebGL.js"
// @codekit-append "Studio/engines/Canvas.js"
// @codekit-append "Studio/Input/Keyboard.js"
// @codekit-append "Studio/Input/Touch.js"
// @codekit-append "Studio/Components/Sound.js"
// @codekit-append "Studio/Input/Gamepad.js"
// @codekit-append "Studio/DisplayObjects/DOMElement.js"
var getWebGLContextType = function(){
var canvas = document.createElement('canvas');
if(canvas.getContext('webgl')){
return 'webgl';
}
if(canvas.getContext('experimental-webgl')){
return 'experimental-webgl';
}
return false;
}
var Studio = Studio || {
stages: [],
_current_stage: null,
assets: {
length: 0
},
asset_count: 0,
queue: 0,
progress: 0,
active: true,
cap: 1000 / 20, // don't let the true frame rate go below 20fps, prevent huge frame skips
draws: 0,
loaded: true,
version: '0.5.1',
now: 0, // to get around Safari not supporting performance.now() you can pull in the timestap with this property.
delta: 0,
time: 1,
RAF: null,
browser_info: {
type: navigator.userAgent.toLowerCase(),
webGL: getWebGLContextType(),
iOS : (/iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream)
},
_temp: {}
}
Studio.updateProgress = function() {
this.progress = this.queue / this.assets.length
}
Studio._continue = function(time_stamp){
if (Studio.stages.length > 1) {
Studio.RAF = requestAnimationFrame(Studio.loopAll)
} else {
Studio._current_stage = Studio.stages[0]
Studio.RAF = requestAnimationFrame(Studio.loop)
}
}
// this function starts the entire engine. It also checks to see if it will be drawing multiple stages.
// if stages.length > 1 it will loop through all the stages, otherwise it just renders the one it has.
// by doing this check we can avoid an aditional for loop, when we don't need it.
Studio.start = function(time_stamp) {
if (Studio.queue === Studio.assets.length) {
Studio.progress = 1
}
if (time_stamp) {
Studio.now = time_stamp
Studio.time = time_stamp
Studio._continue()
} else {
Studio.RAF = requestAnimationFrame(Studio.start)
}
}
// this function renders the _current_stage.
Studio._loop = function() {
if (Studio._current_stage.active) {
Studio._current_stage.loop(Studio.delta)
}
}
Studio.loop = function(time_stamp) {
Studio.tick(time_stamp)
Studio.draws = 0
Studio._loop();
Studio.RAF = requestAnimationFrame(Studio.loop)
}
Studio.loopAll = function(time_stamp) {
Studio.tick(time_stamp)
Studio.draws = 0
for (var m = 0; m !== Studio.stages.length; m++) {
Studio._current_stage = Studio.stages[m]
Studio._loop()
}
Studio.RAF = requestAnimationFrame(Studio.loopAll)
}
Studio._tick = {
console: function(time_stamp) { // slows down, when the processor can't handle it.
this.delta = 16.6666666
this.now += this.delta
},
capped: function(time_stamp) { // never lets us skip too many frames
this.delta = time_stamp - this.now
this.now = time_stamp
this.delta = this.cap > this.delta ? this.delta : this.cap
},
uncapped: function(time_stamp) {
this.delta = time_stamp - this.now
this.now = time_stamp
}
}
Studio.tick = Studio._tick.capped
Studio._addingAsset = function() {
this.assets.length++
this.updateProgress()
}
Studio._loadedAsset = function() {
this.queue++
this.updateProgress()
this.asset_count++
}
Studio.handleVisibilityChange = function() {
if (document.hidden) {
console.log('%cStudio Paused (visibilitychange)', Studio.statStyle)
cancelAnimationFrame(Studio.RAF)
} else {
console.log('%cStudio Play (visibilitychange)', Studio.statStyle)
Studio.RAF = requestAnimationFrame(Studio._continue)
}
}
document.addEventListener('visibilitychange', Studio.handleVisibilityChange, false)
Studio.z_index = function(a, b) {
if (a.z < b.z) {
return -1
}
if (a.z > b.z) {
return 1
}
return 0
}
Studio.round = function(x) {
return x + 0.5 | 0
}
// apply(obj:Object)
// this will modify or add the current object to contain the contents of the object (obj) being passed in.
Studio.apply = function(obj) { // Display Object and a few others share this function. All children of displayObject inherit this function.
Studio._temp.keys = Object.keys(obj) // we use Studio._temp.keys to avoid creating more garbage.
Studio._temp.keys_i = Studio._temp.keys.length
while (Studio._temp.keys_i) {
if (Studio._temp.key === 'color_hex' && this['color']) {
this['color'].setFromHex(obj[Studio._temp.key])
}
Studio._temp.key = Studio._temp.keys[Studio._temp.keys_i - 1]
this[Studio._temp.key] = obj[Studio._temp.key]
Studio._temp.keys_i--
}
return this
}
// addTo()
Studio.addTo = function(a) {
for (var i = 1; i < arguments.length; i++){
var b = arguments[i]
for (var attr in b) {
if (b.hasOwnProperty(attr) && !a.hasOwnProperty(attr)) {
a[attr] = b[attr]
}
}
}
return a
}
// Studio.inherit(a,b)
// A : the New Class
// B : Class to inherit attributes from.
Studio.inherit = function(A, B, properties) {
if (properties) {
A.prototype = new B(properties)
} else {
A.prototype = new B()
}
A.prototype.constructor = A
}
Studio.windowResize = function(){
for (var m = 0; m !== Studio.stages.length; m++) {
if(Studio.stages[m].resize){
Studio.stages[m].resize();
}
}
}
window.addEventListener('resize', Studio.windowResize);
Studio.TOP = Studio.LEFT = 0
Studio.MIDDLE = Studio.CENTER = 0.5
Studio.BOTTOM = Studio.RIGHT = 1
Studio.infoStyle = 'background-color: #3af; padding: 2px 4px; color: #fff'
Studio.errorStyle = 'background-color: #c01; padding: 2px 4px;'
Studio.warningStyle = 'background-color: #fd2; padding: 2px 4px;'
Studio.statStyle = 'background-color: #eee; padding: 2px 4px; color: #555; font-size: 10px'
Studio.engineStyle = 'background-color: #eee; color: #3af; padding: 1px 4px; border: 1px solid #3af'
Studio.Point = function(x,y){
this.x = x || 0
this.y = y || 0
this.temp = 0
return this
}
Studio.Point.prototype = {
constructor: Studio.Point,
translate : function(x,y){
this.x += x
this.y += y
},
scale : function(x,y){
this.x *= x
this.y *= y
},
rotate : function(sin,cos){
this.temp = (this.x * cos) - (this.y * sin)
this.y = (this.x * sin) + (this.y * cos)
this.x = this.temp;
},
set : function(x,y){
this.x = x
this.y = y
}
}
Studio.Box = function(left, top, width, height) {
this.TL = new Studio.Point(left, top)
this.TR = new Studio.Point(left + width, top)
this.BR = new Studio.Point(left, top + height)
this.BL = new Studio.Point(left + width, top + height)
this.left = 0
this.right = 0
this.top = 0
this.bottom = 0
this.sin = 0
this.cos = 0
return this
}
Studio.Box.prototype = {
constructor: Studio.Box,
set: function(left, top, width, height) {
this.TL.set(left, top)
this.TR.set(left + width, top)
this.BL.set(left, top + height)
this.BR.set(left + width, top)
},
get_bounds: function(who) {
if (who._world.rotation) {
if(who.skews){
this.get_rotated_bounds_w_skew(who)
}else{
this.get_rotated_bounds(who)
}
} else {
this.get_straight_bounds(who)
}
},
get_straight_bounds: function(who) {
this.TL.set(who._dx - who._world.width * who.anchorX, who._dy - who._world.height * who.anchorY)
this.TR.set(this.TL.x + who._world.width, this.TL.y)
this.BR.set(this.TR.x, this.TR.y + who._world.height)
this.BL.set(this.TL.x, this.BR.y)
},
_shift : function(x,y){
this.TL.translate(x,y)
this.TR.translate(x,y)
this.BR.translate(x,y)
this.BL.translate(x,y)
},
_scale : function(x,y){
this.TL.scale(x,y)
this.TR.scale(x,y)
this.BR.scale(x,y)
this.BL.scale(x,y)
},
_set_orbit_xy : function(sin,cos){
this.TL.x = ((this.left * cos) - (this.top * sin))
this.TL.y = ((this.left * sin) + (this.top * cos))
this.TR.x = ((this.right * cos) - (this.top * sin))
this.TR.y = ((this.right * sin) + (this.top * cos))
this.BR.x = ((this.right * cos) - (this.bottom * sin))
this.BR.y = ((this.right * sin) + (this.bottom * cos))
this.BL.x = ((this.left * cos) - (this.bottom * sin))
this.BL.y = ((this.left * sin) + (this.bottom * cos))
},
_set_bounds : function( a, b , width, height){
this.left = -a
this.right = this.left + width
this.top = -b
this.bottom = this.top + height
},
get_rotated_bounds_w_skew: function(who) {
this.sin = Math.sin(who._dAngle)
this.cos = Math.cos(who._dAngle)
this._set_bounds(who.width * who.anchorX, who.height * who.anchorY, who.width, who.height)
this._set_orbit_xy(this.sin,this.cos);
this._scale(who._world.scaleX,who._world.scaleY)
this._shift(who._dx, who._dy)
},
get_rotated_bounds: function(who) {
this.sin = Math.sin(who._dAngle)
this.cos = Math.cos(who._dAngle)
this._set_bounds(who._world.width * who.anchorX, who._world.height * who.anchorY, who._world.width, who._world.height)
this._set_orbit_xy(this.sin,this.cos);
this._shift(who._dx, who._dy)
},
}
Studio.RECT_BOX = new Studio.Box(10,0,0,0);
Studio.Color = function(r, g, b, a) {
this.r = r / 255 || 0
this.g = g / 255 || 0
this.b = b / 255 || 0
this.a = a || 1
this.style = 'rgba(255,255,255,1)'
this._build_style()
return this
}
Studio.Color.prototype = {
constructor: Studio.Color,
set: function(r, g, b, a) {
this.r = r / 255
this.g = g / 255
this.b = b / 255
this.a = a
this._build_style()
return this
},
red: function(v) {
this.r = v
return this
},
green: function(v) {
this.g = v
return this
},
blue: function(v) {
this.b = v
return this
},
alpha: function(v) {
this.a = v
return this
},
build: function() {
this._build_style()
return this
},
setFromHex: function(hex) {
if (!hex) return
// if the hex value comes in as shorthand '#333', we should double the values.
if (hex.length === 4) {
hex = hex[0] + hex[1] + hex[1] + hex[2] + hex[2] + hex[3] + hex[3] + 'ff'
}
// if the hex doesn't contain an alpha value lets assume its 'ff'.
if (hex.length === 7) {
hex += 'ff'
}
// take each value besides [0] an convert it to RGBA since that works for both Canvas and WebGL
this.set('0x' + hex[1] + hex[2] | 0, '0x' + hex[3] + hex[4] | 0, '0x' + hex[5] + hex[6] | 0, ('0x' + hex[7] + hex[8] | 0) / 255)
return this
},
_build_style: function() {
this.style = 'rgba(' + parseInt(this.r * 255) + ',' + parseInt(this.g * 255) + ',' + parseInt(this.b * 255) + ',' + this.a + ')'
},
dirty: false
}
Studio.RED = new Studio.Color(204, 0, 17, 1)
Studio.ORANGE = new Studio.Color(255, 150, 0)
Studio.YELLOW = new Studio.Color(255, 221, 34, 1)
Studio.GREEN = new Studio.Color(0, 200, 0, 1)
Studio.BLUE = new Studio.Color(51, 170, 255, 1)
Studio.PURPLE = new Studio.Color(128, 0, 255, 1)
Studio.WHITE = new Studio.Color(255, 255, 255, 1)
Studio.BLACK = new Studio.Color(0, 0, 0, 1)
Studio.TRANSPARENT = Studio.TRANS = new Studio.Color(0, 0, 0, 0)
/**
* DisplayProperty
*/
Studio.DisplayProperty = function() {
this.x = 0
this.y = 0
this.z = 0
this.height = 1
this.width = 1
this.scaleX = 1
this.scaleY = 1
this.rotation = 0
this.angle = 0
this.alpha = 1
this.speed = 1
}
Studio.DisplayProperty.prototype = {
constructor: Studio.DisplayProperty,
apply: Studio.apply
}
Studio.Messenger = function() {
this.listeners = {}
this.message = 0
}
Studio.Messenger.constructor = Studio.Messenger;
Studio.Messenger.prototype.addListener = function(type,callback) {
if(!this.listeners[type]){
this.listeners[type]=[];
}
this.listeners[type].push({callback: callback})
}
Studio.Messenger.prototype.addListenerTo = function(type,callback, who) {
if(!this.listeners[type]){
this.listeners[type]=[];
}
this.listeners[type].push({callback: callback,who: who})
}
Studio.Messenger.prototype.sendMessage = function(type, message) {
this.message = message
// now lets tell everyone that listens.
var who = null
if(!this.listeners[type]){
return
}
for (var i = 0; i < this.listeners[type].length; i++) {
who = this.listeners[type][i].who
if (who) {
who[this.listeners[type][i].callback].call(who,this.message,type)
} else {
this.listeners[type][i].callback(this.message,type)
}
}
}
var LinkedList = function() {
this.first = null
this.last = null
this.length = 0
}
LinkedList.prototype = {
add: function(who) {
// who._parent = this._parent;
this.length++ // add to our length so we can easily tell how big our list is.
if (this.length <= 1 && this.first === null && this.last === null) {
this.first = who
this.last = who
who.prev = null
this.length = 1
return who
}
// this.first.prev = who;
this.last.next = who // we add the new item to the previously last item.
who.prev = this.last // we mark the new items previous to be the last item in the list.
this.last = who // we have a new last item now.
return who
},
addItems: function(who) {
for (var i = 0; i !== arguments.length; i++) {
this.add(arguments[i])
}
},
insert: function(a, b) {
this.length++
a.prev = b
if (b !== this.last) {
b.next = a
} else {
this.last = a
a.next = this.first
}
},
init: function() {
this.next = null
this.prev = null
this.first = null
this.last = null
this.length = 0
},
remove: function(who) {
if (this.length === 1) {
this.init()
who.next = null
who.prev = null
return // nothing to see here lets move on.
}
// check for the begining or the end of the list
if (this.first === who) {
this.first = this.first.next
} else if (this.last === who) {
this.last = this.last.prev
}
// debugger;
if (who.prev) {
who.prev.next = who.next
}
if (who.next) {
who.next.prev = who.prev
}
who.next = null
who.prev = null
if (this.first === null) {
this.last = null
}
this.length--
},
update: function(r, d) {
var listItem = this.first
while (listItem) {
// while we still have a list item lets do some fun stuff.
this.next = listItem.next
// we need to hold on to the next in line.
// WHY: I've been known to delete an object in the list
// thus causing listItem.next to return null.
// By saving this reference we can always continue on
// through the list.
listItem.update(r, d)
// lets perform the objects update function.
listItem = listItem.next || this.next
// if the item has a next lets use it. otherwise lets use the one we saved
// just for this occassion. If both are null thats fine to.
// we really are at the end of the list.
}
},
render: function(e, f) {
var listItem = this.first
while (listItem) {
this.next = listItem.next
listItem._delta(f)
listItem.render(e, f)
listItem = listItem.next || this.next
}
},
action: function(what) {
var listItem = this.first
while (listItem) {
this.next = listItem.next
listItem[what]()
listItem = listItem.next || this.next
}
},
removeAll: function(exception) {
var listItem = this.first
while (listItem) {
this.next = listItem.next
if (this.pdispose) {
this.pdispose()
}
this.remove(listItem)
listItem = listItem.next || this.next
}
listItem = null
if (exception) {
this.add(exception)
}
},
toString: function() {
var listItem = this.first
var toString = 'linked list : ['
while (listItem) {
toString += listItem
listItem = listItem.next
}
toString += '];'
},
constructor: LinkedList
}
Studio.Plugin = function(attr) {
this.init = null
this.options = {}
this.action = null
this.apply(attr)
}
Studio.Plugin.constructor = Studio.Plugin
Studio.Plugin.prototype.apply = Studio.apply
Studio.Plugin.prototype._options = function(a) {
for (var i in a) {
this.options[i] = a[i]
}
}
Studio.Image = function studio_image(path, slices) {
this.path = path + '_'+ parseInt(Math.random()*100000).toString(16)
this.bitmap = null
this.width = 1
this.height = 1
this.slice = {
'Full': {
x: 0,
y: 0,
width: 1,
height: 1
}
}
this.sliceGL = {}
// this.status = new Studio.Messenger()
if (slices) {
this.addSlice(slices)
}
if (path) {
this.loadImage(path)
}
return this
}
Studio.inherit(Studio.Image,Studio.Messenger)
Studio.Image.prototype.ready = false
Studio.Image.prototype.height = 1
Studio.Image.prototype.width = 1
Studio.Image.prototype._onImageLoad = function image_onload(image) { // could have Event passed in
Studio.progress = Studio.queue / Studio.assets.length
Studio._loadedAsset();
this._setWidthHeights(image)
return image
}
Studio.Image.prototype._setWidthHeights = function(image){
this.slice['Full'].height = image.height
this.slice['Full'].width = image.width
this.width = image.width
this.height = image.height
this.addSlice(this.slice)
this.ready = true
this.sendMessage('ready',this.ready)
}
Studio.Image.prototype.loadImage = function studio_image_loadImage(who) {
var image = this;
if (Studio.assets[who]) {
console.warn('Already loaded : ', who, Studio.assets[who])
this.bitmap = Studio.assets[who]
if(Studio.assets.width){
this.ready = true
this.sendMessage('ready',this.ready)
}else{
Studio.assets[who].addEventListener("load", function(e){
image._setWidthHeights(e.target)
} )
}
return this
} else {
Studio.assets[who] = new Image()
Studio._addingAsset();
Studio.assets[who].addEventListener("load", function(e){
image._onImageLoad(e.target)
} )
Studio.assets[who].src = who
this.bitmap = Studio.assets[who]
}
}
Studio.Image.prototype.buildSliceForGL = function studio_buildSliceForGL(slice) {
var x = slice.x / this.width
var y = slice.y / this.height
return {
x: x,
y: y,
width: slice.width / this.width + x,
height: slice.height / this.height + y
}
}
Studio.Image.prototype.addSlice = function studio_image_addSlice(slices) {
for (var i in slices) {
this.slice[i] = slices[i]
this.sliceGL[i] = this.buildSliceForGL(slices[i])
}
}
Studio.Image.prototype._rebuildGLSlices = function(){
for (var i in this.slice) {
this.sliceGL[i] = this.buildSliceForGL(this.slice[i])
}
}
Studio.Cache = function(width, height, resolution) {
this.resolution = resolution || 1
this.path = 'cache_' + parseInt(Math.random()*100000).toString(16)
this.bitmap = document.createElement('canvas')
this.bitmap.width = width * this.resolution || 512
this.bitmap.height = height * this.resolution || 512
this.width = width
this.height = height
this.ready = false
this.ctx = this.bitmap.getContext('2d')
this.ctx.scale(resolution, resolution)
this.slice.Full = {x: 0,y: 0,width: this.bitmap.width,height: this.bitmap.height}
this.sliceGL.Full = {x:0,y:0,width:1, height: 1}
if(Studio.DEBUG){
document.body.appendChild(this.bitmap)
}
}
Studio.inherit(Studio.Cache, Studio.Image)
Studio.Cache.prototype.applyEffect = function(effect){
effect.action(this)
}
Studio.Ease = {}
Studio.Ease.linear = function(t) {
return t
}
Studio.Ease.snap = function(t) {
return t + 0.5 | 0
}
Studio.Ease.chillInOut = function(t) {
var s = 0.75
if ((t *= 2) < 1) {
return 0.5 * (t * t * ((s + 1) * t - s))
}
return 0.5 * ((t -= 2) * t * ((s + 1) * t + s) + 2)
}
Studio.Ease.backOut = function(t) {
var s = 1.70158
return --t * t * ((s + 1) * t + s) + 1
}
Studio.Ease.bounceOut = function(t) {
if (t < (0.363636)) {
return 7.5625 * t * t
} else if (t < 0.727272) {
return 7.5625 * (t -= (0.545454)) * t + 0.75
} else if (t < 0.909090) {
return 7.5625 * (t -= (0.818181)) * t + 0.9375
} else {
return 7.5625 * (t -= (0.959595)) * t + 0.984375
}
}
Studio.Ease.elasticOut = function(t) {
var s, a = 0.1, p = 0.4
if (t === 0) {
return 0
}
if (t === 1) {
return 1
}
if (!a || a < 1) {
a = 1; s = p / 4
} else {
s = p * Math.asin(1 / a) / (6.283)
}
return (a * Math.pow(2, -10 * t) * Math.sin((t - s) * (6.283) / p) + 1)
}
Studio.Ease.linearRandom = function(t) {
return Math.random() * t
}
Studio.Ease.random = function() {
return Math.random()
}
Studio.Ease.shake = function() {
return Math.random() - .5
}
Studio.Ease.quadIn = function(t) {
return t * t
}
Studio.Ease.quadOut = function(t) {
return t * (2 - t)
}
Studio.Ease.quadInOut = function(t) {
if ((t *= 2) < 1) {
return 0.5 * t * t
}
return -0.5 * (--t * (t - 2) - 1)
}
// A really simply pooling stystem.
// Opt-in
// to create a pool run: Studio.createPool (Object_Type, Initial_Size )
// to retreive from the pool run: Object_Type.fromPool()
// which will return an Object_Type from the pool if one is avalible, otherwise it will create a new one, and increase the size of the pool
// to send an item back into the pool. Just run .intoPool on the object. It will put it back into the Object_Type's pool.
//
// the pool and poolSize are private variables, however you can get access to the pool with a couple helper functions.
// Object_Type.getPoolCapacity() will return the .length of the pool array.
// Object_Type.getPool() will return the pool array itself, helpful for debugging.
// Object_Type.isPoolEmpty() will return true is the poolSize === 0. This can be helpful if you want to limit size of the pool.
//
// if(!Object_Type.isPoolEmpty){
// ... pull from the pool ...
// }else{
// ... lets leave the pool alone ...
// }