diff options
| author | historia <[not public]> | 2026-07-10 15:13:41 -0400 |
|---|---|---|
| committer | historia <[not public]> | 2026-07-10 15:13:41 -0400 |
| commit | 6adb8ddd28f2b3370f001bfe8cd54656b5d097ce (patch) | |
| tree | 93121f19af752b6cf8b53853bb10da882ef3c5d4 /internal/admin/static/map.js | |
| parent | 8a31ffa45e912d00c480efe738aa3452e9e567cb (diff) | |
| download | thehouseoficarus-6adb8ddd28f2b3370f001bfe8cd54656b5d097ce.tar.gz | |
feat(admin): exit conditions in map gui match style of all other conditions
Diffstat (limited to 'internal/admin/static/map.js')
| -rw-r--r-- | internal/admin/static/map.js | 201 |
1 files changed, 59 insertions, 142 deletions
diff --git a/internal/admin/static/map.js b/internal/admin/static/map.js index 8bd0e2d..bd884b7 100644 --- a/internal/admin/static/map.js +++ b/internal/admin/static/map.js @@ -1558,6 +1558,33 @@ function renderExitsSection(r) { } var editingExitDir = null; +var _exitPrevEditorData = null; +var _exitPrevIERenderOnly = null; +var _exitPrevIERenderCurrent = null; + +function _renderExitCondCard(cond) { + var h = '<div class="obj-card" data-card="exitCond" style="max-width:100%">'; + h += '<div class="obj-card-header"><span class="obj-card-label">Conditions (Blocked unless met)</span></div>'; + h += '<div class="obj-card-body">'; + h += '<div class="obj-sub-row ie-inter-row" data-idx="0">'; + h += '<div class="ie-inter-panel" style="display:block">'; + h += '<div class="ie-inter-panel-body">'; + h += ie_renderCond(cond, 'exitCond', 0, 'exitConds', 'exit', { alwaysOuterAddbar: true }); + h += '</div></div>'; + h += '</div>'; + h += '</div></div>'; + return h; +} + +function _renderExitCond() { + var menu = document.querySelector('.exit-modal'); + if (!menu) return; + var cond = (window._editorData && window._editorData.exitConds && window._editorData.exitConds[0]) + ? window._editorData.exitConds[0].condition : null; + var card = menu.querySelector('.obj-card[data-card="exitCond"]'); + if (card) card.outerHTML = _renderExitCondCard(cond); + ced_setupSearchFields(menu); +} function editExitCondition(dir) { editingExitDir = dir; @@ -1570,7 +1597,13 @@ function editExitCondition(dir) { var hidden = exit.hidden || false; var alwaysBlocked = exit.always_blocked || false; - var parsed = parseCondition(cond); + _exitPrevEditorData = window._editorData; + _exitPrevIERenderOnly = window._ieRenderOnly; + _exitPrevIERenderCurrent = window._ieRenderCurrent; + + window._editorData = { exitConds: [ { condition: cond } ] }; + window._ieRenderCurrent = _renderExitCond; + window._ieRenderOnly = _renderExitCond; var overlay = document.createElement('div'); overlay.className = 'cm-overlay exit-overlay'; @@ -1578,132 +1611,46 @@ function editExitCondition(dir) { menu.className = 'cm-menu exit-modal'; menu.style.cssText = 'position:fixed;top:50%;left:50%;transform:translate(-50%,-50%);min-width:520px;max-width:90vw;max-height:85vh;overflow-y:auto;overflow-x:hidden;padding:14px;z-index:201'; - var h = '<h3 style="margin-bottom:8px;font-size:13px">Exit: ' + esc(dir) + ' → #' + exit.room + '</h3>'; + var h = '<div style="display:flex;justify-content:space-between;align-items:center;margin-bottom:8px">'; + h += '<h3 style="margin:0;font-size:13px">Exit: ' + esc(dir) + ' → #' + exit.room + '</h3>'; + h += '<button class="btn btn-sm btn-danger" style="background:var(--danger);color:#fff;display:inline-block;width:auto" onclick="saveExitCondition()" title="Close">X</button>'; + h += '</div>'; h += '<div class="form-group"><label>Blocked Message</label><textarea id="exitBmsg" rows="2">' + esc(bmsg) + '</textarea></div>'; h += '<div class="form-group"><label><input type="checkbox" id="exitHidden"' + (hidden ? ' checked' : '') + '> Hidden</label></div>'; h += '<div class="form-group"><label><input type="checkbox" id="exitAlwaysBlocked"' + (alwaysBlocked ? ' checked' : '') + '> Always Blocked</label></div>'; h += '<div style="margin-top:10px;border-top:1px solid var(--border);padding-top:8px">'; - h += '<label style="font-size:11px;color:#aaa;text-transform:uppercase;letter-spacing:.5px">Conditions (Blocked unless these are met)</label>'; - h += '<div id="condClauses" style="margin-top:4px"></div>'; - h += '<button class="btn btn-sm section-add-btn" onclick="addConditionClause()">+ Add Condition</button>'; - h += '<div class="btn-row" style="margin-top:10px">'; - h += '<button class="btn btn-primary" onclick="saveExitCondition()">Save</button>'; - h += '<button class="btn btn-danger" onclick="clearExitCondition()">Clear</button>'; - h += '<button class="btn" onclick="closeExitModal()">Cancel</button>'; - h += '</div></div>'; + h += _renderExitCondCard(cond); + h += '<div style="margin-top:10px;font-size:11px;opacity:0.6">Settings are automatically saved</div>'; + h += '</div>'; menu.innerHTML = h; document.body.appendChild(overlay); document.body.appendChild(menu); - overlay.onclick = closeExitModal; - - menu._condClauses = parsed.clauses; - menu._condMode = parsed.mode; - renderConditionClauses(menu); -} - -function parseCondition(cond) { - var clauses = []; - if (!cond || Object.keys(cond).length === 0) return {clauses: clauses, mode: 'all'}; - var arr = cond.all_of; - if (!arr || !Array.isArray(arr) || arr.length === 0) arr = cond.any_of; - if (arr && Array.isArray(arr) && arr.length > 0) { - arr.forEach(function(c) { - var clause = extractClause(c); - if (clause) clauses.push(clause); - }); - return {clauses: clauses, mode: 'all'}; - } - var clause = extractClause(cond); - if (clause) clauses.push(clause); - return {clauses: clauses, mode: 'all'}; + overlay.onclick = saveExitCondition; + ced_setupSearchFields(menu); + bindExitInputSave(menu); } -function extractClause(c) { - var not = c.not === true; - if (c.player_flag && c.player_flag !== '') return {type: 'player_flag', value: c.player_flag, not: not}; - if (c.global_flag && c.global_flag !== '') return {type: 'global_flag', value: c.global_flag, not: not}; - if (c.has_item && c.has_item !== '') return {type: 'has_item', value: c.has_item, not: not}; - if (c.min_credits && c.min_credits !== 0) return {type: 'min_credits', value: String(c.min_credits), not: not}; - if (c.value && typeof c.value === 'object' && c.value.key) return {type: 'value', value: c.value.key + '=' + (c.value.value || ''), not: not}; - return null; -} - -function renderConditionClauses(menu) { - var container = menu.querySelector('#condClauses'); - if (!container) return; - var clauses = menu._condClauses || []; - var h = ''; - clauses.forEach(function(clause, i) { - h += '<div class="cond-clause" data-idx="' + i + '" style="display:flex;gap:4px;align-items:center;margin-bottom:4px">'; - h += '<select class="cond-type" onchange="var c=this.parentElement;var m=this.closest(\'.exit-modal\');var idx=parseInt(c.getAttribute(\'data-idx\'));m._condClauses[idx].type=this.value;renderConditionClauses(m)">'; - ['player_flag','global_flag','value','has_item','min_credits'].forEach(function(t) { - h += '<option value="' + t + '"' + (clause.type === t ? ' selected' : '') + '>' + t + '</option>'; - }); - h += '</select>'; - if (clause.type === 'value') { - var kv = clause.value ? clause.value.split('=', 2) : ['','']; - var kn = (kv[0] || '').trim(); - var kvv = (kv[1] || '').trim(); - h += '<input class="cond-val-key" placeholder="key" value="' + escAttr(kn) + '" onchange="updateClauseData(this)" style="width:80px">'; - h += '<span style="color:#888">=</span>'; - h += '<input class="cond-val-val" placeholder="value" value="' + escAttr(kvv) + '" onchange="updateClauseData(this)" style="flex:1">'; - } else { - h += '<input class="cond-val" value="' + escAttr(clause.value || '') + '" onchange="updateClauseData(this)" style="flex:1">'; - } - h += '<label style="font-size:10px;color:#aaa;white-space:nowrap"><input type="checkbox" class="cond-not"' + (clause.not ? ' checked' : '') + ' onchange="updateClauseData(this)"> =Not True</label>'; - h += '<button class="btn btn-sm btn-danger" onclick="removeConditionClause(this)" style="flex-shrink:0">X</button>'; - h += '</div>'; - }); - container.innerHTML = h; -} - -function updateClauseData(el) { - var clauseEl = el.closest('.cond-clause'); - var menu = el.closest('.exit-modal'); - if (!clauseEl || !menu) return; - var idx = parseInt(clauseEl.getAttribute('data-idx')); - var clause = menu._condClauses[idx]; - if (!clause) return; - clause.type = clauseEl.querySelector('.cond-type').value; - clause.not = clauseEl.querySelector('.cond-not').checked; - if (clause.type === 'value') { - var k = clauseEl.querySelector('.cond-val-key'); - var v = clauseEl.querySelector('.cond-val-val'); - clause.value = (k ? k.value.trim() : '') + '=' + (v ? v.value.trim() : ''); - } else { - var val = clauseEl.querySelector('.cond-val'); - clause.value = val ? val.value : ''; - } -} - -function addConditionClause() { - var menu = document.querySelector('.exit-modal'); - if (!menu) return; - if (!menu._condClauses) menu._condClauses = []; - menu._condClauses.push({type: 'player_flag', value: '', not: false}); - renderConditionClauses(menu); -} - -function removeConditionClause(btn) { - var menu = btn.closest('.exit-modal'); - var clauseEl = btn.closest('.cond-clause'); - if (!menu || !clauseEl) return; - var idx = parseInt(clauseEl.getAttribute('data-idx')); - menu._condClauses.splice(idx, 1); - renderConditionClauses(menu); +function bindExitInputSave(menu) { + menu.addEventListener('input', collectExitCondition); + menu.addEventListener('change', collectExitCondition); } function closeExitModal() { editingExitDir = null; + if (_exitPrevEditorData !== undefined) { + window._editorData = _exitPrevEditorData; + window._ieRenderOnly = _exitPrevIERenderOnly; + window._ieRenderCurrent = _exitPrevIERenderCurrent; + } var ov = document.querySelector('.exit-overlay'); if (ov) ov.remove(); var m = document.querySelector('.exit-modal'); if (m) m.remove(); } -function saveExitCondition() { +function collectExitCondition() { if (!editingExitDir || !currentRoomData || !currentRoomData.room) return; var menu = document.querySelector('.exit-modal'); if (!menu) return; @@ -1724,47 +1671,17 @@ function saveExitCondition() { var alwaysBlockedEl = document.getElementById('exitAlwaysBlocked'); exit.always_blocked = alwaysBlockedEl ? alwaysBlockedEl.checked : false; - var clauseEls = menu.querySelectorAll('.cond-clause'); - clauseEls.forEach(function(el) { updateClauseData(el); }); - - var clauses = (menu._condClauses || []).filter(function(c) { return c.value && c.value !== '' && c.value !== '='; }); - var condition = null; - if (clauses.length === 1) { - condition = buildSingleCondition(clauses[0]); - } else if (clauses.length > 1) { - condition = {all_of: clauses.map(function(c) { return buildSingleCondition(c); })}; - } - exit.condition = condition; + var condRoot = menu.querySelector('.ie-cond-root'); + exit.condition = condRoot ? (ie_cleanCondition(ie_collectCond(condRoot)) || null) : null; r.exits = exits; autoSave(); - closeExitModal(); - reRenderPanel(); -} - -function buildSingleCondition(clause) { - var obj = {}; - if (clause.not) obj.not = true; - if (clause.type === 'value') { - var parts = (clause.value || '').split('=', 2); - obj.value = {key: (parts[0] || '').trim(), value: (parts[1] || '').trim()}; - } else { - obj[clause.type] = clause.value; - } - return obj; } -function clearExitCondition() { - var menu = document.querySelector('.exit-modal'); - if (!menu) return; - menu._condClauses = []; - renderConditionClauses(menu); - var bmsg = document.getElementById('exitBmsg'); - if (bmsg) bmsg.value = ''; - var hx = document.getElementById('exitHidden'); - if (hx) hx.checked = false; - var ab = document.getElementById('exitAlwaysBlocked'); - if (ab) ab.checked = false; +function saveExitCondition() { + collectExitCondition(); + closeExitModal(); + reRenderPanel(); } function parseFlagInput(val) { |
