LuminaWebsite/assets/map/js/services/TileService.js
Maaxxs c4f94bf84a Member feedback: raid input checks and fixed raid points, premades in the raid form, live raid page, Lumina-style dialogs, leadership calendar entries, class-based weapon picker, map and tactics fixes
- Raids: "Max. Spieler" only whole numbers up to groups x 5 (max. 10 groups / 50), gearscore only a number; fixed +1 Lumipunkt per participation, other values only with the new raids.points permission; pick an existing premade per group when creating a raid; unchanged legacy values no longer block editing
- Raid page updates itself every 15 s while visible (raids_live.php, cards rendered by includes/raid_card.php), open editors and confirm dialogs are kept
- Restore takes the new raid_id from the bot (archived messages are now deleted in Discord) and moves settings, attendance and awards; website signups send the server display name
- Premades: dissolve by leadership needs a reason, lead gets DMs on join/assign/decline/remove (source/actor_id sent to the bot), transfer picker skips players who already lead a group, website accept keeps the one-group rule, no commas in names
- Site-wide Lumina dialog (assets/js/confirm-dialog.js) replaces confirm/prompt/alert via data-confirm; error flashes are a dialog you confirm with OK
- Calendar: audience per entry (all / leadership takes part / internal) with the new calendar.leadership permission; day cells list all entries and scroll
- Gear planner: main-hand picker filtered by the set's class, mismatches marked, "keine Klasse" option, link to an external skill/Daevanion plan per set
- Map: correct kisk icons (Elyos on Verteron/Abyss, Altgard fixed), per-map max zoom and bounded panning, German texts, data source note
- Tactics: toolbar as a uniform grid, whole-tactic copy, automatic versions with restore and a 90-day trash, official tactics protected
- Global thin gold scrollbars, readable hover colours, "Sedes Luminis" spelling, patch notes and README, schema version 34

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

138 lines
No EOL
4.5 KiB
JavaScript

/**
* TileService - Handles tile loading, caching, and manifest management
*/
class TileService {
constructor() {
this.tileCache = {};
this.loadingTiles = new Set();
this.manifests = {}; // slug -> Set of tile keys
}
/**
* Load tile manifest for a map
*/
async loadManifest(slug) {
if (this.manifests[slug]) return;
try {
const response = await fetch(`${CONFIG.TILES_DIR}/${slug}/tile_manifest.json`);
if (!response.ok) throw new Error('Manifest not found');
const data = await response.json();
this.manifests[slug] = new Set(data.tiles || []);
} catch (e) {
console.warn(`Failed to load manifest for ${slug}:`, e);
this.manifests[slug] = null; // No manifest, try all tiles
}
}
/**
* Hoechste Zoomstufe dieser Karte = hoechste Stufe mit Kacheln im Manifest. Eltnen, Morheim
* und die beiden Chaotic-Karten haben nur Kacheln bis Stufe 5 - darueber waere alles leer.
* Ohne Manifest (oder ohne Kacheln darin) gilt CONFIG.MAX_ZOOM.
*/
maxZoom(slug) {
const manifest = this.manifests[slug];
if (!manifest || manifest.size === 0) return CONFIG.MAX_ZOOM;
let max = CONFIG.MIN_ZOOM;
for (const key of manifest) {
// Schluessel "zoom_x_y", z.B. "5_12_7"
const zoom = parseInt(key, 10);
if (zoom > max) max = zoom;
}
return Math.min(max, CONFIG.MAX_ZOOM);
}
/**
* Check if a tile exists in the manifest
*/
hasTile(slug, zoom, x, y) {
const key = `${zoom}_${x}_${y}`;
const manifest = this.manifests[slug];
// If no manifest or null, assume tile might exist
return !manifest || manifest.has(key);
}
/**
* Load a single tile image
*/
async loadTile(slug, zoom, x, y) {
const key = `${slug}_${zoom}_${x}_${y}`;
if (this.tileCache[key]) {
return this.tileCache[key];
}
// Check manifest before attempting to load
if (!this.hasTile(slug, zoom, x, y)) {
return null;
}
// If already loading, wait briefly and check again
if (this.loadingTiles.has(key)) {
await new Promise(r => setTimeout(r, 10));
return this.tileCache[key] || null;
}
this.loadingTiles.add(key);
try {
const img = new Image();
img.src = `${CONFIG.TILES_DIR}/${slug}/${zoom}_${x}_${y}.jpg`;
await new Promise((resolve, reject) => {
img.onload = resolve;
img.onerror = () => reject(new Error('Load failed'));
setTimeout(() => reject(new Error('Timeout')), 5000);
});
this.tileCache[key] = img;
} catch (e) {
// Silently fail for missing tiles
} finally {
this.loadingTiles.delete(key);
}
return this.tileCache[key];
}
/**
* Preload tiles at adjacent zoom levels in background
*/
async preloadAdjacentZoomLevels(slug, currentZoom, viewBounds) {
const worldWidth = CONFIG.WORLD_MAX_X - CONFIG.WORLD_MIN_X;
for (let targetZoom of [currentZoom - 1, currentZoom + 1]) {
if (targetZoom < CONFIG.MIN_ZOOM || targetZoom > CONFIG.MAX_ZOOM) continue;
const tilesPerSide = Math.pow(2, targetZoom);
const tileWorldSize = worldWidth / tilesPerSide;
// Calculate which tiles overlap with viewport
const startTX = Math.floor((viewBounds.minX - CONFIG.WORLD_MIN_X) / tileWorldSize);
const endTX = Math.ceil((viewBounds.maxX - CONFIG.WORLD_MIN_X) / tileWorldSize);
const startTY = Math.floor((viewBounds.minY - CONFIG.WORLD_MIN_Y) / tileWorldSize);
const endTY = Math.ceil((viewBounds.maxY - CONFIG.WORLD_MIN_Y) / tileWorldSize);
// Load tiles in background (fire and forget)
for (let tx = startTX; tx <= endTX; tx++) {
for (let ty = startTY; ty <= endTY; ty++) {
if (tx >= 0 && tx < tilesPerSide && ty >= 0 && ty < tilesPerSide) {
this.loadTile(slug, targetZoom, tx, ty);
}
}
}
}
}
/**
* Clear cache for a specific map (when switching maps)
*/
clearCache() {
this.tileCache = {};
this.loadingTiles.clear();
}
}