From 38b4d5562c5dbb42cae1efb57549f892ef191e66 Mon Sep 17 00:00:00 2001 From: stijnb1234 Date: Wed, 7 Apr 2021 15:34:07 +0200 Subject: [PATCH] First commit, containing the basic system. - TODO: Add/Remove item system (so it's not fixed to two). --- dist/css/beautify.css | 25 +++++++++++++ dist/js/beautify.js | 21 +++++++++++ dist/js/calculator.js | 59 +++++++++++++++++++++++++++++ index.html | 86 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 191 insertions(+) create mode 100644 dist/css/beautify.css create mode 100644 dist/js/beautify.js create mode 100644 dist/js/calculator.js create mode 100644 index.html diff --git a/dist/css/beautify.css b/dist/css/beautify.css new file mode 100644 index 0000000..87edbfd --- /dev/null +++ b/dist/css/beautify.css @@ -0,0 +1,25 @@ +pre { + outline: 1px solid #ccc; + padding: 5px; + margin: 5px; +} + +.string { + color: green; +} + +.number { + color: darkorange; +} + +.boolean { + color: blue; +} + +.null { + color: magenta; +} + +.key { + color: red; +} \ No newline at end of file diff --git a/dist/js/beautify.js b/dist/js/beautify.js new file mode 100644 index 0000000..d6dae79 --- /dev/null +++ b/dist/js/beautify.js @@ -0,0 +1,21 @@ +function syntaxHighlight(json) { + if (typeof json != 'string') { + json = JSON.stringify(json, undefined, 4); + } + json = json.replace(/&/g, '&').replace(//g, '>'); + return json.replace(/("(\\u[a-zA-Z0-9]{4}|\\[^u]|[^\\"])*"(\s*:)?|\b(true|false|null)\b|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?)/g, function (match) { + let cls = 'number'; + if (/^"/.test(match)) { + if (/:$/.test(match)) { + cls = 'key'; + } else { + cls = 'string'; + } + } else if (/true|false/.test(match)) { + cls = 'boolean'; + } else if (/null/.test(match)) { + cls = 'null'; + } + return '' + match + ''; + }); +} \ No newline at end of file diff --git a/dist/js/calculator.js b/dist/js/calculator.js new file mode 100644 index 0000000..c320f73 --- /dev/null +++ b/dist/js/calculator.js @@ -0,0 +1,59 @@ +//TODO Support more items +const itemDamages = { + 'leather_boots': 65 +}; + +/** + * 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. + * + * @param item The item to generate it for. + * @param models An array of models to insert. + * @returns {String} The JSON for the texturepack. + */ +function toJSON(item, models) { + const json = {}; + + //Default values + json['parent'] = 'item/handheld'; + json['textures'] = { + 'layer0': 'item/leather_boots', + 'layer1': 'items/leather_boots_overlay' + }; + + //Insert models + json['overrides'] = []; + + for (let i = 0; i < models.length; i++) { + const model = models[i]; + const damage = getMappedDamage(i+1, itemDamages[item]); + + json['overrides'][i] = { + 'predicate': { + 'damaged': 0, + 'damage': damage, + 'model': 'item/' + model + } + }; + } + + //Insert damaged model + json['overrides'][models.length] = { + 'predicate': { + 'damaged': 1, + 'damage': 0, + 'model': 'item/' + item + } + }; + + return JSON.stringify(json, null, 2); +} \ No newline at end of file diff --git a/index.html b/index.html new file mode 100644 index 0000000..cf04d09 --- /dev/null +++ b/index.html @@ -0,0 +1,86 @@ + + + + VehiclesPlus - Damage calculator + + + + + + + + +
+
+

VolmitSoftware - Damage calculator

+

Simply calculate the damage values for your texture pack.

+
+

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 +
+ + + + + \ No newline at end of file