diff options
| author | historia <[not public]> | 2026-07-13 16:10:40 -0400 |
|---|---|---|
| committer | historia <[not public]> | 2026-07-13 16:10:40 -0400 |
| commit | 3274b700a6f655b8ecc3505e814ac5d782ae6ffe (patch) | |
| tree | e669b47726f8cb93b75c7df85997cc8556009f20 /internal/admin/static/cardeditor.js | |
| parent | 93a412aed2b11406399504c81d6d19ed1341908a (diff) | |
| download | thehouseoficarus-3274b700a6f655b8ecc3505e814ac5d782ae6ffe.tar.gz | |
feat(admin): reminder text for color tags and item variables, improve placeholder text
Diffstat (limited to 'internal/admin/static/cardeditor.js')
| -rw-r--r-- | internal/admin/static/cardeditor.js | 37 |
1 files changed, 31 insertions, 6 deletions
diff --git a/internal/admin/static/cardeditor.js b/internal/admin/static/cardeditor.js index f32ea7e..6a8cda7 100644 --- a/internal/admin/static/cardeditor.js +++ b/internal/admin/static/cardeditor.js @@ -42,7 +42,7 @@ function ced_collectFieldValue(el, type) { if (type === 'checkbox') return el.checked; if (type === 'select') return el.value; if (type === 'search') return el.value; - if (type === 'number') { var n = parseFloat(el.value); return isNaN(n) ? 0 : n; } + if (type === 'number') { var n = parseFloat(el.value); return isNaN(n) ? '' : n; } if (type === 'json') { var raw = el.value.trim(); if (!raw) return null; @@ -86,7 +86,7 @@ function ced_addKVRow(cardID, subKey) { if (!el) return; var row = document.createElement('div'); row.className = 'obj-kv-row'; - row.innerHTML = '<input value="" placeholder="key" class="obj-kv-key"><input value="0" placeholder="val" class="obj-kv-val"><button class="btn btn-sm btn-danger" onclick="this.parentElement.remove()">X</button>'; + row.innerHTML = '<input value="" placeholder="key" class="obj-kv-key"><input value="" placeholder="val" class="obj-kv-val"><button class="btn btn-sm btn-danger" onclick="this.parentElement.remove()">X</button>'; el.appendChild(row); } @@ -125,7 +125,7 @@ function ced_addKVSearchRow(cardID, subKey, entity) { if (!el) return; var row = document.createElement('div'); row.className = 'obj-kv-row'; - row.innerHTML = '<div class="obj-kv-key-wrap obj-search" style="flex:1;position:relative"><div style="position:relative;width:100%"><input value="" class="search-input obj-kv-key" data-search-type="' + entity + '" placeholder="Search ' + entity + '..."><div class="search-results" style="display:none"></div></div></div><input value="0" placeholder="val" class="obj-kv-val"><button class="btn btn-sm btn-danger" onclick="this.parentElement.remove()">X</button>'; + row.innerHTML = '<div class="obj-kv-key-wrap obj-search" style="flex:1;position:relative"><div style="position:relative;width:100%"><input value="" class="search-input obj-kv-key" data-search-type="' + entity + '" placeholder="Search ' + entity + '..."><div class="search-results" style="display:none"></div></div></div><input value="" placeholder="val" class="obj-kv-val"><button class="btn btn-sm btn-danger" onclick="this.parentElement.remove()">X</button>'; el.appendChild(row); ced_setupSearchFields(row); } @@ -398,7 +398,7 @@ function ced_addSubRow(sec, subKey, dataRef, cardPathFn) { var st = (sec.subtables || []).find(function(s) { return s.key === subKey; }); if (st) { st.fields.forEach(function(f) { - empty[f[0]] = f[2] === 'checkbox' ? false : (f[2] === 'number' ? 0 : ''); + empty[f[0]] = f[2] === 'checkbox' ? false : ''; }); } arr.push(empty); @@ -579,8 +579,18 @@ function ced_cleanOutput(obj) { } else if (typeof val === 'object' && val !== null && !Array.isArray(val)) { ced_cleanOutput(val); if (Object.keys(val).length === 0) delete obj[key]; - } else if (Array.isArray(val) && val.length === 0) { - delete obj[key]; + } else if (Array.isArray(val)) { + if (val.length === 0) { + delete obj[key]; + } else { + for (var i = val.length - 1; i >= 0; i--) { + if (typeof val[i] === 'object' && val[i] !== null) { + ced_cleanOutput(val[i]); + if (Object.keys(val[i]).length === 0) val.splice(i, 1); + } + } + if (val.length === 0) delete obj[key]; + } } } } @@ -658,3 +668,18 @@ function ced_collectAtkType(widgetID) { if (sci && sci.checked) out.push('science'); return out; } + +function ced_renderTagHelp(type) { + var h = '<div style="margin-top:8px;font-size:10px;color:#aaa;line-height:1.5">'; + if (type === 'color') { + h += 'Name is displayed without an article (e.g. "John Smith" instead of "a John Smith")<br>'; + h += 'Cannot be attacked by players. Combat level hidden<br>'; + h += 'Text fields support color tags: <code style="color:#aaa;font-family:monospace">{NN}text{/}</code> where <code style="color:#aaa;font-family:monospace">NN</code> is a hex color index (00–FF).'; + } else if (type === 'crafting') { + h += 'Message fields support template variables:<br>%i1 = first ingredient name<br>%i2 = second ingredient name<br>%n = output item name.<br>Color tags are also supported: {NN}text{/} where NN is a hex color index (00–FF).'; + } else if (type === 'gather') { + h += 'Message fields support template variables: {name} = object name.<br>Color tags are also supported: {NN}text{/} where NN is a hex color index (00–FF).'; + } + h += '</div>'; + return h; +} |
