First commit, containing the basic system.

- TODO: Add/Remove item system (so it's not fixed to two).
This commit is contained in:
stijnb1234 2021-04-07 15:34:07 +02:00
parent c2264dd11b
commit 38b4d5562c
4 changed files with 191 additions and 0 deletions

25
dist/css/beautify.css vendored Normal file
View file

@ -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;
}

21
dist/js/beautify.js vendored Normal file
View file

@ -0,0 +1,21 @@
function syntaxHighlight(json) {
if (typeof json != 'string') {
json = JSON.stringify(json, undefined, 4);
}
json = json.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
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 '<span class="' + cls + '">' + match + '</span>';
});
}

59
dist/js/calculator.js vendored Normal file
View file

@ -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);
}