/
myApp.js
1443 lines (1125 loc) · 42.9 KB
/
myApp.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
/*
Z order
0 bg_node背景色の四角形
2 bg_sprite
4 グリッド
4 emitter
5 guideRect
6 fg_sprte
7 prev_screen(drawnode)
8 prev_emitter
*/
var clog=function(str) {
// console.log(str)
};
var plist_changed=0;
var guideC=[];
var emit_timer=[];
var emit_timer_switch=[];
var isAllActive;
var current_reso={};
var current_reso_scale=0.5;
var guiderect=[];
var snap=[];
var json_corona=null;
var xml=null;
var xmls=[];
var dn=0;
var bg_sprite;
var fg_sprite;
var texture1;
var prev_dn; // drawnode rect for Preview Mask
var prev_string;
var current_start_color;
var current_end_color;
var MyLayer = cc.Layer.extend({
init:function () {
this._super();
var size = cc.Director.getInstance().getWinSize();
setCSize(resos['iPhone6/6s'],current_reso_scale);//canvas size初期値
setGrid($('#grid').val());
this.scheduleUpdate();
this.setTouchEnabled(true);
this.setKeyboardEnabled(true);
//Mask for preview
prev_dn = cc.DrawNode.create();
prev_dn.drawPoly([cc.p(0,0),cc.p(s_size.width,0),cc.p(s_size.width,s_size.height),cc.p(0,s_size.height)] ,
cc.c4f(0,0,0, 0.8 ), 0, cc.c4f(0,0,0, 1 ));
layers=cc.Director.getInstance().getRunningScene().getChildren();
layers[0].addChild(prev_dn,10);
prev_dn.setVisible(false);
prev_string = cc.LabelTTF.create("Preview", "Arial", 40);//フォント、大きさ
layers[0].addChild(prev_string, 12);//画面に追加
prev_string.setPosition(cc.p( 80 , s_size.height - 30 ));//位置
prev_string.setVisible(false);
//デフォルトエミッタを作成;
getPlist("meteor_me3.plist");
togglePane('template');//初期表示panel
},
//focusをcocosのcanvasの外に
onKeyUp:function(keycode) {
clog("onKeyUp:"+keycode);
$('#duration').focus();
//keyShortCut(keycode);
},
onKeyDown:function(keycode) { clog("onKeyDown:"+keycode); },
onMouseUp:function(e){
alert(1);
},
update:function(dt){
if (emitter.length==0) { return false; }
//selected emitter active check
if (emitter[p2dx.slot_current].isActive()) {
$('#isActive').html("true");
$('#isActive').css("color","white");
}else {
$('#isActive').html("false");
$('#isActive').css("color","red");
}
//plist [update] sign
time= parseInt((new Date)/1);
if (time - plist_changed <= 200){
$("#plist_changed").html("<span style='color:red;'>update</span>");
}else{
$("#plist_changed").html("<span style='color:gray;'>update</span>");
}
//count emitter-life and loop
isAllActive=true;
for (ind in emitter){
if (emitter[ind].getDuration()!=-1){
//count up
if (emit_timer_switch[ind]==1){
emit_timer[ind]+=dt;
// timer start if inactive
} else if (!emitter[ind].isActive()){
emit_timer_switch[ind]=1;
emit_timer[ind]=0;
}
//reset emitter if inactive and
if (emit_timer[ind]> emitter[ind].getDuration()+ emitter[ind].getLife() + 0.5){
emitter[ind].resetSystem();
emit_timer_switch[ind]=0;
emit_timer[ind]=0;
}
}
}
},
onTouchesBegan:function(touch,event){
clog("began");
var loc = touch[0].getLocation();
if (p2dx.slot_bg != 0) {
moveBGImage( p2dx.slot_bg ,loc);
return;
}
if (touch.length==0) { return false; }//タッチしてなければ戻る(canvas外タッチでも来るので)
if (emitter.length==0) { return false; }
emitter[p2dx.slot_current].setPosition(loc);
if (!emitter[p2dx.slot_current].isActive()) {emitter[p2dx.slot_current].resetSystem();}
$("#emitter_posi").html(parseInt(loc.x)+" "+parseInt(loc.y));
guiderect[p2dx.slot_current].setVisible(true);
},
onTouchesMoved:function(touch,event){
clog("onTouchesMoved");
var loc = touch[0].getLocation();
if ( p2dx.slot_bg != 0) {
moveBGImage( p2dx.slot_bg , loc );
return;
}
if (touch.length==0) { return false; } //タッチしてなければ戻る(canvas外タッチでも来るので)
if (emitter.length==0) { return false; }
emitter[p2dx.slot_current].setPosition(loc);
$("#emitter_posi").html(parseInt(loc.x)+" "+parseInt(loc.y));
},
onTouchesEnded:function(touch,event){
clog("onTouchesEnded");
var loc = touch[0].getLocation();
if ( p2dx.slot_bg !=0) {
moveBGImage(p2dx.slot_bg,loc);
return;
}
if (touch.length==0) { return false; } //タッチしてなければ戻る(canvas外タッチでも来るので)
if (emitter.length==0) { return false; }
emitter[p2dx.slot_current].setPosition(loc);
$('#emitter_posi').html(parseInt(loc.x)+" "+parseInt(loc.y));
guiderect[p2dx.slot_current].setVisible(false);
dumpToInputTag(p2dx.slot_current);
}
});
var MyScene = cc.Scene.extend({
onEnter:function () {
this._super();
var layer = new MyLayer();
this.addChild(layer);
layer.init();
}
});
function round1(val1){
return parseInt(val1*10)/10;
}
function round2(val1){
return parseInt(val1*100)/100;
}
function setBGSlot(p_num){
clog("setBGSlot:"+p_num);
p2dx.slot_bg = p_num;
p2dx.slot_current=0;
dumpToInputTag(p_num);
}
function moveBGImage(p_slot_bg,posi){
clog("moveBGImage");
if (p_slot_bg == -1){
bg_sprite.setPosition(posi);
}
if (p_slot_bg == -2){
fg_sprite.setPosition(posi);
}
}
function setGrid(interval_px){
clog("setGrid" + interval_px);
s_size=cc.Director.getInstance().getWinSize();
gridwidth=1;
if (s_size.width >= 640) gridwidth=2;
if (s_size.width >= 1000) gridwidth=3;
if (dn){
dn.removeFromParent();
dn=null;
delete dn;
}
clog("gridwidth:"+gridwidth);
dn=cc.DrawNode.create();
//yoko
for (i=1 ;i<=Math.floor(s_size.height / interval_px);i=i+1){
dn.drawSegment(cc.p(0,s_size.height - i*interval_px ), cc.p(s_size.width,s_size.height - i*interval_px ),gridwidth, cc.c4f(0.5,0.5,0.5, 0.5 ) );
}
//tate
for (i=1 ;i<=Math.floor(s_size.width / interval_px);i=i+1){
dn.drawSegment(cc.p(i*interval_px ,0), cc.p(i*interval_px ,s_size.height),gridwidth, cc.c4f(0.5,0.5,0.5, 0.5 ) );
}
layers=cc.Director.getInstance().getRunningScene().getChildren();
layers[0].addChild(dn,3);
}
function dumpToInputTag(p_slot){
clog("dumpToInputTag slot:"+p_slot);
refreshSlot();
//slotなければreturn
if (emitter.length==0) { return false; }
if (!p_slot) { p_slot = p2dx.slot_current;}
$('#angle').val(parseInt(emitter[p_slot].getAngle()));
$('#angle_text').val(parseInt(emitter[p_slot].getAngle()));
$('#angle_var').val(parseInt(emitter[p_slot].getAngleVar()));
$('#angle_var_text').val(parseInt(emitter[p_slot].getAngleVar()));
$('#angle_disp').html(emitter[p_slot].getAngle()+"±"+emitter[p_slot].getAngleVar());
$('#duration').val(emitter[p_slot].getDuration());
$('#duration_text').val(emitter[p_slot].getDuration());
$('#duration_disp').html(emitter[p_slot].getDuration());
$("#duration_forever_disp").html(" ");
if (emitter[p_slot].getDuration()==-1){
$("#duration_forever_disp").html("<span style='color:red;' >forever</span>");
}
$('#life').val(emitter[p_slot].getLife());
$('#life_text').val(emitter[p_slot].getLife());
$('#lifeVar').val(emitter[p_slot].getLifeVar());
$('#lifeVar_text').val(emitter[p_slot].getLifeVar());
$('#life_disp').html(emitter[p_slot].getLife()+"±"+emitter[p_slot].getLifeVar());
//start
start_col=emitter[p_slot].getStartColor(); //c4f var.r var.g var.b var.a
$('#start_a').val(round2(start_col.a));
$('#start_r').val(round2(start_col.r));
$('#start_g').val(round2(start_col.g));
$('#start_b').val(round2(start_col.b));
$("#start_color").css("background-color","rgba("+start_col.r*100+"%, "+start_col.g*100+"%, "+start_col.b*100+"%, "+round2(start_col.a)+")");
$("#start_color").html($("#start_color").css("background-color"));
start_col_var=emitter[p_slot].getStartColorVar(); //c4f type var.r var.g var.b var.a
$('#start_a_var').val(start_col_var.a);
$('#start_r_var').val(start_col_var.r);
$('#start_g_var').val(start_col_var.g);
$('#start_b_var').val(start_col_var.b);
$('#start_a_disp').html(round2(start_col.a)+"±" + round2(start_col_var.a));
$('#start_r_disp').html(round2(start_col.r)+"±" + round2(start_col_var.r));
$('#start_g_disp').html(round2(start_col.g)+"±" + round2(start_col_var.g));
$('#start_b_disp').html(round2(start_col.b)+"±" + round2(start_col_var.b));
$('#start_size_pic').attr('width',emitter[p_slot].getStartSize());
$('#start_size_pic').attr('height',emitter[p_slot].getStartSize());
$('#start_size_disp').html(parseInt(emitter[p_slot].getStartSize())+"±"+parseInt(emitter[p_slot].getStartSizeVar()));
$('#startSize').val(emitter[p_slot].getStartSize());
$('#startSizeVar').val(emitter[p_slot].getStartSizeVar());
$('#startSpin').val(emitter[p_slot].getStartSpin());
$('#startSpinVar').val(emitter[p_slot].getStartSpinVar());
$('#start_spin_disp').html(emitter[p_slot].getStartSpin()+"±"+emitter[p_slot].getStartSpinVar());
end_col=emitter[p_slot].getEndColor();
$('#end_a').val(end_col.a);
$('#end_r').val(end_col.r);
$('#end_g').val(end_col.g);
$('#end_b').val(end_col.b);
$("#end_color").css("background-color","rgba("+end_col.r*100+"%, "+end_col.g*100+"%, "+end_col.b*100+"%, "+round2(end_col.a)+")");
$("#end_color").html($("#end_color").css("background-color"));
end_col_var=emitter[p_slot].getEndColorVar(); //c4f type var.r var.g var.b var.a
$('#end_a_var').val(end_col_var.a);
$('#end_r_var').val(end_col_var.r);
$('#end_g_var').val(end_col_var.g);
$('#end_b_var').val(end_col_var.b);
$('#end_a_disp').html(round2(end_col.a)+"±" + round2(end_col_var.a));
$('#end_r_disp').html(round2(end_col.r)+"±" + round2(end_col_var.r));
$('#end_g_disp').html(round2(end_col.g)+"±" + round2(end_col_var.g));
$('#end_b_disp').html(round2(end_col.b)+"±" + round2(end_col_var.b));
$('#end_size_disp').html(parseInt(emitter[p_slot].getEndSize())+"±"+parseInt(emitter[p_slot].getEndSizeVar()));
$('#endSize').val(emitter[p_slot].getEndSize());
$('#endSizeVar').val(emitter[p_slot].getEndSizeVar());
$('#endSpin').val(emitter[p_slot].getEndSpin());
$('#endSpin_var').val(emitter[p_slot].getEndSpinVar());
$('#end_spin_disp').html(emitter[p_slot].getEndSpin()+"±"+emitter[p_slot].getEndSpinVar());
//gravity
pos=emitter[p_slot].getPosition();
posvar=emitter[p_slot].getPosVar();
//$('#posx').val(pos.x);
//$('#posy').val(pos.y);
//$('#posx_var').val(posvar.x);
//$('#posy_var').val(posvar.y);
$('#pos_var_x').val(posvar.x);
$('#pos_var_x_text').val(posvar.x);
$('#pos_var_y').val(posvar.y);
$('#pos_var_y_text').val(posvar.y);
$('#pos_var_disp').html(parseInt(posvar.x)+"x"+parseInt(posvar.y));
if (emitter[p_slot].getEmitterMode()==cc.PARTICLE_MODE_GRAVITY){
$('#disp_angle').html(parseInt(emitter[p_slot].getAngle()));
$('#disp_speed').html(parseInt(emitter[p_slot].getSpeed()));
$('#speed').val(parseInt(emitter[p_slot].getSpeed()));
$('#speed_text').val(parseInt(emitter[p_slot].getSpeed()));
$('#speedVar').val(parseInt(emitter[p_slot].getSpeedVar()));
$('#speedVar_text').val(parseInt(emitter[p_slot].getSpeedVar()));
$('#speedVar_disp').html(emitter[p_slot].getSpeed()+"±"+emitter[p_slot].getSpeedVar());
grv=emitter[p_slot].getGravity();
//$('#grav_x').val(grv.x);
//$('#grav_y').val(grv.y);
$('#gravity_x').val(grv.x);
$('#gravity_x_text').val(grv.x);
$('#gravity_y').val(grv.y);
$('#gravity_y_text').val(grv.y);
$('#gravity_disp').html(round1(grv.x)+"x"+round1(grv.y));
$('#rad_accel').val(emitter[p_slot].getRadialAccel());
$('#rad_accel_text').val(emitter[p_slot].getRadialAccel());
$('#rad_accel_var').val(emitter[p_slot].getRadialAccelVar());
$('#rad_accel_var_text').val(emitter[p_slot].getRadialAccelVar());
$('#rad_accel_disp').html(emitter[p_slot].getRadialAccel()+"±"+emitter[p_slot].getRadialAccelVar());
$('#tan_accel').val(emitter[p_slot].getTangentialAccel());
$('#tan_accel_text').val(emitter[p_slot].getTangentialAccel());
$('#tan_accel_var').val(emitter[p_slot].getTangentialAccelVar());
$('#tan_accel_var_text').val(emitter[p_slot].getTangentialAccelVar());
$('#tan_accel_disp').html(emitter[p_slot].getTangentialAccel()+"±"+emitter[p_slot].getTangentialAccelVar());
}else{
//radius
$('#maxRadius').val(emitter[p_slot].getStartRadius());
$('#maxRadiusVar').val(emitter[p_slot].getStartRadiusVar());
$('#minRadius').val(emitter[p_slot].getEndRadius());
$('#maxRadius_text').val(emitter[p_slot].getStartRadius());
$('#maxRadiusVar_text').val(emitter[p_slot].getStartRadiusVar());
$('#minRadius_text').val(emitter[p_slot].getEndRadius());
$('#rotatePerSecond').val(emitter[p_slot].getRotatePerSecond());
$('#rotatePerSecondVar').val(emitter[p_slot].getRotatePerSecondVar());
$('#rotatePerSecond_text').val(emitter[p_slot].getRotatePerSecond());
$('#rotatePerSecondVar_text').val(emitter[p_slot].getRotatePerSecondVar());
$('#max_radius_disp').html(emitter[p_slot].getStartRadius()+"±"+emitter[p_slot].getStartRadiusVar());
$('#min_radius_disp').html(emitter[p_slot].getEndRadius());
$('#rotate_par_second_disp').html(emitter[p_slot].getRotatePerSecond()+"±"+emitter[p_slot].getRotatePerSecondVar());
}
$('#maxParticles').val(emitter[p_slot].getTotalParticles());
$('#emissionRate').val(parseInt(emitter[p_slot].getEmissionRate()));
$('#emissionRate_text').val(parseInt(emitter[p_slot].getEmissionRate()));
//position
pos=emitter[p_slot].getPosition();
$('#emitter_posi').html(parseInt(pos.x)+" "+parseInt(pos.y));
$('#blend_normal').css('font-weight','normal');
$('#blend_add').css('font-weight','normal');
if (emitter[p_slot].isBlendAdditive()==true){
$('#blend_add').css('font-weight','bold');
}else{
$('#blend_normal').css('font-weight','bold');
}
$('#type_grav').css('font-weight','normal');
$('#type_rad').css('font-weight','normal');
if (emitter[p_slot].getEmitterMode()==cc.PARTICLE_MODE_GRAVITY){
$('#type_grav').css('font-weight','bold');
drawAngle(p_slot,emitter[p_slot].getAngle(),emitter[p_slot].getSpeed());
drawGrav(p_slot,emitter[p_slot].getGravity().x,emitter[p_slot].getGravity().y);
drawEmitArea(p_slot,posvar.x,posvar.y);
}else{
$('#type_rad').css('font-weight','bold');
}
$('#emit_rate_disp').html(round2(emitter[p_slot].getEmissionRate()));
xml=baseXML2Plist(p_slot,true,'cocos',cc.Codec.Base64.decode( xml_base64 ));
xmls[p_slot]=xml;
xmlout=$('<div/>').text(xml).html();//htmlencode
$("#plist").html(xmlout);
plist_changed=parseInt((new Date)/1);
if (!png_gz_b64[p_slot] || png_gz_b64[p_slot]=="undefined"){
alert("no png_gz_b64["+p_slot+"] = " + png_gz_b64[p_slot]);
}
//xmlに出した画像をimgタグで表示してみる
$("#img_check").attr("src","data:image/png;base64,"+base64encode( cc.Codec.GZip.gunzip(base64decode(png_gz_b64[p_slot]))));
//画像をセット
if (!png_gz_b64[p_slot]) {
clog('no element '+ png_gz_b64[p_slot])
}else{
clog("element :length="+png_gz_b64[p_slot].length);
}
//$("img[id*=_pic]").attr("src","data:image/png;base64,"+base64encode( cc.Codec.GZip.gunzip(base64decode(png_gz_b64[p_slot]))));
$('#grid_disp').html($('#grid').val());
}
function baseXML2Plist(p_slot,isPNG,p_type,baseStr){
clog("baseXML2Plist:slot"+p_slot+" png:"+png_name[p_slot]);
// p_type cocos corona
rev=1;
if (p_type=='corona') rev= -1;
l_xml=baseStr;
l_xml=l_xml.replace(/__angle__/m, emitter[p_slot].getAngle() * rev);
l_xml=l_xml.replace(/__angleVar__/m, emitter[p_slot].getAngleVar());
l_xml=l_xml.replace(/__duration__/m, emitter[p_slot].getDuration());
l_xml=l_xml.replace(/__life__/m, emitter[p_slot].getLife());
l_xml=l_xml.replace(/__lifeVar__/m, emitter[p_slot].getLifeVar());
//start
start_col=emitter[p_slot].getStartColor(); //c4f type var.r var.g var.b var.a
l_xml=l_xml.replace(/__start_a__/m, round2(start_col.a));
l_xml=l_xml.replace(/__start_r__/m, round2(start_col.r));
l_xml=l_xml.replace(/__start_g__/m, round2(start_col.g));
l_xml=l_xml.replace(/__start_b__/m, round2(start_col.b));
start_col_var=emitter[p_slot].getStartColorVar(); //c4f type var.r var.g var.b var.a
l_xml=l_xml.replace(/__start_a_var__/m, round2(start_col_var.a));
l_xml=l_xml.replace(/__start_r_var__/m, round2(start_col_var.r));
l_xml=l_xml.replace(/__start_g_var__/m, round2(start_col_var.g));
l_xml=l_xml.replace(/__start_b_var__/m, round2(start_col_var.b));
end_col=emitter[p_slot].getEndColor();
l_xml=l_xml.replace(/__end_a__/m, round2(end_col.a));
l_xml=l_xml.replace(/__end_r__/m, round2(end_col.r));
l_xml=l_xml.replace(/__end_g__/m, round2(end_col.g));
l_xml=l_xml.replace(/__end_b__/m, round2(end_col.b));
end_col_var=emitter[p_slot].getEndColorVar(); //c4f type var.r var.g var.b var.a
l_xml=l_xml.replace(/__end_a_var__/m, round2(end_col_var.a));
l_xml=l_xml.replace(/__end_r_var__/m, round2(end_col_var.r));
l_xml=l_xml.replace(/__end_g_var__/m, round2(end_col_var.g));
l_xml=l_xml.replace(/__end_b_var__/m, round2(end_col_var.b));
l_xml=l_xml.replace(/__startSize__/m, emitter[p_slot].getStartSize() );
l_xml=l_xml.replace(/__startSizeVar__/m, emitter[p_slot].getStartSizeVar());
l_xml=l_xml.replace(/__endSize__/m, emitter[p_slot].getEndSize() );
l_xml=l_xml.replace(/__endSizeVar__/m, emitter[p_slot].getEndSizeVar() );
l_xml=l_xml.replace(/__startSpin__/m, emitter[p_slot].getStartSpin() );
l_xml=l_xml.replace(/__startSpinVar__/m, emitter[p_slot].getStartSpinVar());
l_xml=l_xml.replace(/__endSpin__/m, emitter[p_slot].getEndSpin() );
l_xml=l_xml.replace(/__emitterMode__/m, emitter[p_slot].getEmitterMode() );
//gravity
pos=emitter[p_slot].getPosition();
posvar=emitter[p_slot].getPosVar();
l_xml=l_xml.replace(/__posx__/m, pos.x);
l_xml=l_xml.replace(/__posx_var__/m, posvar.x);
l_xml=l_xml.replace(/__posy__/m, pos.y);
l_xml=l_xml.replace(/__posy_var__/m, posvar.y);
if (emitter[p_slot].getEmitterMode()==cc.PARTICLE_MODE_GRAVITY){
l_xml=l_xml.replace(/__speed__/m, emitter[p_slot].getSpeed());
l_xml=l_xml.replace(/__speedVar__/m, emitter[p_slot].getSpeedVar());
grv=emitter[p_slot].getGravity();
l_xml=l_xml.replace(/__grav_x__/m, grv.x );
l_xml=l_xml.replace(/__grav_y__/m, grv.y * rev);
l_xml=l_xml.replace(/__rad_accel__/m, emitter[p_slot].getRadialAccel() );
l_xml=l_xml.replace(/__rad_accel_var__/m, emitter[p_slot].getRadialAccelVar());
l_xml=l_xml.replace(/__tan_accel__/m, emitter[p_slot].getTangentialAccel() * rev);
l_xml=l_xml.replace(/__tan_accel_var__/m, emitter[p_slot].getTangentialAccelVar());
}else{
//radial
l_xml=l_xml.replace(/__maxRadius__/m, emitter[p_slot].getStartRadius());
l_xml=l_xml.replace(/__maxRadiusVar__/m, emitter[p_slot].getStartRadiusVar());
l_xml=l_xml.replace(/__minRadius__/m, emitter[p_slot].getEndRadius());
l_xml=l_xml.replace(/__rotatePerSecond__/m, emitter[p_slot].getRotatePerSecond() * rev);
l_xml=l_xml.replace(/__rotatePerSecondVar__/m, emitter[p_slot].getRotatePerSecondVar());
}
l_xml=l_xml.replace(/__maxParticles__/m, emitter[p_slot].getTotalParticles());
bl=emitter[p_slot].getBlendFunc();
l_xml=l_xml.replace(/__blendFuncDestination__/m, bl.dst);
l_xml=l_xml.replace(/__blendFuncSource__/m, bl.src);
if (isPNG){
if (png_gz_b64[p_slot]=="undefined") alert("pnz_gz_b64["+ p_slot + "] undefined");
l_xml=l_xml.replace(/__png_base64__/m, png_gz_b64[p_slot]); //gzipしてbase64
}else{
l_xml=l_xml.replace(/__png_base64__/m, "");
}
l_xml=l_xml.replace(/__textureFileName__/m, $("#png_filename").val());
l_xml=l_xml.replace(/__.*?__/mg, "0"); //gravity radius のセットしてないほう __****__ として残っている項目を全部0に
return l_xml;
}
function refreshSlot(){
//clog("refreshSlot slot:"+slot+" p2dx.slot_bg:"+p2dx.slot_bg);
if (emitter.length==0) { p2dx.slot_current=null; }
//slotリンク作成
this.str="";
this.str+= "<table><tr><td style='vertical-align:top;' >";
//forground background
if (p2dx.slot_bg == -1 && bg_sprite) bg_str='<b style="color:#EEDDDD;" >BG</b>';
else if (bg_sprite) bg_str='<span style="color:#EEDDDD;" >BG</span>';
else bg_str='BG';
this.str+='<a href="javascript:setBGSlot(-1);" id="slot_m1" style="font-size:130%" >'+bg_str+'</a> ';
if (p2dx.slot_bg == -2 && fg_sprite) fg_str='<b style="color:#EEDDDD;">FG</b>';
else if (fg_sprite) fg_str='<span style="color:#EEDDDD;" >FG</span>';
else fg_str='FG';
this.str+='<a href="javascript:setBGSlot(-2);" id="slot_m2" style="font-size:130%" >'+fg_str+'</a> ';
this.str+= "</td><td style='vertical-align:top;'>";
//スロット
for (ind in emitter){
clog(" emitter "+ind+":"+emitter[ind].toString());
ind=parseInt(ind);
this.str+='<a href="javascript:setSlot('+ind+'); " id="slot_'+ind+'" style="font-size:130%" onMouseOver="checkSlot('+ind+');" onMouseOut="checkSlotOff('+ind+')" >Emit'+(ind+1)+'</a> ';
}
//offリンク
this.str+='<a href="javascript:addSlot();" id="plusbutton" style="font-size:130%">+</a> <br/>'
for (ind in emitter){
ind=parseInt(ind);
this.str+='<a href="javascript:setSlotOff('+ind+');" id="slot_off_'+ind+'" style="place-hub:">Off'+(ind+1)+'</a> ';
}
this.str+="</td></tr></table>";
$("#slots").html(this.str);
//p_slotの強調
$("a[id*=slot_]").css("color","#888888");
$("a[id*=slot_]").css("font-weight","");
//選択中エミッタが表示中なら太字、
if (p2dx.slot_bg == 0 ){
clog("p2dx.slot_bg=0");
if ( emitter.length > 0 ){
$("a[id=slot_" + p2dx.slot_current + "]").css("font-weight","bold");
}else{
//選択中エミッタを決め直す
for (ind in emitter){
clog("new active sch");
if (emitter[ind].isVisible()==true){
$("a[id=slot_" + ind + "]").css("font-weight","bold");
p2dx.slot_current = ind;
break;
}
}
}
}
if (emitter.length==0){
$("#current_slot").html("");
}else{
for (ind in emitter){
if (emitter[ind].isVisible()==true){
$("a[id=slot_" + ind + "]").css("color","");
}
}
$("#current_slot").html("Emit"+(parseInt( p2dx.slot_current )+1));
}
}
//エミッタをcocos2dxのものに変更、テクスチャはそのまま
function setEmitter( name , p_slot ){
clog("setEmitter name: " + name + " p_slot:" + p_slot );
if (p_slot==null) { p_slot = p2dx.slot_current = 0; }
if (emitter[p_slot]==undefined){
//新規
clog("new emitter:"+p_slot+" emitterCt:"+emitter.length);
texture1=cc.TextureCache.getInstance().addImage("png/_s_fire.png");
clog('setEmitter texture1=' + texture1);
//画像をbase64にして保存
png_gz_b64[p_slot]=png_gz_b64["_s_fire"];
p2dx.slot_current=p_slot;//今作ったものをアクティブに
new_pos=cc.p(40 + (p_slot % 4) * 120 , 60 + Math.floor(p_slot / 4) * 200);
}else{
clog("replace emitter:"+p_slot +" emitterCt:"+emitter.length);
texture1=emitter[p_slot].getTexture();
emitter[p_slot].removeFromParent();
new_pos=emitter[p_slot].getPosition();
delete emitter[ind];
emitter.splice(ind,1);
}
//既存テクスチャ処理
eval('emitter[p_slot] = cc.Particle'+name+'.create();');
emitter[p_slot].setTexture(texture1);
clog('setEmitter2 texture1=' + texture1);
emitter[p_slot].setPosition(new_pos);
layers=cc.Director.getInstance().getRunningScene().getChildren();
layers[0].addChild(emitter[p_slot],5);
setGuideObj(p_slot);
dumpToInputTag(p_slot);
}
function toggleStats(){
director=cc.Director.getInstance();
if (director.isDisplayStats()){
director.setDisplayStats(false);
}else{
director.setDisplayStats(true);
}
}
function toggleGrid(){
if (dn.isVisible()==true){
dn.setVisible(false);
}else{
dn.setVisible(true);
}
}
var pre_filename="";
var prev_emitter;
var pre_index=""
function prevEnd(){
if (prev_emitter){
prev_emitter.removeFromParent();
prev_emitter=null;
delete prev_emitter;
}
prev_dn.setVisible(false);
prev_string.setVisible(false);
pre_filename=""
pre_index="99"
return;
}
function prevSnapshot(index){
console.log('log ' + pre_index + ' ' + index);
if (pre_index == index) return;
console.log('prevSnapshot:' + index);
prev_dn.setVisible(true);
prev_string.setVisible(true);
pre_index = index;
particle_dict=xml2ary(snap[index]);
if (!particle_dict) { alert("Plist fail"); return false; exit(); }
//すでにemitterが存在していれば除去
if (prev_emitter != undefined){
if (prev_emitter.getParent()) {
prev_emitter.removeFromParent();
prev_emitter=null;
delete prev_emitter;
}
}
cc.TextureCache.getInstance().removeTextureForKey(particle_dict['textureFileName']);//この名前のテクスチャはキャッシュを消す
prev_emitter= cc.ParticleSystem.create();
//ここで
//テクスチャデータがある場合
if (particle_dict['textureImageData']){
clog("textureImageData exist");
if (particle_dict['textureImageData']=="undefined") alert("textureImageData undefined");
gzip_png=cc.Codec.Base64.decode(particle_dict['textureImageData']);
//clog("png_gz_b64:"+p_slot+" "+ particle_dict['textureImageData'].length);
png_gz_b64_prev=particle_dict['textureImageData'];
}else{
clog("no textureImageData");
///デフォルトのtexture
png_gz_b64_prev=png_gz_b64["_s_fire"];
particle_dict['textureImageData']=png_gz_b64["_s_fire"];
}
prev_emitter.initWithDictionary(particle_dict,"");
layers=cc.Director.getInstance().getRunningScene().getChildren();
layers[0].addChild(prev_emitter,11);
}
function prevParticle(p_filename){
if (pre_filename == p_filename) return;
prev_string.setVisible(true);
console.log('prevParticle:' + p_filename);
prev_dn.setVisible(true);
pre_filename = p_filename;
$.ajax({
async:false,
type: "GET",
url: "plist/"+p_filename,
success:function(data){
particle_dict=xml2ary(data);
if (!particle_dict) { alert("Plist fail"); return false; exit(); }
//すでにemitterが存在していれば除去
if (prev_emitter != undefined){
if (prev_emitter.getParent()) {
prev_emitter.removeFromParent();
prev_emitter=null;
delete prev_emitter;
}
}
cc.TextureCache.getInstance().removeTextureForKey(particle_dict['textureFileName']);//この名前のテクスチャはキャッシュを消す
prev_emitter= cc.ParticleSystem.create();
//ここで
//テクスチャデータがある場合
if (particle_dict['textureImageData']){
clog("textureImageData exist");
if (particle_dict['textureImageData']=="undefined") alert("textureImageData undefined");
gzip_png=cc.Codec.Base64.decode(particle_dict['textureImageData']);
//clog("png_gz_b64:"+p_slot+" "+ particle_dict['textureImageData'].length);
png_gz_b64_prev=particle_dict['textureImageData'];
}else{
clog("no textureImageData");
///デフォルトのtexture
png_gz_b64_prev=png_gz_b64["_s_fire"];
particle_dict['textureImageData']=png_gz_b64["_s_fire"];
}
prev_emitter.initWithDictionary(particle_dict,"");
layers=cc.Director.getInstance().getRunningScene().getChildren();
layers[0].addChild(prev_emitter,11);
}
});
}
//ajax取得
function getPlist(fname){
$.ajax({
async:false,
type: "GET",
url: "plist/"+fname,
success:function(data){
xmlStr2emitter(data,p2dx.slot_current);
}
});
}
function getP2dx(fname){
$.ajax({
async:false,
type: "GET",
url: "plist/"+fname,
success:function(data){
decodeP2DX(data);
}
});
}
//XML文書をjsのaryに
function xml2ary(xml_str){
var xmlDoc = null;
if ( typeof(xml_str) == "object" ) { // If xml_str is object then use directly
xmlDoc = xml_str;
} else { // Otherwise parse str
var parser = new DOMParser();
xmlDoc = parser.parseFromString(xml_str, "text/xml");
}
var plist = xmlDoc.documentElement;
// Get first real node
var node = null;
for (var i = 0, len = plist.childNodes.length; i < len; i++) {
node = plist.childNodes[i];
if (node.nodeType == 1)
break
}
xmlDoc = null;
return cc.SAXParser.getInstance()._parseNode(node); //xmlを配列に
}
//cocos2dxのplist > emitter
function xmlStr2emitter(p_xml,p_slot){
clog("xmlStr2emitter p_slot:" + p_slot);
if (p_slot==null) {
p2dx.slot_current = p_slot = 0;
clog("p_slot is NULL and override p_slot:" + p_slot);
}
particle_dict=xml2ary(p_xml);
if (!particle_dict) { alert("Plist fail"); return false; exit(); }
//すでにemitterが存在していれば除去
if (emitter[p_slot]!=undefined){
if (emitter[p_slot].getParent()) {
emitter[p_slot].removeFromParent();
emitter[p_slot]=null;
delete emitter[p_slot];
clog(" emitter:"+p_slot+" setNULL");
}
}
cc.TextureCache.getInstance().removeTextureForKey(particle_dict['textureFileName']);//この名前のテクスチャはキャッシュを消す
emitter[p_slot] = cc.ParticleSystem.create();
clog("emitter:"+p_slot+" create");
//ここで
//テクスチャデータがある場合
if (particle_dict['textureImageData']){
clog("textureImageData exist");
if (particle_dict['textureImageData']=="undefined") alert("textureImageData undefined");
gzip_png=cc.Codec.Base64.decode(particle_dict['textureImageData']);
//clog("png_gz_b64:"+p_slot+" "+ particle_dict['textureImageData'].length);
png_gz_b64[p_slot]=particle_dict['textureImageData'];
clog("slot:" + p2dx.slot_current);
}else{
clog("no textureImageData");
///デフォルトのtexture
png_gz_b64[p_slot]=png_gz_b64["_s_fire"];
particle_dict['textureImageData']=png_gz_b64["_s_fire"];
}
emitter[p_slot].initWithDictionary(particle_dict,"");
layers=cc.Director.getInstance().getRunningScene().getChildren();
layers[0].addChild(emitter[p_slot],5);
texture1=emitter[p_slot].getTexture();
if (emitter[p_slot].getEmitterMode()==cc.PARTICLE_MODE_GRAVITY){
toggleGravityRadius("gravity",p_slot);
}else{
toggleGravityRadius("radius",p_slot);
}
prev_dn.setVisible(false);
prev_string.setVisible(false);
current_start_color=emitter[p2dx.slot_current].getStartColor();
current_end_color=emitter[p2dx.slot_current].getEndColor();
}
//すべてのスロットとsnapshotをjsonに
function encodeP2DX(){
//xmlsのプログラムをセットする。
for (ind in emitter){
dumpToInputTag(ind);
}
return xmls;
}
function decodeP2DX(p2dx_JSON){
clog("decodeP2DX");
//画面上のemitter 全削除
for(ind in emitter){
emitter[ind].removeFromParent();
emitter[ind]=null;
delete emitter[ind];
clog( " emitter:"+ind+" setNULL");
}
emitter=[];
json=JSON.parse(p2dx_JSON);
clog("decodeP2DX emitters:"+json.length);
for (ind in json){
clog("emit "+ind + "xml"+json[ind]);
p2dx.slot_current=ind;
xmlStr2emitter(json[ind],ind);
}
}
function getSnapshot(){
snap[snap.length]=xml;
$("#snapshots").html($("#snapshots").html()+" <a href='"+'javascript:xmlStr2emitter(snap['+(snap.length-1)+'],p2dx.slot_current)' + "' " + 'onMouseOver="prevSnapshot('+(snap.length-1)+');" onMouseOut="prevEnd(); "' + '>s' + (snap.length-1) + "</a> ");
}
function clrSnapshot(){
snap=[];
$("#snapshots").html(" ");
}
// slot関連 ---------------------------------------
function rotateSlot(p_slot,digree){
rad= Math.PI /180 * digree;
emitter[p_slot].setAngle(emitter[p_slot].getAngle() +digree);
g = emitter[p_slot].getGravity();
emitter[p_slot].setGravity(cc.p( round2(g.x * Math.cos(rad) - g.y * Math.sin(rad)) ,round2( g.x * Math.sin(rad) + g.y * Math.cos(rad) )));
dumpToInputTag(p_slot);
}
function changeEmitterSize(p_slot , bairitu){
clog("changeEmitterSize slot:"+p_slot + " bairitu:"+bairitu );
emitter[p_slot].setSpeed( Math.floor(emitter[p_slot].getSpeed()*bairitu) );
emitter[p_slot].setSpeedVar( Math.floor(emitter[p_slot].getSpeedVar()*bairitu) );
g=emitter[p_slot].getGravity();