forked from Vultren/k2badge
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathkaini.min.js
executable file
·1 lines (1 loc) · 32.7 KB
/
kaini.min.js
1
let lang="en";var globalship=null,globalbg=null,globalavatar=null;let loader,tabManager;var k2={},colle={},shipDB={},fleets=[new Array(6),new Array(6),new Array(6),new Array(6)],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]],shipTypes={};function setCookie(e,t,a){var l=a?"; domain="+a:"";document.cookie=e+"="+encodeURIComponent(t)+"; max-age=31536000; path=/"+l}function getCookie(e){for(var t=e+"=",a=document.cookie.split(";"),l=0;l<a.length;l++){for(var i=a[l];" "==i.charAt(0);)i=i.substring(1,i.length);if(0==i.indexOf(t))return decodeURIComponent(i.substring(t.length,i.length))}return null}function store(e,t){storage?localStorage.setItem(e,t):setCookie(e,t)}function restore(e){var t=null;return storage&&(t=localStorage.getItem(e))?t:getCookie(e)}function getBase64Image(e){var t=document.createElement("canvas");return t.width=e.width,t.height=e.height,t.getContext("2d").drawImage(e,0,0),t.toDataURL("image/png")}var storage=function(){var e,t,a=new Date;try{return(e=window.localStorage).setItem(a,a),t=e.getItem(a)==a,e.removeItem(a),t&&e}catch(e){}}();$(document).ready(function(){$(".shipClass").each(function(){for(var e=$(this).find("input").length,t=new Array(e);e--;)t[e]=!1;k2[this.id]=t});var e={},t=0,a=0,l={},i=0,n={"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}},s=document.getElementById("result"),o=s.getContext("2d"),r=24,d=Math.sin(.523598776)*r,c=Math.cos(.523598776)*r,h=r+2*d,g=2*c,p=(5*h/4-g)/2,v=(5*h/4-h)/2+5,m="'Ubuntu', 'メイリオ', Times, serif",f="'Exo', 'メイリオ', Times, serif",u=function(e){r=e,d=Math.sin(.523598776)*r,c=Math.cos(.523598776)*r,p=(5*(h=r+2*d)/4-(g=2*c))/2,v=(5*h/4-h)/2+5},b=function(){($(this).hasClass("abyss")||(fleets[t][a]=$(this).prev("img").attr("id"),$("#fleets .chosen").html('<img style="height:50px; width:50px;" src="'+$(this).prev("img").attr("src")+'"/>')),0==t&&0==a)&&($(this).hasClass("damaged")||$(".damaged").removeClass("damaged"),$(this).toggleClass("damaged"),$(".flagship").removeClass("flagship"),$(this).prev("img").toggleClass("flagship"),i=shipDB[$(this).prev("img").attr("id").substring(4)]?shipDB[$(this).prev("img").attr("id").substring(4)].rarity:0,y("fleetFlagshipChange"))},y=function(e){if(console.log(e),$("#loadingDiv").html("Rendering..."),$("#buttons button").prop("disabled",!0),$("#save").prop("disabled",!0),o.clearRect(0,0,s.width,s.height),o.save(),o.fillStyle="#666",o.fillRect(0,0,s.width,s.height),$("#useBG").prop("checked"))S("displayBadge"!=$("#buttonToggles .active").attr("id")?132:parseInt(document.getElementById("roomY").value)),o.globalAlpha=.33,o.fillRect(0,0,s.width,s.height);else{var t=document.getElementById("bg"),a=$("#bgStretch").prop("checked"),l=$("#bgX").val()||0,i=$("#bgY").val()||0,n=$("#bgZ").val()||0;o.drawImage(t,l,i,a?s.width:t.width*(n/100),a?s.height:t.height*(n/100))}o.restore(),o.strokeRect(0,0,s.width,s.height),w()},k=function(e,t){var a=$("#avatar"),n=$(".flagship")[0]?$(".flagship")[0].id.substring(4):null,r=!1;n&&$("#hit"+n).hasClass("damaged")&&(r=!0);var d=$(".flagship").parent().length>0?$(".flagship").parent().attr("class"):null;if(null!=globalship)(c=new Image).onload=function(){var a=0,l=0;a+=document.getElementById("customX").value?parseInt(document.getElementById("customX").value):0,l+=document.getElementById("customY").value?parseInt(document.getElementById("customY").value):0,o.save();var i=document.getElementById("customZ").value?parseInt(document.getElementById("customZ").value)+100:100;i/=100,o.translate(s.width-7*c.width/8+a,s.height/2-c.height/5+l),o.translate(c.width/2,c.height/2),o.scale(i,i),o.drawImage(c,-c.width/2,-c.height/2),o.restore(),e(),t||C(o)},c.onerror=e,c.src=globalship;else if(n){var c;(c=new Image).onload=function(){var d=0,h=0;0==i&&l[n]?r&&l[n].offset2?(d=l[n].offset2.x,h=l[n].offset2.y):(d=l[n].offset.x,h=l[n].offset.y):shipDB[n]&&(r&&shipDB[n].offset2?(d=shipDB[n].offset2.x,h=shipDB[n].offset2.y):shipDB[n].offset&&(d=shipDB[n].offset.x,h=shipDB[n].offset.y)),d+=document.getElementById("customX").value?parseInt(document.getElementById("customX").value):0,h+=document.getElementById("customY").value?parseInt(document.getElementById("customY").value):0,o.save();var g=document.getElementById("customZ").value?parseInt(document.getElementById("customZ").value)+100:100;g>=50&&g<=150?(g/=100,o.translate(s.width-7*c.width/8+d,s.height/2-c.height/5+h),o.translate(c.width/2,c.height/2),o.scale(g,g),o.drawImage(c,-c.width/2,-c.height/2)):o.drawImage(c,s.width-7*c.width/8+d,s.height/2-c.height/5+h),o.restore(),e(),t||(a.attr("src")?C(o):x(o,n,i))},c.onerror=e,c.src="full/"+d+"/"+n+(r?"x":"")+".png"}else e(),a.attr("src")&&!t&&C(o)},x=function(e,t,a){a=document.getElementById("r"+a);var l=document.getElementById("icon"+t);e.save(),e.fillStyle="black",e.fillRect(35,.1875*s.height,100,100),e.strokeRect(35,.1875*s.height,100,100),e.restore(),e.drawImage(a,30,5,100,100,35,.1875*s.height,100,100),e.drawImage(l,35,.1875*s.height)},C=function(e){var t=document.getElementById("avatar");e.save(),e.fillStyle="transparent",e.fillRect(35,.1875*s.height,100,100),e.strokeRect(35,.1875*s.height,100,100),e.restore(),e.drawImage(t,35,.1875*s.height,100,100)},w=function(){var e=$("#buttonToggles .active").attr("id");"displayBadge"==e?$("#k2").prop("checked")?k(A):k(E):"displayPoster"==e?k(I,!0):"displayRoom"==e&&S(132)},I=function(){u(10),o.save();var e=$("[name='name']")[0],t=$("[name='level']")[0],a=$("[name='server'] :selected").text(),l=($("#useBlue").prop("checked"),10*(2*Math.sin(Math.PI/2)+1)),i=s.height-10,n=40+c,r=55+c;o.font="20px "+m,o.imageSmoothingEnabled=!0,o.fillStyle="white",o.strokeStyle="black",e.value?D(e.value,20,25,3):D("en"==lang?"Nameless Admiral":"無名提督",20,25,3),o.save(),o.font="10px "+m,o.globalCompositeOperation="lighter",o.fillStyle="rgba(255, 255, 255, 0.25)",o.strokeStyle="transparent";var d=new Date;D(d.getFullYear()+"-"+(d.getMonth()+1)+"-"+d.getDate(),5,s.height-5,3),o.restore(),o.font="14px "+m,o.textAlign="right",D("en"==lang?"DE":"海",40,56);var h=0,p=$("#colleDiv .divDE img.selected").length;o.save(),o.fillStyle="white",$("#colleDiv .divDE img").each(function(e){var t=55+h*g,a=Math.floor(h/40)*+l/2+55-15,i=document.getElementById(this.id);B(i,t,a,$(this).hasClass("selected"),!1),h++}),o.textAlign="left",o.font="14px "+f,D(p+"/"+h+" ("+(p/h*100).toFixed()+"%)",55+h*g+8,55),o.restore();var v=55+l/2+l/4;o.font="14px "+m,o.textAlign="right",D("en"==lang?"DD":"駆",n,v+10-9);var b=0,y=$("#colleDiv .divDD img.selected").length;o.save(),o.fillStyle="white",$("#colleDiv .divDD img").each(function(e){var t=r+b%40*g;Math.floor(b/40%2)>0&&(t=r+(40-b%40)*g-c);var a=Math.floor(b/40)*+l/2+v-15,i=document.getElementById(this.id);B(i,t,a,$(this).hasClass("selected"),!1),b++}),o.textAlign="left",o.font="14px "+f,D(y+"/"+b+" ("+(y/b*100).toFixed()+"%)",r+40*g+8,v),o.restore();var k=v+l+l/4+8*Math.floor(b/40),x=k+l/2+l/4,C=x+l/2+l/4,w=C+l/2+l/4,I=w+l/2+l/4,S=I+l/2+l/4,A=S+l/2+l/4;D("en"==lang?"CL":"軽巡",40,k+10-9);var E=0,O=$("#colleDiv .divCL img.selected").length;o.save(),o.fillStyle="white",$("#colleDiv .divCL img").each(function(){var e=55+E*g,t=k-15,a=document.getElementById(this.id);B(a,e,t,$(this).hasClass("selected"),!1),E++}),o.textAlign="left",o.font="14px "+f,D(O+"/"+E+" ("+(O/E*100).toFixed()+"%)",55+E*g+8,k),o.restore(),D("en"==lang?"CA":"重巡",n,x+10-9);var L=0,F=$("#colleDiv .divCA img.selected").length;o.save(),o.fillStyle="white",$("#colleDiv .divCA img").each(function(){var e=r+L*g,t=x-15,a=document.getElementById(this.id);B(a,e,t,$(this).hasClass("selected"),!1),L++}),o.textAlign="left",o.font="14px "+f,D(F+"/"+L+" ("+(F/L*100).toFixed()+"%)",55+L*g+8,x),o.restore(),D("en"==lang?"CVL":"軽母",n,w+10-9);var R=0,T=$("#colleDiv .divCVL img.selected").length;o.save(),o.fillStyle="white",$("#colleDiv .divCVL img").each(function(){var e=r+R*g,t=w-15,a=document.getElementById(this.id);B(a,e,t,$(this).hasClass("selected"),!1),R++}),o.textAlign="left",o.font="14px "+f,D(T+"/"+R+" ("+(T/R*100).toFixed()+"%)",r+R*g+8,w),o.restore(),D("en"==lang?"BB":"戦",40,C+10-9);var j=0,M=$("#colleDiv .divBB img.selected").length;o.save(),o.fillStyle="white",$("#colleDiv .divBB img").each(function(){var e=55+j*g,t=C-15,a=document.getElementById(this.id);B(a,e,t,$(this).hasClass("selected"),!1),j++}),o.textAlign="left",o.font="14px "+f,D(M+"/"+j+" ("+(M/j*100).toFixed()+"%)",55+j*g+8,C),o.restore(),D("en"==lang?"CV":"航",40,I+10-9);var N=0,W=$("#colleDiv .divCV img.selected").length;o.save(),o.fillStyle="white",$("#colleDiv .divCV img").each(function(){var e=55+N*g,t=I-15,a=document.getElementById(this.id);B(a,e,t,$(this).hasClass("selected"),!1),N++}),o.textAlign="left",o.font="14px "+f,D(W+"/"+N+" ("+(W/N*100).toFixed()+"%)",55+N*g+8,I),o.restore(),D("en"==lang?"SS":"潜",n,S+10-9);var Y=0,H=$("#colleDiv .divSS img.selected").length;o.save(),o.fillStyle="white",$("#colleDiv .divSS img").each(function(){var e=r+Y*g,t=S-15,a=document.getElementById(this.id);B(a,e,t,$(this).hasClass("selected"),!1),Y++}),o.textAlign="left",o.font="14px "+f,D(H+"/"+Y+" ("+(H/Y*100).toFixed()+"%)",r+Y*g+8,S),o.restore(),D("en"==lang?"AX":"他",40,A+10-9);var P=0,U=$("#colleDiv .divAX img.selected").length;o.save(),o.fillStyle="white",$("#colleDiv .divAX img").each(function(){var e=55+P*g,t=A-15,a=document.getElementById(this.id);B(a,e,t,$(this).hasClass("selected"),!1),P++}),o.textAlign="left",o.font="14px "+f,D(U+"/"+P+" ("+(U/P*100).toFixed()+"%)",55+P*g+8,A),o.restore(),o.font="12px "+m;var X=$("#colleDiv"),J=X.find("img.selected").length,Z=X.find("img").length,G=J+"/"+Z,V=J/Z;o.save(),o.strokeRect(540,i-10,300,8);var _=o.createLinearGradient(540,0,840,0);_.addColorStop(0,"#A00000"),_.addColorStop(.33,"#FF9900"),_.addColorStop(.66,"#DDDD33"),_.addColorStop(1,"#00A000"),o.fillStyle=_,o.fillRect(540,i-10,(300*V).toFixed(),8),o.restore(),o.font="20px "+f,D(G+" ("+(100*V).toFixed(1)+"%)",840,i-l/2,3),o.font="12px "+m,o.textAlign="right",D("Lv. "+(t.value?t.value:"?"),s.width/2,25),D("Your Server"!=a?a.substring(a.indexOf(" ")+1):"en"==lang?"Unknown Server":"不明サーバ",s.width-25,25),o.textAlign="left",o.restore(),$("#loadingDiv").html(""),$("#loadingProgress").hide(),$("#buttons button").prop("disabled",!1)},S=function(e){var t=(s.width,bg.clientWidth),a=document.getElementById("activeFloor"),l=document.getElementById("activeWall"),i=document.getElementById("activeDesk"),r=document.getElementById("activeOutside"),d=document.getElementById("activeWindow"),c=document.getElementById("activeObject"),h=document.getElementById("activeChest");o.globalAlpha=1,t=s.width/a.clientWidth,a.complete&&o.drawImage(a,0,150*t+e,s.width,a.clientHeight*t),l.complete&&o.drawImage(l,0,-125*t+e,s.width,l.clientHeight*t),c.complete&&o.drawImage(c,0,-125*t+e,c.clientWidth*t,c.clientHeight*t),r.complete&&o.drawImage(r,210,-125*t+e,r.clientWidth*t,r.clientHeight*t),d.complete&&o.drawImage(d,210,-125*t+e,d.clientWidth*t,d.clientHeight*t);var g=i.src.match(/(\d\d\d.?).png$/gm),p=null;g&&(p=n[g[0]]),p?o.drawImage(i,p.x,p.y+e+7,i.clientWidth*t,i.clientHeight*t):o.drawImage(i,0,e+7,i.clientWidth*t,i.clientHeight*t),o.drawImage(h,s.width-h.clientWidth*t,-125*t+e,h.clientWidth*t,h.clientHeight*t);var v=$("#tint-color").val();o.fillStyle=v||"#ffffff",$("#loadingDiv").html(""),$("#loadingProgress").hide(),$("#buttons button").prop("disabled",!1)},D=function(e,t,a,l){o.save(),o.lineWidth=void 0!==l?l:2,o.strokeText(e,t,a),o.fillText(e,t,a),o.restore()},B=function(e,t,a,l,i){o.save(),o.beginPath(),o.moveTo(t+c,a),o.lineTo(t+g,a+d),o.lineTo(t+g,a+d+r),o.lineTo(t+c,a+h),o.lineTo(t,a+r+d),o.lineTo(t,a+d),o.closePath(),o.stroke(),o.fillStyle=i||"white",o.globalAlpha=$("#hexOpa").val()?$("#hexOpa").val():0,o.fill(),o.globalAlpha=1,o.clip(),e&&l&&o.drawImage(e,t-p,a-v,5*h/4,5*h/4),o.restore()},A=function(){u(22),o.save(),o.strokeRect(35,.1875*s.height,100,100);var e=$("[name='name']")[0],t=($("[name='level']")[0],$("[name='server'] :selected").text()),a=45+1.5*r+8,l=a+1.5*r+8,i=l+1.5*r+8,n=210+c,d=225+c,h=n+c,p=d+c,v=h+c,f=p+c;o.font="20px "+m,o.imageSmoothingEnabled=!0,o.fillStyle="white",o.strokeStyle="black",e.value?D(e.value,20,25,3):D("en"==lang?"Nameless Admiral":"無名提督",20,25,3),o.save(),o.font="10px "+m,o.globalCompositeOperation="darker",o.fillStyle="rgba(255, 255, 255, 0.25)",o.strokeStyle="transparent";var b=new Date;D(b.getFullYear()+"-"+(b.getMonth()+1)+"-"+b.getDate(),5,s.height-5,3),o.restore(),o.font="14px "+m,o.textAlign="right",o.drawImage(document.getElementById("fleet1a"),187,45+r/2-15),o.drawImage(document.getElementById("fleet2a"),n-23,a+r/2-15),o.drawImage(document.getElementById("fleet3a"),h-23,l+r/2-15),o.drawImage(document.getElementById("fleet4a"),v-23,i+r/2-15),o.save(),o.fillStyle="white";for(var y=0;y<6;y++){var k=225+y*g,x=30,C=document.getElementById(fleets[0][y]),w=fleetLevels[0][y];B(C,k,x,!0),C&&(o.font="10px "+m,o.textAlign="left",D(w,k,x+8));k=d+y*g,x=a-15,C=document.getElementById(fleets[1][y]),w=fleetLevels[1][y];B(C,k,x,!0),C&&(o.font="10px "+m,o.textAlign="left",D(w,k,x+8));k=p+y*g,x=l-15,C=document.getElementById(fleets[2][y]),w=fleetLevels[2][y];B(C,k,x,!0),C&&(o.font="10px "+m,o.textAlign="left",D(w,k,x+8));k=f+y*g,x=i-15,C=document.getElementById(fleets[3][y]),w=fleetLevels[3][y];B(C,k,x,!0),C&&(o.font="10px "+m,o.textAlign="left",D(w,k,x+8))}o.restore(),o.font="12px "+m,o.textAlign="center",D("Lv. "+(w.value?w.value:"?"),85,i+5),"------"!==t?D("en"==lang?t.substring(t.indexOf(" ")+1):t,85,i+19):D("en"==lang?"Unknown Server":"不明サーバ",85,i+22),o.textAlign="left",o.restore(),$("#loadingDiv").html(""),$("#buttons button").prop("disabled",!1)},E=function(){u(16),o.save(),o.strokeRect(35,.1875*s.height,100,100);var e=$("[name='name']")[0],t=$("[name='level']")[0],a=$("[name='server'] :selected").text(),l=$("#useBlue").prop("checked"),i=16*(2*Math.sin(Math.PI/2)+1),n=10,r=!0;o.font="20px "+m,o.imageSmoothingEnabled=!0,o.fillStyle="white",o.strokeStyle="black",e.value?D(e.value,20,25,3):D("en"==lang?"Nameless Admiral":"無名提督",20,25,3),o.save(),o.font="10px "+m,o.globalCompositeOperation="lighter",o.fillStyle="rgba(255, 255, 255, 0.25)",o.strokeStyle="transparent";var d=new Date;for(var h in D(d.getFullYear()+"-"+(d.getMonth()+1)+"-"+d.getDate(),5,s.height-5,3),o.restore(),shipTypes)if(!(0==$("#"+h.toLowerCase()).find("[type='checkbox']").length||["SS","AX"].indexOf(h)>-1)){var p=shipTypes[h],v=175,b=v+15,y=(h.toLowerCase(),0),k=$("#"+h.toLowerCase()).find(".blueprint").not(".kai").length,x=$("#"+h.toLowerCase()).find("[type='checkbox']").length,C=$("#"+h.toLowerCase()).find("[type='checkbox']:checked").length;if(k>0&&l){x-=k;var w=$("#"+h.toLowerCase()).find(".blueprint").not(".kai").find("[type='checkbox']:checked").length;C=Math.max(0,C-w)}var I=Math.min(12,x);1==Math.floor((x-1)/12%2)&&(r=!r),x/12>1&&(n+=i*Math.floor(x/12)/2),r&&(v+=c,b+=c),o.font="14px "+m,o.textAlign="right",D("en"==lang?p[lang]:p.jp,v,n+16-9),o.save(),o.fillStyle="white",$($("#"+h.toLowerCase()).find("[type='checkbox']").get().reverse()).each(function(e){var t=$(this).parent().parent(),a=x-y-1;if(!l||!t.hasClass("blueprint")||t.hasClass("kai")){var s=b+a%12*g;Math.floor(a/12%2)>0&&(s=b+(12-(a+1)%12)*g-c);var o=Math.floor(a/12)*-i/2+n-15,r=document.getElementById("icon"+this.id),d=t.hasClass("blueprint")?t.hasClass("prototype")?"pink":"lightblue":"white";B(r,s,o,this.checked,d),y++}}),o.textAlign="left",o.font="14px "+f,D(C+"/"+y,b+I*g+8,n+16-9),o.restore(),n+=i/2,r=!r}var S=($("#cv").find("[type='checkbox']").length-(l?$("#cv").find(".blueprint").not(".kai").length:0)+3)*g,A=0,E=$("#ss").find("[type='checkbox']:checked").length;k=0;D("en"==lang?"SS":"潜",190+S,(n-=i)+i/2+16-9),o.save(),o.fillStyle="white",$("#ss").find("[type='checkbox']").each(function(){var e=$(this).parent().parent();if(l&&e.hasClass("blueprint")&&!e.hasClass("kai"))this.checked&&e.hasClass("blueprint")&&k++;else{var t=S+205+A*g,a=n-15+i/2,s=document.getElementById("icon"+this.id),o=$(this).parent().parent().find("label").hasClass("blueprint")?"lightblue":"white";B(s,t,a,this.checked,o),A++}}),o.textAlign="left",o.font="14px "+f,D(E-k+"/"+A,S+205+A*g+8,n+16-9+i/2),o.restore();var O=($("#cvl").find("[type='checkbox']").length-(l?$("#cvl").find(".blueprint").not(".kai").length:0)+3.5)*g,L=163+c,F=L+c;D("en"==lang?"AX":"その他",L+O,n+16-9);var R=0,T=$("#ax").find("[type='checkbox']:checked").length;k=0;o.save(),o.fillStyle="white",$("#ax").find("[type='checkbox']").each(function(){var e=$(this).parent().parent();if(l&&e.hasClass("blueprint")&&!e.hasClass("kai"))this.checked&&e.hasClass("blueprint")&&k++;else{var t=O+F+R*g,a=n-15,i=document.getElementById("icon"+this.id),s=$(this).parent().parent().find("label").hasClass("blueprint")?"lightblue":"white";B(i,t,a,this.checked,s),R++}}),o.textAlign="left",o.font="14px "+f,D(T-k+"/"+R,O+F+R*g+8,n+16-9),o.restore(),o.font="12px "+m;var j,M,N,W,Y,H,P=$(".shipOptions"),U=P.find(".blueprint").length-P.find(".kai").length,X=P.find(".blueprint :checked").length-P.find(".kai :checked").length,J=l?P.find("[type='checkbox']:checked").length-X:P.find("[type='checkbox']:checked").length,Z=l?P.find("[type='checkbox']").length-U:P.find("[type='checkbox']").length;N=20,W=(j=J)+"/"+(M=Z),Y=j/M,H=o.createLinearGradient(540,0,840,0),o.save(),o.strokeRect(540,s.height-N,300,8),H.addColorStop(0,"#A00000"),H.addColorStop(.33,"#FF9900"),H.addColorStop(.66,"#DDDD33"),H.addColorStop(1,"#00A000"),o.fillStyle=H,o.fillRect(540,s.height-N,(300*Y).toFixed(),8),o.restore(),o.font="20px "+f,D(W+" ("+(100*Y).toFixed(1)+"%)",840,s.height-25,3),o.font="12px "+m,o.textAlign="center",D("Lv. "+(t.value?t.value:"?"),85,173),"------"!==a?D("en"==lang?a.substring(a.indexOf(" ")+1):a,85,187):D("en"==lang?"Unknown Server":"不明サーバ",85,190),o.textAlign="left",o.restore(),$("#loadingDiv").html(""),$("#loadingProgress").hide(),$("#buttons button").prop("disabled",!1)},O=function(){for(var e in colle)$("#kore"+e).addClass("selected");for(var e in $(".flagship").removeClass("flagship"),$(".damaged").removeClass("damaged"),fleets[0]){var t=fleets[0][e],a=t.substring(4);if(null!==t&&""!==t){0==e&&($("#"+t).addClass("flagship"),i=shipDB[a]?shipDB[a].rarity:0);var l=parseInt(e)+1;$("#slot"+l).html('<img style="height:50px; width:50px;" src="icons/'+shipDB[a].type+"/"+a+'.png"/>')}}for(var e in fleetLevels[0]){var n=parseInt(fleetLevels[0][e]);if(n&&n>0){l=parseInt(e)+1;$("#level"+l).val(n)}}y("initial")};(loader=new DataLoader(lang)).initData(function(){var n=loader.getMstIdTable();if(shipTypes=loader.getShipTypes(),shipDB=loader.getShips(),l=loader.getAbyssals(),implications=loader.getImplications(),(tabManager=new TabManager(loader)).loadTabs(),apiMode){if(importName&&$("input[name='name']").val(importName),importLvl&&$("input[name='level']").val(importLvl),importServer&&$("select[name='server']").val(importServer),importShips){importShips=JSON.parse(importShips);var r={},d={};for(var c in importShips)if(importShips[c]in n&&(r[u=n[importShips[c]]]=!0,u in implications))for(var h in implications[u])r[implications[u][h]]=!0;if(importK2){for(var c in r)if((u=$("#"+c)).length>0){var g=shipDB[c].type;d[g]||(d[g]={}),d[g][c]=!0,$("#"+c).prop("checked",!0)}k2=d}importColle&&(colle=r)}if(importFleets){importFleets=JSON.parse(importFleets);var p=[new Array(6),new Array(6),new Array(6),new Array(6)],v=[[1,1,1,1,1,1],[1,1,1,1,1,1],[1,1,1,1,1,1],[1,1,1,1,1,1]];for(var m in importFleets)for(var c in importFleets[m])importFleets[m][c]&&null!=importFleets[m][c]&&n[importFleets[m][c].id]&&(p[m][c]="icon"+n[importFleets[m][c].id],v[m][c]=importFleets[m][c].lvl);fleets=p,fleetLevels=v}}o.strokeRect(0,0,s.width,s.height),o.imageSmoothingEnabled=!0,o.mozImageSmoothingEnabled=!0,o.webkitImageSmoothingEnabled=!0;c=0;for(var f in shipDB){var u;if((u=shipDB[f]).name){var k=$('<img class="tooltip" title="'+u.full+'" src="icons/'+u.type+"/"+f+'.png" id="icon'+f+'"></img>'),x=$('<span id="hit'+f+'">破</span>');k.on("load",function(){c++,$("#loadingProgress").html(c+"/"+Object.keys(shipDB).length),c==Object.keys(shipDB).length&&O()}),0==$(".shipList [data-name='"+u.name+"']").length&&$(".div"+u.type).append("<div><label>"+u.name.replace(new RegExp("_","g")," ")+'</label><div data-name="'+u.name+'" class="'+u.type+'"></div></div>'),u.unique&&$("#colleDiv [data-name='"+u.name+"']").append('<img title="'+u.full+'"alt="full/FinalBoss.png" src="icons/'+u.type+"/"+f+'.png" id="kore'+f+'"></img>').append(x),$("#avatars [data-name='"+u.name+"']").append(k),0!=u.damageable&&$("#avatars [data-name='"+u.name+"']").append(x)}}$("#colleDiv .shipClasses").each(function(e){var t=$("<div class='colleAll'><input id='selectAll-"+e+"' type='checkbox'/><label for='selectAll-"+e+"'>"+("jp"==lang?"全て選択":"cn"==lang||"tw"==lang?"全選":"Select All")+"</label></div>");$(this).append(t),t.find("input").on("change",function(){var e=$(this).parent().parent().find("img");for(var t in e.toArray()){var a=$(e[t]);colle[a.attr("id").substring(4)]=this.checked,a.toggleClass("selected",this.checked)}y("colleChangeAll")})}),$(".tooltip").tooltipster(),$("#fleetSelect div").on("click",function(){$("#fleetSelect .chosen").removeClass("chosen"),$(this).toggleClass("chosen");var e=this.id.substring(5);for(var a in t=parseInt(e)-1,$("#fleets div").html(""),$("#fleetLevels input").val(1),fleets[t]){var l=fleets[t][a],i=parseInt(a)+1;null!==l&&""!==l&&$("#slot"+i).html('<img style="height:50px; width:50px;" src="'+$("#"+l).attr("src")+'"/>'),$("#level"+i).val(fleetLevels[t][a])}}),$("#fleets div").on("click",function(){$("#fleets .chosen").removeClass("chosen"),$(this).toggleClass("chosen");var e=this.id.substring(4);a=parseInt(e)-1}),$("#fleetLevels input").on("change",function(){var e=this.id.substring(5);a=parseInt(e)-1,fleetLevels[t][a]=this.value,y("fleetLevelChange")}),$("#avatars img").on("click",function(){$(this).hasClass("abyss")||(fleets[t][a]=$(this).attr("id"),$("#fleets .chosen").html('<img style="height:50px; width:50px;" src="'+$(this).attr("src")+'"/>')),0==t&&0==a&&($(".flagship").removeClass("flagship"),$(".damaged").removeClass("damaged"),$(this).toggleClass("flagship"),i=shipDB[this.id.substring(4)]?shipDB[this.id.substring(4)].rarity:0),y("fleetShipChange")}),$("#colleDiv img").on("click",function(){colle[$(this).attr("id").substring(4)]&&$(this).hasClass("selected")?delete colle[$(this).attr("id").substring(4)]:$(this).hasClass("selected")||(colle[$(this).attr("id").substring(4)]=!0),$(this).toggleClass("selected"),y("colleChange")}),$("#avatars span").on("click",b),$(".shipList > label").on("click",function(){$(this).next("div").slideToggle()}),$(".shipClasses label").on("click",function(){$(this).next("div").toggle()}),$("#removeSlot").on("click",function(){0==t&&0==a&&($(".damaged").removeClass("damaged"),$(".flagship").removeClass("flagship"),i=0),fleets[t][a]=null,$("#fleets .chosen").html(""),y("fleetRemoveSlot")}),$(".shipOptions input[type='checkbox']").on("change",function(){y("kainiShipChange")}),$("#selectAll").on("change",function(){this.checked?$(".shipOptions [type='checkbox']").prop("checked",!0):$(".shipOptions [type='checkbox']").prop("checked",!1),y("kainiSelectAll")}),$("#displayBadge").on("click",function(){$("#buttonToggles button").removeClass("active"),$(this).addClass("active"),s.width=850,s.height=320,y("displayBadge")}),$("#displayRoom").on("click",function(){$("#buttonToggles button").removeClass("active"),$(this).addClass("active"),s.width=850,s.height=510,S(132)}),$("#displayPoster").on("click",function(){$("#buttonToggles button").removeClass("active"),$(this).addClass("active"),s.width=850,s.height=510,y("displayPoster")}),$("#generate").on("click",y),$("#Floor,#Wall,#Desk,#Object,#Chest,#Window").on("change",function(){var t=this.id;delete e[t];var a=$("#active"+t),l=$(this).find(":checked").val();a.off("load"),a.attr("src","furniture/"+this.id.toLowerCase()+"/"+l+".png"),a.prop("complete")?$.isEmptyObject(e)&&"Window"!=t&&($("#buttons button").prop("disabled",!1),$("#loadingDiv").html(""),$("#displayRoom").hasClass("on")?S(132):y("furnitureChangeCache")):(e[t]=l,$("#buttons button").prop("disabled",!0),$("#loadingDiv").html("Rendering..."),a.on("load",function(){delete e[t],$.isEmptyObject(e)&&($("#buttons button").prop("disabled",!1),$("#loadingDiv").html(""),$("#displayRoom").hasClass("on")?S(132):y("furnitureChangeLoaded"))}).error(function(){delete e[t],$.isEmptyObject(e)&&($("#buttons button").prop("disabled",!1),$("#loadingDiv").html("Couldn't find this furniture's image."))})),"Window"==t&&$("#Outside").on("change")}),$("#Outside").on("change",function(t){delete e.Outside;var a=$("#activeOutside"),l=$("#Outside").find(":checked"),i=$("#Window").find(":checked").attr("data-pType"),n="furniture/outside/"+(l.val()+i)+".png";a.off("load"),a.attr("src",n),a.prop("complete")&&$.isEmptyObject(e)?($("#buttons button").prop("disabled",!1),$("#loadingDiv").html(""),$("#displayRoom").hasClass("on")?S(132):y("furnitureOutsideCache")):a.on("load",function(){delete e.Outside,$.isEmptyObject(e)&&($("#buttons button").prop("disabled",!1),$("#loadingDiv").html(""),$("#displayRoom").hasClass("on")?S(132):y("furnitureOutsideLoaded"))})}),$("#ttkInfo input[type='text'],#ttkInfo input[type='number']").on("blur",function(){y("ttkInfo")}),$("#ttkInfo select").on("click",function(){y("ttkServer")}),$("#ttkInfo input[type='checkbox']").on("click",function(){y("ttkLevel")}),$("#loadAbyss").on("click",function(){$("#loadAbyss").remove(),$("#avatars .hidden").removeClass("hidden"),$.ajax({dataType:"json",timeout:1e4,url:"en"==lang?"db2.json?v=13":"db2j.json?v=13",success:function(e){l=e,$("#loadingDiv").html("Loading images: "),$("#loadingProgress").show().html("0/"+Object.keys(e).length);var t=0;for(var a in l){var n=e[a];if(n.name){var s=$('<img class="abyss tooltip2" title="'+n.full+'" src="icons/'+n.type+"/"+a+'.png" id="icon'+a+'"></img>'),o=$('<span class="abyss" id="hit'+a+'">破</span>');s.on("load",function(){t++,$("#loadingProgress").html(t+"/"+Object.keys(e).length),t==Object.keys(e).length&&($("#loadingDiv").html(""),$("#loadingProgress").hide())}),s.on("click",function(){$(".flagship").removeClass("flagship"),$(".damaged").removeClass("damaged"),$(this).toggleClass("flagship"),i=0,y("fleetShipChangeAbyss")}),0==$(".shipList [data-name='"+n.name+"']").length&&$(".div"+n.type).append("<div><label>"+n.name.replace(new RegExp("_","g")," ")+'</label><div data-name="'+n.name+'" class="'+n.type+'"></div></div>'),$("#avatars [data-name='"+n.name+"']").append(s),n.damageable&&$("#avatars [data-name='"+n.name+"']").append(o)}}$("#avatars span").unbind("click").on("click",b),$(".tooltip2").tooltipster()},error:function(){$("#loadingDiv").html("Can't find Abyssal DB, please contact Harvestasya or Nya-chan on Github")}})}),$("#save").on("click",function(){!function(){var e=$(".furnitureClass input:checked").toArray(),t={};for(var a in e)t[e[a].name]=e[a].id;$(".shipClass").each(function(){var e=this.id,t=$(this).find("input"),a={};t.each(function(e){a[this.id]=$(this).prop("checked")}),k2[e]=a}),store("ttkName",$("input[name='name']").val()),store("ttkLvl",$("input[name='level']").val()),store("ttkServer",$("select[name='server']").val()),store("ttkFurn",Base64.encode(JSON.stringify(t))),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").length>0&&!$($(".damaged")[0]).hasClass("abyss")),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)}(),this.setAttribute("disabled","disabled")}),$("#load").on("click",function(){!function(){$(".flagship").removeClass("flagship"),$(".damaged").removeClass("damaged"),$("input[name='name']").val(restore("ttkName")),$("input[name='level']").val(restore("ttkLvl"));var e=restore("bgCam");e=e?JSON.parse(e):[0,0,100],$("#bgX").val(e[0]),$("#bgY").val(e[1]),$("#bgZ").val(e[2]),$("#useBG").prop("checked",!restore("bgUse")||"true"==restore("bgUse"));var t=restore("secretaryCam");t=t?JSON.parse(t):[0,0,0],$("#customX").val(t[0]),$("#customY").val(t[1]),$("#customZ").val(t[2]),$("#roomY").val(restore("ttkFurnCam")||0),$("#tint-color").val(restore("ttkTint")||"#ffffff"),$("#hexOpa").val(restore("ttkHexOpa")||.33),$("#hexOpa").val(restore("ttkHexOpa")||.33),$("#bgStretch").prop("checked",!restore("bgStretch")||"true"==restore("bgStretch")),"null"!=(globalbg=restore("bg"))&&$("#bg").attr("src",globalbg),"null"!=(globalavatar=restore("avatar"))?$("#avatar").attr("src",globalavatar):$("#avatar").removeAttr("src");var a=restore("ttkServer");"null"!=a&&$("select[name='server']").val(a);var l=restore("k2");l=l?JSON.parse(Base64.decode(l)):null;var n=restore("colle");n=n?JSON.parse(Base64.decode(n)):null;var s=restore("ttkFurn");s=s?JSON.parse(Base64.decode(s)):null;var o=restore("fleet");for(var r in o=o?Base64.decode(o).split("|"):null)o[r]=o[r].split(",");var d=restore("fleetLvl");for(var r in d=d?Base64.decode(d).split("|"):null)d[r]=d[r].split(",");if(l)for(var r in k2=l,$(".shipClass input").prop("checked",!1),k2)for(var c in k2[r])$("#"+c).prop("checked",k2[r][c]);if(n)for(var r in colle=n,$("#colleDiv img").removeClass("selected"),colle)$("#kore"+r).addClass("selected");if(o)for(var r in(fleets=o)[0]){var h=fleets[0][r];if(null!==h&&""!==h){0==r&&($("#"+h).addClass("flagship"),"true"==restore("secretaryHit")&&$("#"+h).next("span").addClass("damaged"),i=shipDB[h.substring(4)]?shipDB[h.substring(4)].rarity:0);var g=parseInt(r)+1;$("#slot"+g).html('<img style="height:50px; width:50px;" src="'+$("#"+h).attr("src")+'"/>')}}if(d)for(var r in(fleetLevels=d)[0]){var p=parseInt(fleetLevels[0][r]);p&&p>0&&(g=parseInt(r)+1,$("#level"+g).val(p))}if(s){var v=0;$("#buttons button").prop("disabled",!0),$("#loadingDiv").html("Rendering...");var m=!1;for(var r in s){var f=s[r],u=$("#"+f);u.prop("checked",!0);var b=u.parent().parent().parent().attr("id"),k=$("#active"+b);if(k.off("load"),"Outside"==b){var x=$("#Outside").find(":checked"),C=$("#Window").find(":checked").attr("data-pType"),w="furniture/outside/"+(I=x.val()+C)+".png";k.attr("src",w)}else{var I=u.val();k.attr("src","furniture/"+b.toLowerCase()+"/"+I+".png")}k.prop("complete")?++v==Object.keys(s).length&&($("#buttons button").prop("disabled",!1),$("#loadingDiv").html(""),$("#displayRoom").hasClass("on")?S(132):y("loadAllImgCached")):k.on("load",function(){++v==Object.keys(s).length&&($("#buttons button").prop("disabled",!1),$("#loadingDiv").html(m?"Couldn't find a furniture's image.":""),$("#displayRoom").hasClass("on")?S(132):y("loadAllImgLoaded"))}).error(function(e){m=!0,++v==Object.keys(s).length&&($("#buttons button").prop("disabled",!1),$("#loadingDiv").html("Couldn't find a furniture's image."))})}}else y("loadNoFurniture")}()}),$("#export").on("click",function(){var e=document.createElement("img");$(e).attr("src",s.toDataURL("image/png"));var t=document.createElement("div");$(t).attr("class","export-container"),$(t).append(e);var a=document.createElement("span");$(a).text('Right-click the image and choose "Save As..." to save it to your computer.'),$(t).append(a);var l=document.createElement("span");$(l).attr("class","close"),$(l).text("+"),$(t).append(l),$("body").prepend(t)}),$("body").on("click",".export-container",function(){$(".export-container").remove()}),$("#avatar").on("load",function(){$.isEmptyObject(e)&&y("avatarImgChange")}),$("#bg").on("load",function(){$.isEmptyObject(e)&&y("bgImgChange")}),$("#customInputs input[type='checkbox']").on("change",function(){y("customInputChange")}),$("#customInputs input[type='number']").on("change",function(){y("customInputChange")}),$("#avatarImg").on("change",function(){if(this.files&&this.files[0]){var e=new FileReader;e.onload=function(e){$("#avatar").attr("src",e.target.result),globalavatar=e.target.result},e.readAsDataURL(this.files[0])}}),$("#shipImg").on("change",function(){if(this.files&&this.files[0]){var e=new FileReader;e.onload=function(e){$("#customShip").attr("src",e.target.result),globalship=e.target.result,y("customShipChange")},e.readAsDataURL(this.files[0])}}),$("#bgImg").on("change",function(){if($("#useBG").prop("checked",!1),this.files&&this.files[0]){var e=new FileReader;e.onload=function(e){$("#bg").attr("src",e.target.result),globalbg=e.target.result},e.readAsDataURL(this.files[0])}}),$("#shipClear").on("click",function(){globalship=null,$("#shipImg").val(""),$("#customShip").removeAttr("src"),y("clear")}),$("#avatarClear").on("click",function(){globalavatar=null,$("#avatarImg").val(""),$("#avatar").removeAttr("src"),y("clear")}),$("#bgClear").on("click",function(){globalbg=null,$("#bgImg").val(""),$("#bg").attr("src","bg.jpg"),y("clear")})})}),$(window).on("load",function(){$("#tabs").liteTabs({width:"100%"}),$("#tabs").show(),$(".furnitureClass.invert > div div").each(function(){$(this).prependTo(this.parentNode)})});