Add attribute modifiers + improve translation keys for enums and sets

This commit is contained in:
Misode
2019-09-13 12:51:03 +02:00
parent 07a103fb64
commit 9e97ccd363
5 changed files with 107 additions and 93 deletions

View File

@@ -1107,7 +1107,6 @@
<script src="https://cdnjs.cloudflare.com/ajax/libs/i18next-xhr-backend/3.0.0/i18nextXHRBackend.min.js" integrity="sha384-dK+VwLEvPDbpKM7G7D/LtbW6W2zlt99nuVTwoYIkMulAedST9Vj9OCRkv2xV8GjD" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-i18next/1.2.1/jquery-i18next.min.js" integrity="sha384-fLTSt6zHOb152KeFkj7kSiXdkyjKf6fjk5bdzWYLDPDo9evwd9PVs3TKoYYaaxdl" crossorigin="anonymous"></script>
<script src="i18n.js" charset="utf-8"></script>
<script src="validate.js" charset="utf-8"></script>
<script src="view.js" charset="utf-8"></script>
<script src="model.js" charset="utf-8"></script>
</body>

View File

@@ -199,9 +199,6 @@ function removeFromSet(el, array) {
let index = parent[array].indexOf($(el).attr('value'));
if (index > -1) {
parent[array].splice(index, 1);
if (parent[array].length === 0) {
delete parent[array];
}
invalidated();
}
}

View File

