/** * TokenIcons - die Figuren des Raidplaners (Form 'token'): Klassen, Rollen, Spielernummern, * Markierungen, Gegner und Mechaniken. Gezeichnet wird alles hier - auf der Karte (TacticLayer) * und in der Auswahl im Taktik-Panel -, damit beide gleich aussehen. * * Die Kennungen muessen zu TACTIC_TOKEN_ICONS in includes/tactics.php passen. */ const TOKEN_ICONS = [ { group: 'Klassen', items: [ { id: 'class-templar', label: 'Templer', image: 'Templar' }, { id: 'class-gladiator', label: 'Gladiator', image: 'Gladiator' }, { id: 'class-assassin', label: 'Assassine', image: 'Assassin' }, { id: 'class-ranger', label: 'Jäger', image: 'Ranger' }, { id: 'class-sorcerer', label: 'Magier', image: 'Sorcerer' }, { id: 'class-spiritmaster', label: 'Beschwörer', image: 'Spiritmaster' }, { id: 'class-cleric', label: 'Kleriker', image: 'Cleric' }, { id: 'class-chanter', label: 'Kantor', image: 'Chanter' } ] }, { group: 'Rollen', items: [ { id: 'role-tank', label: 'Tank' }, { id: 'role-heal', label: 'Heiler' }, { id: 'role-dps', label: 'Schaden' } ] }, { group: 'Spieler', items: [1, 2, 3, 4, 5, 6, 7, 8].map(n => ({ id: `num-${n}`, label: `Spieler ${n}`, next: n < 8 ? `num-${n + 1}` : null })) }, { group: 'Markierungen', items: [ { id: 'mark-a', label: 'Markierung A', next: 'mark-b' }, { id: 'mark-b', label: 'Markierung B', next: 'mark-c' }, { id: 'mark-c', label: 'Markierung C', next: 'mark-d' }, { id: 'mark-d', label: 'Markierung D' }, { id: 'mark-star', label: 'Stern' }, { id: 'mark-circle', label: 'Kreis' }, { id: 'mark-triangle', label: 'Dreieck' }, { id: 'mark-square', label: 'Quadrat' }, { id: 'mark-cross', label: 'Kreuz' } ] }, { group: 'Gegner & Mechaniken', items: [ { id: 'boss', label: 'Boss', scale: 1.45 }, { id: 'add', label: 'Gegner', scale: 0.8 }, { id: 'danger', label: 'Gefahr' }, { id: 'stack', label: 'Sammeln' }, { id: 'spread', label: 'Verteilen' }, { id: 'tower', label: 'Turm' }, { id: 'orb', label: 'Kugel' }, { id: 'bomb', label: 'Bombe' } ] } ]; class TokenIcons { static find(id) { for (const group of TOKEN_ICONS) { const item = group.items.find(i => i.id === id); if (item) return item; } return null; } /** Eigene Groesse der Figur (Boss groesser, Gegner kleiner). */ static scale(id) { const item = TokenIcons.find(id); return item && item.scale ? item.scale : 1; } /** Klassen-Wappen laden; ist eines fertig, zeichnen alle Angemeldeten neu (onImageLoad). */ static image(name) { if (!TokenIcons.images) TokenIcons.images = new Map(); let img = TokenIcons.images.get(name); if (!img) { img = new Image(); img.onload = () => TokenIcons.listeners.forEach(fn => fn()); img.src = `/assets/images/Classes/normalized/${name}_ICO.png`; TokenIcons.images.set(name, img); } return img.complete && img.naturalWidth ? img : null; } static onImageLoad(fn) { TokenIcons.listeners.push(fn); } /** Figur id mit Mittelpunkt x/y und Radius r (Bildschirmpixel) zeichnen; color = gewaehlte Farbe. */ static draw(ctx, id, x, y, r, color) { ctx.save(); ctx.lineJoin = 'round'; ctx.lineCap = 'round'; const item = TokenIcons.find(id); if (id.startsWith('class-')) { TokenIcons.badge(ctx, x, y, r, color); const img = item ? TokenIcons.image(item.image) : null; ctx.shadowBlur = 0; if (img) { ctx.drawImage(img, x - r * 0.82, y - r * 0.82, r * 1.64, r * 1.64); } else { TokenIcons.text(ctx, item ? item.label.charAt(0) : '?', x, y, r, '#ffffff'); } } else if (id.startsWith('role-')) { TokenIcons.badge(ctx, x, y, r, color); ctx.shadowBlur = 0; TokenIcons.role(ctx, id, x, y, r); } else if (id.startsWith('num-')) { ctx.beginPath(); ctx.arc(x, y, r, 0, Math.PI * 2); ctx.fillStyle = color; ctx.fill(); ctx.shadowBlur = 0; ctx.lineWidth = Math.max(1.5, r * 0.13); ctx.strokeStyle = '#ffffff'; ctx.stroke(); TokenIcons.text(ctx, id.slice(4), x, y + r * 0.04, r * 1.05, '#ffffff'); } else if (/^mark-[abcd]$/.test(id)) { ctx.beginPath(); ctx.moveTo(x, y - r * 1.12); ctx.lineTo(x + r * 1.12, y); ctx.lineTo(x, y + r * 1.12); ctx.lineTo(x - r * 1.12, y); ctx.closePath(); ctx.fillStyle = color; ctx.fill(); ctx.shadowBlur = 0; ctx.lineWidth = Math.max(1.5, r * 0.13); ctx.strokeStyle = '#ffffff'; ctx.stroke(); TokenIcons.text(ctx, id.slice(5).toUpperCase(), x, y + r * 0.04, r * 0.95, '#ffffff'); } else if (id.startsWith('mark-')) { TokenIcons.badge(ctx, x, y, r, color); ctx.shadowBlur = 0; TokenIcons.symbol(ctx, id.slice(5), x, y, r, color); } else if (id === 'danger') { ctx.beginPath(); ctx.moveTo(x, y - r * 1.05); ctx.lineTo(x + r * 1.05, y + r * 0.8); ctx.lineTo(x - r * 1.05, y + r * 0.8); ctx.closePath(); ctx.fillStyle = '#ffcc33'; ctx.fill(); ctx.shadowBlur = 0; ctx.lineWidth = Math.max(1.5, r * 0.12); ctx.strokeStyle = '#1b1406'; ctx.stroke(); TokenIcons.text(ctx, '!', x, y + r * 0.18, r * 1.05, '#1b1406', false); } else if (id === 'orb') { const gradient = ctx.createRadialGradient(x - r * 0.3, y - r * 0.3, r * 0.1, x, y, r); gradient.addColorStop(0, '#ffffff'); gradient.addColorStop(0.35, color); gradient.addColorStop(1, 'rgba(0, 0, 0, 0.35)'); ctx.beginPath(); ctx.arc(x, y, r, 0, Math.PI * 2); ctx.fillStyle = gradient; ctx.fill(); ctx.shadowBlur = 0; ctx.lineWidth = Math.max(1, r * 0.08); ctx.strokeStyle = color; ctx.stroke(); } else if (id === 'bomb') { TokenIcons.bomb(ctx, x, y, r, color); } else { // boss, add, stack, spread, tower TokenIcons.badge(ctx, x, y, r, color); ctx.shadowBlur = 0; if (id === 'boss' || id === 'add') TokenIcons.skull(ctx, x, y, r, id === 'boss' ? '#ffffff' : '#e8e8e8'); else if (id === 'stack') TokenIcons.arrows(ctx, x, y, r, true); else if (id === 'spread') TokenIcons.arrows(ctx, x, y, r, false); else if (id === 'tower') TokenIcons.tower(ctx, x, y, r, color); } ctx.restore(); } /** Runde Plakette: dunkle Flaeche, Rand in der gewaehlten Farbe. */ static badge(ctx, x, y, r, color) { ctx.beginPath(); ctx.arc(x, y, r, 0, Math.PI * 2); ctx.fillStyle = 'rgba(12, 14, 28, 0.92)'; ctx.fill(); ctx.lineWidth = Math.max(1.5, r * 0.16); ctx.strokeStyle = color; ctx.stroke(); } static text(ctx, text, x, y, size, color, outline = true) { ctx.font = `bold ${Math.round(size)}px 'Segoe UI', sans-serif`; ctx.textAlign = 'center'; ctx.textBaseline = 'middle'; if (outline) { ctx.lineWidth = Math.max(2, size / 6); ctx.strokeStyle = 'rgba(0, 0, 0, 0.75)'; ctx.strokeText(text, x, y); } ctx.fillStyle = color; ctx.fillText(text, x, y); } static role(ctx, id, x, y, r) { ctx.beginPath(); if (id === 'role-tank') { // Schild ctx.moveTo(x - r * 0.5, y - r * 0.52); ctx.lineTo(x + r * 0.5, y - r * 0.52); ctx.lineTo(x + r * 0.5, y - r * 0.02); ctx.quadraticCurveTo(x + r * 0.45, y + r * 0.42, x, y + r * 0.62); ctx.quadraticCurveTo(x - r * 0.45, y + r * 0.42, x - r * 0.5, y - r * 0.02); ctx.closePath(); ctx.fillStyle = '#4da3ff'; ctx.fill(); } else if (id === 'role-heal') { // Kreuz const t = r * 0.19; const l = r * 0.56; ctx.rect(x - t, y - l, t * 2, l * 2); ctx.rect(x - l, y - t, l * 2, t * 2); ctx.fillStyle = '#5ddc7a'; ctx.fill(); } else { // Schwert, schraeg ctx.translate(x, y); ctx.rotate(Math.PI / 4); ctx.moveTo(0, -r * 0.68); ctx.lineTo(r * 0.11, -r * 0.5); ctx.lineTo(r * 0.11, r * 0.24); ctx.lineTo(-r * 0.11, r * 0.24); ctx.lineTo(-r * 0.11, -r * 0.5); ctx.closePath(); ctx.rect(-r * 0.36, r * 0.24, r * 0.72, r * 0.13); ctx.rect(-r * 0.08, r * 0.37, r * 0.16, r * 0.3); ctx.fillStyle = '#ff6b6b'; ctx.fill(); } } static symbol(ctx, kind, x, y, r, color) { ctx.fillStyle = color; ctx.strokeStyle = color; ctx.beginPath(); switch (kind) { case 'star': for (let i = 0; i < 10; i++) { const radius = i % 2 === 0 ? r * 0.64 : r * 0.27; const angle = -Math.PI / 2 + i * Math.PI / 5; const px = x + Math.cos(angle) * radius; const py = y + Math.sin(angle) * radius; if (i === 0) ctx.moveTo(px, py); else ctx.lineTo(px, py); } ctx.closePath(); ctx.fill(); break; case 'circle': ctx.arc(x, y, r * 0.48, 0, Math.PI * 2); ctx.fill(); break; case 'triangle': ctx.moveTo(x, y - r * 0.6); ctx.lineTo(x + r * 0.55, y + r * 0.42); ctx.lineTo(x - r * 0.55, y + r * 0.42); ctx.closePath(); ctx.fill(); break; case 'square': ctx.rect(x - r * 0.44, y - r * 0.44, r * 0.88, r * 0.88); ctx.fill(); break; case 'cross': ctx.lineWidth = r * 0.24; ctx.moveTo(x - r * 0.42, y - r * 0.42); ctx.lineTo(x + r * 0.42, y + r * 0.42); ctx.moveTo(x + r * 0.42, y - r * 0.42); ctx.lineTo(x - r * 0.42, y + r * 0.42); ctx.stroke(); break; } } static skull(ctx, x, y, r, color) { ctx.fillStyle = color; ctx.beginPath(); ctx.arc(x, y - r * 0.12, r * 0.5, 0, Math.PI * 2); ctx.fill(); ctx.beginPath(); ctx.rect(x - r * 0.3, y + r * 0.18, r * 0.6, r * 0.34); ctx.fill(); ctx.fillStyle = '#12141f'; ctx.beginPath(); ctx.arc(x - r * 0.2, y - r * 0.12, r * 0.14, 0, Math.PI * 2); ctx.arc(x + r * 0.2, y - r * 0.12, r * 0.14, 0, Math.PI * 2); ctx.fill(); ctx.beginPath(); ctx.moveTo(x, y + r * 0.02); ctx.lineTo(x + r * 0.08, y + r * 0.16); ctx.lineTo(x - r * 0.08, y + r * 0.16); ctx.closePath(); ctx.fill(); // Zaehne ctx.fillRect(x - r * 0.1 - r * 0.02, y + r * 0.34, r * 0.04, r * 0.18); ctx.fillRect(x + r * 0.1 - r * 0.02, y + r * 0.34, r * 0.04, r * 0.18); } /** Vier Pfeile: nach innen (Sammeln) oder nach aussen (Verteilen). */ static arrows(ctx, x, y, r, inward) { ctx.strokeStyle = '#ffffff'; ctx.fillStyle = '#ffffff'; ctx.lineWidth = Math.max(1.5, r * 0.12); for (let i = 0; i < 4; i++) { const angle = i * Math.PI / 2 + Math.PI / 4; const cos = Math.cos(angle); const sin = Math.sin(angle); const from = inward ? r * 0.78 : r * 0.2; const to = inward ? r * 0.28 : r * 0.72; ctx.beginPath(); ctx.moveTo(x + cos * from, y + sin * from); ctx.lineTo(x + cos * to, y + sin * to); ctx.stroke(); const dir = inward ? -1 : 1; const tipX = x + cos * to; const tipY = y + sin * to; const head = r * 0.2; ctx.beginPath(); ctx.moveTo(tipX + cos * head * 0.6 * dir, tipY + sin * head * 0.6 * dir); ctx.lineTo(tipX - sin * head * 0.7, tipY + cos * head * 0.7); ctx.lineTo(tipX + sin * head * 0.7, tipY - cos * head * 0.7); ctx.closePath(); ctx.fill(); } if (inward) { ctx.beginPath(); ctx.arc(x, y, r * 0.14, 0, Math.PI * 2); ctx.fill(); } } static tower(ctx, x, y, r, color) { ctx.fillStyle = color; const w = r * 0.62; const top = y - r * 0.3; ctx.fillRect(x - w / 2, top, w, r * 0.84); // Zinnen const tooth = w / 5; for (let i = 0; i < 3; i++) { ctx.fillRect(x - w / 2 + i * tooth * 2, top - r * 0.2, tooth, r * 0.2); } ctx.fillStyle = '#12141f'; ctx.fillRect(x - r * 0.1, y + r * 0.22, r * 0.2, r * 0.32); } static bomb(ctx, x, y, r, color) { ctx.beginPath(); ctx.arc(x, y + r * 0.1, r * 0.78, 0, Math.PI * 2); ctx.fillStyle = '#1b1d26'; ctx.fill(); ctx.shadowBlur = 0; ctx.lineWidth = Math.max(1.5, r * 0.12); ctx.strokeStyle = color; ctx.stroke(); // Glanz ctx.beginPath(); ctx.arc(x - r * 0.28, y - r * 0.18, r * 0.16, 0, Math.PI * 2); ctx.fillStyle = 'rgba(255, 255, 255, 0.45)'; ctx.fill(); // Lunte mit Funke ctx.beginPath(); ctx.moveTo(x + r * 0.42, y - r * 0.5); ctx.quadraticCurveTo(x + r * 0.7, y - r * 0.95, x + r * 0.95, y - r * 0.78); ctx.lineWidth = Math.max(1.5, r * 0.1); ctx.strokeStyle = '#c8a064'; ctx.stroke(); ctx.beginPath(); ctx.arc(x + r * 0.98, y - r * 0.8, r * 0.18, 0, Math.PI * 2); ctx.fillStyle = '#ffb02e'; ctx.fill(); } } TokenIcons.listeners = [];