LuminaWebsite/assets/map/js/controllers/LocationController.js
Maaxxs 03597f14ad Raidplaner: tactics on the maps of all dungeons and raids, with tokens that move from step to step
Asked for in Discord: "raidplan.io bitte einbauen für die harten Dungeons". raidplan.io has no Aion 2
(only WoW, FFXIV, Lost Ark, New World), so the map tactics got what it offers.

- Dungeon maps: the in-game map textures of 11 expeditions, 7 transcendence dungeons, the 3 sanctuaries
  (Ludra, Corroded Decontamination Facility, Chalice of Muspel), the 6 awakening towers and 3
  subjugations, as published by the DPS meter Waffle-ens/waffle_meter (dotnet/Assets/Maps, pinned
  commit). assets/map/dungeons/dungeons.json is kept by hand: groups, slugs (= tactics.map_slug),
  German names from the Global client (aion2.app), KR/TW-only dungeons marked as unavailable, boss
  hints for the awakening towers. scripts/download_dungeon_maps.py fetches the images, writes
  dungeons/<slug>.webp (2048 px, about 3 MB in total, in Git) and the previews, and finds the dungeon
  area (bounds) by comparing each map with the shared background of all maps. Two empty arenas
  (round, square) are drawn in code.
- Viewer: image maps and arenas next to the tile maps (MapView.drawImageMap/drawArena, half zoom
  steps, opens fitted to the dungeon beside the tactic panel), map picker with the tabs "Welt" and
  "Dungeons & Raids", each area remembers its last map, no category panel without markers. The mouse
  wheel zooms to the cursor.
- New page raidplan.php ("Raidplaner" in the menu, map.view) = map.php started in the dungeon area.
  Location links on dungeon maps point to /raidplan.php and are recognized in texts and by the
  calendar picker.
- Tokens (shape type 'token', TokenIcons.js): classes, roles, players 1-8, markers A-D and symbols,
  boss, add, danger, stack, spread, tower, orb, bomb. Colour and size come from the toolbar, numbers
  and letters count up while placing, tokens are drawn above areas. Server whitelist
  TACTIC_TOKEN_ICONS.
- Move tool (✥) with label/delete actions above the selected shape, double click and Del; new action
  shape_update in tactics_api.php (points and label, same permissions, snapshot before). Undo also
  reverts moves and labels. Rectangle and cone tools, saved as areas.
- Step transitions: tactic_shapes.ref is kept by "Kopie dieses Schritts", tactic copies and restores
  (existing shapes get s<id>), so the same shape glides to its new place when stepping or playing;
  play button (and space) runs through all steps. 🔗 copies a link to the tactic and step
  (?taktik=&schritt=), which opens it after loading.
- Live view: the bot relay only knows the old shape types and events, so placing tokens and moving
  send "changed" and the others reload - no bot deploy needed.
- Schema version 60 (tactic_shapes.icon, .ref, enum 'token'; also in sql/schema.sql), tour step on the
  dashboard, patch notes and README.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-26 12:45:00 +02:00