@@ -102,6 +102,7 @@
"type": "array",
"values": "entry",
"button": "field",
"color": "success",
"require": [
"minecraft:alternatives",
"minecraft:sequence",
@@ -187,13 +188,6 @@
"minecraft:set_lore"
]
},
{
"id": "replace",
"type": "boolean",
"require": [
"minecraft:set_lore"
]
},
{
"id": "tag",
"type": "string",
@@ -233,6 +227,8 @@
{
"id": "entity",
"type": "enum",
"source": "source",
"default": "minecraft:this",
"values": [
"minecraft:this",
"minecraft:killer",
@@ -247,6 +243,8 @@
{
"id": "source",
"type": "enum",
"source": "source",
"default": "minecraft:this",
"values": [
"minecraft:block_entity",
"minecraft:this",
@@ -258,9 +256,17 @@
"minecraft:copy_nbt"
]
},
{
"id": "replace",
"type": "boolean",
"require": [
"minecraft:set_lore"
]
},
{
"id": "enchantments",
"type": "set",
"source": "enchantment",
"values": [
"minecraft:aqua_affinity",
"minecraft:bane_of_arthropods",
@@ -304,6 +310,15 @@
"minecraft:enchant_randomly"
]
},
{
"id": "modifiers",
"type": "array",
"button": "field",
"values": "attribute_modifier",
"require": [
"minecraft:set_attributes"
]
},
{
"id": "conditions",
"type": "array",
@@ -323,6 +338,73 @@
"fields": [
]
},
{
"id": "attribute_modifier",
"type": "object",
"color": "dark",
"default": {
"attribute": "generic.attackDamage",
"name": "Attack Damage",
"amount": 1,
"operation": "addition",
"slot": []
},
"fields": [
{
"id": "attribute",
"type": "enum",
"source": "attribute",
"default": "generic.attackDamage",
"values": [
"generic.maxHealth",
"generic.followRange",
"generic.knockbackResistance",
"generic.movementSpeed",
"generic.attackDamage",
"generic.armor",
"generic.armorToughness",
"generic.attackSpeed",
"generic.luck",
"horse.jumpStrength",
"generic.attackKnockback",
"generic.flyingSpeed",
"zombie.spawnReinforcements"
]
},
{
"id": "name",
"type": "string"
},
{
"id": "amount",
"type": "float",
"default": 1
},
{
"id": "operation",
"type": "enum",
"source": "modifier.operation",
"default": "addition",
"values": [
"addition",
"multiply_base",
"multiply_total"
]
},
{
"id": "slots",
"type": "set",
"values": [
"mainhand",
"offhand",
"head",
"chest",
"legs",
"feet"
]
}
]
}
]
}

View File

@@ -1,72 +0,0 @@
function isString(data) {
return data != undefined && typeof data === 'string';
}
function isNumber(data) {
return data != undefined && typeof data === 'number';
}
function isObject(data) {
return data != undefined && typeof data === 'object' && !Array.isArray(data);
}
function isArray(data) {
return data != undefined && typeof data === 'object' && Array.isArray(data);
}
function validateRange(data) {
if (data === undefined) return false;
if (isObject(data)) {
if (isString(data.type) && data.type.endsWith('binomial')) {
if (isNumber(data.n) && isNumber(data.p)) {
return {
type: 'minecraft:binomial',
n: data.n,
p: data.p
};
}
}
let res = {};
if (isNumber(data.min)) res.min = data.min;
if (isNumber(data.max)) res.max = data.max;
}
return false;
}
function chooseOption(options, value, def) {
for (option of options) {
if (value === option) {
return value;
} else if('minecraft:' + value === option) {
return 'minecraft:' + value;
}
}
return def;
}
function namespace(list) {
let res = [];
for (let item of list) {
res.push('minecraft:' + item);
}
return res;
}
function validateTable(table) {
let res = {};
res.type = chooseOption(namespace(['empty', 'entity', 'block', 'chest', 'fishing', 'generic']), table.type, 'minecraft:generic');
res.pools = [];
if (isArray(table.pools)) {
for (let pool of table.pools) {
res.pools.push(validatePool(pool));
}
}
return res;
}
function validatePool() {
let res = {};
res
return res;
}

28
view.js
View File

@@ -127,8 +127,8 @@ function generateEnum(data, struct) {
let $el = $('#components').find('[data-type="enum"]').clone();
$el.attr('data-field', struct.id);
$el.find('[data-name]').attr('data-i18n', struct.id);
for (let option of struct.values) {
$('<option/>').appendTo($el.find('select')).attr('value', option).attr('data-i18n', struct.source + '.' + option);
for (let value of struct.values) {
$el.find('select').append(setValueAndName($('<option/>'), value, struct.source));
}
if (data) {
$el.find('select').val(data);
@@ -142,23 +142,30 @@ function generateSet(data, struct) {
let $el = $('#components').find('[data-type="set"]').clone();
$el.attr('data-field', struct.id);
$el.find('[data-name]').attr('data-i18n', struct.id);
for (let option of struct.values) {
$('<a class="dropdown-item" onclick="addToSet(this, \'' + struct.id + '\')" />').appendTo($el.find('.dropdown-menu')).attr('value', option).attr('data-i18n', struct.source + '.' + option);
for (let value of struct.values) {
let $item = $('<a class="dropdown-item" onclick="addToSet(this, \'' + struct.id + '\')" />');
setValueAndName($item, value, struct.source);
$el.find('.dropdown-menu').append($item);
}
if (data) {
console.log(data);
let $setContainer = $('<div/>');
for (let option of data) {
let $item = $('<button type="button" onclick="removeFromSet(this, \'' + struct.id + '\')" />').addClass('btn btn-outline-danger bg-light btn-sm mr-2 mt-2').attr('value', option).attr('data-i18n', struct.source + '.' + option);
console.log($item);
let $item = $('<button type="button" onclick="removeFromSet(this, \'' + struct.id + '\')" />').addClass('btn btn-outline-danger bg-light btn-sm mr-2 mt-2');
setValueAndName($item, option, struct.source);
$setContainer.append($item);
console.log($setContainer);
}
$el.append($setContainer);
}
return $el;
}
function setValueAndName($el, value, source) {
let option = value.split(':').slice(-1);
let name = (source) ? source + '.' + option : option;
return $el.attr('value', value).attr('data-i18n', name);
}
function generateJson(data, struct) {
let $el = $('#components').find('[data-type="json"]').clone();
$el.attr('data-field', struct.id);
@@ -233,12 +240,14 @@ function generateObject(data, struct) {
$field = generateError('Failed generating "' + field.id + '" component');
}
if (field.type === 'array') {
let color = field.color;
if (color === undefined) {
color = components.find(e => e.id === field.values).color;
}
if (field.button === 'header') {
let color = components.find(e => e.id === field.values).color;
$header.append('<button type="button" class="btn btn-' + color + ' mr-3 mb-2 float-left" onclick="addComponent(this, \'' + field.id + '\')" data-i18n="add_' + field.values + '"></button>');
}
if (field.button === 'field') {
let color = 'outline-success';
$body.append('<button type="button" class="btn btn-' + color + ' mr-3 mt-3" onclick="addComponent(this, \'' + field.id + '\')" data-i18n="add_' + field.values + '"></button>');
}
} else {
@@ -252,7 +261,6 @@ function generateObject(data, struct) {
}
function preventNewline(e) {
console.log('ahahahah!!!')
if (e.which === 13) {
$(e.target).trigger('change');
e.preventDefault();