diff options
Diffstat (limited to 'internal/admin/static/map.js')
| -rw-r--r-- | internal/admin/static/map.js | 33 |
1 files changed, 21 insertions, 12 deletions
diff --git a/internal/admin/static/map.js b/internal/admin/static/map.js index 7cd4430..3507e2d 100644 --- a/internal/admin/static/map.js +++ b/internal/admin/static/map.js @@ -20,7 +20,8 @@ var gridDirs = [ var oppositeDir = { north:'south', south:'north', east:'west', west:'east', northeast:'southwest', northwest:'southeast', - southeast:'northwest', southwest:'northeast' + southeast:'northwest', southwest:'northeast', + up:'down', down:'up' }; var saveTimer = null; var upTarget = {}, downTarget = {}; @@ -2215,13 +2216,13 @@ function showRoomContextMenu(x, y, id) { } // buildSubmenuItem constructs a parent menu row ("Insert Room"/"Remove Room") -// that carries a nested submenu of the room's horizontal exits. The submenu is +// that carries a nested submenu of the room's exits. The submenu is // revealed by both hover (Windows-style: mouseenter with a small dismiss delay // on mouseleave) and click (keyboard/mobile accessibility), mirroring how // Windows cascading menus behave. closeAll closes the whole context menu; // overlay carries the shared hide-timer slot. function buildSubmenuItem(label, id, mode, closeAll, overlay, menu) { - var dirs = roomHorizontalDirs(id); + var dirs = roomDirs(id); var empty = dirs.length === 0; var item = document.createElement('div'); @@ -2239,8 +2240,8 @@ function buildSubmenuItem(label, id, mode, closeAll, overlay, menu) { // Still surface the "no exits" reason on click so it's discoverable. btn.onclick = function() { notify(mode === 'insert' - ? 'No horizontal exits to insert into from #' + id - : 'No horizontal exits to remove from #' + id, 'error'); + ? 'No exits to insert into from #' + id + : 'No exits to remove from #' + id, 'error'); }; return item; } @@ -2312,31 +2313,39 @@ function buildSubmenuItem(label, id, mode, closeAll, overlay, menu) { return item; } -// roomHorizontalDirs returns the room's outward horizontal exits on the current -// z-level, in gridDirs order, derived from mapData.links. Empty when the room -// has no horizontal exits to insert into / remove from. -function roomHorizontalDirs(id) { +// roomDirs returns the room's outward exits (horizontal + up/down) derived from +// mapData.links and mapData.{upLinks,downLinks}. Horizontal exits are ordered by +// gridDirs; up/down appear last. Empty when the room has no exits. +function roomDirs(id) { if (!mapData || !mapData.links) return []; var horizontal = {}; gridDirs.forEach(function(d) { horizontal[d.dir] = true; }); var seen = {}; - var dirs = []; + mapData.links.forEach(function(l) { if (l.from === id && horizontal[l.dir] && !seen[l.dir]) { seen[l.dir] = true; - dirs.push(l.dir); } else if (l.to === id && l.bidirectional && horizontal[l.dir]) { var opp = oppositeDir[l.dir]; if (opp && !seen[opp]) { seen[opp] = true; - dirs.push(opp); } } }); + + if (mapData.upLinks) mapData.upLinks.forEach(function(l) { + if (l.from === id) seen['up'] = true; + }); + if (mapData.downLinks) mapData.downLinks.forEach(function(l) { + if (l.from === id) seen['down'] = true; + }); + var ordered = []; gridDirs.forEach(function(d) { if (seen[d.dir]) ordered.push(d.dir); }); + if (seen['up']) ordered.push('up'); + if (seen['down']) ordered.push('down'); return ordered; } |
