From ebacf9ec5e5813b7be557eefd524f505006d08bf Mon Sep 17 00:00:00 2001 From: Misode Date: Fri, 21 Jun 2019 04:51:33 +0200 Subject: [PATCH] Support for text components and float ranges --- index.html | 8 ++++---- model.js | 34 ++++++++++++++++++++++++++++------ view.js | 16 ++++++++++------ 3 files changed, 42 insertions(+), 16 deletions(-) diff --git a/index.html b/index.html index b449be86..4dbbc9d0 100644 --- a/index.html +++ b/index.html @@ -214,9 +214,9 @@ Min - + Max - + n p @@ -329,7 +329,7 @@
Name
- +
@@ -355,7 +355,7 @@
- +
diff --git a/model.js b/model.js index 7d2f547c..7090ec80 100644 --- a/model.js +++ b/model.js @@ -12,7 +12,7 @@ let table = { pools: [] }; addPool(); -addCondition($('#structure .pool').get()); +addEntry($('#structure .pool').get()); const params = new URLSearchParams(window.location.search); if (params.has('q')) { @@ -247,7 +247,12 @@ function deleteValue(root, field) { function updateField(el, field) { updateValue(getParent(el), field, $(el).val()); - console.log(getParent(el)); + invalidated(); +} + +function updateJSONField(el, field) { + let value = parseJSONValue($(el).val()); + updateValue(getParent(el), field, value); invalidated(); } @@ -290,13 +295,13 @@ function updateRangeField(el, field) { function getRangeField($el, type) { if (type === 'exact') { - return parseInt($el.find('.exact').val()); + return parseFloat($el.find('.exact').val()); } else if (type === 'range') { let data = {}; let min = $el.find('.range.min').val(); let max = $el.find('.range.max').val(); - if (min) data.min = parseInt(min); - if (max) data.max = parseInt(max); + if (min) data.min = parseFloat(min); + if (max) data.max = parseFloat(max); return data; } else if (type === 'binomial') { let data = {type: "minecraft:binomial"}; @@ -406,8 +411,25 @@ function updateScoreField(el) { invalidated(); } +function parseJSONValue(value) { + if (value.startsWith('"') || value.startsWith('{') || value.startsWith('[')) { + try { + return JSON.parse(value); + } catch { + return value; + } + } + return value; +} + function updateLoreField(el) { - console.log($(el).val()); + let lines = $(el).val().split('\n'); + let parent = getParent(el); + parent.lore = []; + for (let line of lines) { + parent.lore.push(parseJSONValue(line)); + } + invalidated(); } function addOperation(el) { diff --git a/view.js b/view.js index c1ff67b0..d3040005 100644 --- a/view.js +++ b/view.js @@ -230,7 +230,11 @@ function generateFunction(func, i) { if (func.function === 'minecraft:set_name') { $function.find('.function-name').removeClass('d-none'); - $function.find('.function-name input').val(func.name); + let value = func.name; + if (typeof value !== 'string') { + value = JSON.stringify(value); + } + $function.find('.function-name input').val(value); } else { delete func.name; } @@ -239,7 +243,11 @@ function generateFunction(func, i) { let lore = ""; if (func.lore) { for (let j = 0; j < func.lore.length; j += 1) { - lore += func.lore[j]; + let value = func.lore[j]; + if (typeof value !== 'string') { + value = JSON.stringify(value); + } + lore += value; if (j < func.lore.length - 1) { lore += "\n"; } @@ -385,7 +393,6 @@ function generateModifier(modifier, i) { } function generateOperation(operation, i) { - console.log(operation, i); let $operation = $('#operationTemplate').clone(); $operation.removeAttr('id').attr('data-index', i); @@ -508,8 +515,6 @@ function generateCondition(condition, i) { } if (condition.condition === 'minecraft:match_tool') { - console.log('!!'); - console.log(condition.predicate); let $item = generateItem(condition.predicate); $condition.children('.card-body').append($item); } else { @@ -692,7 +697,6 @@ function generateEntity(entity) { function generateItem(item) { let $item = $('#itemTemplate').clone().removeAttr('id').addClass('predicate'); - console.log(item.nbt); if (!item) { item = {}; }