diff --git a/custom.css b/custom.css index 42e52d05..7714c16c 100644 --- a/custom.css +++ b/custom.css @@ -1,25 +1,43 @@ .card.bg-info { background-color: #91cdd6 !important; + color: black !important; } .card.bg-success { background-color: #91d8a1 !important; + color: black !important; } .card.bg-secondary { background-color: #adb5bd !important; + color: black !important; } .card.bg-dark { background-color: #646b72 !important; + color: white !important; } .dropdown-item { cursor: pointer; } + +.code { + font-family: Courier New, Courier, Lucida Sans Typewriter, Lucida Typewriter, monospace; + tab-size: 4; + -moz-tab-size: 4; + -o-tab-size: 4; + -webkit-tab-size: 4; +} + textarea.invalid { border-color: red !important; } + +textarea.invalid:focus { + box-shadow: 0 0 0 .2rem rgba(255,0,0,.25) !important; +} + .scrollable-menu { height: auto; max-height: 300px; diff --git a/index.html b/index.html index 838908c1..11729aef 100644 --- a/index.html +++ b/index.html @@ -47,10 +47,10 @@ - + - + @@ -68,40 +68,40 @@ Rolls - + Min - + Max - + n - + p - +
Bonus Rolls
- + Min - + Max - + n - + p - +
@@ -109,41 +109,41 @@
- `` +
Type
- - +
Name
- +
Weight
- +
Quality
- +
@@ -160,15 +160,24 @@
Function
- + + + + + + + + +
@@ -176,46 +185,46 @@ Count
- + Min - + Max - + n - + p - +
Damage
- + Min - + Max - + n - + p - +
Tag
- +
@@ -273,24 +282,24 @@ Levels
- + Min - + Max - + n - + p - +
- +
@@ -298,11 +307,107 @@
Limit
- +
+
+
+ Source +
+ +
+
+
+ Name +
+ +
+
+
+ limit + + +
+ + Min + + Max + + n + + p + +
+
+ +
+
+ +
+
+
+ + +
+
+
+
+ Entity +
+ +
+
+ +
+
+
+ Enchantment +
+ +
+
+
+ Formula +
+ +
+
+
+ Multiplier +
+ +
+
+
+ Extra +
+ +
+
+
+ Propability +
+ +
@@ -314,7 +419,7 @@
Attribute
- @@ -334,33 +439,33 @@
Name
- +
Amount
- + Min - + Max - + n - + p - +
Operation
- @@ -388,6 +493,35 @@
+
+
+ +
+
+
+
+ Source +
+ +
+
+
+ Target +
+ +
+
+
+ Operation +
+ +
+
+
@@ -397,7 +531,7 @@
Condition
- @@ -409,17 +543,17 @@
Chance
- +
Looting Multiplier
- +
- +
@@ -427,7 +561,7 @@
Entity
- @@ -456,15 +590,15 @@
- + Min - + Max - +
diff --git a/model.js b/model.js index 321e6733..e4f07df6 100644 --- a/model.js +++ b/model.js @@ -5,6 +5,7 @@ $('#tableType').val("minecraft:generic"); $('#indentationSelect').val("2"); let indentation = 2; let luck_based = false; +let nodes = '.table, .pool, .entry, .child, .term, .terms, .function, .condition, .modifier, .operation'; let table = { type: "minecraft:generic", pools: [] @@ -48,7 +49,7 @@ function copySource(el) { } function getParent(el) { - let $parent = $(el).closest('.table, .pool, .entry, .child, .term, .function, .condition, .modifier'); + let $parent = $(el).closest(nodes); let index = $parent.attr('data-index'); if ($parent.hasClass('table')) { return table; @@ -60,22 +61,26 @@ function getParent(el) { return getParent($parent.parent()).children[index]; } else if ($parent.hasClass('term')) { return getParent($parent.parent()).term; + } else if ($parent.hasClass('terms')) { + return getParent($parent.parent()).terms[index]; } else if ($parent.hasClass('function')) { return getParent($parent.parent()).functions[index]; } else if ($parent.hasClass('condition')) { return getParent($parent.parent()).conditions[index]; } else if ($parent.hasClass('modifier')) { return getParent($parent.parent()).modifiers[index]; + } else if ($parent.hasClass('operation')) { + return getParent($parent.parent()).ops[index]; } } function getSuperParent(el) { - let $parent = $(el).closest('.table, .pool, .entry, .child, .term, .function, .condition, .modifier .score'); + let $parent = $(el).closest(nodes); return getParent($parent.parent()); } function getIndex(el) { - let $parent = $(el).closest('.table, .pool, .entry, .child, .term, .function, .condition, .modifier'); + let $parent = $(el).closest(nodes); return parseInt($parent.attr('data-index')); } @@ -94,7 +99,11 @@ function removePool(el) { } function addEntry(el) { - getParent(el).entries.push({ + let pool = getParent(el); + if (!pool.entries) { + pool.entries = []; + } + pool.entries.push({ type: "minecraft:item", name: "minecraft:stone" }); @@ -108,7 +117,11 @@ function removeEntry(el) { } function addChild(el) { - getParent(el).children.push({ + let entry = getParent(el); + if (!entry.children) { + entry.children = []; + } + entry.children.push({ type: "minecraft:item", name: "minecraft:stone" }); @@ -116,8 +129,12 @@ function addChild(el) { } function removeChild(el) { + let parent = getSuperParent(el); let index = getIndex(el); - getSuperParent(el).children.splice(index, 1); + parent.children.splice(index, 1); + if (parent.children.length === 0) { + delete parent.children; + } invalidated(); } @@ -162,6 +179,48 @@ function removeCondition(el) { invalidated(); } +function updateField(el, field) { + getParent(el)[field] = $(el).val(); + invalidated(); +} + +function updateIntField(el, field) { + let value = parseInt($(el).val()); + if (isNaN(value)) { + delete getParent(el)[field]; + } else { + getParent(el)[field] = value; + } + invalidated(); +} + +function updateFloatField(el, field) { + let value = parseFloat($(el).val()); + if (isNaN(value)) { + delete getParent(el)[field]; + } else { + getParent(el)[field] = value; + } + invalidated(); +} + +function updateCheckedField(el, field) { + getParent(el)[field] = $(el).prop('checked'); + invalidated(); +} + +function updateRangeField(el, field) { + let type = $(el).closest('[data-type]').attr('data-type'); + let data = getRangeField($(el).closest('[data-type]'), type); + getParent(el)[field] = data; + invalidated(); +} + +function updateRangeType(el, field, type) { + $(el).closest('[data-type]').attr('data-type', type); + updateRangeField(el, field); +} + function getRangeField($el, type) { if (type === 'exact') { return parseInt($el.find('.exact').val()); @@ -182,114 +241,6 @@ function getRangeField($el, type) { } } -function switchRollsType(el, type) { - $(el).closest('.rolls').attr('data-type', type); - updateRollsField(el); -} - -function updateRollsField(el) { - let type = $(el).closest('.rolls').attr('data-type'); - let data = getRangeField($(el).closest('.rolls'), type); - getParent(el).rolls = data; - invalidated(); -} - -function switchBonusRollsType(el, type) { - $(el).closest('.bonus-rolls').attr('data-type', type); - updateBonusRollsField(el); -} - -function updateBonusRollsField(el) { - let type = $(el).closest('.bonus-rolls').attr('data-type'); - let data = getRangeField($(el).closest('.bonus-rolls'), type); - if (type ==='exact' && isNaN(data)) { - delete getParent(el).bonus_rolls; - } else { - getParent(el).bonus_rolls = data; - } - invalidated(); -} - -function updateEntryType(el) { - let entry = getParent(el); - entry.type = $(el).val(); - if (entry.type === 'minecraft:dynamic') { - entry.name = 'minecraft:contents'; - } - invalidated(); -} - -function updateEntryName(el) { - let entry = getParent(el); - if (entry.type === 'minecraft:dynamic') { - entry.name = 'minecraft:contents'; - } else { - entry.name = $(el).val(); - } - invalidated(); -} - -function updateEntryWeight(el) { - let weight = parseInt($(el).val()); - if (isNaN(weight)) { - delete getParent(el).weight; - } else { - getParent(el).weight = weight; - } - invalidated(); -} - -function updateEntryQuality(el) { - let quality = parseInt($(el).val()); - if (isNaN(quality)) { - delete getParent(el).quality; - } else { - getParent(el).quality = quality; - } - invalidated(); -} - -function updateFunctionType(el) { - getParent(el).function = $(el).val(); - invalidated(); -} - -function switchCountType(el, type) { - $(el).closest('.function-count').attr('data-type', type); - updateCountField(el); -} - -function updateCountField(el) { - let type = $(el).closest('.function-count').attr('data-type'); - let data = getRangeField($(el).closest('.function-count'), type); - getParent(el).count = data; - invalidated(); -} - -function switchDamageType(el, type) { - $(el).closest('.function-damage').attr('data-type', type); - updateDamageField(el); -} - -function updateDamageField(el) { - let type = $(el).closest('.function-damage').attr('data-type'); - let data = getRangeField($(el).closest('.function-damage'), type); - getParent(el).damage = data; - invalidated(); -} - -function updateTagField(el) { - let nbt = $(el).val(); - if (!nbt.startsWith('{')) { - nbt = '{' + nbt; - } - if (!nbt.endsWith('}')) { - nbt = nbt + '}'; - } - getParent(el).tag = nbt; - invalidated(); -} - function addEnchantment(el) { let func = getParent(el); let enchantment = $(el).attr('data-ench'); @@ -313,38 +264,6 @@ function removeEnchantment(el) { } } -function switchLevelsType(el, type) { - $(el).closest('.function-ench-levels').attr('data-type', type); - updateLevelsField(el); -} - -function updateLevelsField(el) { - let type = $(el).closest('.function-ench-levels').attr('data-type'); - let data = getRangeField($(el).closest('.function-ench-levels'), type); - getParent(el).levels = data; - invalidated(); -} - -function updateTreasureField(el) { - let treasure = $(el).prop('checked'); - if (treasure) { - getParent(el).treasure = true; - } else { - delete getParent(el).treasure; - } - invalidated(); -} - -function updateLimitField(el) { - let limit = parseInt($(el).val()); - if (isNaN(limit)) { - delete getParent(el).limit; - } else { - getParent(el).limit = limit; - } - invalidated(); -} - function addModifier(el) { let func = getParent(el); if (!func.modifiers) { @@ -362,34 +281,7 @@ function addModifier(el) { function removeModifier(el) { let index = parseInt($(el).closest('.modifier').attr('data-index')); - getParent(el).modifiers.splice(index, 1); - invalidated(); -} - -function updateModifierAttribute(el) { - getParent(el).attribute = $(el).val(); - invalidated(); -} - -function updateModifierName(el) { - getParent(el).name = $(el).val(); - invalidated(); -} - -function switchModifierAmountType(el, type) { - $(el).closest('.modifier-amount').attr('data-type', type); - updateModifierAmountField(el); -} - -function updateModifierAmountField(el) { - let type = $(el).closest('.modifier-amount').attr('data-type'); - let data = getRangeField($(el).closest('.modifier-amount'), type); - getParent(el).amount = data; - invalidated(); -} - -function updateModifierOperation(el) { - getParent(el).operation = $(el).val(); + getSuperParent(el).modifiers.splice(index, 1); invalidated(); } @@ -415,52 +307,6 @@ function removeModifierSlot(el) { } } -function updateConditionType(el) { - let condition = $(el).val(); - let $condition = getParent(el); - if (condition === 'minecraft:random_chance_with_looting') { - $condition.looting_multiplier = 1; - } else if (condition === 'minecraft:entity_properties' || condition === 'minecraft:entity_scores'){ - $condition.entity = 'this'; - } - $condition.condition = condition; - invalidated(); -} - -function updateConditionChance(el) { - let chance = parseFloat($(el).val()); - if (isNaN(chance)) { - delete getParent(el).chance; - } else { - getParent(el).chance = chance; - } - invalidated(); -} - -function updateConditionLootingMultiplier(el) { - let multiplier = parseFloat($(el).val()); - if (isNaN(multiplier)) { - multiplier = 1; - } - getParent(el).looting_multiplier = multiplier; - invalidated(); -} - -function updateInvertedField(el) { - let inverted = $(el).prop('checked'); - if (inverted) { - getParent(el).inverted = true; - } else { - delete getParent(el).inverted; - } - invalidated(); -} - -function updateConditionEntity(el) { - getParent(el).entity = $(el).val(); - invalidated(); -} - function addScore(el) { let condition = getParent(el); let objective = $(el).closest('.condition-entity-scores').find('input').val(); @@ -477,15 +323,58 @@ function removeScore(el) { invalidated(); } -function switchConditionScoreType(el, type) { +function updateScoreType(el, type) { $(el).closest('.score').attr('data-type', type); updateConditionScoreField(el); } -function updateConditionScoreField(el) { +function updateScoreField(el) { let type = $(el).closest('.score').attr('data-type'); let data = getRangeField($(el).closest('.score'), type); let objective = $(el).closest('.score').attr('data-objective'); getParent(el).scores[objective] = data; invalidated(); } + +function updateLoreField(el) { + console.log($(el).val()); +} + +function addOperation(el) { + let func = getParent(el); + if (!func.ops) { + func.ops = []; + } + func.ops.push({ + source: '', + target: '', + op: 'replace' + }); + invalidated(); +} + +function removeOperation(el) { + let index = parseInt($(el).closest('.operation').attr('data-index')); + getSuperParent(el).ops.splice(index, 1); + invalidated(); +} + +function updateIntField(el, field) { + let value = parseInt($(el).val()); + if (isNaN(value)) { + delete getParent(el).parameters[field]; + } else { + getParent(el).parameters[field] = value; + } + invalidated(); +} + +function updateFloatField(el, field) { + let value = parseFloat($(el).val()); + if (isNaN(value)) { + delete getParent(el).parameters[field]; + } else { + getParent(el).parameters[field] = value; + } + invalidated(); +} diff --git a/view.js b/view.js index ed270484..8918326c 100644 --- a/view.js +++ b/view.js @@ -39,14 +39,12 @@ function generatePool(pool, i) { let $pool = $('#poolTemplate').clone(); $pool.removeAttr('id').attr('data-index', i); - // Rolls if (!pool.rolls) { pool.rolls = 1; } let $rolls = $pool.find('.rolls'); generateRange($rolls, pool.rolls); - // Bonus Rolls let $bonus_rolls = $pool.find('.bonus-rolls'); if (pool.bonus_rolls) { luck_based = true; @@ -59,7 +57,7 @@ function generatePool(pool, i) { } for (let j = 0; j < pool.entries.length; j += 1) { - let $entry = generateEntry(pool.entries[j], j); + let $entry = generateEntry(pool.entries[j], j, pool.entries.length); $pool.children('.card-body').append($entry); } @@ -73,7 +71,7 @@ function generatePool(pool, i) { return $pool; } -function generateEntry(entry, i) { +function generateEntry(entry, i, size) { let $entry = $('#entryTemplate').clone(); $entry.removeAttr('id').attr('data-index', i); @@ -85,13 +83,15 @@ function generateEntry(entry, i) { } $entry.find('.entry-name input').val(entry.name); } - $entry.find('.entry-weight').removeClass('d-none'); + if (size > 1) { + $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) { + if (entry.weight ) { $entry.find('.entry-weight input').val(entry.weight); } if (entry.quality) { @@ -105,7 +105,7 @@ function generateEntry(entry, i) { if (entry.children) { for (let j = 0; j < entry.children.length; j += 1) { - let $child = generateEntry(entry.children[j], j); + let $child = generateEntry(entry.children[j], j, entry.children.length); $child.removeClass('entry').addClass('child'); $entry.children('.card-body').append($child); } @@ -133,24 +133,36 @@ function generateFunction(func, i) { $function.removeAttr('id').attr('data-index', i); $function.find('.function-type').val(func.function); + if (func.function === 'minecraft:set_count' || func.function === 'minecraft:looting_enchant') { $function.find('.function-count').removeClass('d-none'); generateRange($function.find('.function-count'), func.count); } else { delete func.count; } + if (func.function === 'minecraft:set_damage') { $function.find('.function-damage').removeClass('d-none'); generateRange($function.find('.function-damage'), func.damage); } else { delete func.damage; } + if (func.function === 'minecraft:set_nbt') { + if (func.tag) { + if (!func.tag.startsWith('{')) { + func.tag = '{' + func.tag; + } + if (!func.tag.endsWith('}')) { + func.tag = func.tag + '}'; + } + } $function.find('.function-nbt').removeClass('d-none'); $function.find('.function-nbt input').val(func.tag); } else { delete func.tag; } + if (func.function === 'minecraft:enchant_randomly') { $function.find('.function-ench-rand').removeClass('d-none'); if (func.enchantments) { @@ -164,6 +176,7 @@ function generateFunction(func, i) { } else { delete func.enchantments; } + if (func.function === 'minecraft:enchant_with_levels') { $function.find('.function-ench-levels').removeClass('d-none'); generateRange($function.find('.function-ench-levels'), func.levels); @@ -171,6 +184,8 @@ function generateFunction(func, i) { let treasure = false; if (func.treasure) { treasure = true; + } else { + delete func.treasure; } let id = 'treasureCheckbox' + Math.floor(1000000*Math.random()); $function.find('.function-ench-treasure label').attr('for', id); @@ -179,12 +194,19 @@ function generateFunction(func, i) { delete func.levels; delete func.treasure; } - if (func.function === 'minecraft:looting_enchant') { - $function.find('.function-limit').removeClass('d-none'); - $function.find('.function-limit input').val(func.limit); + + if (func.function === 'minecraft:looting_enchant' || func.function === 'minecraft:looting_enchant' || func.function === 'minecraft:limit_count') { + if (func.function === 'minecraft:looting_enchant' || func.function === 'minecraft:limit_count') { + $function.find('.function-limit').removeClass('d-none'); + $function.find('.function-limit input').val(func.limit); + } else { + $function.find('.function-limit-range').removeClass('d-none'); + generateRange($function.find('.function-limit-range'), func.limit); + } } else { delete func.limit; } + if (func.function === 'minecraft:set_attributes') { $function.find('.function-attributes').removeClass('d-none'); if (func.modifiers) { @@ -197,6 +219,132 @@ function generateFunction(func, i) { delete func.modifiers; } + if (func.function === 'minecraft:set_name') { + $function.find('.function-name').removeClass('d-none'); + $function.find('.function-name input').val(func.name); + } else { + delete func.name; + } + + if (func.function === 'minecraft:set_lore') { + let lore = ""; + if (func.lore) { + for (let j = 0; j < func.lore.length; j += 1) { + lore += func.lore[j]; + if (j < func.lore.length - 1) { + lore += "\n"; + } + } + } + + $function.find('.function-lore').removeClass('d-none'); + $function.find('.function-lore textarea').val(lore); + + if(!func.replace) { + delete func.replace; + } + + $function.find('.function-lore-replace').removeClass('d-none'); + $function.find('.function-lore-replace input').prop('checked', func.replace); + } else { + delete func.lore; + delete func.replace; + } + + if (func.function === 'minecraft:copy_name' || func.function === 'minecraft:copy_nbt') { + if (func.function === 'minecraft:copy_name') { + func.source = 'block_entity'; + } + if (!func.source) { + func.source = 'this'; + } + $function.find('.function-source').removeClass('d-none'); + $function.find('.function-source select').val(func.source); + } else { + delete func.source; + } + + if (func.function === 'minecraft:set_name' || func.function === 'minecraft:fill_player_head') { + if (!func.entity) { + func.entity = 'this'; + } + $function.find('.function-entity').removeClass('d-none'); + $function.find('.function-entity select').val(func.entity); + } else { + delete func.entity; + } + + if (func.function === 'minecraft:set_contents') { + $function.find('.function-entries').removeClass('d-none'); + } else { + delete func.entries; + } + + if (func.function === 'minecraft:copy_nbt') { + $function.find('.function-operations').removeClass('d-none'); + } else { + delete func.ops; + } + + if (func.function === 'minecraft:apply_bonus') { + $function.find('.function-enchantment').removeClass('d-none'); + $function.find('.function-entity input').val(func.enchantment); + } else { + delete func.enchantment; + } + + if (func.function === 'minecraft:apply_bonus') { + if (!func.formula) { + func.formula = 'minecraft:uniform_bonus_count'; + } + $function.find('.function-formula').removeClass('d-none'); + $function.find('.function-formula select').val(func.formula); + + if (!func.parameters){ + func.parameters = {}; + } + if (func.formula === 'minecraft:uniform_bonus_count') { + if (!func.parameters.bonusMultiplier) { + func.parameters.bonusMultiplier = 1; + } + delete func.parameters.extra; + delete func.parameters.probability; + $function.find('.function-bonus-multiplier').removeClass('d-none'); + $function.find('.function-bonus-multiplier input').val(func.parameters.bonusMultiplier); + } else if (func.formula === 'minecraft:binomial_with_bonus_count') { + if (!func.parameters.extra) { + func.parameters.extra = 0; + } + if (!func.parameters.probability) { + func.parameters.probability = 0.5; + } + delete func.parameters.multiplier; + console.log(func); + $function.find('.function-bonus-extra').removeClass('d-none'); + $function.find('.function-bonus-extra input').val(func.parameters.extra); + $function.find('.function-bonus-probability').removeClass('d-none'); + $function.find('.function-bonus-probability input').val(func.parameters.probability); + } else { + delete func.parameters; + } + } else { + delete func.formula; + } + + if (func.ops) { + for (let j = 0; j < func.ops.length; j += 1) { + let $operation = generateOperation(func.ops[j], j); + $function.children('.card-body').append($operation); + } + } + + if (func.entries) { + for (let j = 0; j < func.entries.length; j += 1) { + let $entry = generateEntry(func.entries[j], j, func.entries.length); + $function.children('.card-body').append($entry); + } + } + if (func.conditions) { for (let j = 0; j < func.conditions.length; j += 1) { let $condition = generateCondition(func.conditions[j], j); @@ -228,6 +376,19 @@ function generateModifier(modifier, i) { return $modifier } +function generateOperation(operation, i) { + console.log(operation, i); + let $operation = $('#operationTemplate').clone(); + $operation.removeAttr('id').attr('data-index', i); + + $operation.find('.operation-source').val(operation.source); + $operation.find('.operation-target').val(operation.target); + + $operation.find('.operation-type').val(operation.op); + + return $operation +} + function generateCondition(condition, i) { let $condition = $('#conditionTemplate').clone(); $condition.removeAttr('id').attr('data-index', i);