';
h += '' + d + '';
h += '# ' + target + '';
- h += '';
if (bmsg) h += 'Blocked: ' + esc(bmsg) + '';
if (cond) h += 'Conditional';
h += '';
+ if (isBidi) h += '';
h += '';
h += '
';
});
@@ -1175,6 +1198,7 @@ function renderExitsSection(r) {
exitDirs.forEach(function(d) { h += ''; });
h += '';
h += '';
+ h += '';
h += '';
h += '';
h += '';
@@ -1421,8 +1445,13 @@ function addExit() {
var dir = $('#exitDirSelect').value;
var target = parseInt($('#exitTargetID').value);
if (!dir || !target) { notify('Enter target room ID', 'error'); return; }
- API.post('/api/rooms/link', {from: selectedRoom, to: target, dir: dir}).then(function() {
- notify('Exit added: ' + dir + ' #' + target, 'success');
+ var reciprocalEl = $('#exitReciprocal');
+ var reciprocal = reciprocalEl ? reciprocalEl.checked : true;
+ var body = {from: selectedRoom, to: target, dir: dir};
+ if (!reciprocal) body.oneway = true;
+ API.post('/api/rooms/link', body).then(function(res) {
+ if (res && res.error) { notify('Add exit failed: ' + res.error, 'error'); return; }
+ notify('Exit added: ' + dir + ' #' + target + (reciprocal ? '' : ' (one-way)'), 'success');
updateUndoBar();
loadMap().then(function() { selectRoom(selectedRoom); });
}).catch(function(e) { notify('Add exit failed: ' + extractError(e), 'error'); });
@@ -1430,15 +1459,17 @@ function addExit() {
function deleteExit(dir, target) {
if (!selectedRoom || !currentRoomData) return;
- if (!confirm('Delete exit ' + dir + ' to #' + target + '?')) return;
fetch('/api/rooms/link', {
method: 'DELETE',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({from: selectedRoom, to: target}),
credentials: 'same-origin'
}).then(function(r) {
- if (!r.ok) return r.json().then(function(j) { throw new Error(j.error || 'request failed'); });
- return r.json();
+ return r.json().then(function(j) {
+ if (!r.ok) throw new Error(j.error || 'request failed');
+ if (j.error) throw new Error(j.error);
+ return j;
+ });
}).then(function() {
notify('Removed exit ' + dir + ' to #' + target, 'success');
updateUndoBar();
@@ -2014,21 +2045,16 @@ function clearLinkHighlight() {
}
}
-function createLink(fromId, toId) {
- API.post('/api/rooms/link', {from: fromId, to: toId}).then(function() {
- notify('Linked rooms #'+fromId+' '+toId, 'success');
+function createLink(fromId, toId, oneway) {
+ var body = {from: fromId, to: toId};
+ if (oneway) body.oneway = true;
+ API.post('/api/rooms/link', body).then(function(res) {
+ if (res && res.error) { notify('Link failed: ' + res.error, 'error'); return; }
+ notify('Linked rooms #'+fromId+' '+toId + (oneway ? ' (one-way)' : ''), 'success');
updateUndoBar();
- if (mapData && mapData.rooms) {
- var fr = mapData.rooms.find(function(r) { return r.id === fromId; });
- var tr = mapData.rooms.find(function(r) { return r.id === toId; });
- if (fr && tr) {
- mapData.links = mapData.links || [];
- mapData.links.push({from: fromId, to: toId, dir: gridDeltaToDir(tr.x - fr.x, tr.y - fr.y) || '', bidirectional: true});
- renderMap(mapData);
- }
- }
+ loadMap().then(function() { selectRoom(selectedRoom); });
}).catch(function(e) {
- notify('Link failed: ' + e.message, 'error');
+ notify('Link failed: ' + extractError(e), 'error');
});
}
@@ -2105,26 +2131,26 @@ function clearDelHighlight() {
}
}
-function deleteLink(fromId, toId) {
+function deleteLink(fromId, toId, side) {
+ var body = {from: fromId, to: toId};
+ if (side) body.side = side;
fetch('/api/rooms/link', {
method: 'DELETE',
headers: {'Content-Type': 'application/json'},
- body: JSON.stringify({from: fromId, to: toId}),
+ body: JSON.stringify(body),
credentials: 'same-origin'
}).then(function(r) {
- if (!r.ok) throw new Error('unlink failed');
- return r.json();
+ return r.json().then(function(j) {
+ if (!r.ok) throw new Error(j.error || 'unlink failed');
+ if (j.error) throw new Error(j.error);
+ return j;
+ });
}).then(function() {
- notify('Removed link #'+fromId+' '+toId, 'success');
+ notify('Removed link #'+fromId+' '+toId + (side ? ' (' + side + ' side only)' : ''), 'success');
updateUndoBar();
- if (mapData && mapData.links) {
- mapData.links = mapData.links.filter(function(l) {
- return !((l.from === fromId && l.to === toId) || (l.from === toId && l.to === fromId));
- });
- renderMap(mapData);
- }
+ loadMap().then(function() { selectRoom(selectedRoom); });
}).catch(function(e) {
- notify('Delete link failed: ' + e.message, 'error');
+ notify('Delete link failed: ' + extractError(e), 'error');
});
}
@@ -2368,4 +2394,7 @@ function reloadRoomDirs(cb) {
});
}
-document.addEventListener('DOMContentLoaded', function() { loadRoomDirs(function() { loadMap(); }); initPanelResize(); });
+document.addEventListener('DOMContentLoaded', function() { loadRoomDirs(function() { loadMap(); }); initPanelResize();
+ document.addEventListener('keydown', function(e) { if (e.key === 'Shift') shiftHeld = true; });
+ document.addEventListener('keyup', function(e) { if (e.key === 'Shift') shiftHeld = false; });
+});
--
cgit v1.2.3