Initial commit

This commit is contained in:
Misode
2019-06-17 06:13:30 +02:00
commit bd6e7fc570
3 changed files with 178 additions and 0 deletions
+76
View File
@@ -0,0 +1,76 @@
(function($)
{
/**
* Auto-growing textareas; technique ripped from Facebook
*
*
* http://github.com/jaz303/jquery-grab-bag/tree/master/javascripts/jquery.autogrow-textarea.js
*/
$.fn.autogrow = function(options)
{
return this.filter('textarea').each(function()
{
var self = this;
var $self = $(self);
var minHeight = $self.height();
var noFlickerPad = $self.hasClass('autogrow-short') ? 0 : parseInt($self.css('lineHeight')) || 0;
var settings = $.extend({
preGrowCallback: null,
postGrowCallback: null
}, options );
var shadow = $('<div></div>').css({
position: 'absolute',
top: -10000,
left: -10000,
width: $self.width(),
fontSize: $self.css('fontSize'),
fontFamily: $self.css('fontFamily'),
fontWeight: $self.css('fontWeight'),
lineHeight: $self.css('lineHeight'),
resize: 'none',
'word-wrap': 'break-word'
}).appendTo(document.body);
var update = function(event)
{
var times = function(string, number)
{
for (var i=0, r=''; i<number; i++) r += string;
return r;
};
var val = self.value.replace(/&/g, '&amp;')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/\n$/, '<br/>&#xa0;')
.replace(/\n/g, '<br/>')
.replace(/ {2,}/g, function(space){ return times('&#xa0;', space.length - 1) + ' ' });
// Did enter get pressed? Resize in this keydown event so that the flicker doesn't occur.
if (event && event.data && event.data.event === 'keydown' && event.keyCode === 13) {
val += '<br />';
}
shadow.css('width', $self.width());
shadow.html(val + (noFlickerPad === 0 ? '...' : '')); // Append '...' to resize pre-emptively.
var newHeight=Math.max(shadow.height() + noFlickerPad, minHeight);
if(settings.preGrowCallback!=null){
newHeight=settings.preGrowCallback($self,shadow,newHeight,minHeight);
}
$self.height(newHeight);
if(settings.postGrowCallback!=null){
settings.postGrowCallback($self);
}
}
$self.change(update).keyup(update).keydown({event:'keydown'},update);
$(window).resize(update);
update();
});
};
})(jQuery);
+55
View File
@@ -0,0 +1,55 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<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">
</head>
<body>
<nav class="navbar navbar-dark bg-dark">
<span class="navbar-brand mb-0 h1">Loot Table Generator for Minecraft 1.14</span>
</nav>
<div class="container">
<div class="row my-4">
<div class="col-12 col-md-7">
<div class="btn-group pb-3">
<button type="button" class="btn btn-success d-block float-left" onclick="addPool(this)">Add Pool</button>
</div>
<div id="structure">
</div>
</div>
<div class="col-12 col-md-5">
<div class="btn-group pb-3 float-right">
<button type="button" class="btn btn-light" onclick="copySource(this)">Copy</button>
</div>
<textarea id="source" class="form-control"></textarea>
</div>
</div>
</div>
<div class="d-none">
<div id="poolTemplate" class="card pool">
<div class="card-header">
<button type="button" class="btn btn-outline-success mr-3 float-left">Add Entry</button>
<button type="button" class="btn btn-outline-success float-left">Add Condition</button>
<button type="button" class="btn btn-danger float-right" onclick="removePool(this)">Remove Pool</button>
</div>
<div class="card-body">
<div class="input-group">
<div class="input-group-prepend">
<span class="input-group-text">Rolls</span>
</div>
<input type="text" class="form-control" onchange="updateRollsField(this)" value="1">
</div>
</div>
</div>
</div>
<script src="https://code.jquery.com/jquery-3.4.1.min.js" integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo=" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.6/umd/popper.min.js" integrity="sha384-wHAiFfRlMFy6i5SRaxvfOCifBUQy1xHdJ/yoi7FRNXMRBu5WHdZYu1hA6ZOblgut" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/js/bootstrap.min.js" integrity="sha384-B0UglyR+jN6CkvvICOB2joaf5I4l3gm9GU6Hc1og6Ls7i6U/mkkaduKaBhlAXv9k" crossorigin="anonymous"></script>
<script src="autogrow.js" charset="utf-8"></script>
<script src="script.js" charset="utf-8"></script>
</body>
</html>
+47
View File
@@ -0,0 +1,47 @@
$("#source").val('');
let table = {
pools: []
};
addPool();
function addPool(el) {
table.pools.push({
rolls: 1,
entries: []
});
let $pool = $('#poolTemplate').clone();
$pool.removeAttr('id').attr('data-index', table.pools.length - 1);
$('#structure').append($pool);
invalidated();
}
function removePool(el) {
let $pool = $(el).parent().parent();
table.pools.pop($pool.attr('data-index'));
$('#structure .pool').each((i, el) => {
if ($(el).attr('data-index') > $pool.attr('data-index')) {
$(el).attr('data-index', $(el).attr('data-index') - 1);
}
});
$pool.remove();
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, 2));
$('#source').autogrow();
}
function copySource(el) {
$('#source').get()[0].select();
document.execCommand('copy');
}