First commit, containing the basic system.
- TODO: Add/Remove item system (so it's not fixed to two).
This commit is contained in:
parent
c2264dd11b
commit
38b4d5562c
4 changed files with 191 additions and 0 deletions
21
dist/js/beautify.js
vendored
Normal file
21
dist/js/beautify.js
vendored
Normal file
|
@ -0,0 +1,21 @@
|
|||
function syntaxHighlight(json) {
|
||||
if (typeof json != 'string') {
|
||||
json = JSON.stringify(json, undefined, 4);
|
||||
}
|
||||
json = json.replace(/&/g, '&').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 '<span class="' + cls + '">' + match + '</span>';
|
||||
});
|
||||
}
|
59
dist/js/calculator.js
vendored
Normal file
59
dist/js/calculator.js
vendored
Normal 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);
|
||||
}
|
Reference in a new issue