display items on map, switch to grid layout

closes #2
This commit is contained in:
jomo 2022-08-05 22:04:56 +02:00
parent fda7352e22
commit 8e19a1dbad
6 changed files with 151 additions and 42 deletions

View file

@ -39,23 +39,23 @@ function renderItems() {
}
function getLocString(items, item) {
let ancestors = [];
item.ancestors = [];
let next = item;
let loop = false;
while (next) {
if (ancestors.includes(next)) {
if (item.ancestors.includes(next)) {
loop = true;
if (ancestors.length == 1) {
ancestors.push(null);
if (item.ancestors.length == 1) {
item.ancestors.push(null);
}
break;
}
ancestors.unshift(next);
item.ancestors.unshift(next);
next = items[next.is_in];
}
ancestors.pop();
let loc = ancestors.map(i => i.id).join(' ➜ ') || '⬚';
let longloc = ancestors.map(i => `${i.type || ''} ${i.id} ${i.name && `(${i.name})` || ''}`).join(' ➜ ') || 'universe';
item.ancestors.pop();
let loc = item.ancestors.map(i => i.id).join(' ➜ ') || '⬚';
let longloc = item.ancestors.map(i => `${i.type || ''} ${i.id} ${i.name && `(${i.name})` || ''}`).join(' ➜ ') || 'universe';
if (loop) {
loc += ' ↻';
longloc += ' ↻';
@ -69,7 +69,7 @@ function search(e) {
const regex = new RegExp(query, 'i')
for (const elem of document.getElementsByClassName('result')) {
const item = items[elem.id.substr(5)];
const item = items[elem.id.slice(5)];
let found = false;
if (query) {
for (const a in searchAttrs) {
@ -99,3 +99,23 @@ function showhidden(e){
results.classList.remove('showhidden');
}
}
function showItem(e) {
const item = items[e.target.id.slice(5)];
const ancestors = item.ancestors.concat(item);
for (let i = ancestors.length-1; i >= 0; i--) {
const ancestor = ancestors[i];
if (ancestor.coords_bl && ancestor.coords_tr) {
if (ancestor != item) {
const mapnote = `Showing ${ancestor.type || ''} ${ancestor.id} ${ancestor.name && `(${ancestor.name})` || ''}`;
document.getElementById('mapnote').textContent = mapnote;
}
coordsToMap(ancestor.coords_bl, ancestor.coords_tr);
break;
}
}
}
function hideItem(e) {
clearMap();
}