mirror of
https://github.com/misode/misode.github.io.git
synced 2026-05-05 07:01:48 +00:00
Add range and binomial options
This commit is contained in:
+21
-2
@@ -5,6 +5,11 @@
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
||||
<title>Loot Table Generator</title>
|
||||
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css" integrity="sha384-GJzZqFGwb1QTTN6wy59ffF1BuGJpLSa9DkKMp0DgiMDm4iYMj70gZWKYbI706tWS" crossorigin="anonymous">
|
||||
<style media="screen">
|
||||
.dropdown-item {
|
||||
cursor: pointer;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<nav class="navbar navbar-dark bg-dark">
|
||||
@@ -47,11 +52,25 @@
|
||||
<button type="button" class="btn btn-outline-success mr-3 mb-2 float-left">Add Condition</button>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<div class="input-group">
|
||||
<div class="input-group mb-3 rolls">
|
||||
<div class="input-group-prepend">
|
||||
<span class="input-group-text">Rolls</span>
|
||||
<button type="button" class="btn btn-outline-secondary dropdown-toggle dropdown-toggle-split" data-toggle="dropdown">
|
||||
<div class="dropdown-menu">
|
||||
<a class="dropdown-item" onclick="switchExact(this)">Exact</a>
|
||||
<a class="dropdown-item" onclick="switchRange(this)">Range</a>
|
||||
<a class="dropdown-item" onclick="switchBinomial(this)">Binomial</a>
|
||||
</div>
|
||||
</div>
|
||||
<input type="text" class="form-control" onchange="updateRollsField(this)" value="1">
|
||||
<input type="text" class="form-control exact" onchange="updateRollsField(this)" value="1">
|
||||
<span class="input-group-text rounded-0 range d-none">Min</span>
|
||||
<input type="text" class="form-control range min d-none" value="1" onchange="updateRollsField(this)">
|
||||
<span class="input-group-text rounded-0 range d-none">Max</span>
|
||||
<input type="text" class="form-control range max d-none" value="2" onchange="updateRollsField(this)">
|
||||
<span class="input-group-text rounded-0 binomial d-none">n</span>
|
||||
<input type="text" class="form-control binomial n d-none" value="1" onchange="updateRollsField(this)">
|
||||
<span class="input-group-text rounded-0 binomial d-none">p</span>
|
||||
<input type="text" class="form-control binomial p d-none" value="2" onchange="updateRollsField(this)">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -19,7 +19,7 @@ function addPool(el) {
|
||||
}
|
||||
|
||||
function removePool(el) {
|
||||
let $pool = $(el).parent().parent();
|
||||
let $pool = $(el).closest('.pool');
|
||||
table.pools.pop($pool.attr('data-index'));
|
||||
$('#structure .pool').each((i, el) => {
|
||||
if ($(el).attr('data-index') > $pool.attr('data-index')) {
|
||||
@@ -30,6 +30,59 @@ function removePool(el) {
|
||||
invalidated();
|
||||
}
|
||||
|
||||
function updateRollsField(el) {
|
||||
let $pool = $(el).closest('.pool')
|
||||
let $rolls = $(el).closest('.rolls');
|
||||
let data = parseInt($rolls.find('.exact').val());
|
||||
if ($rolls.attr('data-type') === 'range') {
|
||||
data = {};
|
||||
let min = $rolls.find('.range.min').val();
|
||||
let max = $rolls.find('.range.max').val();
|
||||
if (min) data.min = parseInt(min);
|
||||
if (max) data.max = parseInt(max);
|
||||
} else if ($rolls.attr('data-type') === 'binomial') {
|
||||
data = {type: "minecraft:binomial"};
|
||||
let n = $rolls.find('.binomial.n').val();
|
||||
let p = $rolls.find('.binomial.p').val();
|
||||
if (n) data.n = parseInt(n);
|
||||
if (p) data.p = parseFloat(p);
|
||||
}
|
||||
table.pools[$pool.attr('data-index')].rolls = data;
|
||||
invalidated();
|
||||
}
|
||||
|
||||
function switchExact(el) {
|
||||
let $rolls = $(el).closest('.rolls');
|
||||
$rolls.attr('data-type', 'exact');
|
||||
$rolls.find('.exact').removeClass('d-none');
|
||||
$rolls.find('.range').addClass('d-none');
|
||||
$rolls.find('.binomial').addClass('d-none');
|
||||
updateRollsField(el);
|
||||
}
|
||||
|
||||
function switchRange(el) {
|
||||
let $rolls = $(el).closest('.rolls');
|
||||
$rolls.attr('data-type', 'range');
|
||||
$rolls.find('.exact').addClass('d-none');
|
||||
$rolls.find('.range').removeClass('d-none');
|
||||
$rolls.find('.binomial').addClass('d-none');
|
||||
updateRollsField(el);
|
||||
}
|
||||
|
||||
function switchBinomial(el) {
|
||||
let $rolls = $(el).closest('.rolls');
|
||||
$rolls.attr('data-type', 'binomial');
|
||||
$rolls.find('.exact').addClass('d-none');
|
||||
$rolls.find('.range').addClass('d-none');
|
||||
$rolls.find('.binomial').removeClass('d-none');
|
||||
updateRollsField(el);
|
||||
}
|
||||
|
||||
function invalidated() {
|
||||
$('#source').val(JSON.stringify(table, null, indentation));
|
||||
$('#source').autogrow();
|
||||
}
|
||||
|
||||
function updateIndentation(el) {
|
||||
if (el.value === 'tab') {
|
||||
indentation = '\t';
|
||||
@@ -39,18 +92,6 @@ function updateIndentation(el) {
|
||||
invalidated();
|
||||
}
|
||||
|
||||
function updateRollsField(el) {
|
||||
let $pool = $(el).parent().parent().parent();
|
||||
let value = parseInt($(el).val());
|
||||
table.pools[$pool.attr('data-index')].rolls = value;
|
||||
invalidated();
|
||||
}
|
||||
|
||||
function invalidated() {
|
||||
$('#source').val(JSON.stringify(table, null, indentation));
|
||||
$('#source').autogrow();
|
||||
}
|
||||
|
||||
function copySource(el) {
|
||||
$('#source').get()[0].select();
|
||||
document.execCommand('copy');
|
||||
|
||||
Reference in New Issue
Block a user