diff options
Diffstat (limited to 'internal/admin/static/objecteditor.js')
| -rw-r--r-- | internal/admin/static/objecteditor.js | 206 |
1 files changed, 5 insertions, 201 deletions
diff --git a/internal/admin/static/objecteditor.js b/internal/admin/static/objecteditor.js index 56894d2..c2374a7 100644 --- a/internal/admin/static/objecteditor.js +++ b/internal/admin/static/objecteditor.js @@ -112,11 +112,6 @@ var SECTIONS = [ ] }, { - id: 'talk', label: 'Talk', path: 'talk', - detect: function(d) { return d.talk && d.talk.nodes; }, - fields: [] - }, - { id: 'on_look', label: 'On Look', path: 'on_look', detect: function(d) { return d.on_look; }, fields: [ @@ -144,10 +139,6 @@ function initObjectEditor() { if (window.location.hash) loadObject(window.location.hash.substring(1)); } -window.onTalkTreeChange = function(data) { - objectData.talk = data.talk; -}; - function loadObject(id) { objectID = id; currentID = id; @@ -206,12 +197,6 @@ function renderObjectEditor(id, data) { setTimeout(function() { document.querySelectorAll('.color-field').forEach(function(el) { bindColorField(el); }); }, 50); - - SECTIONS.forEach(function(sec) { - if (sec.id === 'talk' && data.talk && data.talk.nodes) { - renderTalkTree(data); - } - }); } function cardPath(sec) { @@ -319,10 +304,6 @@ function renderCard(sec, data) { h += renderSubtable(sec, st, data); }); } - - if (sec.id === 'talk') { - h += '<div id="talktree"></div>'; - } } h += '</div>'; } @@ -573,8 +554,6 @@ function addSection() { objectData[sec.path] = {message:'', wait:1, consume:{}, reward:{}, fail_message:'', success:{base:0, per_level:0, cap:1}, skill:'', level:1, xp:0}; } else if (sec.id === 'safespot') { objectData[sec.path] = {tier:1, max_block_size:'', max_occupants:1, unsafe_chance:0, decay_ticks:0, decay_chance:0, respawn_on_hide:false, respawn_ticks:0, levels:[]}; - } else if (sec.id === 'talk') { - objectData[sec.path] = {nodes:{start:{message:'',options:[]}}}; } else { objectData[sec.path] = {}; } @@ -678,185 +657,15 @@ function toggleGatherConditionals() { }); } -function setupSearchFields() { - document.querySelectorAll('.search-input').forEach(function(input) { - if (input._searchSetup) return; - input._searchSetup = true; - var entityType = input.getAttribute('data-search-type') || 'items'; - var results = input.parentElement.querySelector('.search-results'); - if (!results) return; - - results._targetInput = input; - - input.addEventListener('input', function() { - var val = input.value.trim(); - if (!val) { results.style.display = 'none'; results.innerHTML = ''; results._selectedIndex = -1; return; } - API.get('/api/search?q=' + encodeURIComponent(val)).then(function(data) { - var items = []; - if (entityType === 'items' && data.items) items = data.items; - if (entityType === 'objects' && data.objects) items = data.objects; - if (entityType === 'mobs' && data.mobs) items = data.mobs; - if (entityType === 'drops' && data.drops) items = data.drops; - if (items.length === 0) { - results.style.display = 'block'; - results.innerHTML = '<div class="sr-item" style="color:#888">No results</div>'; - return; - } - results.style.display = 'block'; - results.innerHTML = items.map(function(r) { - return '<div class="sr-item" onclick="event.stopPropagation();selectObjSearchResult(this)">' + esc(r.id) + ' <span style="color:#aaa">' + esc(r.name || '') + '</span></div>'; - }).join(''); - results._items = items; - results._selectedIndex = -1; - }).catch(function() { - results.style.display = 'none'; - }); - }); - - input.addEventListener('focus', function() { - if (input.value.trim()) { - input.dispatchEvent(new Event('input')); - } - }); - - input.addEventListener('blur', function() { - setTimeout(function() { results.style.display = 'none'; }, 200); - }); +function setupSearchFields() { ced_setupSearchFields(); } - input.addEventListener('keydown', function(e) { - if (results.style.display === 'none' || !results.children.length) return; - if (results._selectedIndex === undefined) results._selectedIndex = -1; - - if (e.key === 'ArrowDown') { - e.preventDefault(); - results._selectedIndex = Math.min(results._selectedIndex + 1, results.children.length - 1); - updateSearchHighlight(results); - } else if (e.key === 'ArrowUp') { - e.preventDefault(); - results._selectedIndex = Math.max(results._selectedIndex - 1, 0); - updateSearchHighlight(results); - } else if (e.key === 'Enter') { - if (results._selectedIndex >= 0) { - e.preventDefault(); - selectObjSearchResult(results.children[results._selectedIndex]); - } - } else if (e.key === 'Escape') { - results.style.display = 'none'; - results._selectedIndex = -1; - } - }); - }); +function selectObjSearchResult(el) { ced_selectSearchResult(el); } - document.addEventListener('click', function(e) { - if (!e.target.closest('.search-results') && !e.target.closest('.search-input')) { - document.querySelectorAll('.search-results').forEach(function(r) { r.style.display = 'none'; }); - } - }); -} +function updateSearchHighlight(results) { ced_updateSearchHighlight(results); } -function selectObjSearchResult(el) { - var results = el.parentElement; - var idx = Array.prototype.indexOf.call(results.children, el); - if (results._items && results._items[idx] && results._targetInput) { - results._targetInput.value = results._items[idx].id; - results._targetInput.dispatchEvent(new Event('input')); - results.style.display = 'none'; - results.innerHTML = ''; - } -} +function validateFields() { return ced_validateFields(SECTIONS, fieldID, fieldIDSub); } -function updateSearchHighlight(results) { - for (var i = 0; i < results.children.length; i++) { - results.children[i].classList.toggle('active', i === results._selectedIndex); - if (i === results._selectedIndex) results.children[i].scrollIntoView({block: 'nearest'}); - } -} - -function validateFields() { - var errors = []; - document.querySelectorAll('.obj-field-error').forEach(function(field) { - field.classList.remove('obj-field-error'); - }); - - document.querySelectorAll('input[id][type="text"], input[id]:not([type])').forEach(function(input) { - var id = input.id; - if (!id) return; - var labelEl = input.closest('.obj-field'); - if (!labelEl) return; - - var fieldDiv = labelEl.closest('[data-card]'); - var cardID = fieldDiv ? fieldDiv.getAttribute('data-card') : ''; - var sec = SECTIONS.find(function(s) { return s.id === cardID; }); - if (!sec) return; - - var isSearch = input.classList.contains('search-input'); - var subKeyMatch = id.match(/^f_(\w+)_(\w+)_(\d+)_(\w+)$/); - var numberField = null; - - if (isSearch) { - return; - } - - if (subKeyMatch) { - var subKey = subKeyMatch[2]; - var st = (sec.subtables || []).find(function(s) { return s.key === subKey; }); - if (st) { - var fieldKey = subKeyMatch[4]; - numberField = st.fields.find(function(f) { return f[0] === fieldKey && f[2] === 'number'; }); - } - } else { - numberField = sec.fields.find(function(f) { - var fp = f[0]; - if (sec.path && sec.path !== 'on_look') fp = fp; - var fid = fieldID(sec, fp, -1); - return fid === id && f[2] === 'number'; - }); - if (!numberField && sec.inline) { - sec.inline.forEach(function(il) { - if (il.fields) { - var nf = il.fields.find(function(f) { - var fid = fieldID(sec, il.path + '.' + f[0], -1); - return fid === id && f[2] === 'number'; - }); - if (nf) numberField = nf; - } - }); - } - } - - if (numberField) { - var rawVal = input.value.trim(); - if (rawVal !== '' && !/^-?\d*\.?\d*$/.test(rawVal)) { - labelEl.classList.add('obj-field-error'); - input.focus(); - input.select(); - var labelText = (labelEl.querySelector('span') || {}).textContent || numberField[1] || ''; - errors.push('Invalid value in "' + esc(labelText) + '": "' + esc(rawVal) + '"'); - return; - } - } - }); - - if (errors.length > 0) { - notify(errors.join('; '), 'error'); - return false; - } - return true; -} - -function 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 === 'json') { - var raw = el.value.trim(); - if (!raw) return null; - try { return JSON.parse(raw); } catch(e) { return raw; } - } - if (type === 'textarea') return el.value; - return el.value; -} +function collectFieldValue(el, type) { return ced_collectFieldValue(el, type); } function saveObject() { if (!validateFields()) return; @@ -882,11 +691,6 @@ function saveObject() { return; } - if (sec.id === 'talk') { - if (objectData.talk) out.talk = objectData.talk; - return; - } - var sectionObj = {}; var hasValues = sec.always; |
