mirror of
https://github.com/misode/misode.github.io.git
synced 2026-04-24 23:56:51 +00:00
Add set, json, json-list, boundary types + catch errors on components
This commit is contained in:
38
model.js
38
model.js
@@ -185,6 +185,26 @@ function removeComponent(el) {
|
||||
}
|
||||
invalidated();
|
||||
}
|
||||
function addToSet(el, array) {
|
||||
let parent = getParent(el);
|
||||
if (!parent[array]) {
|
||||
parent[array] = [];
|
||||
}
|
||||
parent[array].push($(el).attr('value'));
|
||||
invalidated();
|
||||
}
|
||||
|
||||
function removeFromSet(el, array) {
|
||||
let parent = getParent(el);
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
function updateField(el) {
|
||||
let $field = $(el).closest('[data-field]');
|
||||
@@ -217,6 +237,14 @@ function updateField(el) {
|
||||
}
|
||||
} else if (type === 'json') {
|
||||
value = parseJSONValue(value)
|
||||
} else if (type === 'json-list') {
|
||||
let value = [];
|
||||
for (let line of $(el).val().split('\n')) {
|
||||
value.push(parseJSONValue(line));
|
||||
}
|
||||
if (value.length === 0) {
|
||||
value = '';
|
||||
}
|
||||
} else if (type === 'range' || type === 'random') {
|
||||
value = getRangeValue($field, node[field]);
|
||||
} else if (type === 'checkbox') {
|
||||
@@ -406,16 +434,6 @@ function parseJSONValue(value) {
|
||||
return value;
|
||||
}
|
||||
|
||||
function updateLoreField(el) {
|
||||
let lines = $(el).val().split('\n');
|
||||
let parent = getParent(el);
|
||||
parent.lore = [];
|
||||
for (let line of lines) {
|
||||
parent.lore.push(parseJSONValue(line));
|
||||
}
|
||||
invalidated();
|
||||
}
|
||||
|
||||
function addOperation(el) {
|
||||
let func = getParent(el);
|
||||
if (!func.ops) {
|
||||
|
||||
Reference in New Issue
Block a user