This repository has been archived on 2024-10-13. You can view files and clone it, but cannot push or open issues or pull requests.
VPModelFileTool/dist/js/scripts.min.js

1 line
No EOL
2.5 KiB
JavaScript

let namespace="vp";$(document).ready((function(){const t=$("#custommodeldata"),e=$("#calculatorForm"),a=$("#formItems"),n=$("#item"),i=$("#itemcount"),c=$("#items"),o=$("#content"),s=$("#copyButton"),r=$("#downloadButton"),l=$("#minus"),p=$("#plus"),m=$("input[name='quant']"),u=$("#namespace"),d=$("#item");function f(t){return t.split("_").map((t=>t.charAt(0).toUpperCase()+t.slice(1))).join(" ")}l.click((function(t){const e=parseInt(m.attr("value"));isNaN(e)?m.attr("value","0"):(e>m.attr("min")&&m.attr("value",(e-1).toString()),e-1==m.attr("min")&&$(this).attr("disabled",!0),$("#iteminput"+e).remove())})),p.click((function(t){const e=parseInt(m.attr("value"));if(isNaN(e))m.attr("value","0");else{if(e<m.attr("max")&&m.attr("value",(e+1).toString()),e==m.attr("max"))return void $(this).attr("disabled",!0);parseInt(m.attr("value"))>1?l.prop("disabled",!1):l.prop("disabled",!0),c.append('<div id="iteminput'+(e+1)+'" class="mb-3 w-50"><label for="item'+(e+1)+'">Model for damage '+(e+1)+':</label><div class="input-group mb-3"><span class="input-group-text" id="namespace'+(e+1)+'">'+namespace+':item/</span><input type="text" class="form-control" id="item'+(e+1)+'" name="item'+(e+1)+'" placeholder="cars/'+function(){const t=["red_car","blue_car","green_car","orange_car","blue_bicycle","red_bicycle","green_bicycle","orange_bicycle"];return t[Math.floor(Math.random()*t.length)]}()+'" required></div></div>')}})),$.each(itemDamages,(function(t,e){const a=f(t);d.append($("<option></option>").attr("value",t).text(a))})),t.change((function(){d.find("option").each((function(){const e=$(this).val(),a=f(e),n=$(this).text().includes("(supports");if(""!==e)if(t.is(":checked")){if(n){const t=a;$(this).text(t)}}else if(!n){const t=a+" (supports "+itemDamages[e]+" models)";$(this).text(t)}}))})),u.change((function(){namespace=u.val(),""==namespace&&(namespace="minecraft"),u.val(namespace),$("span[id^='namespace']").text(namespace+":item/")})),n.change((function(){if(""!==this.value){a.show();const t=itemDamages[this.value];i.prop("max",t),p.prop("disabled",!1)}else a.hide()})),e.on("submit",(function(e){e.preventDefault();const a=t.is(":checked"),i=n.val(),c=parseInt(m.attr("value")),s=[];for(let t=0;t<c;t++)s[t]=$("#item"+(t+1)).val();const l=buildJSON(a,i,namespace,s);o.html(syntaxHighlight(l));const p="data:text/json;charset=utf-8,"+encodeURIComponent(l);return r.attr("href",p),r.attr("download",i+".json"),!1})),s.click((function(t){t.preventDefault(),navigator.clipboard.writeText(o.text())}))}));