diff --git a/assets/css/style.css b/assets/css/style.css index 04d729a..f0d559c 100644 --- a/assets/css/style.css +++ b/assets/css/style.css @@ -6800,6 +6800,13 @@ button.gear-guide-skill:hover { border-color: var(--gold); transform: translateY .gear-guide-skill-chip:hover, .gear-guide-skill-chip:focus-visible { outline: none; text-decoration: underline; text-decoration-color: rgba(227, 189, 110, 0.55); text-underline-offset: 3px; } .gear-guide-skill-chip.is-stigma { color: #c9adf5; } .gear-guide-skill-chip.is-stigma img { box-shadow: 0 0 0 1px rgba(160, 120, 230, 0.6); } +/* [[Item:...]] / [[Flügel:...]]: Bild und Name in der Farbe der Seltenheit, Info-Blase wie im Lagerhaus */ +.gear-guide-item-chip { display: inline; color: var(--grade, #e3bd6e); font-weight: 600; white-space: nowrap; cursor: help; } +.gear-guide-item-chip img { width: 1.3em; height: 1.3em; margin-right: 0.25em; border-radius: 3px; object-fit: contain; vertical-align: -0.28em; background: #10131a; box-shadow: 0 0 0 1px color-mix(in srgb, var(--grade, #c9a227) 60%, transparent); } +.gear-guide-item-chip:hover, .gear-guide-item-chip:focus-visible { outline: none; text-decoration: underline; text-underline-offset: 3px; } +.gear-guide-item-chip.is-missing { color: var(--text-muted); font-weight: 400; text-decoration: underline dotted; cursor: default; } +.gear-tip .item-tip-head { margin-bottom: 0.2rem; } +.gear-guide-item-tip-icon { flex-shrink: 0; border-radius: 8px; background: #10131a; } /* [[Skillname:2]]: Symbol der Spezialisierung und ihr Text; beim Drueberfahren die Skill-Info mit hervorgehobener Zeile */ .gear-guide-spec-ref { display: inline; color: #e8dcc0; font-weight: 600; cursor: help; text-decoration: underline dotted rgba(227, 189, 110, 0.55); text-underline-offset: 3px; } .gear-guide-spec-ref:hover, .gear-guide-spec-ref:focus-visible { outline: none; color: #f1d98a; text-decoration-style: solid; } diff --git a/gear_action.php b/gear_action.php index 7d95138..82478d3 100644 --- a/gear_action.php +++ b/gear_action.php @@ -58,6 +58,22 @@ $setCount = static function () use ($pdo, $userId): int { return (int) $count->fetchColumn(); }; +// Guide-Texte: [[Item:...]] bei aion2hub nachschlagen (includes/gear_guide.php) und Bescheid geben, was es nicht gibt +$itemNote = static function (string $text): void { + if (!preg_match(gear_guide_item_pattern(), $text)) { + return; + } + session_write_close(); // ein Abruf bei aion2hub dauert - andere Seiten sollen nicht warten + $result = gear_guide_items_lookup($text); + @session_start(); + if ($result['missing']) { + set_flash('info', 'Bei aion2hub nicht gefunden: ' . implode(', ', $result['missing']) . ' – schreib den Namen bzw. die ID wie dort (englisch).'); + } + if ($result['later']) { + set_flash('info', 'Noch nicht nachgeschlagen (aion2hub-Tempolimit): ' . implode(', ', $result['later']) . ' – speichere den Guide gleich noch einmal.'); + } +}; + switch ($action) { case 'create': $name = $cleanName((string) ($_POST['name'] ?? '')); @@ -677,6 +693,8 @@ switch ($action) { $pdo->prepare('UPDATE gear_sets SET description = ?, guide = ?, updated_at = NOW() WHERE id = ?') ->execute([$description !== '' ? $description : null, gear_guide_json($guide), $set['id']]); set_flash('success', 'Guide gespeichert.'); + $itemNote($description . " +" . (string) gear_guide_json($guide)); redirect($back); case 'save_guide_notes': @@ -693,6 +711,7 @@ switch ($action) { ])); $pdo->prepare('UPDATE gear_sets SET guide = ?, updated_at = NOW() WHERE id = ?')->execute([gear_guide_json($guide), $set['id']]); set_flash('success', 'Erklärungen gespeichert.'); + $itemNote((string) gear_guide_json($guide)); redirect('/gear.php?set=' . (int) $set['id'] . '&tab=guide'); case 'save_guide_stats': diff --git a/includes/gear_guide.php b/includes/gear_guide.php index 95383a9..8e92d05 100644 --- a/includes/gear_guide.php +++ b/includes/gear_guide.php @@ -37,6 +37,10 @@ const GEAR_GUIDE_STAT_GROUPS = [ const GEAR_GUIDE_SLOT_GROUPS = ['Waffen' => 'weapon', 'Rüstung' => 'armor', 'Schmuck' => 'jewelry']; const GEAR_GUIDE_STATS_MAX = 6; // Werte je Gruppe const GEAR_GUIDE_STAT_LENGTH = 40; +// Gegenstaende in Guide-Texten: [[Item:Name]] bzw. [[Item:ID]] (Name/ID wie bei aion2hub), auch mit "Flügel:" - +// beim Speichern nachgeschlagen (hoechstens so viele neue je Speichern, aion2hub hat ein Tempolimit) +const GEAR_GUIDE_ITEM_PREFIXES = ['item', 'gegenstand', 'flügel', 'fluegel', 'wings', 'wing']; +const GEAR_GUIDE_ITEM_LOOKUPS = 8; const GEAR_GUIDE_STAT_NOTE_LENGTH = 80; /** Einzeiliger Text: Leerraum zusammengefasst und gekuerzt. */ @@ -323,6 +327,119 @@ function gear_guide_spec_chip(array $skill, int $no): ?string . $icon . '' . e($part['text']) . ''; } +/** Muster fuer [[Item:Name]] / [[Flügel:ID]] - Gruppe 1: Name oder ID (im Rohtext wie im maskierten HTML). */ +function gear_guide_item_pattern(): string +{ + return '/\[\[\s*(?:' . implode('|', array_map(static fn (string $p): string => preg_quote($p, '/'), GEAR_GUIDE_ITEM_PREFIXES)) . ')\s*:\s*([^\[\]<>]{1,150}?)\s*\]\]/iu'; +} + +/** Gegenstands-Verweise in einem Text (Namen bzw. IDs, ohne Doppelte). */ +function gear_guide_item_refs(string $text): array +{ + preg_match_all(gear_guide_item_pattern(), $text, $m); + $refs = []; + foreach ($m[1] as $ref) { + $refs[mb_strtolower(trim($ref))] = trim($ref); + } + return array_values($refs); +} + +/** Schon nachgeschlagener Gegenstand zu einem Verweis (ID oder Name wie bei aion2hub) - null = (noch) unbekannt. */ +function gear_guide_item_cached(string $ref): ?array +{ + require_once __DIR__ . '/item_db.php'; + if (ctype_digit($ref)) { + return item_db_get((int) $ref); + } + $stmt = db()->prepare('SELECT item_id FROM item_db_names WHERE name = ? AND item_id IS NOT NULL'); + $stmt->execute([$ref]); + $id = $stmt->fetchColumn(); + return $id !== false ? item_db_get((int) $id) : null; +} + +/** + * Gegenstaende eines Guides bei aion2hub nachschlagen (beim Speichern): Daten in item_db, Bild unter + * assets/uploads/gear. Schon bekannte zaehlen nicht mit. Liefert die Verweise, die es nicht gibt bzw. die + * diesmal nicht drankamen (Tempolimit) - fuer den Hinweis nach dem Speichern. + * + * @return array{missing: string[], later: string[]} + */ +function gear_guide_items_lookup(string $text): array +{ + require_once __DIR__ . '/item_db.php'; + $result = ['missing' => [], 'later' => []]; + $fetched = 0; + foreach (gear_guide_item_refs($text) as $ref) { + $item = gear_guide_item_cached($ref); + if ($item === null) { + if ($fetched >= GEAR_GUIDE_ITEM_LOOKUPS) { + $result['later'][] = $ref; + continue; + } + $fetched++; + if (ctype_digit($ref)) { + try { + $item = item_db_parse(item_db_fetch(GEAR_SOURCE_ITEM_URL . (int) $ref), (int) $ref); + item_db_store($item); + } catch (ItemDbBusyException $e) { + $result['later'][] = $ref; + continue; + } catch (RuntimeException $e) { + $item = null; + } + } else { + $found = item_db_lookup($ref); + $item = $found['status'] === 'ok' ? $found['item'] : null; + if ($found['status'] === 'busy') { + $result['later'][] = $ref; + continue; + } + } + if ($item === null) { + $result['missing'][] = $ref; + continue; + } + } + if (gear_guide_item_icon_url((int) $item['id']) === null) { + gear_icon_download((int) $item['id']); + } + } + return $result; +} + +/** Bild eines Gegenstands (assets/uploads/gear/.*), null = nicht geladen. */ +function gear_guide_item_icon_url(int $id): ?string +{ + foreach (['png', 'webp', 'jpg', 'gif'] as $ext) { + $file = GEAR_ICON_DIR . $id . '.' . $ext; + if (is_file($file)) { + return GEAR_ICON_URL . $id . '.' . $ext . '?v=' . filemtime($file); + } + } + return null; +} + +/** + * [[Item:...]] im Text: Bild und Name in der Farbe der Seltenheit, beim Drueberfahren die Info-Blase wie im Lagerhaus + * (Werte, Effekte, Infos von aion2hub; assets/js/gear.js). Unbekannt: nur der Name, gedaempft. + */ +function gear_guide_item_chip(string $ref): string +{ + require_once __DIR__ . '/item_db.php'; + $item = gear_guide_item_cached($ref); + if ($item === null) { + return '' . e($ref) . ''; + } + $grade = strtolower((string) $item['grade']); + $icon = gear_guide_item_icon_url((int) $item['id']); + $iconHtml = $icon !== null ? '' : ''; + return '' + . ($icon !== null ? '' : '') + . e((string) $item['name']) + //