mirror of
https://github.com/misode/misode.github.io.git
synced 2026-04-24 23:56:51 +00:00
Add object nesting and object collapsing
This commit is contained in:
@@ -185,7 +185,7 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="poolTemplate" class="card bg-success text-white mt-3 pool" data-field="pools[]">
|
||||
<!--div id="poolTemplate" class="card bg-success text-white mt-3 pool" data-field="pools[]">
|
||||
<div class="card-header pb-1">
|
||||
<button type="button" class="btn btn-danger mb-2 float-right" onclick="removeField(this)" data-i18n="remove_pool"></button>
|
||||
<button type="button" class="btn btn-light mr-3 mb-2 float-left" onclick="addEntry(this)" data-i18n="add_entry"></button>
|
||||
@@ -1102,7 +1102,7 @@
|
||||
<input type="text" class="form-control range max d-none rounded-right" value="2" onchange="updateField(this)" onfocus="this.select()">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div-->
|
||||
</div>
|
||||
|
||||
<script src="https://code.jquery.com/jquery-3.4.1.min.js" integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo=" crossorigin="anonymous"></script>
|
||||
|
||||
87
model.js
87
model.js
@@ -245,6 +245,17 @@ function removeFromSet(el, array) {
|
||||
}
|
||||
}
|
||||
|
||||
function toggleCollapseObject(el) {
|
||||
let parent = getSuperParent(el);
|
||||
let field = $(el).closest('[data-field]').attr('data-field');
|
||||
if (!parent[field]) {
|
||||
parent[field] = {};
|
||||
} else {
|
||||
delete parent[field];
|
||||
}
|
||||
invalidated();
|
||||
}
|
||||
|
||||
function updateField(el) {
|
||||
let $field = $(el).closest('[data-field]');
|
||||
let fields = $field.attr('data-field');
|
||||
@@ -349,63 +360,6 @@ function getBooleanValue(oldvalue, newvalue) {
|
||||
}
|
||||
}
|
||||
|
||||
function addEnchantment(el) {
|
||||
let func = getParent(el);
|
||||
let enchantment = $(el).attr('data-ench');
|
||||
if (!func.enchantments) {
|
||||
func.enchantments = [];
|
||||
}
|
||||
func.enchantments.push(enchantment);
|
||||
invalidated();
|
||||
}
|
||||
|
||||
function removeEnchantment(el) {
|
||||
let func = getParent(el);
|
||||
let ench = $(el).attr('data-ench');
|
||||
let index = func.enchantments.indexOf(ench);
|
||||
if (index > -1) {
|
||||
func.enchantments.splice(index, 1);
|
||||
if (func.enchantments.length === 0) {
|
||||
delete func.enchantments;
|
||||
}
|
||||
invalidated();
|
||||
}
|
||||
}
|
||||
|
||||
function addModifier(el) {
|
||||
let func = getParent(el);
|
||||
if (!func.modifiers) {
|
||||
func.modifiers = [];
|
||||
}
|
||||
func.modifiers.push({
|
||||
attribute: 'generic.attackDamage',
|
||||
name: 'Attack Damage',
|
||||
amount: 1,
|
||||
operation: 'addition',
|
||||
slot: []
|
||||
});
|
||||
invalidated();
|
||||
}
|
||||
|
||||
function addModifierSlot(el) {
|
||||
let modifier = getParent(el);
|
||||
if (!modifier.slot) {
|
||||
modifier.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.slot.indexOf(slot);
|
||||
if (index > -1) {
|
||||
modifier.slot.splice(index, 1);
|
||||
invalidated();
|
||||
}
|
||||
}
|
||||
|
||||
function addScore(el) {
|
||||
let condition = getParent(el);
|
||||
let objective = $(el).closest('.condition-entity-scores').find('input').val();
|
||||
@@ -473,25 +427,6 @@ function parseJSONValue(value) {
|
||||
return value;
|
||||
}
|
||||
|
||||
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 addBlockProperty(el) {
|
||||
let func = getParent(el);
|
||||
let blockstate = $(el).closest('.condition-block-properties').find('input').val();
|
||||
|
||||
@@ -438,7 +438,158 @@
|
||||
"chance": 0.5
|
||||
},
|
||||
"fields": [
|
||||
|
||||
{
|
||||
"id": "condition",
|
||||
"type": "enum",
|
||||
"source": "condition",
|
||||
"default": "minecraft:random_chance",
|
||||
"values": [
|
||||
"minecraft:alternative",
|
||||
"minecraft:inverted",
|
||||
"minecraft:entity_properties",
|
||||
"minecraft:block_state_propery",
|
||||
"minecraft:match_tool",
|
||||
"minecraft:damage_source_properties",
|
||||
"minecraft:location_check",
|
||||
"minecraft:weather_check",
|
||||
"minecraft:entity_scores",
|
||||
"minecraft:random_chance",
|
||||
"minecraft:random_chance_with_looting",
|
||||
"minecraft:table_bonus",
|
||||
"minecraft:killed_by_player",
|
||||
"minecraft:survives_explosion"
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "chance",
|
||||
"type": "float",
|
||||
"require": [
|
||||
"minecraft:random_chance",
|
||||
"minecraft:random_chance_with_looting"
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "looting_multiplier",
|
||||
"type": "float",
|
||||
"require": [
|
||||
"minecraft:random_chance_with_looting"
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "inverted",
|
||||
"type": "boolean",
|
||||
"require": [
|
||||
"minecraft:killed_by_player"
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "entity",
|
||||
"type": "enum",
|
||||
"default": "this",
|
||||
"values": [
|
||||
"this",
|
||||
"killer",
|
||||
"killer_player"
|
||||
],
|
||||
"require": [
|
||||
"minecraft:entity_properties",
|
||||
"minecraft:entity_scores"
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "enchantment",
|
||||
"type": "enum",
|
||||
"source": "enchantment",
|
||||
"values": [
|
||||
"minecraft:aqua_affinity",
|
||||
"minecraft:bane_of_arthropods",
|
||||
"minecraft:blast_protection",
|
||||
"minecraft:channeling",
|
||||
"minecraft:binding_curse",
|
||||
"minecraft:vanishing_curse",
|
||||
"minecraft:depth_strider",
|
||||
"minecraft:efficiency",
|
||||
"minecraft:feather_falling",
|
||||
"minecraft:fire_aspect",
|
||||
"minecraft:fire_protection",
|
||||
"minecraft:flame",
|
||||
"minecraft:fortune",
|
||||
"minecraft:frost_walker",
|
||||
"minecraft:impaling",
|
||||
"minecraft:infinity",
|
||||
"minecraft:knockback",
|
||||
"minecraft:looting",
|
||||
"minecraft:loyalty",
|
||||
"minecraft:luck_of_the_sea",
|
||||
"minecraft:lure",
|
||||
"minecraft:mending",
|
||||
"minecraft:multishot",
|
||||
"minecraft:piercing",
|
||||
"minecraft:power",
|
||||
"minecraft:projectile_protection",
|
||||
"minecraft:protection",
|
||||
"minecraft:punch",
|
||||
"minecraft:quick_charge",
|
||||
"minecraft:respiration",
|
||||
"minecraft:riptide",
|
||||
"minecraft:sharpness",
|
||||
"minecraft:silk_touch",
|
||||
"minecraft:smite",
|
||||
"minecraft:sweeping",
|
||||
"minecraft:thorns",
|
||||
"minecraft:unbreaking"
|
||||
],
|
||||
"require": [
|
||||
"minecraft:table_bonus"
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "chances",
|
||||
"type": "list",
|
||||
"require": [
|
||||
"minecraft:table_bonus"
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "raining",
|
||||
"type": "boolean",
|
||||
"require": [
|
||||
"minecraft:weather_check"
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "thundering",
|
||||
"type": "boolean",
|
||||
"require": [
|
||||
"minecraft:weather_check"
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "predicate",
|
||||
"type": "object",
|
||||
"value": "entity",
|
||||
"require": [
|
||||
"minecraft:entity_properties"
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "term",
|
||||
"type": "object",
|
||||
"value": "condition",
|
||||
"button": "field",
|
||||
"require": [
|
||||
"minecraft:inverted"
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "terms",
|
||||
"type": "array",
|
||||
"values": "condition",
|
||||
"button": "field",
|
||||
"require": [
|
||||
"minecraft:alternative"
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -538,6 +689,38 @@
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "entity",
|
||||
"type": "object",
|
||||
"color": "dark",
|
||||
"fields": [
|
||||
{
|
||||
"id": "type",
|
||||
"type": "string"
|
||||
},
|
||||
{
|
||||
"id": "nbt",
|
||||
"type": "nbt"
|
||||
},
|
||||
{
|
||||
"id": "location",
|
||||
"type": "object",
|
||||
"value": "location",
|
||||
"collapse": true
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "location",
|
||||
"type": "object",
|
||||
"color": "dark",
|
||||
"fields": [
|
||||
{
|
||||
"id": "biome",
|
||||
"type": "string"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
61
view.js
61
view.js
@@ -53,7 +53,7 @@ function generateComponent(data, struct) {
|
||||
case 'json-list': return generateJsonList(data, struct);
|
||||
case 'nbt': return generateNbt(data, struct);
|
||||
case 'array': return generateArray(data, struct);
|
||||
case 'object': return generateObject(data, struct);
|
||||
case 'object': return generateObject(data, struct, false);
|
||||
default: return generateError('Unknown component type "' + struct.type + '"')};
|
||||
}
|
||||
|
||||
@@ -131,11 +131,7 @@ function generateEnum(data, struct) {
|
||||
for (let value of struct.values) {
|
||||
$el.find('select').append(setValueAndName($('<option/>'), value, struct.source));
|
||||
}
|
||||
if (data) {
|
||||
$el.find('select').val(data);
|
||||
} else {
|
||||
$el.find('select').val(struct.default);
|
||||
}
|
||||
$el.find('select').val(data);
|
||||
return $el;
|
||||
}
|
||||
|
||||
@@ -220,7 +216,7 @@ function generateArray(data, struct) {
|
||||
let $el = $('<div/>').addClass('mt-3');
|
||||
let child = components.find(e => e.id === struct.values);
|
||||
for (let i = 0; i < data.length; i += 1) {
|
||||
let $child = generateObject(data[i], child);
|
||||
let $child = generateObject(data[i], child, true);
|
||||
$child.attr('data-field', struct.id + '[]');
|
||||
$child.attr('data-index', i);
|
||||
$child.removeAttr('data-type');
|
||||
@@ -230,25 +226,39 @@ function generateArray(data, struct) {
|
||||
return $el;
|
||||
}
|
||||
|
||||
function generateObject(data, struct) {
|
||||
function generateObject(data, struct, header) {
|
||||
let $el = $('<div/>').addClass('card bg-' + struct.color + ' mt-3');
|
||||
let $header = $('<div class="card-header pb-1"></div>').appendTo($el);
|
||||
let $header = $('<div class="card-header pb-1"></div>');
|
||||
if (header) {
|
||||
$header.appendTo($el);
|
||||
$header.append('<button type="button" class="btn btn-danger mb-2 float-right" onclick="removeComponent(this)" data-i18n="remove_' + struct.id + '"></button>');
|
||||
}
|
||||
let $body = $('<div class="card-body"></div>').appendTo($el);
|
||||
$header.append('<button type="button" class="btn btn-danger mb-2 float-right" onclick="removeComponent(this)" data-i18n="remove_' + struct.id + '"></button>');
|
||||
if (data._collapsed) {
|
||||
return $el;
|
||||
if (!struct.fields) {
|
||||
let child = components.find(e => e.id === struct.value);
|
||||
return generateObject(data, child, false);
|
||||
}
|
||||
for (let field of struct.fields) {
|
||||
let $field = generateField(data, field, struct);
|
||||
let $field;
|
||||
if (field.collapse) {
|
||||
$body.append('<button type="button" class="btn btn-light mt-3 dropdown-toggle" onclick="toggleCollapseObject(this)" data-field="' + field.id + '" data-i18n="' + field.id + '"></button>');
|
||||
if (data[field.id] === undefined) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
try {
|
||||
$field = generateField(data, field, struct);
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
$field = generateError('Failed generating "' + field.id + '" field');
|
||||
}
|
||||
if ($field !== false) {
|
||||
if (field.type === 'array') {
|
||||
console.log('array!');
|
||||
console.log(field.id);
|
||||
let color = field.color;
|
||||
if (color === undefined) {
|
||||
color = components.find(e => e.id === field.values).color;
|
||||
}
|
||||
if (field.button === 'header') {
|
||||
if (header && field.button === 'header') {
|
||||
$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') {
|
||||
@@ -296,17 +306,26 @@ function generateField(data, field, parent) {
|
||||
}
|
||||
|
||||
let $field;
|
||||
if (data[field.id] === undefined) {
|
||||
if (field.type === 'object') {
|
||||
data[field.id] = {};
|
||||
} else if (field.type === 'enum' && field.default) {
|
||||
data[field.id] = field.default;
|
||||
}
|
||||
}
|
||||
try {
|
||||
$field = generateComponent(data[field.id], field);
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
$field = generateError('Failed generating "' + field.id + '" component');
|
||||
}
|
||||
if (field.class) {
|
||||
$field.addClass(field.class);
|
||||
}
|
||||
if (field.type !== 'array') {
|
||||
$field.attr('data-field', field.id);
|
||||
if ($field) {
|
||||
if (field.class) {
|
||||
$field.addClass(field.class);
|
||||
}
|
||||
if (field.type !== 'array') {
|
||||
$field.attr('data-field', field.id);
|
||||
}
|
||||
}
|
||||
return $field;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user