mirror of
https://github.com/misode/misode.github.io.git
synced 2026-04-23 15:17:09 +00:00
Add nbt operations
This commit is contained in:
@@ -159,6 +159,12 @@
|
||||
<div class="input-group mt-3" data-type="json-list">
|
||||
<textarea class="form-control code" onchange="updateJsonListField(this)" rows=3></textarea>
|
||||
</div>
|
||||
<div class="input-group mt-3" data-type="nbt">
|
||||
<div class="input-group-prepend">
|
||||
<span class="input-group-text" data-name></span>
|
||||
</div>
|
||||
<textarea type="text" class="form-control code" onchange="updateField(this)" onfocus="this.select()" style="height: 0px"></textarea>
|
||||
</div>
|
||||
<div class="input-group mt-3" data-type="error">
|
||||
<div class="input-group-prepend">
|
||||
<span class="input-group-text text-danger" data-i18n="error"></span>
|
||||
|
||||
@@ -190,7 +190,7 @@
|
||||
},
|
||||
{
|
||||
"id": "tag",
|
||||
"type": "string",
|
||||
"type": "nbt",
|
||||
"require": [
|
||||
"minecraft:set_nbt"
|
||||
]
|
||||
@@ -319,6 +319,15 @@
|
||||
"minecraft:set_attributes"
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "ops",
|
||||
"type": "array",
|
||||
"button": "field",
|
||||
"values": "nbt_operation",
|
||||
"require": [
|
||||
"minecraft:copy_nbt"
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "conditions",
|
||||
"type": "array",
|
||||
@@ -405,6 +414,37 @@
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "nbt_operation",
|
||||
"type": "object",
|
||||
"color": "dark",
|
||||
"default": {
|
||||
"operation": "replace"
|
||||
},
|
||||
"fields": [
|
||||
{
|
||||
"id": "source",
|
||||
"type": "string",
|
||||
"class": "code"
|
||||
},
|
||||
{
|
||||
"id": "target",
|
||||
"type": "string",
|
||||
"class": "code"
|
||||
},
|
||||
{
|
||||
"id": "op",
|
||||
"type": "enum",
|
||||
"source": "operation.type",
|
||||
"default": "replace",
|
||||
"values": [
|
||||
"replace",
|
||||
"append",
|
||||
"merge"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
14
view.js
14
view.js
@@ -51,6 +51,7 @@ function generateComponent(data, struct) {
|
||||
case 'set': return generateSet(data, struct);
|
||||
case 'json': return generateJson(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);
|
||||
default: return generateError('Unknown component type "' + struct.type + '"')};
|
||||
@@ -198,6 +199,14 @@ function generateJsonList(data, struct) {
|
||||
return $el;
|
||||
}
|
||||
|
||||
function generateNbt(data, struct) {
|
||||
let $el = $('#components').find('[data-type="nbt"]').clone();
|
||||
$el.attr('data-field', struct.id);
|
||||
$el.find('[data-name]').attr('data-i18n', struct.id);
|
||||
$el.find('textarea').val(data).keydown(e => preventNewline(e));
|
||||
return $el;
|
||||
}
|
||||
|
||||
function generateError(error) {
|
||||
let $el = $('#components').find('[data-type="error"]').clone();
|
||||
$el.find('[data-name]').val(error);
|
||||
@@ -239,6 +248,9 @@ function generateObject(data, struct) {
|
||||
console.error(e);
|
||||
$field = generateError('Failed generating "' + field.id + '" component');
|
||||
}
|
||||
if (field.class) {
|
||||
$field.addClass(field.class);
|
||||
}
|
||||
if (field.type === 'array') {
|
||||
let color = field.color;
|
||||
if (color === undefined) {
|
||||
@@ -254,6 +266,8 @@ function generateObject(data, struct) {
|
||||
$field.attr('data-field', field.id);
|
||||
}
|
||||
$body.append($field);
|
||||
} else {
|
||||
delete data[field.id];
|
||||
}
|
||||
}
|
||||
$body.children().first().removeClass('mt-3');
|
||||
|
||||
Reference in New Issue
Block a user