mirror of
https://github.com/misode/misode.github.io.git
synced 2026-04-24 23:56:51 +00:00
Add quality and luck-based checkbox
This commit is contained in:
16
index.html
16
index.html
@@ -21,13 +21,13 @@
|
||||
</nav>
|
||||
<div class="container">
|
||||
<div class="row my-4">
|
||||
<div class="col-12 col-md-7">
|
||||
<div class="col-12 col-md-7 mb-3">
|
||||
<div class="input-group">
|
||||
<button type="button" class="btn btn-success d-block mr-3 float-left" onclick="addPool(this)">Add Pool</button>
|
||||
<div class="input-group-prepend">
|
||||
<span class="input-group-text rounded-left">Type</span>
|
||||
</div>
|
||||
<select id="tableType" class="form-control" style="max-width: 9em;" onchange="updateTableType(this)">
|
||||
<select id="tableType" class="form-control mr-3 rounded-right" style="max-width: 9em;" onchange="updateTableType(this)">
|
||||
<option value="minecraft:empty">Empty</option>
|
||||
<option value="minecraft:entity">Entity</option>
|
||||
<option value="minecraft:block">Block</option>
|
||||
@@ -35,6 +35,12 @@
|
||||
<option value="minecraft:fishing">Fishing</option>
|
||||
<option value="minecraft:generic">Generic</option>
|
||||
</select>
|
||||
<div class="input-group-prepend">
|
||||
<div class="input-group-text rounded-left">
|
||||
<input id="luckBased" type="checkbox" onchange="updateLuckBased(this)">
|
||||
</div>
|
||||
</div>
|
||||
<label class="form-control overflow-hidden" for="luckBased" style="max-width: 7em;">Luck based</label>
|
||||
</div>
|
||||
<div id="structure"">
|
||||
</div>
|
||||
@@ -142,6 +148,12 @@
|
||||
</div>
|
||||
<input type="text" class="form-control" onchange="updateEntryWeight(this)">
|
||||
</div>
|
||||
<div class="input-group mt-3 entry-quality d-none">
|
||||
<div class="input-group-prepend">
|
||||
<span class="input-group-text">Quality</span>
|
||||
</div>
|
||||
<input type="text" class="form-control" onchange="updateEntryQuality(this)">
|
||||
</div>
|
||||
<div class="input-group mt-3 entry-children d-none">
|
||||
<button type="button" class="btn btn-outline-success">Add Child</button>
|
||||
</div>
|
||||
|
||||
31
script.js
31
script.js
@@ -3,6 +3,7 @@ $("#source").val('');
|
||||
$('#tableType').val("minecraft:generic");
|
||||
$('#indentationSelect').val("2");
|
||||
let indentation = 2;
|
||||
let luck_based = false;
|
||||
let table = {
|
||||
type: "minecraft:generic",
|
||||
pools: []
|
||||
@@ -134,11 +135,26 @@ function updateEntryWeight(el) {
|
||||
invalidated();
|
||||
}
|
||||
|
||||
function updateEntryQuality(el) {
|
||||
let quality = parseInt($(el).val());
|
||||
if (isNaN(quality)) {
|
||||
delete getEntry(el).quality;
|
||||
} else {
|
||||
getEntry(el).quality = quality;
|
||||
}
|
||||
invalidated();
|
||||
}
|
||||
|
||||
function updateTableType() {
|
||||
table.type = $('#tableType').val();
|
||||
invalidated();
|
||||
}
|
||||
|
||||
function updateLuckBased() {
|
||||
luck_based = $('#luckBased').prop('checked');
|
||||
invalidated();
|
||||
}
|
||||
|
||||
function updateSouce() {
|
||||
$('#source').removeClass('invalid');
|
||||
try {
|
||||
@@ -203,6 +219,7 @@ function generateStructure() {
|
||||
// Bonus Rolls
|
||||
let $bonus_rolls = $pool.find('.bonus-rolls');
|
||||
if (pool.bonus_rolls) {
|
||||
luck_based = true;
|
||||
if (typeof pool.bonus_rolls === 'object') {
|
||||
if (pool.bonus_rolls.type && pool.bonus_rolls.type.match(/(minecraft:)?binomial/)) {
|
||||
$bonus_rolls.attr('data-type', 'binomial');
|
||||
@@ -223,6 +240,9 @@ function generateStructure() {
|
||||
} else {
|
||||
$bonus_rolls.find('.exact').removeClass('d-none');
|
||||
}
|
||||
if (!luck_based) {
|
||||
$pool.find('.bonus-rolls').addClass('d-none');
|
||||
}
|
||||
|
||||
// Entries
|
||||
for (let j = 0; j < pool.entries.length; j += 1) {
|
||||
@@ -239,9 +259,18 @@ function generateStructure() {
|
||||
$entry.find('.entry-name input').val(entry.name);
|
||||
}
|
||||
$entry.find('.entry-weight').removeClass('d-none');
|
||||
if (luck_based) {
|
||||
$entry.find('.entry-quality').removeClass('d-none');
|
||||
} else {
|
||||
$entry.find('.entry-quality').addClass('d-none');
|
||||
}
|
||||
if (entry.weight) {
|
||||
$entry.find('.entry-weight input').val(entry.weight);
|
||||
}
|
||||
if (entry.quality) {
|
||||
luck_based = true;
|
||||
$entry.find('.entry-quality input').val(entry.quality);
|
||||
}
|
||||
if (entry.type === 'minecraft:alternatives' || entry.type === 'minecraft:sequence' || entry.type === 'minecraft:group') {
|
||||
delete entry.name;
|
||||
$entry.find('.entry-children').removeClass('d-none');
|
||||
@@ -250,5 +279,7 @@ function generateStructure() {
|
||||
$pool.children('.card-body').append($entry);
|
||||
}
|
||||
$('#structure').append($pool);
|
||||
|
||||
$('#luck-based').attr('checked', luck_based);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user