forked from cyrismustang/k2badge
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathkaini.js
executable file
·1789 lines (1599 loc) · 71.8 KB
/
kaini.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
var lang = "en";
var globalship = null;
var globalbg = null;
var globalavatar = null;
var k2 = {};
var colle = {};
var shipDB = {};
var fleets = [
new Array(6),
new Array(6),
new Array(6),
new Array(6),
];
var fleetLevels = [
[1, 1, 1, 1, 1, 1],
[1, 1, 1, 1, 1, 1],
[1, 1, 1, 1, 1, 1],
[1, 1, 1, 1, 1, 1]
];
function setCookie(name, value, domain) {
var dom = domain ? ("; domain=" + domain) : '';
document.cookie = name + "=" + encodeURIComponent(value) + "; max-age=" + (60 * 60 * 24 * 365) + "; path=/" + dom;
}
function getCookie(name) {
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for (var i = 0; i < ca.length; i++) {
var c = ca[i];
while (c.charAt(0) == ' ') c = c.substring(1, c.length);
if (c.indexOf(nameEQ) == 0) return decodeURIComponent(c.substring(nameEQ.length, c.length));
}
return null;
}
function store(key, value) {
if (storage) {
localStorage.setItem(key, value)
} else {
setCookie(key, value);
}
}
function restore(key) {
var item = null;
if (storage) {
item = localStorage.getItem(key)
if (item) return item;
}
return getCookie(key);
}
function getBase64Image(img) {
var canvas = document.createElement("canvas");
canvas.width = img.width;
canvas.height = img.height;
var ctx = canvas.getContext("2d");
ctx.drawImage(img, 0, 0);
var dataURL = canvas.toDataURL("image/png");
return dataURL;
}
var storage = (function() {
var uid = new Date;
var storage;
var result;
try {
(storage = window.localStorage).setItem(uid, uid);
result = storage.getItem(uid) == uid;
storage.removeItem(uid);
return result && storage;
} catch (exception) {}
}());
$(document).ready(function() {
$(".shipClass").each(function() {
var arrLength = $(this).find("input").length;
var blankArray = new Array(arrLength);
while (arrLength--) blankArray[arrLength] = false;
k2[this.id] = blankArray;
});
var loading = {};
var selectedFleet = 0;
var selectedSlot = 0;
var conversion = {};
var abyssDB = {};
var flagRarity = 0;
$.ajax({
dataType: "json",
timeout: 10000,
url: (lang == "en" ? 'db.json?v=13' : 'dbj.json?v=13')
})
.then(function(data) {
shipDB = data;
$.ajax({
dataType: "json",
timeout: 10000,
url: 'conversion.json?v=13'
}).then(function(data2) {
conversion = data2;
init();
}, function(error) {
//Continue but warn
console.log("import db not found or invalid format, not performing import");
init();
});
}, function() {
//Kill the App
$("#buttons").html("Can't find Kanmusu DB, please contact Vultren or Nya-chan on Github");
$("#tabs").remove();
})
var deskoffsetdb = {
"016.png": { x: 0, y: -140 },
"017.png": { x: 0, y: -140 },
"021.png": { x: 0, y: -140 },
"026.png": { x: 0, y: -140 },
"037.png": { x: 0, y: -140 },
"042a.png": { x: 0, y: 70 },
"042b.png": { x: 0, y: 70 },
"046.png": { x: 0, y: -140 },
"057.png": { x: 0, y: -140 },
}
var c = document.getElementById("result");
var ctx = c.getContext("2d");
var hexagonAngle = 0.523598776,
sideLength = 24;
var hexHeight = Math.sin(hexagonAngle) * sideLength;
var hexRadius = Math.cos(hexagonAngle) * sideLength;
var hexRectangleHeight = sideLength + 2 * hexHeight;
var hexRectangleWidth = 2 * hexRadius;
var centerx = (hexRectangleHeight * 5 / 4 - hexRectangleWidth) / 2;
var centery = (hexRectangleHeight * 5 / 4 - hexRectangleHeight) / 2 + 5;
var textfont = "'Ubuntu', 'メイリオ', Times, serif";
var numberfont = "'Exo', 'メイリオ', Times, serif";
var recalculateSides = function(side) {
sideLength = side;
hexHeight = Math.sin(hexagonAngle) * sideLength;
hexRadius = Math.cos(hexagonAngle) * sideLength;
hexRectangleHeight = sideLength + 2 * hexHeight;
hexRectangleWidth = 2 * hexRadius;
centerx = (hexRectangleHeight * 5 / 4 - hexRectangleWidth) / 2;
centery = (hexRectangleHeight * 5 / 4 - hexRectangleHeight) / 2 + 5;
};
var saveAll = function() {
var furnitures = $(".furnitureClass input:checked").toArray();
var furnObj = {};
for (var i in furnitures) {
furnObj[furnitures[i].name] = furnitures[i].id;
}
$(".shipClass").each(function() {
var abbr = this.id;
var k2s = $(this).find("input");
var k2Array = {};
k2s.each(function(i) {
k2Array[this.id] = $(this).prop("checked");
});
k2[abbr] = k2Array;
});
store("ttkName", $("input[name='name']").val());
store("ttkLvl", $("input[name='level']").val());
store("ttkServer", $("select[name='server']").val());
store("ttkFurn", Base64.encode(JSON.stringify(furnObj)));
store("ttkFurnCam", $("#roomY").val());
store("ttkTint", $("#tint-color").val());
store("ttkHexOpa", $("#hexOpa").val());
store("k2", Base64.encode(JSON.stringify(k2)));
store("secretaryCam", JSON.stringify([$("#customX").val(), $("#customY").val(), $("#customZ").val()]));
store("secretaryHit", $(".damaged").size() > 0 && !$($(".damaged")[0]).hasClass("abyss")) ? true : false;
store("fleet", Base64.encode(fleets.join("|")));
store("fleetLvl", Base64.encode(fleetLevels.join("|")));
store("colle", Base64.encode(JSON.stringify(colle)));
store("bg", globalbg);
store("bgUse", $("#useBG").prop("checked"));
store("bgCam", JSON.stringify([$("#bgX").val(), $("#bgY").val(), $("#bgZ").val()]));
store("bgStretch", $("#bgStretch").prop("checked"));
store("avatar", globalavatar);
};
var loadAll = function() {
$(".flagship").removeClass("flagship");
$(".damaged").removeClass("damaged");
$("input[name='name']").val(restore("ttkName"));
$("input[name='level']").val(restore("ttkLvl"));
var bgCamTemp = restore("bgCam");
bgCamTemp = bgCamTemp ? JSON.parse(bgCamTemp) : [0, 0, 100]
$("#bgX").val(bgCamTemp[0]);
$("#bgY").val(bgCamTemp[1]);
$("#bgZ").val(bgCamTemp[2]);
$("#useBG").prop("checked", (!restore("bgUse") || restore("bgUse") == "true"));
var secretaryCamTemp = restore("secretaryCam");
secretaryCamTemp = secretaryCamTemp ? JSON.parse(secretaryCamTemp) : [0, 0, 0]
$("#customX").val(secretaryCamTemp[0]);
$("#customY").val(secretaryCamTemp[1]);
$("#customZ").val(secretaryCamTemp[2]);
$("#roomY").val(restore("ttkFurnCam") || 0);
$("#tint-color").val(restore("ttkTint") || "#ffffff");
$("#hexOpa").val(restore("ttkHexOpa") || 0.33);
$("#hexOpa").val(restore("ttkHexOpa") || 0.33);
$("#bgStretch").prop("checked", (!restore("bgStretch") || restore("bgStretch") == "true"));
globalbg = restore("bg");
if (globalbg != 'null') $('#bg').attr('src', globalbg);
globalavatar = restore("avatar");
if (globalavatar != 'null') {
$('#avatar').attr('src', globalavatar);
} else $('#avatar').removeAttr('src');
var serverTemp = restore("ttkServer");
if (serverTemp != 'null') {
$("select[name='server']").val(serverTemp);
}
var k2Temp = restore("k2");
k2Temp = k2Temp ? JSON.parse(Base64.decode(k2Temp)) : null;
var colleTemp = restore("colle");
colleTemp = colleTemp ? JSON.parse(Base64.decode(colleTemp)) : null;
var furnTemp = restore("ttkFurn");
furnTemp = furnTemp ? JSON.parse(Base64.decode(furnTemp)) : null;
var fleetsTemp = restore("fleet");
fleetsTemp = fleetsTemp ? Base64.decode(fleetsTemp).split("|") : null;
for (var i in fleetsTemp) {
fleetsTemp[i] = fleetsTemp[i].split(",");
}
var fleetLevelsTemp = restore("fleetLvl");
fleetLevelsTemp = fleetLevelsTemp ? Base64.decode(fleetLevelsTemp).split("|") : null;
for (var i in fleetLevelsTemp) {
fleetLevelsTemp[i] = fleetLevelsTemp[i].split(",");
}
if (k2Temp) {
k2 = k2Temp;
$(".shipClass input").prop("checked", false);
for (var i in k2) {
for (var j in k2[i]) {
$("#" + j).prop("checked", k2[i][j]);
}
}
}
if (colleTemp) {
colle = colleTemp;
$("#colleDiv img").removeClass("selected");
for (var i in colle) {
$("#kore" + i).addClass("selected");
}
}
if (fleetsTemp) {
fleets = fleetsTemp;
for (var i in fleets[0]) {
var ship = fleets[0][i];
if (ship !== null && ship !== "") {
if (i == 0) {
$("#" + ship).addClass("flagship");
if (restore("secretaryHit") == "true") $("#" + ship).next("span").addClass("damaged");
flagRarity = shipDB[ship.substring(4)] ? shipDB[ship.substring(4)].rarity : 0;
}
var slot = parseInt(i) + 1;
$("#slot" + slot).html('<img style="height:50px; width:50px;" src="' + $("#" + ship).attr("src") + '"/>');
}
}
}
if (fleetLevelsTemp) {
fleetLevels = fleetLevelsTemp;
for (var i in fleetLevels[0]) {
var level = parseInt(fleetLevels[0][i]);
if (level && level > 0) {
var slot = parseInt(i) + 1;
$("#level" + slot).val(level);
}
}
}
if (furnTemp) {
var loadCount = 0;
$("#buttons button").prop("disabled", true);
$("#loadingDiv").html("Rendering...");
var imgError = false;
for (var i in furnTemp) {
var furniture = furnTemp[i];
var current = $("#" + furniture);
current.prop("checked", true);
var type = current.parent().parent().parent().attr("id");
var activeImg = $("#active" + type);
activeImg.off("load");
if (type == "Outside") {
var selectedOut = $("#Outside").find(":checked");
var windowType = $("#Window").find(":checked").attr("data-pType");
var imgToLoad = selectedOut.val() + windowType;
var path = "furniture/outside/" + imgToLoad + ".png";
activeImg.attr("src", path);
} else {
var imgToLoad = current.val();
activeImg.attr("src", "furniture/" + type.toLowerCase() + "/" + imgToLoad + ".png");
}
if (activeImg.prop("complete")) {
loadCount++;
if (loadCount == Object.keys(furnTemp).length) {
$("#buttons button").prop("disabled", false);
$("#loadingDiv").html("");
if ($("#displayRoom").hasClass("on")) {
drawRoom(132);
} else {
generateFunction("loadAllImgCached");
}
}
} else {
activeImg.load(function() {
loadCount++;
if (loadCount == Object.keys(furnTemp).length) {
$("#buttons button").prop("disabled", false);
$("#loadingDiv").html(imgError ? "Couldn't find a furniture's image." : "");
if ($("#displayRoom").hasClass("on")) {
drawRoom(132);
} else {
generateFunction("loadAllImgLoaded");
}
}
})
.error(function(error) {
loadCount++;
imgError = true;
if (loadCount == Object.keys(furnTemp).length) {
$("#buttons button").prop("disabled", false);
$("#loadingDiv").html("Couldn't find a furniture's image.");
}
});
}
}
} else {
generateFunction("loadNoFurniture");
}
};
var bindAvatars = function() {
if (!$(this).hasClass("abyss")) {
fleets[selectedFleet][selectedSlot] = $(this).prev("img").attr("id");
$("#fleets .chosen").html('<img style="height:50px; width:50px;" src="' + $(this).prev("img").attr("src") + '"/>');
}
if (selectedFleet == 0 && selectedSlot == 0) {
if (!$(this).hasClass("damaged")) {
$(".damaged").removeClass("damaged");
}
$(this).toggleClass("damaged");
$(".flagship").removeClass("flagship");
var flagship = $(this).prev("img");
flagship.toggleClass("flagship");
flagRarity = shipDB[$(this).prev("img").attr("id").substring(4)] ? shipDB[$(this).prev("img").attr("id").substring(4)].rarity : 0;
generateFunction("fleetFlagshipChange");
}
}
var loadAbyssalShips = function() {
$("#loadAbyss").remove();
$("#avatars .hidden").removeClass("hidden");
$.ajax({
dataType: "json",
timeout: 10000,
url: (lang == "en" ? 'db2.json?v=13' : 'db2j.json?v=13'),
success: function(data) {
abyssDB = data;
$("#loadingDiv").html("Loading images: ");
$("#loadingProgress").show().html("0/" + Object.keys(data).length);
var i = 0;
for (var e in abyssDB) {
var ship = data[e];
if (ship.name) {
var newDiv = $('<img class="abyss tooltip2" title="' + ship.full + '" src="icons/' + ship.type + '/' + e + '.png" id="icon' + e + '"></img>');
var extraSpan = $('<span class="abyss" id="hit' + e + '">破</span>');
newDiv.on("load", function() {
i++;
$("#loadingProgress").html(i + "/" + Object.keys(data).length);
if (i == Object.keys(data).length) {
$("#loadingDiv").html("");
$("#loadingProgress").hide();
}
});
newDiv.on("click", function() {
$(".flagship").removeClass("flagship");
$(".damaged").removeClass("damaged");
$(this).toggleClass("flagship");
flagRarity = 0;
generateFunction("fleetShipChangeAbyss");
});
if ($(".shipList [data-name='" + ship.name + "']").length == 0) {
$(".div" + ship.type).append('<div><label>' + ship.name.replace(new RegExp('_', 'g'), ' ') + '</label><div data-name="' + ship.name + '" class="' + ship.type + '"></div></div>');
}
$("#avatars [data-name='" + ship.name + "']").append(newDiv);
if (ship.damageable) {
$("#avatars [data-name='" + ship.name + "']").append(extraSpan);
}
}
}
$("#avatars span").unbind("click").on("click", bindAvatars);
$('.tooltip2').tooltipster();
},
error: function() {
$("#loadingDiv").html("Can't find Abyssal DB, please contact Vultren or Nya-chan on Github");
}
});
}
var generateFunction = function(source) {
console.log(source);
$("#loadingDiv").html("Rendering...");
$("#buttons button").prop('disabled', true);
$("#save").prop("disabled", true);
ctx.clearRect(0, 0, c.width, c.height);
ctx.save();
ctx.fillStyle = "#666";
ctx.fillRect(0, 0, c.width, c.height);
if ($("#useBG").prop("checked")) {
drawRoom($("#buttonToggles .active").attr("id") != "displayBadge" ? 132 : parseInt(document.getElementById("roomY").value));
ctx.globalAlpha = 0.33;
ctx.fillRect(0, 0, c.width, c.height);
} else {
var bg = document.getElementById("bg");
var stretch = $("#bgStretch").prop("checked");
var x = $("#bgX").val() || 0;
var y = $("#bgY").val() || 0;
var z = $("#bgZ").val() || 0;
ctx.drawImage(bg, x, y, stretch ? c.width : bg.width * (z / 100), stretch ? c.height : bg.height * (z / 100));
}
ctx.restore();
ctx.strokeRect(0, 0, c.width, c.height);
redraw();
}
var drawSecretary = function(callback, hideAvatar) {
var avatarImg = $('#avatar');
var selected = $(".flagship")[0] ? $(".flagship")[0].id.substring(4) : null;
var damaged = false;
if (selected && $("#hit" + selected).hasClass("damaged")) damaged = true;
var dir = $(".flagship").parent().length > 0 ? $(".flagship").parent().attr("class") : null;
if (globalship != null) {
var img = new Image();
img.onload = function() {
var offx = 0;
var offy = 0;
offx += document.getElementById("customX").value ? parseInt(document.getElementById("customX").value) : 0;
offy += document.getElementById("customY").value ? parseInt(document.getElementById("customY").value) : 0;
ctx.save();
var scale = document.getElementById("customZ").value ? parseInt(document.getElementById("customZ").value) + 100 : 100;
scale = scale / 100;
ctx.translate(c.width - img.width * 7 / 8 + offx, c.height / 2 - img.height / 5 + offy);
ctx.translate(img.width / 2, img.height / 2);
ctx.scale(scale, scale);
ctx.drawImage(img, -img.width / 2, -img.height / 2);
ctx.restore();
callback();
if (!hideAvatar) {
drawCustomAvatar(ctx);
}
};
img.onerror = callback;
img.src = globalship;
} else if (selected) {
var img = new Image();
img.onload = function() {
var offx = 0;
var offy = 0;
if (flagRarity == 0 && abyssDB[selected]) {
if (damaged && abyssDB[selected].offset2) {
offx = abyssDB[selected].offset2.x;
offy = abyssDB[selected].offset2.y;
} else {
offx = abyssDB[selected].offset.x;
offy = abyssDB[selected].offset.y;
}
} else if (shipDB[selected]) {
if (damaged && shipDB[selected].offset2) {
offx = shipDB[selected].offset2.x;
offy = shipDB[selected].offset2.y;
} else if (shipDB[selected].offset) {
offx = shipDB[selected].offset.x;
offy = shipDB[selected].offset.y;
}
}
offx += document.getElementById("customX").value ? parseInt(document.getElementById("customX").value) : 0;
offy += document.getElementById("customY").value ? parseInt(document.getElementById("customY").value) : 0;
ctx.save();
var scale = document.getElementById("customZ").value ? parseInt(document.getElementById("customZ").value) + 100 : 100;
if (scale >= 50 && scale <= 150) {
scale = scale / 100;
ctx.translate(c.width - img.width * 7 / 8 + offx, c.height / 2 - img.height / 5 + offy);
ctx.translate(img.width / 2, img.height / 2);
ctx.scale(scale, scale);
ctx.drawImage(img, -img.width / 2, -img.height / 2);
} else {
ctx.drawImage(img, c.width - img.width * 7 / 8 + offx, c.height / 2 - img.height / 5 + offy);
}
ctx.restore();
callback();
if (!hideAvatar) {
if (!avatarImg.attr("src")) {
drawDefaultAvatar(ctx, selected, flagRarity);
} else {
drawCustomAvatar(ctx);
}
}
};
img.onerror = callback;
img.src = "full/" + dir + "/" + selected + (damaged ? "x" : "") + ".png";
} else {
callback();
if (avatarImg.attr("src") && !hideAvatar) {
drawCustomAvatar(ctx);
}
}
}
var drawDefaultAvatar = function(ctx, id, rarity) {
var rarity = document.getElementById("r" + rarity);
var icon = document.getElementById("icon" + id);
ctx.save();
ctx.fillStyle = "black";
ctx.fillRect(35, 45, 100, 100);
ctx.strokeRect(35, 45, 100, 100);
ctx.restore();
ctx.drawImage(rarity, 30, 5, 100, 100, 35, 45, 100, 100);
ctx.drawImage(icon, 35, 45);
}
var drawCustomAvatar = function(ctx) {
var avatar = document.getElementById("avatar");
ctx.save();
ctx.fillStyle = "transparent";
ctx.fillRect(35, 45, 100, 100);
ctx.strokeRect(35, 45, 100, 100);
ctx.restore();
ctx.drawImage(avatar, 35, 45, 100, 100);
}
var redraw = function() {
var mode = $("#buttonToggles .active").attr("id");
if (mode == "displayBadge") {
if ($("#k2").prop("checked")) {
drawSecretary(drawNewBadge);
} else {
drawSecretary(drawBadge);
}
} else if (mode == "displayPoster") {
drawSecretary(drawPoster, true);
} else if (mode == "displayRoom") {
drawRoom(132);
}
}
var drawPoster = function() {
var newLength = 10;
recalculateSides(newLength);
ctx.save();
var name = $("[name='name']")[0];
var level = $("[name='level']")[0];
var server = $("[name='server'] :selected").text();
var useBlue = $("#useBlue").prop("checked");
var maxPerLine = 40;
var linebarwidth = newLength * (2 * Math.sin(Math.PI / 2) + 1);
var line1 = 55;
var bottomLine = c.height - 10;
var row1 = 40;
var row1box = row1 + 15;
var row2 = row1 + hexRadius;
var row2box = row1box + hexRadius;
var progressrow = 530;
var progressrowbox = 540;
ctx.font = "20px " + textfont;
ctx.imageSmoothingEnabled = true;
ctx.fillStyle = 'white';
ctx.strokeStyle = 'black';
if (name.value) {
drawText(name.value, 20, 25, 3);
} else {
drawText((lang == "en" ? "Nameless Admiral" : "無名提督"), 20, 25, 3);
}
ctx.save();
ctx.font = "10px " + textfont;
ctx.globalCompositeOperation = "lighter";
ctx.fillStyle = 'rgba(255, 255, 255, 0.25)';
ctx.strokeStyle = 'transparent';
var date = new Date();
drawText(date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + date.getDate(), 5, c.height - 5, 3);
ctx.restore();
ctx.font = "14px " + textfont;
ctx.textAlign = "right";
drawText((lang == "en" ? "DE" : "海"), row1, line1 + newLength - 9);
var numDE = 0;
var maxDE = $("#colleDiv .divDE img.selected").length;
ctx.save();
ctx.fillStyle = "white";
$("#colleDiv .divDE img").each(function(i) {
var x = row1box + numDE * hexRectangleWidth;
var y = Math.floor(numDE / maxPerLine) * +linebarwidth / 2 + line1 - 15;
var img = document.getElementById(this.id);
drawHexagon(img, x, y, $(this).hasClass("selected"), false);
numDE++;
});
ctx.textAlign = "left";
ctx.font = "14px " + numberfont;
drawText(maxDE + "/" + numDE + " (" + (maxDE / numDE * 100).toFixed() + "%)", row1box + numDE * hexRectangleWidth + 8, line1);
ctx.restore();
var line2 = line1 + linebarwidth / 2 + linebarwidth / 4;
ctx.font = "14px " + textfont;
ctx.textAlign = "right";
drawText((lang == "en" ? "DD" : "駆"), row2, line2 + newLength - 9);
var numDD = 0;
var maxDD = $("#colleDiv .divDD img.selected").length;
ctx.save();
ctx.fillStyle = "white";
$("#colleDiv .divDD img").each(function(i) {
var x = row2box + numDD % maxPerLine * hexRectangleWidth;
if (Math.floor(numDD / maxPerLine % 2) > 0) {
x = row2box + (maxPerLine - numDD % maxPerLine) * hexRectangleWidth - hexRadius;
}
var y = Math.floor(numDD / maxPerLine) * +linebarwidth / 2 + line2 - 15;
var img = document.getElementById(this.id);
drawHexagon(img, x, y, $(this).hasClass("selected"), false);
numDD++;
});
ctx.textAlign = "left";
ctx.font = "14px " + numberfont;
drawText(maxDD + "/" + numDD + " (" + (maxDD / numDD * 100).toFixed() + "%)", row2box + maxPerLine * hexRectangleWidth + 8, line2);
ctx.restore();
var line3 = line2 + linebarwidth + linebarwidth / 4 + Math.floor(numDD / maxPerLine) * 8;
var line4 = line3 + linebarwidth / 2 + linebarwidth / 4;
var line5 = line4 + linebarwidth / 2 + linebarwidth / 4;
var line6 = line5 + linebarwidth / 2 + linebarwidth / 4;
var line7 = line6 + linebarwidth / 2 + linebarwidth / 4;
var line8 = line7 + linebarwidth / 2 + linebarwidth / 4;
var line9 = line8 + linebarwidth / 2 + linebarwidth / 4;
drawText((lang == "en" ? "CL" : "軽巡"), row1, line3 + newLength - 9);
var numCL = 0;
var maxCL = $("#colleDiv .divCL img.selected").length;
ctx.save();
ctx.fillStyle = "white";
$("#colleDiv .divCL img").each(function() {
var x = row1box + numCL * hexRectangleWidth;
var y = line3 - 15;
var img = document.getElementById(this.id);
drawHexagon(img, x, y, $(this).hasClass("selected"), false);
numCL++;
});
ctx.textAlign = "left";
ctx.font = "14px " + numberfont;
drawText(maxCL + "/" + numCL + " (" + (maxCL / numCL * 100).toFixed() + "%)", row1box + numCL * hexRectangleWidth + 8, line3);
ctx.restore();
drawText((lang == "en" ? "CA" : "重巡"), row2, line4 + newLength - 9);
var numCA = 0;
var maxCA = $("#colleDiv .divCA img.selected").length;
var blue = 0;
ctx.save();
ctx.fillStyle = "white";
$("#colleDiv .divCA img").each(function() {
var x = row2box + numCA * hexRectangleWidth;
var y = line4 - 15;
var img = document.getElementById(this.id);
drawHexagon(img, x, y, $(this).hasClass("selected"), false);
numCA++;
});
ctx.textAlign = "left";
ctx.font = "14px " + numberfont;
drawText(maxCA + "/" + numCA + " (" + (maxCA / numCA * 100).toFixed() + "%)", row1box + numCA * hexRectangleWidth + 8, line4);
ctx.restore();
drawText((lang == "en" ? "CVL" : "軽母"), row2, line6 + newLength - 9);
var numCVL = 0;
var maxCVL = $("#colleDiv .divCVL img.selected").length;
ctx.save();
ctx.fillStyle = "white";
$("#colleDiv .divCVL img").each(function() {
var x = row2box + numCVL * hexRectangleWidth;
var y = line6 - 15;
var img = document.getElementById(this.id);
drawHexagon(img, x, y, $(this).hasClass("selected"), false);
numCVL++;
});
ctx.textAlign = "left";
ctx.font = "14px " + numberfont;
drawText(maxCVL + "/" + numCVL + " (" + (maxCVL / numCVL * 100).toFixed() + "%)", row2box + numCVL * hexRectangleWidth + 8, line6);
ctx.restore();
drawText((lang == "en" ? "BB" : "戦"), row1, line5 + newLength - 9);
var numBB = 0;
var maxBB = $("#colleDiv .divBB img.selected").length;
ctx.save();
ctx.fillStyle = "white";
$("#colleDiv .divBB img").each(function() {
var x = row1box + numBB * hexRectangleWidth;
var y = line5 - 15;
var img = document.getElementById(this.id);
drawHexagon(img, x, y, $(this).hasClass("selected"), false);
numBB++;
});
ctx.textAlign = "left";
ctx.font = "14px " + numberfont;
drawText(maxBB + "/" + numBB + " (" + (maxBB / numBB * 100).toFixed() + "%)", row1box + numBB * hexRectangleWidth + 8, line5);
ctx.restore();
drawText((lang == "en" ? "CV" : "航"), row1, line7 + newLength - 9);
var numCV = 0;
var maxCV = $("#colleDiv .divCV img.selected").length;
ctx.save();
ctx.fillStyle = "white";
$("#colleDiv .divCV img").each(function() {
var x = row1box + numCV * hexRectangleWidth;
var y = line7 - 15;
var img = document.getElementById(this.id);
drawHexagon(img, x, y, $(this).hasClass("selected"), false);
numCV++;
});
ctx.textAlign = "left";
ctx.font = "14px " + numberfont;
drawText(maxCV + "/" + numCV + " (" + (maxCV / numCV * 100).toFixed() + "%)", row1box + numCV * hexRectangleWidth + 8, line7);
ctx.restore();
drawText((lang == "en" ? "SS" : "潜"), row2, line8 + newLength - 9);
var numSS = 0;
var maxSS = $("#colleDiv .divSS img.selected").length;
ctx.save();
ctx.fillStyle = "white";
$("#colleDiv .divSS img").each(function() {
var x = row2box + numSS * hexRectangleWidth;
var y = line8 - 15;
var img = document.getElementById(this.id);
drawHexagon(img, x, y, $(this).hasClass("selected"), false);
numSS++;
});
ctx.textAlign = "left";
ctx.font = "14px " + numberfont;
drawText(maxSS + "/" + numSS + " (" + (maxSS / numSS * 100).toFixed() + "%)", row2box + numSS * hexRectangleWidth + 8, line8);
ctx.restore();
drawText((lang == "en" ? "AX" : "他"), row1, line9 + newLength - 9);
var numAX = 0;
var maxAX = $("#colleDiv .divAX img.selected").length;
ctx.save();
ctx.fillStyle = "white";
$("#colleDiv .divAX img").each(function() {
var x = row1box + numAX * hexRectangleWidth;
var y = line9 - 15;
var img = document.getElementById(this.id);
drawHexagon(img, x, y, $(this).hasClass("selected"), false);
numAX++;
});
ctx.textAlign = "left";
ctx.font = "14px " + numberfont;
drawText(maxAX + "/" + numAX + " (" + (maxAX / numAX * 100).toFixed() + "%)", row1box + numAX * hexRectangleWidth + 8, line9);
ctx.restore();
ctx.font = "12px " + textfont;
var shipBoxes = $("#colleDiv");
var chkShips = shipBoxes.find("img.selected").length;
var allShips = shipBoxes.find("img").length;
var ships = chkShips + "/" + allShips;
var shipPct = chkShips / allShips;
var barWidth = 300;
ctx.save();
ctx.strokeRect(progressrowbox, bottomLine - 10, barWidth, 8);
var grd = ctx.createLinearGradient(progressrowbox, 0, progressrowbox + barWidth, 0);
grd.addColorStop(0, "#A00000");
grd.addColorStop(0.33, "#FF9900");
grd.addColorStop(0.66, "#DDDD33");
grd.addColorStop(1, "#00A000");
ctx.fillStyle = grd;
ctx.fillRect(progressrowbox, bottomLine - 10, (barWidth * shipPct).toFixed(), 8);
ctx.restore();
ctx.font = "20px " + numberfont;
drawText(ships + " (" + (shipPct * 100).toFixed() + "%)", progressrowbox + barWidth, bottomLine - linebarwidth / 2, 3);
ctx.font = "12px " + textfont;
ctx.textAlign = "right";
drawText("Lv. " + (level.value ? level.value : "?"), c.width / 2, 25);
if (server != "Your Server") {
drawText(server.substring(server.indexOf(" ") + 1), c.width - 25, 25);
} else {
drawText((lang == "en" ? "Unknown Server" : "不明サーバ"), c.width - 25, 25);
}
ctx.textAlign = "left";
ctx.restore();
$("#loadingDiv").html("");
$("#loadingProgress").hide();
$("#buttons button").prop('disabled', false);
};
var drawRoom = function(roomY) {
var ratio = c.width / bg.clientWidth;
var activeFloor = document.getElementById("activeFloor");
var activeWall = document.getElementById("activeWall");
var activeDesk = document.getElementById("activeDesk");
var activeOutside = document.getElementById("activeOutside");
var activeWindow = document.getElementById("activeWindow");
var activeObject = document.getElementById("activeObject");
var activeChest = document.getElementById("activeChest");
ctx.globalAlpha = 1;
ratio = c.width / activeFloor.clientWidth;
if (activeFloor.complete)
ctx.drawImage(activeFloor, 0, 150 * ratio + roomY, c.width, activeFloor.clientHeight * ratio);
if (activeWall.complete)
ctx.drawImage(activeWall, 0, -125 * ratio + roomY, c.width, activeWall.clientHeight * ratio);
if (activeObject.complete)
ctx.drawImage(activeObject, 0, -125 * ratio + roomY, activeObject.clientWidth * ratio, activeObject.clientHeight * ratio);
if (activeOutside.complete)
ctx.drawImage(activeOutside, 210, -125 * ratio + roomY, activeOutside.clientWidth * ratio, activeOutside.clientHeight * ratio);
if (activeWindow.complete)
ctx.drawImage(activeWindow, 210, -125 * ratio + roomY, activeWindow.clientWidth * ratio, activeWindow.clientHeight * ratio);
var isNormalDesk = activeDesk.src.match(/(\d\d\d.?).png$/gm);
var deskOffset = null;
if (isNormalDesk) {
deskOffset = deskoffsetdb[isNormalDesk[0]];
}
if (deskOffset) {
ctx.drawImage(activeDesk, deskOffset.x, deskOffset.y + roomY + 7, activeDesk.clientWidth * ratio, activeDesk.clientHeight * ratio);
} else {
ctx.drawImage(activeDesk, 0, roomY + 7, activeDesk.clientWidth * ratio, activeDesk.clientHeight * ratio);
}
ctx.drawImage(activeChest, c.width - activeChest.clientWidth * ratio, -125 * ratio + roomY, activeChest.clientWidth * ratio, activeChest.clientHeight * ratio);
var fillTint = $("#tint-color").val();
ctx.fillStyle = fillTint ? fillTint : "#ffffff";
$("#loadingDiv").html("");
$("#loadingProgress").hide();
$("#buttons button").prop('disabled', false);
};
var drawText = function(text, posx, posy, width) {
ctx.save();
ctx.lineWidth = typeof width !== 'undefined' ? width : 2;
ctx.strokeText(text, posx, posy);
ctx.fillText(text, posx, posy);
ctx.restore();
};
var drawHexagon = function(img, x, y, checked, color) {
ctx.save();
ctx.beginPath();
ctx.moveTo(x + hexRadius, y);
ctx.lineTo(x + hexRectangleWidth, y + hexHeight);
ctx.lineTo(x + hexRectangleWidth, y + hexHeight + sideLength);
ctx.lineTo(x + hexRadius, y + hexRectangleHeight);
ctx.lineTo(x, y + sideLength + hexHeight);
ctx.lineTo(x, y + hexHeight);
ctx.closePath();
ctx.stroke();
ctx.fillStyle = color ? color : "white";
ctx.globalAlpha = $("#hexOpa").val() ? $("#hexOpa").val() : 0;
ctx.fill();
ctx.globalAlpha = 1;
ctx.clip();
if (img && checked) {
ctx.drawImage(img, x - centerx, y - centery, hexRectangleHeight * 5 / 4, hexRectangleHeight * 5 / 4);
}
ctx.restore();
}
var drawNewBadge = function() {
recalculateSides(22);
ctx.save();
ctx.strokeRect(35, 45, 100, 100);
var name = $("[name='name']")[0];
var alevel = $("[name='level']")[0];
var server = $("[name='server'] :selected").text();
var line1 = 45;
var line2 = line1 + sideLength * 1.5 + 8;
var line3 = line2 + sideLength * 1.5 + 8;
var line4 = line3 + sideLength * 1.5 + 8;
var row1 = 210;
var row1box = row1 + 15;
var row2 = row1 + hexRadius;
var row2box = row1box + hexRadius;
var row3 = row2 + hexRadius;
var row3box = row2box + hexRadius;
var row4 = row3 + hexRadius;
var row4box = row3box + hexRadius;
ctx.font = "20px " + textfont;
ctx.imageSmoothingEnabled = true;
ctx.fillStyle = 'white';
ctx.strokeStyle = 'black';
if (name.value) {
drawText(name.value, 20, 25, 3);
} else {
drawText((lang == "en" ? "Nameless Admiral" : "無名提督"), 20, 25, 3);
}
ctx.save();
ctx.font = "10px " + textfont;
ctx.globalCompositeOperation = "darker";
ctx.fillStyle = 'rgba(255, 255, 255, 0.25)';
ctx.strokeStyle = 'transparent';
var date = new Date();
drawText(date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + date.getDate(), 5, c.height - 5, 3);
ctx.restore();
ctx.font = "14px " + textfont;
ctx.textAlign = "right";
ctx.drawImage(document.getElementById("fleet1a"), row1 - 23, line1 + sideLength / 2 - 15);
ctx.drawImage(document.getElementById("fleet2a"), row2 - 23, line2 + sideLength / 2 - 15);
ctx.drawImage(document.getElementById("fleet3a"), row3 - 23, line3 + sideLength / 2 - 15);
ctx.drawImage(document.getElementById("fleet4a"), row4 - 23, line4 + sideLength / 2 - 15);
ctx.save();
ctx.fillStyle = "white";
for (var i = 0; i < 6; i++) {
var x = row1box + i * hexRectangleWidth;
var y = line1 - 15;
var img = document.getElementById(fleets[0][i]);
var level = fleetLevels[0][i];
drawHexagon(img, x, y, true);
if (img) {
ctx.font = "10px " + textfont;
ctx.textAlign = "left";
drawText(level, x, y + 8);
}
var x = row2box + i * hexRectangleWidth;
var y = line2 - 15;
var img = document.getElementById(fleets[1][i]);
var level = fleetLevels[1][i];
drawHexagon(img, x, y, true);
if (img) {
ctx.font = "10px " + textfont;
ctx.textAlign = "left";
drawText(level, x, y + 8);
}
var x = row3box + i * hexRectangleWidth;
var y = line3 - 15;
var img = document.getElementById(fleets[2][i]);
var level = fleetLevels[2][i];
drawHexagon(img, x, y, true);
if (img) {
ctx.font = "10px " + textfont;
ctx.textAlign = "left";
drawText(level, x, y + 8);
}
var x = row4box + i * hexRectangleWidth;
var y = line4 - 15;
var img = document.getElementById(fleets[3][i]);
var level = fleetLevels[3][i];
drawHexagon(img, x, y, true);
if (img) {