268 lines
11 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* Orte auf der Karte verlinken:
* - Link oeffnen: /map.php?karte=verteron&x=1234&y=2345&zoom=5&ort=Treffpunkt oeffnet die Karte an
* der Stelle und setzt dort einen Pin (map.php reicht die Parameter an diesen Viewer weiter).
* - Ort teilen (📍-Knopf): auf die Karte klicken, Namen eingeben, Link kopieren.
* - Ort auswaehlen (?pick=1): die Karte laeuft in einem Fenster der Website (z.B. Kalender);
* "Diesen Ort uebernehmen" schickt den Ort per postMessage an die Seite zurueck.
*/
class LocationController {
constructor(mapController) {
this.map = mapController;
this.view = mapController.view;
this.params = new URLSearchParams(window.location.search);
this.pickMode = this.params.get('pick') === '1';
this.active = false; // Klick auf die Karte setzt gerade einen Ort
this.pin = null; // {x, y} in Weltkoordinaten
this.label = '';
this.buildUi();
this.view.onPinUpdate = () => this.updatePin();
this.map.onTap = (clientX, clientY) => this.handleTap(clientX, clientY);
this.map.onMapChanged = this.chain(this.map.onMapChanged, () => this.clearPin());
// Mausklick (ohne Ziehen) auf die Karte
let down = null;
this.view.canvas.addEventListener('mousedown', e => { down = { x: e.clientX, y: e.clientY }; });
this.view.canvas.addEventListener('mouseup', e => {
if (down && Math.hypot(e.clientX - down.x, e.clientY - down.y) < 5) this.handleTap(e.clientX, e.clientY);
down = null;
});
if (this.pickMode) {
document.body.classList.add('pick-mode');
this.start();
}
}
/** Zwei Callbacks hintereinander (TacticController haengt sich auch an onMapChanged). */
chain(first, second) {
return (...args) => {
if (first) first(...args);
second(...args);
};
}
/** Karte aus dem Link (?karte=...), sonst null. */
requestedMap() {
const slug = this.params.get('karte');
return slug && this.map.mapData.maps.some(m => m.slug === slug) ? slug : null;
}
/** Nach dem Laden der Karte aus dem Link: an die Stelle springen und den Pin setzen. */
applyLink() {
const x = parseFloat(this.params.get('x'));
const y = parseFloat(this.params.get('y'));
if (!this.requestedMap() || !isFinite(x) || !isFinite(y)) return;
const zoom = parseInt(this.params.get('zoom'), 10);
// Hoechstens bis zur letzten Zoomstufe dieser Karte (alte Links mit zoom=6 auf Karten bis 5)
this.view.zoom = Math.min(this.view.maxZoom, Math.max(CONFIG.MIN_ZOOM, isFinite(zoom) ? zoom : CONFIG.MIN_ZOOM + 3));
this.view.centerWorldX = x;
this.view.centerWorldY = y;
// Ort am Kartenrand: Ansicht in der Karte halten, der Pin ist dann nicht ganz mittig
this.view.clampView();
this.setPin(x, y, (this.params.get('ort') || '').slice(0, 60));
this.map.render();
if (this.pickMode) this.showPanel();
}
buildUi() {
const overlay = document.getElementById('ui-overlay');
// 📍-Knopf in der Zoom-Leiste
const button = document.createElement('button');
button.id = 'btn-share-location';
button.title = 'Ort teilen - auf die Karte klicken und den Link kopieren';
button.textContent = '📍';
button.addEventListener('click', () => (this.active ? this.stop() : this.start()));
document.getElementById('zoom-controls').appendChild(button);
this.button = button;
// Hinweis oben: "Klicke auf die Karte"
this.banner = document.createElement('div');
this.banner.id = 'loc-banner';
this.banner.className = 'panel hidden';
this.banner.innerHTML = '<span>📍 Klicke auf die Karte, um einen Ort zu markieren</span>';
if (!this.pickMode) {
const cancel = document.createElement('button');
cancel.type = 'button';
cancel.textContent = 'Abbrechen';
cancel.addEventListener('click', () => this.stop());
this.banner.appendChild(cancel);
}
overlay.appendChild(this.banner);
// Pin mit Beschriftung
this.pinEl = document.createElement('div');
this.pinEl.id = 'map-pin';
this.pinEl.className = 'hidden';
this.pinEl.innerHTML = '<span class="pin-label"></span><span class="pin-dot"></span>';
document.getElementById('map-container').appendChild(this.pinEl);
// Fenster mit Name und Link bzw. "Uebernehmen"
this.panel = document.createElement('div');
this.panel.id = 'loc-panel';
this.panel.className = 'panel hidden';
this.panel.innerHTML =
'<button type="button" class="loc-close" title="Schließen" aria-label="Schließen">✕</button>'
+ '<h3>' + (this.pickMode ? 'Ort auswählen' : 'Ort teilen') + '</h3>'
+ '<label><span>Name des Ortes <span class="loc-optional">(optional)</span></span>'
+ '<input type="text" id="loc-name" maxlength="60" placeholder="z.B. Treffpunkt am Portal"></label>'
+ '<div class="loc-where" id="loc-where"></div>'
+ (this.pickMode
? '<button type="button" id="loc-use" class="loc-primary">✓ Diesen Ort übernehmen</button>'
: '<div class="loc-link-row"><input type="text" id="loc-link" readonly aria-label="Link">'
+ '<button type="button" id="loc-copy" class="loc-primary">Link kopieren</button></div>')
+ '<p class="loc-hint">' + (this.pickMode ? 'Woanders klicken, um den Ort zu ändern.' : 'Den Link kannst du in Terminen, Kommentaren oder im Discord einfügen.') + '</p>';
overlay.appendChild(this.panel);
this.nameInput = this.panel.querySelector('#loc-name');
this.nameInput.addEventListener('input', () => {
this.label = this.nameInput.value.trim();
this.updatePin();
this.updateLink();
});
// Tasten wie H oder +/- sollen beim Tippen nicht die Karte steuern
this.nameInput.addEventListener('keydown', e => e.stopPropagation());
this.panel.querySelector('.loc-close').addEventListener('click', () => {
this.panel.classList.add('hidden');
if (!this.pickMode) this.clearPin();
});
if (this.pickMode) {
this.panel.querySelector('#loc-use').addEventListener('click', () => this.sendPick());
} else {
this.panel.querySelector('#loc-copy').addEventListener('click', () => this.copyLink());
}
}
start() {
this.active = true;
this.button.classList.add('active');
this.banner.classList.remove('hidden');
this.view.canvas.classList.add('picking');
}
stop() {
this.active = false;
this.button.classList.remove('active');
this.banner.classList.add('hidden');
this.view.canvas.classList.remove('picking');
}
/** Klick/Tipp auf die Karte - true, wenn er hier verarbeitet wurde. */
handleTap(clientX, clientY) {
if (!this.active || !this.map.mapData.currentMap) return false;
const rect = this.view.canvas.getBoundingClientRect();
const world = this.view.screenToWorld(clientX - rect.left, clientY - rect.top);
const x = Math.round(world.x);
const y = Math.round(world.y);
if (x < CONFIG.WORLD_MIN_X || x > CONFIG.WORLD_MAX_X || y < CONFIG.WORLD_MIN_Y || y > CONFIG.WORLD_MAX_Y) return true;
// Name vorschlagen: der naechste Marker in der Naehe (auch ausgeblendete Kategorien)
const nearby = this.nearestMarkerName(clientX - rect.left, clientY - rect.top);
this.setPin(x, y, this.nameInput.value.trim() || nearby);
this.showPanel();
if (!this.pickMode) this.stop();
return true;
}
nearestMarkerName(screenX, screenY) {
let best = '';
let bestDist = 40;
for (const marker of this.map.mapData.markers) {
const p = this.view.worldToScreen(marker.worldX, marker.worldY);
const dist = Math.hypot(p.x - screenX, p.y - screenY);
if (dist < bestDist) {
bestDist = dist;
best = marker.iconText || marker.nt || marker.name || '';
}
}
return String(best).slice(0, 60);
}
setPin(x, y, label) {
this.pin = { x, y };
this.label = label || '';
this.nameInput.value = this.label;
this.updatePin();
this.updateLink();
}
clearPin() {
this.pin = null;
this.pinEl.classList.add('hidden');
}
updatePin() {
if (!this.pin) return;
const p = this.view.worldToScreen(this.pin.x, this.pin.y);
this.pinEl.style.left = p.x + 'px';
this.pinEl.style.top = p.y + 'px';
this.pinEl.querySelector('.pin-label').textContent = this.label;
this.pinEl.querySelector('.pin-label').hidden = this.label === '';
this.pinEl.classList.remove('hidden');
}
showPanel() {
this.panel.classList.remove('hidden');
this.updateLink();
if (!this.pickMode) this.nameInput.focus();
}
mapName() {
return this.map.mapData.currentMap ? this.map.mapData.currentMap.name : '';
}
/** Pfad des Links, z.B. /map.php?karte=verteron&x=1&y=2&zoom=5&ort=Portal (Dungeon-Karten: /raidplan.php) */
linkPath() {
const map = this.map.mapData.currentMap;
if (!this.pin || !map) return '';
const params = new URLSearchParams({
karte: map.slug,
x: String(this.pin.x),
y: String(this.pin.y),
// Links kennen nur ganze Zoomstufen (Dungeon-Karten zoomen in halben)
zoom: String(Math.max(Math.round(this.view.zoom), CONFIG.MIN_ZOOM + 2)),
});
if (this.label) params.set('ort', this.label);
return this.map.areaInfo(map.area).page + '?' + params.toString();
}
updateLink() {
const where = this.panel.querySelector('#loc-where');
where.textContent = this.pin ? '🗺️ ' + this.mapName() + (this.label ? ' – ' + this.label : '') : '';
const link = this.panel.querySelector('#loc-link');
if (link) link.value = this.pin ? window.location.origin + this.linkPath() : '';
}
copyLink() {
const link = this.panel.querySelector('#loc-link');
const done = () => this.toast('Link kopiert - einfach in Termin, Kommentar oder Discord einfügen.');
if (navigator.clipboard && window.isSecureContext) {
navigator.clipboard.writeText(link.value).then(done, () => { link.select(); document.execCommand('copy'); done(); });
} else {
link.select();
document.execCommand('copy');
done();
}
}
sendPick() {
if (!this.pin) return;
window.parent.postMessage({
type: 'lumina-map-pick',
url: this.linkPath(),
label: this.mapName() + (this.label ? ' – ' + this.label : ''),
}, window.location.origin);
}
toast(text) {
const toast = document.getElementById('toast');
if (!toast) return;
toast.textContent = text;
toast.classList.remove('hidden');
clearTimeout(this.toastTimer);
this.toastTimer = setTimeout(() => toast.classList.add('hidden'), 2500);
}
}