From b48938f8ddca30ace2036003a440ae8e7b00b879 Mon Sep 17 00:00:00 2001 From: Stijn Bannink Date: Fri, 20 Jan 2023 19:51:33 +0100 Subject: [PATCH] Fixed - / + buttons, minifed files --- dist/css/beautify.min.css | 1 + dist/js/beautify.min.js | 1 + dist/js/calculator.js | 15 +-- dist/js/calculator.min.js | 1 + dist/js/scripts.js | 121 ++++++++++++++++++++ dist/js/scripts.min.js | 1 + index.html | 226 +++++++++----------------------------- 7 files changed, 181 insertions(+), 185 deletions(-) create mode 100644 dist/css/beautify.min.css create mode 100644 dist/js/beautify.min.js create mode 100644 dist/js/calculator.min.js create mode 100644 dist/js/scripts.js create mode 100644 dist/js/scripts.min.js diff --git a/dist/css/beautify.min.css b/dist/css/beautify.min.css new file mode 100644 index 0000000..7ca5ed6 --- /dev/null +++ b/dist/css/beautify.min.css @@ -0,0 +1 @@ +pre{outline:1px solid #ccc;padding:5px;margin:5px}.string{color:green}.number{color:#ff8c00}.boolean{color:#00f}.null{color:#ff00ff}.key{color:red} \ No newline at end of file diff --git a/dist/js/beautify.min.js b/dist/js/beautify.min.js new file mode 100644 index 0000000..5afd15d --- /dev/null +++ b/dist/js/beautify.min.js @@ -0,0 +1 @@ +function syntaxHighlight(e){return"string"!=typeof e&&(e=JSON.stringify(e,void 0,4)),e=e.replace(/&/g,"&").replace(//g,">"),e.replace(/("(\\u[a-zA-Z0-9]{4}|\\[^u]|[^\\"])*"(\s*:)?|\b(true|false|null)\b|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?)/g,function(e){let t="number";return/^"/.test(e)?t=/:$/.test(e)?"key":"string":/true|false/.test(e)?t="boolean":/null/.test(e)&&(t="null"),''+e+""})} \ No newline at end of file diff --git a/dist/js/calculator.js b/dist/js/calculator.js index fb3069d..e0bf93e 100644 --- a/dist/js/calculator.js +++ b/dist/js/calculator.js @@ -1,19 +1,8 @@ -//TODO Support more items const itemDamages = { 'leather_boots': 64, 'netherite_hoe': 2030 }; -/** - * Map an in-game Damage to an texturepack Damage. - * - * @param value The input value. - * @param oldMax The old max value, from the itemDamages array. - */ -function getMappedDamage(value, oldMax) { - return value / oldMax; -} - /** * Generate the JSON file. * @@ -21,7 +10,7 @@ function getMappedDamage(value, oldMax) { * @param models An array of models to insert. * @returns {String} The JSON for the texturepack. */ -function toJSON(item, models) { +function buildJSON(item, models) { const json = {}; //Default values @@ -44,7 +33,7 @@ function toJSON(item, models) { for (let i = 0; i < models.length; i++) { const model = models[i]; - const damage = getMappedDamage(i + 1, itemDamages[item]); + const damage = i + 1 / itemDamages[item]; json['overrides'][i + 1] = { 'predicate': { diff --git a/dist/js/calculator.min.js b/dist/js/calculator.min.js new file mode 100644 index 0000000..4d8cf85 --- /dev/null +++ b/dist/js/calculator.min.js @@ -0,0 +1 @@ +function buildJSON(e,t){const a={parent:"item/handheld"};a.textures={layer0:"item/"+e},a.overrides=[],a.overrides[0]={predicate:{damaged:0,damage:0},model:"item/"+e};for(let d=0;d input.attr('min')) { + input.attr('value', (currentVal - 1).toString()); + } + + if (currentVal - 1 == input.attr('min')) { + $(this).attr('disabled', true); + } + + $("#iteminput" + currentVal).remove(); + } else { + input.attr('value', '0'); + } + }); + + plus.click(function (e) { + const currentVal = parseInt(input.attr('value')); + + if (!isNaN(currentVal)) { + if (currentVal < input.attr('max')) { + input.attr('value', (currentVal + 1).toString()); + } + + if (currentVal == input.attr('max')) { + $(this).attr('disabled', true); + return; + } + + if (parseInt(input.attr('value')) > 1) { + minus.prop('disabled', false); + } else { + minus.prop('disabled', true); + } + + items.append("
"); + } else { + input.attr('value', '0'); + } + }); + + item.change(function () { + //If value is not empty, show other options ... + if (this.value !== "") { + formOptions.show(); + + //... and set max value of item count. + const max = itemDamages[this.value]; + itemCount.prop('max', max); + plus.prop('disabled', false); + } else { //Or if empty, hide other options. + formOptions.hide(); + } + }); + + form.on("submit", function (e) { + e.preventDefault(); + + //Get selected item + const selectedItem = item.val(); + + //Get amount of items + const fieldName = $('.btn-number').attr('data-field'); + const input = $("input[name='" + fieldName + "']"); + const currentVal = parseInt(input.attr('value')); + + //Build models array + const models = []; + for (let i = 0; i < currentVal; i++) { + models[i] = $("#item" + (i + 1)).val(); + } + + //Convert to JSON, and set in content field (with syntax highlighting) + const json = buildJSON(selectedItem, models); + output.html(syntaxHighlight(json)); + + //And fix the Download knop + const dataStr = "data:text/json;charset=utf-8," + encodeURIComponent(json); + downloadButton.attr("href", dataStr); + downloadButton.attr("download", selectedItem + ".json"); + + //Return false to not reload the page + return false; + }); + + copyButton.click(function (e) { + e.preventDefault(); + navigator.clipboard.writeText(output.text()); + }); + + /** + * Get a random model. + * + * @return {string} The random model. + */ + function randomModel() { + const months = ["red_car", "blue_car", "green_car", "orange_car", "blue_bicycle", "red_bicycle", "green_bicycle", "orange_bicycle"]; + return months[Math.floor(Math.random() * months.length)]; + } +}); \ No newline at end of file diff --git a/dist/js/scripts.min.js b/dist/js/scripts.min.js new file mode 100644 index 0000000..33e5815 --- /dev/null +++ b/dist/js/scripts.min.js @@ -0,0 +1 @@ +$(document).ready(function(){function t(){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)]}const e=$("#calculatorForm"),a=$("#formItems"),n=$("#item"),r=$("#itemcount"),i=$("#items"),o=$("#content"),l=$("#copyButton"),c=$("#downloadButton"),u=$("#minus"),s=$("#plus"),d=$("input[name='quant']");u.click(function(t){const e=parseInt(d.attr("value"));isNaN(e)?d.attr("value","0"):(console.log("#iteminput"+e),e>d.attr("min")&&d.attr("value",(e-1).toString()),e-1==d.attr("min")&&$(this).attr("disabled",!0),$("#iteminput"+e).remove())}),s.click(function(e){const a=parseInt(d.attr("value"));if(isNaN(a))d.attr("value","0");else{if(a1?u.prop("disabled",!1):u.prop("disabled",!0),i.append('
')}}),n.change(function(){if(""!==this.value){a.show();const t=itemDamages[this.value];r.prop("max",t),s.prop("disabled",!1)}else a.hide()}),e.on("submit",function(t){t.preventDefault();const e=n.val(),a=$(".btn-number").attr("data-field"),r=$("input[name='"+a+"']"),i=parseInt(r.attr("value")),l=[];for(let t=0;t + SBDevelopment - Damage calculator @@ -7,187 +8,68 @@ + integrity="sha512-F7WyTLiiiPqvu2pGumDR15med0MDkUIo5VTVyyfECR5DZmCnDhti9q5VID02ItWjq6fvDfMaBaDl2J3WdL1uxA==" + crossorigin="anonymous" referrerpolicy="no-referrer" /> - + integrity="sha512-1ycn6IcaQQ40/MKBW2W4Rhis/DbILU74C1vSrLJxCq57o941Ym01SwNsOMqvEBFlcgUa6xLiPY/NS5R+E6ztJQ==" + crossorigin="anonymous" referrerpolicy="no-referrer" /> + + -
-
-

SBDevelopment - Damage calculator

-

Generate the texturepack asset files for your damaged items.

-
-

You indicate which item you want to use and where the models are for each damage value. This tool then - creates the .json file for you.

-
-
-
- - +
+
+

SBDevelopment - Damage calculator

+

Generate the texturepack asset files for your damaged items.

+
+

You indicate which item you want to use and where the models are for each damage value. This tool then + creates the .json file for you.

- + +
+
Output JSON:
+
Fill in the form above to get an output.
+ + Download +
- - - + + + - const item = $("#item"); - const itemCount = $("#itemcount"); - const itemCountButton = $('.btn-number'); - const items = $("#items"); - - const output = $("#content"); - - const copyButton = $("#copyButton"); - const downloadButton = $("#downloadButton"); - - itemCountButton.click(function (e) { - e.preventDefault(); - - let fieldName = $(this).attr('data-field'); - let type = $(this).attr('data-type'); - const input = $("input[name='" + fieldName + "']"); - const currentVal = parseInt(input.val()); - - if (!isNaN(currentVal)) { - if (type === 'minus') { - if (currentVal > input.attr('min')) { - input.val(currentVal - 1).change(); - } - - if (input.val() == input.attr('min')) { - $(this).attr('disabled', true); - return; - } - - $("#iteminput" + currentVal).remove(); - } else if (type === 'plus') { - if (currentVal < input.attr('max')) { - input.val(currentVal + 1).change(); - } - - if (input.val() == input.attr('max')) { - $(this).attr('disabled', true); - return; - } - - items.append("
"); - } - } else { - input.val(0); - } - }); - - item.change(function () { - if (this.value !== "") { //If value is not empty, show other options ... - formOptions.show(); - - //... and set max value of item count. - const max = itemDamages[this.value]; - itemCount.prop('max', max); - } else { //Or if empty, hide other options. - formOptions.hide(); - } - }); - - form.on("submit", function (e) { - e.preventDefault(); - - //Get selected item - const selectedItem = item.val(); - - //Get amount of items - const fieldName = $('.btn-number').attr('data-field'); - const input = $("input[name='" + fieldName + "']"); - const currentVal = parseInt(input.val()); - - //Build models array - const models = []; - for (let i = 0; i < currentVal; i++) { - models[i] = $("#item" + (i + 1)).val(); - } - - //Convert to JSON, and set in content field (with syntax highlighting) - const json = toJSON(selectedItem, models); - output.html(syntaxHighlight(json)); - - //And fix the Download knop - const dataStr = "data:text/json;charset=utf-8," + encodeURIComponent(json); - downloadButton.attr("href", dataStr); - downloadButton.attr("download", selectedItem + ".json"); - - //Return false to not reload the page - return false; - }); - - copyButton.click(function (e) { - e.preventDefault(); - - //Get the content. - const copyText = output.text(); - - //Create temporary textarea, select, copy, and remove it again. - const textArea = document.createElement("textarea"); - textArea.textContent = copyText; - document.body.append(textArea); - textArea.select(); - document.execCommand("copy"); - textArea.remove(); - }); - - /** - * Get a random model. - * - * @return {string} The random model. - */ - function randomModel() { - const months = ["red_car", "blue_car", "green_car", "orange_car", "blue_bicycle", "red_bicycle", "green_bicycle", "orange_bicycle"]; - return months[Math.floor(Math.random() * months.length)]; - } - }); - - + \ No newline at end of file