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
25
dist/css/beautify.css
vendored
Normal file
25
dist/css/beautify.css
vendored
Normal 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
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);
|
||||
}
|
86
index.html
Normal file
86
index.html
Normal file
|
@ -0,0 +1,86 @@
|
|||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<title>VehiclesPlus - Damage calculator</title>
|
||||
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
|
||||
<link rel="stylesheet"
|
||||
href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/5.0.0-beta3/css/bootstrap.min.css"
|
||||
integrity="sha512-N415hCJJdJx+1UBfULt+i+ihvOn42V/kOjOpp1UTh4CZ70Hx5bDlKryWaqEKfY/8EYOu/C2MuyaluJryK1Lb5Q=="
|
||||
crossorigin="anonymous"/>
|
||||
<link rel="stylesheet" href="dist/css/beautify.css">
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<div class="jumbotron">
|
||||
<h1 class="display-4">VolmitSoftware - Damage calculator</h1>
|
||||
<p class="lead">Simply calculate the damage values for your texture pack.</p>
|
||||
<hr class="my-4">
|
||||
<p>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.</p>
|
||||
</div>
|
||||
<form id="calculatorForm">
|
||||
<div class="mb-3">
|
||||
<label for="item">Select the item:</label>
|
||||
<select class="form-control" id="item" name="item" required>
|
||||
<option selected>Select an item...</option>
|
||||
<option value="leather_boots">Leather Boots</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="item1">Item for damage 1:</label>
|
||||
<input type="text" class="form-control" id="item1" name="item1" placeholder="cars/blue_car" required>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="item2">Item for damage 2:</label>
|
||||
<input type="text" class="form-control" id="item2" name="item2" placeholder="cars/red_car" required>
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary">Calculate</button>
|
||||
</form>
|
||||
<hr class="my-4">
|
||||
<h6>Output JSON:</h6>
|
||||
<pre id="content" class="mb-3">Fill in the form above to get an output.</pre>
|
||||
<button id="copyButton" class="btn btn-primary mb-3 mr-3">Copy</button> <a id="downloadButton" class="btn btn-secondary mb-3" href="#">Download</a>
|
||||
</div>
|
||||
</body>
|
||||
<script type="application/javascript" src="dist/js/calculator.js"></script>
|
||||
<script type="application/javascript" src="dist/js/beautify.js"></script>
|
||||
<script>
|
||||
const form = document.getElementById("calculatorForm");
|
||||
const output = document.getElementById("content");
|
||||
|
||||
const copybutton = document.getElementById("copyButton");
|
||||
const downloadbutton = document.getElementById("downloadButton");
|
||||
|
||||
form.addEventListener("submit", function (e) {
|
||||
if (e.preventDefault) e.preventDefault();
|
||||
|
||||
const item = document.getElementById('item').value;
|
||||
const model1 = document.getElementById('item1').value;
|
||||
const model2 = document.getElementById('item2').value;
|
||||
const models = [model1, model2];
|
||||
|
||||
const json = toJSON(item, models);
|
||||
|
||||
output.innerHTML = syntaxHighlight(json);
|
||||
|
||||
const dataStr = "data:text/json;charset=utf-8," + encodeURIComponent(json);
|
||||
downloadbutton.setAttribute("href", dataStr);
|
||||
downloadbutton.setAttribute("download", item + ".json");
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
copybutton.addEventListener("click", function() {
|
||||
const copyText = output.textContent;
|
||||
const textArea = document.createElement("textarea");
|
||||
textArea.textContent = copyText;
|
||||
document.body.append(textArea);
|
||||
textArea.select();
|
||||
document.execCommand("copy");
|
||||
textArea.remove();
|
||||
});
|
||||
</script>
|
||||
</html>
|
Reference in a new issue