From 6adb8ddd28f2b3370f001bfe8cd54656b5d097ce Mon Sep 17 00:00:00 2001
From: historia <[not public]>
Date: Fri, 10 Jul 2026 15:13:41 -0400
Subject: feat(admin): exit conditions in map gui match style of all other
conditions
---
internal/admin/static/map.js | 201 +++++++++++++------------------------------
1 file changed, 59 insertions(+), 142 deletions(-)
(limited to 'internal/admin/static/map.js')
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 = '
';
+ h += '';
+ h += '
';
+ h += '
';
+ h += '
';
+ h += '
';
+ h += ie_renderCond(cond, 'exitCond', 0, 'exitConds', 'exit', { alwaysOuterAddbar: true });
+ h += '
';
+ h += '
';
+ h += '
';
+ 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 = 'Exit: ' + esc(dir) + ' → #' + exit.room + '
';
+ var h = '';
+ h += '
Exit: ' + esc(dir) + ' → #' + exit.room + '
';
+ h += '';
+ h += '';
h += '';
h += '';
h += '';
h += '';
- h += '
';
- h += '
';
- h += '
';
- h += '
';
- h += '';
- h += '';
- h += '';
- h += '
';
+ h += _renderExitCondCard(cond);
+ h += 'Settings are automatically saved
';
+ h += '';
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 += '';
- h += '';
- if (clause.type === 'value') {
- var kv = clause.value ? clause.value.split('=', 2) : ['',''];
- var kn = (kv[0] || '').trim();
- var kvv = (kv[1] || '').trim();
- h += '';
- h += '=';
- h += '';
- } else {
- h += '';
- }
- h += '';
- h += '';
- h += '
';
- });
- 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) {
--
cgit v1.2.3