mirror of
https://github.com/misode/misode.github.io.git
synced 2026-05-03 14:12:54 +00:00
Add map component type
This commit is contained in:
+11
@@ -183,6 +183,17 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div data-type="map">
|
||||
<div class="input-group mt-3">
|
||||
<div class="input-group-prepend">
|
||||
<label class="input-group-text" data-name="1"></label>
|
||||
</div>
|
||||
<input type="text" class="form-control">
|
||||
<div class="input-group-append">
|
||||
<button class="btn btn-dark" type="button" onclick="addToMap(this)" data-name="2"></button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -226,6 +226,41 @@ function removeFromSet(el, array) {
|
||||
}
|
||||
}
|
||||
|
||||
function addToMap(el) {
|
||||
let node = getParent(el);
|
||||
let $field = $(el).closest('[data-index]');
|
||||
let key = $field.find('input').val();
|
||||
let map = $field.attr('data-index');
|
||||
let type = $field.attr('data-item-type');
|
||||
if (key.length === 0) {
|
||||
return;
|
||||
}
|
||||
if (!node[map]) {
|
||||
node[map] = {};
|
||||
}
|
||||
if (type === 'int' || type === 'float' || type === 'random' || type === 'range' || type === 'boundary') {
|
||||
node[map][key] = 0;
|
||||
} else if (type === 'boolean') {
|
||||
node[map][key] = false;
|
||||
} else {
|
||||
node[map][key] = "";
|
||||
}
|
||||
invalidated();
|
||||
}
|
||||
|
||||
function removeFromMap(el) {
|
||||
let path = getPath(el);
|
||||
let key = path.pop();
|
||||
let node = getNode(path);
|
||||
delete node[key];
|
||||
if (Object.keys(node).length === 0) {
|
||||
let field = path.pop();
|
||||
let parent = getNode(path);
|
||||
delete parent[field];
|
||||
}
|
||||
invalidated();
|
||||
}
|
||||
|
||||
function toggleCollapseObject(el) {
|
||||
let path = getPath(el);
|
||||
let index = path.pop();
|
||||
|
||||
@@ -442,6 +442,33 @@
|
||||
"minecraft:weather_check"
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "block",
|
||||
"type": "string",
|
||||
"require": [
|
||||
"minecraft:block_state_propery"
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "properties",
|
||||
"type": "map",
|
||||
"values": {
|
||||
"type": "string"
|
||||
},
|
||||
"require": [
|
||||
"minecraft:block_state_propery"
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "scores",
|
||||
"type": "map",
|
||||
"values": {
|
||||
"type": "range"
|
||||
},
|
||||
"require": [
|
||||
"minecraft:entity_scores"
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "predicate",
|
||||
"type": "object",
|
||||
|
||||
@@ -65,6 +65,7 @@ function generateComponent(data, struct) {
|
||||
case 'boundary': return generateBoundary(data, struct);
|
||||
case 'enum': return generateEnum(data, struct);
|
||||
case 'set': return generateSet(data, struct);
|
||||
case 'map': return generateMap(data, struct);
|
||||
case 'json': return generateJson(data, struct);
|
||||
case 'json-list': return generateJsonList(data, struct);
|
||||
case 'nbt': return generateNbt(data, struct);
|
||||
@@ -192,6 +193,22 @@ function generateSet(data, struct) {
|
||||
return $el;
|
||||
}
|
||||
|
||||
function generateMap(data, struct) {
|
||||
let $el = $('#components').find('[data-type="map"]').clone();
|
||||
$el.attr('data-index', struct.id).attr('data-item-type', struct.values.type);
|
||||
$el.find('[data-name="1"]').attr('data-i18n', struct.id);
|
||||
$el.find('[data-name="2"]').attr('data-i18n', 'add_' + struct.id);
|
||||
$el.find('input').keypress((e) => {if (e.which == 13) addToMap(e.target);});
|
||||
if (data) {
|
||||
for (let key of Object.keys(data)) {
|
||||
let $item = generateComponent(data[key], {id: key, type: struct.values.type});
|
||||
$item.append('<div class="input-group-append"><button class="btn btn-outline-danger bg-light" type="button" onclick="removeFromMap(this)" data-i18n="remove"></button></div>');
|
||||
$el.append($item);
|
||||
}
|
||||
}
|
||||
return $el;
|
||||
}
|
||||
|
||||
function setValueAndName($el, value, source) {
|
||||
let option = value.split(':').slice(-1);
|
||||
let name = (source) ? source + '.' + option : option;
|
||||
|
||||
Reference in New Issue
Block a user