From 45001a320426e02cd27831e7c167842211beceba Mon Sep 17 00:00:00 2001 From: Misode Date: Mon, 24 Jun 2019 16:05:51 +0200 Subject: [PATCH 01/22] Abstraction of data fields and nodes --- custom.css | 2 +- index.html | 463 ++++++++++++++++++++++++++--------------------------- model.js | 343 ++++++++++++++++----------------------- view.js | 24 +-- 4 files changed, 375 insertions(+), 457 deletions(-) diff --git a/custom.css b/custom.css index 294eeb6f..bb6c5143 100644 --- a/custom.css +++ b/custom.css @@ -23,7 +23,7 @@ background-color: #eee !important; } -.card.term, .card.terms { +.card.bg-info .card.bg-info { background-color: #7cb6bf !important; } diff --git a/index.html b/index.html index c3ab726c..7fa074b5 100644 --- a/index.html +++ b/index.html @@ -36,7 +36,7 @@ -
+
@@ -63,67 +63,67 @@
-
+
- +
-
+
Rolls
- + Min - + Max - + n - + p - +
-
+
Bonus Rolls
- + Min - + Max - + n - + p - +
-
+
- +
-
+
Type
- @@ -134,40 +134,40 @@
-
+
Name
- +
-
+
Weight
- +
-
+
Quality
- +
-
+
- +
-
+
Function
- @@ -187,53 +187,53 @@
-
+
Count
- + Min - + Max - + n - + p - +
-
+
Damage
- + Min - + Max - + n - + p - +
-
+
- Tag + NBT
- +
-
+
Optional Enchantments @@ -284,95 +284,84 @@
-
+
Levels
- + Min - + Max - + n - + p - +
-
+
- +
-
+
Limit
- +
-
+
Source
-
-
+
Name
- +
-
+
limit - -
- - Min - - Max - - n - - p - + Min + + Max +
-
+
-
+
- +
-
+
Entity
- @@ -381,52 +370,52 @@
-
+
Enchantment
- +
-
+
Formula
-
-
+
Multiplier
- +
-
+
Extra
- +
-
+
Propability
- +
-
+
- +
-
+
Attribute
- @@ -442,44 +431,44 @@
-
+
Name
- +
-
+
Amount
- + Min - + Max - + n - + p - +
-
+
Operation
-
-
+
Slots
@@ -500,28 +489,28 @@
-
+
- +
-
+
Source
- +
-
+
Target
- +
-
+
Operation
- @@ -529,16 +518,16 @@
-
+
- +
-
+
Condition
- @@ -555,29 +544,29 @@
-
+
Chance
- +
-
+
Looting Multiplier
- +
-
+
- +
-
+
Entity
- @@ -597,11 +586,11 @@
-
+
Block
- +
@@ -614,31 +603,31 @@
-
+
Raining
- - + +
-
+
Thundering
- - + +
-
+
Enchantment
- +
-
+
Chances
@@ -646,7 +635,7 @@
-
+
@@ -673,53 +662,53 @@
-
+
-
+
X
- Min - - Max - + Min + + Max +
-
+
Y
- Min - - Max - + Min + + Max +
-
+
Z
Min - + Max - +
-
+
Biome
- +
-
+
Feature
- +
-
+
Dimension
- @@ -728,24 +717,24 @@
-
+
-
+
Type
- +
-
+
NBT
- +
-
+
@@ -761,162 +750,162 @@ Tag
-
+
Count
- + Min - + Max - +
-
+
Durability
- + Min - + Max - +
-
+
Potion
- +
-
+
NBT
- +
-
+
-
+
Projectile
- - + +
-
+
Explosion
- - + +
-
+
Fire
- - + +
-
+
Magic
- - + +
-
+
Lightning
- - + +
-
+
Starvation
- - + +
-
+
Void
- - + +
-
+
Bypass Armor
- - + +
-
+
Dealt
- + Min - + Max - +
-
+
Taken
- + Min - + Max - +
-
+
Blocked
- - + +
diff --git a/model.js b/model.js index 753fd5d1..612432f2 100644 --- a/model.js +++ b/model.js @@ -6,7 +6,6 @@ $('#indentationSelect').val("2"); let indentation = 2; let luck_based = false; -const nodes = '.loot-table, .pool, .entry, .child, .term, .terms, .function, .condition, .modifier, .operation, .predicate, .location, .source-entity, .direct-entity'; let table = { type: "minecraft:generic", pools: [] @@ -77,46 +76,64 @@ function copySource(el) { } function getParent(el) { - let $parent = $(el).closest(nodes); - let index = $parent.attr('data-index'); - if ($parent.hasClass('loot-table')) { + let $node = $(el).closest('[data-field]'); + let fields = $node.attr('data-field').split('.'); + if (fields.length === 1 && fields[0] === 'table') { return table; - } else if ($parent.hasClass('pool')) { - return getParent($parent.parent()).pools[index]; - } else if ($parent.hasClass('entry')) { - return getParent($parent.parent()).entries[index]; - } else if ($parent.hasClass('child')) { - 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]; - } else if ($parent.hasClass('predicate')) { - return getParent($parent.parent()).predicate; - } else if ($parent.hasClass('location')) { - return getParent($parent.parent()).location; - } else if ($parent.hasClass('source-entity')) { - return getParent($parent.parent()).source_entity; - } else if ($parent.hasClass('direct-entity')) { - return getParent($parent.parent()).direct_entity; } + if ($node.attr('data-type')) { + fields = fields.slice(0, -1); + } + let node = getParent($node.parent()); + for (let f of fields) { + if (f.endsWith('[]')) { + f = f.slice(0, -2); + let index = $node.attr('data-index'); + node = node[f][index]; + } else { + if (node[f] === undefined) { + node[f] = {}; + } + node = node[f]; + } + } + return node; } function getSuperParent(el) { - let $parent = $(el).closest(nodes); + let $parent = $(el).closest('[data-field]'); return getParent($parent.parent()); } +function setField(node, field, value) { + let fields = field.split('.'); + let last = fields.splice(-1)[0]; + for (let f of fields) { + node = node[f]; + } + node[last] = value; +} + +function deleteField(node, field) { + let fields = field.split('.'); + let last = fields.splice(-1)[0]; + for (let f of fields) { + node = node[f]; + } + delete node[last]; +} + +function getField(node, field) { + let fields = field.split('.'); + let last = fields.splice(-1)[0]; + for (let f of fields) { + node = node[f]; + } + return node[last]; +} + function getIndex(el) { - let $parent = $(el).closest(nodes); + let $parent = $(el).closest('[data-field]'); return parseInt($parent.attr('data-index')); } @@ -130,16 +147,6 @@ function addPool(el) { invalidated(); } -function removePool(el) { - let parent = getSuperParent(el); - let index = getIndex(el); - parent.pools.splice(index, 1); - if (parent.pools.length === 0) { - delete parent.pools; - } - invalidated(); -} - function addEntry(el) { let pool = getParent(el); if (!pool.entries) { @@ -152,16 +159,6 @@ function addEntry(el) { invalidated(); } -function removeEntry(el) { - let parent = getSuperParent(el); - let index = getIndex(el); - parent.entries.splice(index, 1); - if (parent.entries.length === 0) { - delete parent.entries; - } - invalidated(); -} - function addChild(el) { let entry = getParent(el); if (!entry.children) { @@ -174,16 +171,6 @@ function addChild(el) { invalidated(); } -function removeChild(el) { - let parent = getSuperParent(el); - let index = getIndex(el); - parent.children.splice(index, 1); - if (parent.children.length === 0) { - delete parent.children; - } - invalidated(); -} - function addFunction(el) { let entry = getParent(el); if (!entry.functions) { @@ -195,15 +182,6 @@ function addFunction(el) { invalidated(); } -function removeFunction(el) { - let parent = getSuperParent(el); - parent.functions.splice(getIndex(el), 1); - if (parent.functions.length === 0) { - delete parent.functions; - } - invalidated(); -} - function addCondition(el) { let parent = getParent(el); if (!parent.conditions) { @@ -216,161 +194,115 @@ function addCondition(el) { invalidated(); } -function removeCondition(el) { - let parent = getSuperParent(el); - if (parent.conditions) { - parent.conditions.splice(getIndex(el), 1); - if (parent.conditions.length === 0) { - delete parent.conditions; +function updateField(el) { + let $field = $(el).closest('[data-field]'); + let fields = $field.attr('data-field'); + let field = fields.split('.').slice(-1)[0]; + let type = $field.attr('data-type'); + let node = getParent(el); + let value = undefined; + + if (type === 'string' || type === 'int' || type === 'float' || type === 'enum' || type === 'json' || type === 'nbt') { + value = $(el).val(); + } + if (type === 'int') { + value = parseInt(value); + if (isNaN(value)) { + value = ''; } - } else { - parent.terms.splice(getIndex(el), 1); - if (parent.terms.length === 0) { - delete parent.terms; + } else if (type === 'float') { + value = parseFloat(value); + if (isNaN(value)) { + value = ''; } + } else if (type === 'nbt') { + + if (!value.startsWith('{')) { + value = '{' + value; + } + if (!value.endsWith('}')) { + value = value + '}'; + } + } else if (type === 'json') { + value = parseJSONValue(value) + } else if (type === 'range') { + value = getRangeValue($field, node[field]); + } else if (type === 'checkbox') { + value = $(el).prop('checked'); + } else if (type === 'boolean') { + value = getBooleanValue(node[field], ($(el).val() === 'true')); } - invalidated(); -} - -function updateValue(root, field, value) { - let f = field.split('.'); - if (f.length === 1) return root[f[0]] = value; - if (!root[f[0]]) root[f[0]] = {}; - if (f.length === 2) return root[f[0]][f[1]] = value; - if (!root[f[0]][f[1]]) root[f[0]][f[1]] = {}; - if (f.length === 3) return root[f[0]][f[1]][f[2]] = value; - if (!root[f[0]][f[1]][f[2]]) root[f[0]][f[1]][f[2]] = {}; - if (f.length === 4) return root[f[0]][f[1]][f[2]][f[3]] = value; - if (!root[f[0]][f[1]][f[2]][f[3]]) root[f[0]][f[1]][f[2]][f[3]] = {}; - if (f.length === 5) return root[f[0]][f[1]][f[2]][f[3]][f[4]] = value; - if (!root[f[0]][f[1]][f[2]][f[3]][f[4]]) root[f[0]][f[1]][f[2]][f[3]][f[4]] = {}; - if (f.length === 6) return root[f[0]][f[1]][f[2]][f[3]][f[4]][f[5]] = value; -} - -function deleteValue(root, field) { - let f = field.split('.'); - if (f.length === 1) delete root[f[0]]; - if (f.length === 2) delete root[f[0]][f[1]]; - if (f.length === 3) delete root[f[0]][f[1]][f[2]]; - if (f.length === 4) delete root[f[0]][f[1]][f[2]][f[3]]; - if (f.length === 5) delete root[f[0]][f[1]][f[2]][f[3]][f[4]]; - if (f.length === 6) delete root[f[0]][f[1]][f[2]][f[3]][f[4]][f[6]]; -} - -function getValue(root, field) { - let f = field.split('.'); - if (f.length === 1) return root[f[0]]; - if (f.length === 2) return root[f[0]][f[1]]; - if (f.length === 3) return root[f[0]][f[1]][f[2]]; - if (f.length === 4) return root[f[0]][f[1]][f[2]][f[3]]; - if (f.length === 5) return root[f[0]][f[1]][f[2]][f[3]][f[4]]; - if (f.length === 6) return root[f[0]][f[1]][f[2]][f[3]][f[4]][f[6]]; -} - -function updateField(el, field) { - updateValue(getParent(el), field, $(el).val()); - invalidated(); -} - -function updateJSONField(el, field) { - let value = parseJSONValue($(el).val()); - updateValue(getParent(el), field, value); - invalidated(); -} - -function updateIntField(el, field) { - let value = parseInt($(el).val()); - if (isNaN(value)) { - deleteValue(getParent(el), field); + if (value === '') { + deleteField(node, field); } else { - updateValue(getParent(el), field, value); + setField(node, field, value); } invalidated(); } -function updateFloatField(el, field) { - let value = parseFloat($(el).val()); - if (isNaN(value)) { - deleteValue(getParent(el), field); - } else { - updateValue(getParent(el), field, value); +function removeField(el) { + let node = getSuperParent(el); + let $field = $(el).closest('[data-field]'); + let index = $field.attr('data-index'); + let last = $field.attr('data-field').slice(0, -2); + node[last].splice(index, 1); + if (node[last].length === 0) { + delete node[last]; } invalidated(); } -function updateCheckedField(el, field) { - getParent(el)[field] = $(el).prop('checked'); - invalidated(); -} - -function updateRangeType(el, field, type) { +function updateRangeType(el) { + let $field = $(el).closest('[data-field]'); + let field = $field.attr('data-field'); + let type = $(el).attr('value'); if (type === 'range') { - updateValue(getParent(el), field, {}); + setField(getParent(el), field, {}); } else if (type === 'binomial') { - updateValue(getParent(el), field, {type: "minecraft:binomial"}); + setField(getParent(el), field, {type: "minecraft:binomial"}); } else { - updateValue(getParent(el), field, 0); + setField(getParent(el), field, 0); } - updateRangeField(el, field); + updateField(el); } -function updateRangeField(el, field) { - let parent = getParent(el); - let data = getValue(parent, field); - let $range = $(el).closest('[data-type="range"]'); +function getRangeValue($field, data) { + console.log(data); if (typeof data === 'object') { + console.log('object'); if (data.type && data.type.match(/(minecraft:)?binomial/)) { - let n = $range.find('.binomial.n').val(); - let p = $range.find('.binomial.p').val(); - if (n) { - data.n = parseInt(n); - } else { - delete data.n; - } - if (p) { - data.p = parseFloat(p); - } else { - delete data.min; - } + let n = $field.find('.binomial.n').val(); + let p = $field.find('.binomial.p').val(); + if (n) data.n = parseInt(n); + else delete data.n; + if (p) data.p = parseFloat(p); + else delete data.p; } else { - let min = $range.find('.range.min').val(); - let max = $range.find('.range.max').val(); - if (min) { - data.min = parseFloat(min); - } else { - delete data.min; - } - if (max) { - data.max = parseFloat(max); - } else { - delete data.max; - } + let min = $field.find('.range.min').val(); + let max = $field.find('.range.max').val(); + if (min) data.min = parseFloat(min); + else delete data.min; + if (max) data.max = parseFloat(max); + else delete data.max; } } else { - data = parseFloat($range.find('.exact').val()); + console.log('else'); + data = parseFloat($field.find('.exact').val()); + if (isNaN(data)) { + data = ''; + } } - updateValue(parent, field, data); - invalidated(); + return data; } -function updateRadioField(el, field) { - let parent = getParent(el); - let value = $(el).val(); - let oldvalue = getValue(parent, field); - if (value === 'true') { - if (oldvalue === true) { - deleteValue(parent, field); - } else { - updateValue(getParent(el), field, true); - } - } else if (value === 'false') { - if (oldvalue === false) { - deleteValue(parent, field); - } else { - updateValue(getParent(el), field, false); - } +function getBooleanValue(oldvalue, newvalue) { + if (oldvalue === newvalue) { + return ''; + } else if (newvalue) { + return true; + } else { + return false; } - invalidated(); } function addEnchantment(el) { @@ -419,22 +351,19 @@ function removeModifier(el) { function addModifierSlot(el) { let modifier = getParent(el); - if (!modifier.slots) { - modifier.slots = []; + if (!modifier.slot) { + modifier.slot = []; } - modifier.slots.push($(el).attr('data-slot')); + modifier.slot.push($(el).attr('data-slot')); invalidated(); } function removeModifierSlot(el) { let modifier = getParent(el); let slot = $(el).attr('data-slot'); - let index = modifier.slots.indexOf(slot); + let index = modifier.slot.indexOf(slot); if (index > -1) { - modifier.slots.splice(index, 1); - if (modifier.slots.length === 0) { - delete modifier.slots; - } + modifier.slot.splice(index, 1); invalidated(); } } diff --git a/view.js b/view.js index 3206d6ea..a9c9f3c6 100644 --- a/view.js +++ b/view.js @@ -127,7 +127,7 @@ function generateEntry(entry, i, size) { if (entry.children) { for (let j = 0; j < entry.children.length; j += 1) { let $child = generateEntry(entry.children[j], j, entry.children.length); - $child.removeClass('entry').addClass('child'); + $child.attr('data-field', 'children[]'); $entry.children('.card-body').append($child); } } @@ -216,8 +216,8 @@ function generateFunction(func, i) { delete func.treasure; } - 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') { + if (func.function === 'minecraft:looting_enchant' || func.function === 'minecraft:limit_count') { + if (func.function === 'minecraft:looting_enchant') { $function.find('.function-limit').removeClass('d-none'); $function.find('.function-limit input').val(func.limit); } else { @@ -317,7 +317,7 @@ function generateFunction(func, i) { if (func.function === 'minecraft:apply_bonus') { $function.find('.function-enchantment').removeClass('d-none'); - $function.find('.function-entity input').val(func.enchantment); + $function.find('.function-enchantment input').val(func.enchantment); } else { delete func.enchantment; } @@ -392,8 +392,8 @@ function generateModifier(modifier, i) { generateRange($modifier.find('.modifier-amount'), modifier.amount); $modifier.find('.modifier-operation').val(modifier.operation); - if (modifier.slots) { - for (let s of modifier.slots) { + if (modifier.slot) { + for (let s of modifier.slot) { let item = $modifier.find('.dropdown-item[data-slot="' + s + '"]'); item.addClass('d-none'); let html = ''; @@ -623,7 +623,7 @@ function generateCondition(condition, i) { if (condition.term) { let $term = generateCondition(condition.term, 0); - $term.removeClass('condition').addClass('term'); + $term.attr('data-field', 'term'); $term.find('.card-header').remove(); $condition.children('.card-body').append($term); } @@ -631,7 +631,7 @@ function generateCondition(condition, i) { if (condition.terms) { for (let j = 0; j < condition.terms.length; j += 1) { let $term = generateCondition(condition.terms[j], j); - $term.removeClass('condition').addClass('terms'); + $term.attr('data-field', 'terms[]'); $condition.children('.card-body').append($term); } } @@ -693,7 +693,7 @@ function generateEntity(entity) { } if (entity.location) { let $location = generateLocation(entity.location); - $location.removeClass('predicate').addClass('location'); + $location.attr('data-field', 'location'); $entity.children('.card-body').append($location); } if (entity.nbt) { @@ -756,7 +756,7 @@ function generateItem(item) { } function generateDamage(damage) { - let $damage = $('#damageTemplate').clone().removeAttr('id').addClass('predicate'); + let $damage = $('#damageTemplate').clone().removeAttr('id'); if (!damage) { damage = {}; } @@ -774,12 +774,12 @@ function generateDamage(damage) { if (damage.source_entity) { let $entity = generateEntity(damage.source_entity); - $entity.removeClass('predicate'); + $entity.attr('data-field', 'source_entity'); $damage.find('.source-entity').append($entity); } if (damage.direct_entity) { let $entity = generateEntity(damage.direct_entity); - $entity.removeClass('predicate'); + $entity.attr('data-field', 'direct_entity'); $damage.find('.direct-entity').append($entity); } From fa2b869bea88ce6205b96f2a34ecae3e1f8b5852 Mon Sep 17 00:00:00 2001 From: Misode Date: Mon, 24 Jun 2019 16:42:03 +0200 Subject: [PATCH 02/22] Add item enchantments field --- index.html | 71 +++++++++++++++++++++++++++++++++++++++++++++++++++--- model.js | 18 +++++++++----- view.js | 17 +++++++++++++ 3 files changed, 97 insertions(+), 9 deletions(-) diff --git a/index.html b/index.html index 7fa074b5..f3f98684 100644 --- a/index.html +++ b/index.html @@ -407,10 +407,8 @@
-
- -
+
Attribute @@ -792,6 +790,9 @@
+
+ +
@@ -916,6 +917,70 @@
+
+
+ +
+
+ Enchantment +
+ +
+
+
+ Level + + +
+ + Min + + Max + +
+
+
diff --git a/model.js b/model.js index 612432f2..a6192fe4 100644 --- a/model.js +++ b/model.js @@ -343,12 +343,6 @@ function addModifier(el) { invalidated(); } -function removeModifier(el) { - let index = parseInt($(el).closest('.modifier').attr('data-index')); - getSuperParent(el).modifiers.splice(index, 1); - invalidated(); -} - function addModifierSlot(el) { let modifier = getParent(el); if (!modifier.slot) { @@ -586,3 +580,15 @@ function updateChancesField(el) { } invalidated(); } + +function addConditionEnchantment(el) { + let condition = getParent(el); + if (!condition.enchantments) { + condition.enchantments = []; + } + condition.enchantments.push({ + enchantment: 'minecraft:silk_touch', + level: 1 + }); + invalidated(); +} diff --git a/view.js b/view.js index a9c9f3c6..c149de20 100644 --- a/view.js +++ b/view.js @@ -752,6 +752,13 @@ function generateItem(item) { delete item.nbt; } + if (item.enchantments) { + for (let j = 0; j < item.enchantments.length; j += 1) { + let $enchantment = generateEnchantment(item.enchantments[j], j); + $item.children('.card-body').append($enchantment); + } + } + return $item; } @@ -796,3 +803,13 @@ function generateDamage(damage) { return $damage; } + +function generateEnchantment(enchantment, i) { + let $enchantment = $('#enchantmentTemplate').clone(); + $enchantment.removeAttr('id').attr('data-index', i); + + $enchantment.find('.enchantment-id').val(enchantment.enchantment); + generateRange($enchantment.find('.enchantment-level'), enchantment.level); + + return $enchantment; +} From 91d2060cbb46c657ab6049055215f0d82739708c Mon Sep 17 00:00:00 2001 From: Misode Date: Thu, 4 Jul 2019 21:28:44 +0200 Subject: [PATCH 03/22] Fix levels enchantment predicate having incorrect name --- index.html | 4 ++-- view.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/index.html b/index.html index f3f98684..6b77dab6 100644 --- a/index.html +++ b/index.html @@ -964,9 +964,9 @@
-
+
- Level + Levels
@@ -621,7 +621,7 @@
- +
@@ -638,7 +638,7 @@
@@ -902,7 +902,7 @@
- +
diff --git a/locales/en.json b/locales/en.json index a7dd3062..5f0bfc7d 100644 --- a/locales/en.json +++ b/locales/en.json @@ -22,7 +22,6 @@ "damage_type": "Damage Type", "projectile": "Projectile", "explosion": "Explosion", - "location": "Location", "fire": "Fire", "magic": "Magic", "lightning": "Lightning", @@ -244,7 +243,6 @@ "dimension": "Dimension", "durability": "Durability", "enchantment": "Enchantment", - "enchatment": "Enchantment", "entity": "Entity", "entry": "Entry", "false": "False", @@ -254,6 +252,7 @@ "inverted": "Inverted", "item": "Item", "level_plural": "Levels", + "location": "Location", "looting_multiplier": "Looting Multiplier", "luck_based": "Luck-based", "modifier": "Modifier", From d448ecfa4accabaa4854a76f521935eb05c1a3b3 Mon Sep 17 00:00:00 2001 From: SPGoding Date: Tue, 16 Jul 2019 17:58:26 +0800 Subject: [PATCH 07/22] Add an option to change language --- i18n.js | 16 ++++++++++++++-- index.html | 12 ++++++++++-- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/i18n.js b/i18n.js index 44fb3bda..25d049d8 100644 --- a/i18n.js +++ b/i18n.js @@ -1,12 +1,24 @@ +const lngs = [ + ['en', 'English'] +] + +lngs.forEach(v => $('#lngList').append(`${v[1]}`)) + i18next .use(i18nextBrowserLanguageDetector) .use(i18nextXHRBackend) .init({ backend: { loadPath: 'locales/{{lng}}.json' }, - whitelist: ['en'], - fallbackLng: 'en' + fallbackLng: 'en', + whitelist: lngs.map(v => v[0]) }) .then(() => { jqueryI18next.init(i18next, $, { parseDefaultValueFromContent: false }) $('html').localize() }) + +function changeLng(code) { + i18next.changeLanguage(code).then(() => { + $('html').localize() + }) +} diff --git a/index.html b/index.html index 54e49c7d..f593eb48 100644 --- a/index.html +++ b/index.html @@ -1,5 +1,5 @@ - + @@ -8,8 +8,16 @@ -
@@ -780,23 +780,23 @@
- + - + - +
- +
- +
@@ -887,11 +887,11 @@
- + - + - +
@@ -902,11 +902,11 @@
- + - + - +
@@ -981,11 +981,11 @@
- + - + - +
From 1995d2288153877a7cdd75a89bec2ba9e3d69739 Mon Sep 17 00:00:00 2001 From: Jerozgen Date: Tue, 20 Aug 2019 21:04:29 +0300 Subject: [PATCH 19/22] Added Russian (#8) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Added Russian * Updated Russian, removed old «source_enitity», «direct_enitity» * zh-CN: Moved «direct_entity» and «source_entity» --- i18n.js | 1 + locales/en.json | 4 +- locales/ru.json | 302 +++++++++++++++++++++++++++++++++++++++++++++ locales/zh-CN.json | 6 +- 4 files changed, 307 insertions(+), 6 deletions(-) create mode 100644 locales/ru.json diff --git a/i18n.js b/i18n.js index ffc54e44..8646686b 100644 --- a/i18n.js +++ b/i18n.js @@ -1,5 +1,6 @@ const lngs = [ ['en', 'English'], + ['ru', 'Русский'], ['zh-CN', '简体中文'] ] diff --git a/locales/en.json b/locales/en.json index bed32b2a..d2ba20e0 100644 --- a/locales/en.json +++ b/locales/en.json @@ -27,9 +27,7 @@ "bypass_armor": "Bypass Armor", "dealt": "Dealt", "taken": "Taken", - "blocked": "Blocked", - "source_enitity": "Source Entity", - "direct_enitity": "Direct Entity" + "blocked": "Blocked" }, "$dimension": { "overworld": "Overworld", diff --git a/locales/ru.json b/locales/ru.json new file mode 100644 index 00000000..6711d973 --- /dev/null +++ b/locales/ru.json @@ -0,0 +1,302 @@ +{ + "$condition": { + "alternative": "Выбор", + "inverted": "Инвертирование", + "entity_properties": "Свойства сущности", + "block_state_propery": "Свойства блока", + "match_tool": "Свойства инструмента", + "damage_source_properties": "Источник урона", + "location_check": "Местоположение", + "weather_check": "Погода", + "entity_scores": "Счёты сущности", + "random_chance": "Случайность", + "random_chance_with_looting": "Случайность с «Добычей»", + "table_bonus": "Бонус таблицы", + "killed_by_player": "Убит игроком", + "survives_explosion": "Переживает взрыв" + }, + "$damage": { + "damage_type": "Тип урона", + "projectile": "Снаряд", + "explosion": "Взрыв", + "fire": "Огонь", + "magic": "Магия", + "lightning": "Молния", + "starvation": "Голод", + "void": "Бездна", + "bypass_armor": "Обход брони", + "dealt": "Нанесено", + "taken": "Получено", + "blocked": "Заблокирован" + }, + "$dimension": { + "overworld": "Обычный мир", + "the_nether": "Незер", + "the_end": "Энд" + }, + "$enchantment": { + "aqua_affinity": "Подводник", + "bane_of_arthropods": "Бич членистоногих", + "blast_protection": "Взрывоустойчивость", + "channeling": "Громовержец", + "binding_curse": "Проклятие несъёмности", + "vanishing_curse": "Проклятие утраты", + "depth_strider": "Подводная ходьба", + "efficiency": "Эффективность", + "feather_falling": "Невесомость", + "fire_aspect": "Заговор огня", + "fire_protection": "Огнеупорность", + "flame": "Горящая стрела", + "fortune": "Удача", + "frost_walker": "Ледоход", + "impaling": "Пронзатель", + "infinity": "Бесконечность", + "knockback": "Отдача", + "looting": "Добыча", + "loyalty": "Верность", + "luck_of_the_sea": "Везучий рыбак", + "lure": "Приманка", + "mending": "Починка", + "multishot": "Тройной выстрел", + "piercing": "Пронзающая стрела", + "power": "Сила", + "projectile_protection": "Защита от снарядов", + "protection": "Защита", + "punch": "Откидывание", + "quick_charge": "Быстрая перезарядка", + "respiration": "Подводное дыхание", + "riptide": "Тягун", + "sharpness": "Острота", + "silk_touch": "Шёлковое касание", + "smite": "Небесная кара", + "sweeping": "Разящий клинок", + "thorns": "Шипы", + "unbreaking": "Прочность" + }, + "$entry": { + "name": "ID", + "type": "Тип", + "$type": { + "empty": "Ничего", + "item": "Предмет", + "tag": "Тег предметов", + "loot_table": "Таблица добычи", + "alternatives": "Выбор", + "sequence": "Последовательность", + "group": "Группа", + "dynamic": "Динамический" + }, + "weight": "Вес", + "quality": "Качество" + }, + "$function": { + "set_count": "Задать количество", + "set_damage": "Задать повреждение", + "set_name": "Задать имя", + "set_lore": "Задать описание", + "set_nbt": "Задать NBT", + "set_attributes": "Задать атрибуты", + "set_contents": "Задать содержимое", + "enchant_randomly": "Наложить случайные чары", + "enchant_with_levels": "Наложить чары с уровнем", + "looting_enchant": "Чары «Добыча»", + "limit_count": "Ограничить количество", + "furnace_smelt": "Расплавить в печи", + "explosion_decay": "Разрушить взрывом", + "fill_player_head": "Задать скин голове игрока", + "copy_name": "Скопировать имя", + "copy_nbt": "Скопировать NBT", + "apply_bonus": "Применить бонус", + "$damage": { + "damage": "Повреждение" + }, + "$ench_rand": { + "ench": "Чары" + }, + "$limit": { + "limit": "Ограничение" + }, + "$name": { + "name": "Имя" + }, + "$lore_replace": { + "replace": "Заменить старое" + }, + "$entity": { + "entity": "Сущность" + }, + "$operations": { + "add_op": "Добавить действие" + }, + "$formula": { + "formula": "Формула", + "uniform_bonus_count": "Равномерное распределение", + "binomial_with_bonus_count": "Биноминальное распределение", + "ore_drops": "Добыча руд" + }, + "$bonus_multiplier": { + "multiplier": "Множитель" + }, + "$bonus_extra": { + "extra": "Дополнительное значение" + }, + "$bonus_probability": { + "probability": "Вероятность" + } + }, + "$modifier": { + "attribute": "Атрибут", + "generic_maxHealth": "Максимальное здоровье", + "generic_followRange": "Диапазон преследования моба", + "generic_knockbackResistance": "Сопротивление отбрасыванию", + "generic_movementSpeed": "Скорость", + "generic_attackDamage": "Урон", + "generic_armor": "Броня", + "generic_armorThoughness": "Твёрдость брони", + "generic_attackSpeed": "Скорость атаки", + "generic_luck": "Удача", + "horse_jumpStrength": "Сила прыжка лошади", + "generic_attackKnockback": "Отбрасывание", + "generic_flyingSpeed": "Скорость полёта", + "zombie_spawnReinforcements": "Подкрепление зомби", + "name": "Имя", + "amount": "Количество", + "operation": "Действие", + "$operation": { + "addition": "Прибавление", + "multiply_base": "Умножение базового", + "multiply_total": "Умножение общего" + }, + "slots": "Ячейки" + }, + "$operation": { + "source": "Источник", + "target": "Цель", + "operation": "Действие", + "$operation": { + "replace": "Замена", + "append": "Добавление", + "merge": "Объединение" + } + }, + "$pool": { + "rolls": "Бросков", + "bonus_rolls": "Бонусных бросков" + }, + "$range": { + "exact": "Число", + "range": "Диапазон", + "$range": { + "min": "Мин.", + "max": "Макс." + }, + "binomial": "Биномиальное распределение", + "$binomial": { + "n": "n", + "p": "p" + } + }, + "$slot": { + "mainhand": "Ведущая рука", + "offhand": "Вторая рука", + "head": "Голова", + "chest": "Тело", + "legs": "Ноги", + "feet": "Стопы" + }, + "$source": { + "block_entity": "Блок-сущность", + "this": "Текущая", + "killer": "Убийца", + "killer_player": "Игрок-убийца" + }, + "$table": { + "type": "Тип", + "$type": { + "empty": "Ничего", + "entity": "Сущность", + "block": "Блок", + "chest": "Сундук", + "fishing": "Рыбалка", + "generic": "Общий" + } + }, + "2_spaces": "2 пробела", + "4_spaces": "4 пробела", + "add_block_state": "Добавить состояние блока", + "add_child": "Добавить потомка", + "add_condition": "Добавить условие", + "add_enchantment": "Добавить чары", + "add_entry": "Добавить запись", + "add_function": "Добавить функцию", + "add_modifier": "Добавить модификатор", + "add_operation": "Добавить действие", + "add_pool": "Добавить пул", + "add_score": "Добавить счёт", + "add_term": "Добавить выражение", + "author": "Автор: Misode", + "biome": "Биом", + "block": "Блок", + "block_state": "состояние блока", + "chance": "Шанс", + "chance_plural": "Шансы", + "child": "Потомок", + "condition": "Условие", + "copy": "Скопировать", + "count": "Количество", + "description": "Генератор таблицы добычи для Minecraft 1.14", + "dimension": "Измерение", + "direct_entity": "Сущность-причина урона", + "durability": "Прочность", + "enchantment": "Чары", + "entity": "Сущность", + "entry": "Запись", + "false": "Нет", + "feature": "Строение", + "function": "Функция", + "hide_source": "Скрыть источник", + "inverted": "Инвертировать", + "item": "Предмет", + "level_plural": "Уровень", + "location": "Местоположение", + "looting_multiplier": "Множитель «Добычи»", + "luck_based": "Основано на удаче", + "modifier": "Модификатор", + "more": "Больше", + "name": "ID", + "nbt": "NBT", + "objective": "Задача", + "operation": "Действие", + "pool": "Пул", + "position": "Позиция", + "potion": "Зелье", + "raining": "Дождь", + "remove": "Удалить", + "remove_block_state": "Удалить состояние блока", + "remove_condition": "Удалить условие", + "remove_enchantment": "Удалить чары", + "remove_entry": "Удалить запись", + "remove_function": "Удалить функцию", + "remove_modifier": "Удалить модификатор", + "remove_operation": "Удалить действие", + "remove_pool": "Удалить пул", + "remove_score": "Удалить счёт", + "remove_term": "Удалить выражение", + "score": "Счёт", + "share": "Поделиться", + "show_source": "Показать источник", + "source": "Источник", + "source_entity": "Сущность-источник урона", + "tabs": "Табуляция", + "tag": "Тег", + "term": "Выражение", + "thundering": "Гроза", + "title": "Генератор таблицы добычи", + "treasure": "Чары-сокровища", + "true": "Да", + "type": "Тип", + "unset": "Не задано", + "x": "X", + "y": "Y", + "z": "Z" +} diff --git a/locales/zh-CN.json b/locales/zh-CN.json index 0c1fb439..0ff553ab 100644 --- a/locales/zh-CN.json +++ b/locales/zh-CN.json @@ -27,9 +27,7 @@ "bypass_armor": "破甲", "dealt": "被防御前的伤害", "taken": "实际造成的伤害", - "blocked": "被盾牌阻挡", - "source_enitity": "根本来源实体", - "direct_enitity": "直接来源实体" + "blocked": "被盾牌阻挡" }, "$dimension": { "overworld": "主世界", @@ -248,6 +246,7 @@ "count": "数量", "description": "适用于 Minecraft 1.14 的战利品表生成器", "dimension": "维度", + "direct_entity": "直接来源实体", "durability": "耐久度", "enchantment": "附魔", "entity": "实体", @@ -287,6 +286,7 @@ "share": "分享", "show_source": "显示源代码", "source": "源", + "source_entity": "根本来源实体", "tabs": "Tab 缩进", "tag": "标签", "term": "条件", From 7596079c0248bf3067e2f2ec7c4141eac7ea93f6 Mon Sep 17 00:00:00 2001 From: SPGoding Date: Wed, 21 Aug 2019 16:36:37 +0800 Subject: [PATCH 20/22] Bugfixes (#11) * Fix #9 * Fix #10 --- index.html | 8 ++++---- locales/en.json | 2 +- locales/ru.json | 2 +- locales/zh-CN.json | 2 +- model.js | 12 ++++++------ view.js | 6 +++--- 6 files changed, 16 insertions(+), 16 deletions(-) diff --git a/index.html b/index.html index e59048cd..649fcd68 100644 --- a/index.html +++ b/index.html @@ -428,7 +428,7 @@ - + @@ -747,12 +747,12 @@
- - + +
diff --git a/locales/en.json b/locales/en.json index d2ba20e0..384ffe2a 100644 --- a/locales/en.json +++ b/locales/en.json @@ -152,7 +152,7 @@ "generic_movementSpeed": "Movement Speed", "generic_attackDamage": "Attack Damage", "generic_armor": "Armor", - "generic_armorThoughness": "Armor Toughness", + "generic_armorToughness": "Armor Toughness", "generic_attackSpeed": "Attack Speed", "generic_luck": "Luck", "horse_jumpStrength": "Jump Strength", diff --git a/locales/ru.json b/locales/ru.json index 6711d973..451e8e35 100644 --- a/locales/ru.json +++ b/locales/ru.json @@ -152,7 +152,7 @@ "generic_movementSpeed": "Скорость", "generic_attackDamage": "Урон", "generic_armor": "Броня", - "generic_armorThoughness": "Твёрдость брони", + "generic_armorToughness": "Твёрдость брони", "generic_attackSpeed": "Скорость атаки", "generic_luck": "Удача", "horse_jumpStrength": "Сила прыжка лошади", diff --git a/locales/zh-CN.json b/locales/zh-CN.json index 0ff553ab..e66e130b 100644 --- a/locales/zh-CN.json +++ b/locales/zh-CN.json @@ -152,7 +152,7 @@ "generic_movementSpeed": "移动速度", "generic_attackDamage": "普通攻击伤害", "generic_armor": "盔甲防御点数", - "generic_armorThoughness": "盔甲韧性", + "generic_armorToughness": "盔甲韧性", "generic_attackSpeed": "攻击速度", "generic_luck": "幸运", "horse_jumpStrength": "弹跳力", diff --git a/model.js b/model.js index fba0d411..d5750995 100644 --- a/model.js +++ b/model.js @@ -514,23 +514,23 @@ function toggleEntityLocation(el) { function updateItemType(el, type) { let $predicate = $(el).closest('.predicate'); - if (type === 'name') { - $predicate.find('.name').removeClass('d-none'); + if (type === 'item') { + $predicate.find('.item').removeClass('d-none'); $predicate.find('.tag').addClass('d-none'); } else { $predicate.find('.tag').removeClass('d-none'); - $predicate.find('.name').addClass('d-none'); + $predicate.find('.item').addClass('d-none'); } } function updateItemField(el, type) { let parent = getParent(el); - if (type === 'name') { - parent.name = $(el).closest('.predicate').find('input.name').val(); + if (type === 'item') { + parent.item = $(el).closest('.predicate').find('input.item').val(); delete parent.tag; } else { parent.tag = $(el).closest('.predicate').find('input.tag').val(); - delete parent.name; + delete parent.item; } invalidated(); } diff --git a/view.js b/view.js index 77904ccd..86f4a684 100644 --- a/view.js +++ b/view.js @@ -733,14 +733,14 @@ function generateItem(item) { if (item.tag) { $item.find('.tag').removeClass('d-none').val(item.tag); } else { - $item.find('.name').removeClass('d-none').val(item.name); + $item.find('.item').removeClass('d-none').val(item.item); } generateRange($item.find('.item-count'), item.count); generateRange($item.find('.item-durability'), item.durability); $item.find('.nbt').val(item.nbt).keydown(e => preventNewline(e)); $item.find('.potion').val(item.potion); - if (item.name === '') { - delete item.name; + if (item.item === '') { + delete item.item; } if (item.tag === '') { delete item.tag; From d10135a65cf3e078c74c89e61cce61683d4e9bb4 Mon Sep 17 00:00:00 2001 From: Misode Date: Tue, 10 Sep 2019 13:22:09 +0200 Subject: [PATCH 21/22] Fix typo in function name --- index.html | 2 +- model.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/index.html b/index.html index e59048cd..9e37384b 100644 --- a/index.html +++ b/index.html @@ -65,7 +65,7 @@
- +
diff --git a/model.js b/model.js index fba0d411..f7610342 100644 --- a/model.js +++ b/model.js @@ -16,7 +16,7 @@ addEntry($('#structure .pool').get()); const params = new URLSearchParams(window.location.search); if (params.has('q')) { $('#source').val(atob(params.get('q'))); - updateSouce(); + updateSource(); } function updateTableType() { @@ -51,7 +51,7 @@ function linkSource() { }, 2000); } -function updateSouce() { +function updateSource() { $('#source').removeClass('invalid'); try { table = JSON.parse($('#source').val()); From ecbc381c8dc48e85b625c6e45599b4155739106e Mon Sep 17 00:00:00 2001 From: Misode Date: Tue, 10 Sep 2019 15:52:43 +0200 Subject: [PATCH 22/22] Use zero width shortener for links under 500 characters --- index.html | 7 +++++-- model.js | 29 ++++++++++++++++++++++++----- 2 files changed, 29 insertions(+), 7 deletions(-) diff --git a/index.html b/index.html index deb988f8..854fd8f6 100644 --- a/index.html +++ b/index.html @@ -20,7 +20,7 @@ -
+
@@ -64,7 +64,10 @@
- +
+ + +
diff --git a/model.js b/model.js index 50a271fe..10148024 100644 --- a/model.js +++ b/model.js @@ -17,6 +17,12 @@ const params = new URLSearchParams(window.location.search); if (params.has('q')) { $('#source').val(atob(params.get('q'))); updateSource(); + $('.container').removeClass('d-none'); +} else if (params.has('s')) { + let short = params.get('s').slice(0, -7); + window.location = 'https://zws.im/' + short; +} else { + $('.container').removeClass('d-none'); } function updateTableType() { @@ -41,14 +47,27 @@ function showSource() { $('#showSourceButton').addClass('d-none'); } -function linkSource() { - let link = window.location.origin + window.location.pathname + '?q=' + btoa(JSON.stringify(table)); - $('#copyTextarea').removeClass('d-none').val(link); +async function linkSource() { + let site = window.location.origin + window.location.pathname; + let url = site + '?q=' + btoa(JSON.stringify(table)); + if (url.length <= 500) { + let shortener = 'https://us-central1-zero-width-shortener.cloudfunctions.net/shortenURL?url='; + let response = await fetch(shortener + url); + let json = await response.json(); + let id = Math.random().toString(36).substring(2, 9); + url = site + '?s=' + json.short + id; + } + $('#copyContainer').removeClass('d-none'); + $('#copyTextarea').val(url); + $('#copyTextarea').get()[0].select(); +} + +function copyLink() { $('#copyTextarea').get()[0].select(); document.execCommand('copy'); setTimeout(() => { - $('#copyTextarea').addClass('d-none'); - }, 2000); + $('#copyContainer').addClass('d-none'); + }, 100); } function updateSource() {