From e3a6bc49733a1e6d9085e183d69339206fabd51f Mon Sep 17 00:00:00 2001 From: Shaydera Date: Fri, 20 Nov 2026 22:47:31 +0100 Subject: [PATCH 1/5] Drop a pull that joined a run from a followed set --- ui/src/pulls/follow.test.ts | 7 +++++++ ui/src/pulls/follow.ts | 4 +++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/ui/src/pulls/follow.test.ts b/ui/src/pulls/follow.test.ts index 895db4a..623cef4 100644 --- a/ui/src/pulls/follow.test.ts +++ b/ui/src/pulls/follow.test.ts @@ -150,6 +150,13 @@ describe('followUpdate set', () => { expect(followUpdate(before, after, set('wipes', [10, 20, 30]), true, false).set?.fights).toEqual(fights); }); + it('drops a pull that joined a run without following it', () => { + const after = [wipe(10), wipe(20), fight(30, 'wipe', 120_000, { runIndex: 5 })]; + const update = followUpdate(before, after, set('wipes', [10, 20, 30]), true, false); + expect(update.set?.fights).toEqual([10, 20]); + expect(followUpdate(before, after, shown(30), true, false).jumpTo).toBeNull(); + }); + it('leaves the set alone when nothing changes for it', () => { expect(followUpdate(before, [...before, kill(40)], set('wipes', [10, 20]), true, false).set).toBeNull(); }); diff --git a/ui/src/pulls/follow.ts b/ui/src/pulls/follow.ts index 3e21820..4cccce8 100644 --- a/ui/src/pulls/follow.ts +++ b/ui/src/pulls/follow.ts @@ -56,7 +56,9 @@ export function followUpdate(before: FightRow[], after: FightRow[], view: View, const present = new Set(after.map((fight) => fight.index)); const shownVanished = view.kind === 'fight' && jumpTo === null && known.has(view.fightIndex) && !present.has(view.fightIndex); - const unchanged = new Set(after.filter((fight) => !isNew(fight)).map((fight) => fight.index)); + // A pull that joined a run on a revisit is no new pull, but it leaves any set it was in. + const regrouped = (fight: FightRow) => known.get(fight.index)?.runIndex !== fight.runIndex; + const unchanged = new Set(after.filter((fight) => !isNew(fight) && !regrouped(fight)).map((fight) => fight.index)); return { jumpTo, set: view.kind === 'set' ? grownSet(view.set, unchanged, arrived) : null, shownVanished, reload }; } From d311fee3da7bc995bca1650a46d93cf68c62b5fb Mon Sep 17 00:00:00 2001 From: Shaydera Date: Fri, 20 Nov 2026 22:53:12 +0100 Subject: [PATCH 2/5] Test the game data a restarted engine session gets --- ui/src/engine/gameDataLog.test.ts | 26 ++++++++++++++++++++++++++ ui/src/engine/gameDataLog.ts | 17 +++++++++++++++++ ui/src/engine/worker.ts | 10 ++++------ 3 files changed, 47 insertions(+), 6 deletions(-) create mode 100644 ui/src/engine/gameDataLog.test.ts create mode 100644 ui/src/engine/gameDataLog.ts diff --git a/ui/src/engine/gameDataLog.test.ts b/ui/src/engine/gameDataLog.test.ts new file mode 100644 index 0000000..f32956d --- /dev/null +++ b/ui/src/engine/gameDataLog.test.ts @@ -0,0 +1,26 @@ +import { describe, expect, it } from 'vitest'; +import { GameDataLog } from './gameDataLog'; + +describe('GameDataLog', () => { + it('gives a fresh session the latest table of each game', () => { + const log = new GameDataLog(); + log.record('set_dungeons', ['keys']); + log.record('set_spell_classes', ['retail classes', 'retail']); + log.record('set_spell_classes', ['forever classes', 'forever']); + log.record('set_spell_classes', ['newer retail classes', 'retail']); + log.record('call', ['damage_done_report', '{}']); + + const given: unknown[][] = []; + const session = { + set_dungeons: (...args: unknown[]) => given.push(['set_dungeons', ...args]), + set_spell_classes: (...args: unknown[]) => given.push(['set_spell_classes', ...args]), + }; + log.replay(session); + + expect(given).toEqual([ + ['set_dungeons', 'keys'], + ['set_spell_classes', 'newer retail classes', 'retail'], + ['set_spell_classes', 'forever classes', 'forever'], + ]); + }); +}); diff --git a/ui/src/engine/gameDataLog.ts b/ui/src/engine/gameDataLog.ts new file mode 100644 index 0000000..7e18d7d --- /dev/null +++ b/ui/src/engine/gameDataLog.ts @@ -0,0 +1,17 @@ +import type { EngineMethod } from './protocol'; + +const GAME_DATA: readonly EngineMethod[] = ['set_dungeons', 'set_channel_spells', 'set_spell_classes', 'set_talent_trees']; + +/** The game data given to the engine, to give again to a session that replaces one that trapped. */ +export class GameDataLog { + /** The latest call per table and game, such as `set_spell_classes:forever`. */ + private readonly calls = new Map(); + + record(method: EngineMethod, args: unknown[]) { + if (GAME_DATA.includes(method)) this.calls.set(`${method}:${String(args[1] ?? '')}`, { method, args }); + } + + replay(session: object) { + this.calls.forEach(({ method, args }) => Reflect.apply(Reflect.get(session, method) as (...args: unknown[]) => unknown, session, args)); + } +} diff --git a/ui/src/engine/worker.ts b/ui/src/engine/worker.ts index 14ae833..d848a87 100644 --- a/ui/src/engine/worker.ts +++ b/ui/src/engine/worker.ts @@ -1,4 +1,5 @@ import init, { Session, take_panic_message } from './pkg/openlogs_wasm'; +import { GameDataLog } from './gameDataLog'; import type { EngineRequest, EngineResponse } from './protocol'; const scope = self as unknown as { @@ -8,14 +9,11 @@ const scope = self as unknown as { const ready = init(); let session: Session | undefined; -const GAME_DATA = ['set_dungeons', 'set_channel_spells', 'set_spell_classes', 'set_talent_trees'] as const; -type GameDataMethod = (typeof GAME_DATA)[number]; -/** Given again to a session that replaces one that trapped; one entry per table and game. */ -const gameData = new Map(); +const gameData = new GameDataLog(); function openSession(): Session { const fresh = new Session(); - gameData.forEach(({ method, args }) => Reflect.apply(fresh[method] as (...args: unknown[]) => unknown, fresh, args)); + gameData.replay(fresh); return fresh; } @@ -24,7 +22,7 @@ scope.onmessage = async ({ data: { id, method, args } }) => { await ready; session ??= openSession(); const result: unknown = Reflect.apply(session[method] as (...args: unknown[]) => unknown, session, args); - if ((GAME_DATA as readonly string[]).includes(method)) gameData.set(`${method}:${String(args[1] ?? '')}`, { method: method as GameDataMethod, args }); + gameData.record(method, args); scope.postMessage({ id, result }); } catch (error) { if (error instanceof WebAssembly.RuntimeError) { From 4d6ac4ce78b240607c62ad106d0695c13602a074 Mon Sep 17 00:00:00 2001 From: Shaydera Date: Fri, 20 Nov 2026 23:01:44 +0100 Subject: [PATCH 3/5] Send the log's game data from the service --- crates/openlogs-index/src/model.rs | 26 ++++++++++++++++++++ crates/openlogs-service/src/log_dto.rs | 5 +++- crates/openlogs-wasm/src/engine.rs | 28 +--------------------- crates/openlogs-wasm/src/lib.rs | 3 ++- crates/openlogs-wasm/tests/engine.rs | 8 +++++++ ui/src/api/client.test.ts | 11 +++++---- ui/src/api/client.ts | 9 +++---- ui/src/api/types.ts | 5 ++++ ui/src/components/StartPage.test.tsx | 1 + ui/src/components/overview/players.test.ts | 8 +++---- ui/src/currentGame.ts | 20 ++++++++++------ ui/src/engine/engine.ts | 2 +- ui/src/gameData.test.ts | 14 +++++------ ui/src/gameData.ts | 16 ++++--------- ui/src/store.test.ts | 1 + ui/src/store.ts | 4 ++-- ui/src/test/compareFixture.ts | 1 + ui/src/test/runFixture.ts | 1 + 18 files changed, 92 insertions(+), 71 deletions(-) diff --git a/crates/openlogs-index/src/model.rs b/crates/openlogs-index/src/model.rs index e2016c5..7f4e926 100644 --- a/crates/openlogs-index/src/model.rs +++ b/crates/openlogs-index/src/model.rs @@ -75,6 +75,32 @@ impl GameFlavor { } } +/// The games with game data of their own: spell tables, and Forever's talent trees. +#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)] +#[serde(rename_all = "lowercase")] +pub enum DataGame { + Retail, + Forever, +} + +impl DataGame { + /// Forever has its own game data; every other game reads retail's. + pub fn of(flavor: Option) -> Self { + match flavor { + Some(GameFlavor::Forever) => Self::Forever, + _ => Self::Retail, + } + } + + pub fn from_name(name: &str) -> Result { + match name { + "retail" => Ok(Self::Retail), + "forever" => Ok(Self::Forever), + _ => Err(format!("No game data for the game {name}")), + } + } +} + /// Difficulty ID of Mythic+ (Mythic Keystone) dungeons; run entries carry it too. pub const MYTHIC_KEYSTONE_DIFFICULTY: u32 = 8; /// Difficulties whose visit is a dungeon run: Normal, Heroic, Mythic, Timewalking, Follower. diff --git a/crates/openlogs-service/src/log_dto.rs b/crates/openlogs-service/src/log_dto.rs index 0196c0f..fd0e156 100644 --- a/crates/openlogs-service/src/log_dto.rs +++ b/crates/openlogs-service/src/log_dto.rs @@ -2,7 +2,7 @@ use std::collections::BTreeMap; use openlogs_analysis::{BossProgress, run_result}; use openlogs_gamedata::{DungeonTable, KeyTimer}; -use openlogs_index::{FightSummary, GameFlavor, LogIndex, Outcome, difficulty_label}; +use openlogs_index::{DataGame, FightSummary, GameFlavor, LogIndex, Outcome, difficulty_label}; use openlogs_parser::Timestamp; use serde::Serialize; @@ -160,6 +160,8 @@ pub struct LogView { pub log_version: Option, pub build: Option, pub game: Option, + /// The game data the log's game reads. + pub data_game: DataGame, pub advanced_logging: bool, pub broken_lines: u64, pub broken_by_event: BTreeMap, @@ -239,6 +241,7 @@ pub fn log_view( log_version: index.log_version, build: index.build.clone(), game: index.flavor.map(Into::into), + data_game: DataGame::of(index.flavor), advanced_logging: index.advanced_logging, broken_lines: index.broken_lines, broken_by_event: index.broken_by_event.clone(), diff --git a/crates/openlogs-wasm/src/engine.rs b/crates/openlogs-wasm/src/engine.rs index 707464b..ca46724 100644 --- a/crates/openlogs-wasm/src/engine.rs +++ b/crates/openlogs-wasm/src/engine.rs @@ -5,7 +5,7 @@ use openlogs_analysis::{ load_fight_slice_with, }; use openlogs_gamedata::{ChannelSpells, Curated, DungeonTable, SpellClasses, TalentTrees}; -use openlogs_index::{FightSummary, GameFlavor, Indexer, LogIndex}; +use openlogs_index::{DataGame, FightSummary, GameFlavor, Indexer, LogIndex}; use openlogs_service::auras_dto::AuraKindDto; use openlogs_service::casts_dto::CastsReportDto; use openlogs_service::log_dto::log_view; @@ -26,32 +26,6 @@ use serde_json::Value; /// Pulls kept loaded: the shown pull and the one it is compared with. const LOADED_PULLS: usize = 2; -/// The games with spell tables of their own. -#[derive(Debug, Clone, Copy, PartialEq, Eq)] -pub enum DataGame { - Retail, - Forever, -} - -impl DataGame { - /// Forever has its own tables; every other game reads retail's. The app follows the same - /// rule (`dataGameOf`). - pub fn of(flavor: Option) -> Self { - match flavor { - Some(GameFlavor::Forever) => Self::Forever, - _ => Self::Retail, - } - } - - pub fn from_name(name: &str) -> Result { - match name { - "retail" => Ok(Self::Retail), - "forever" => Ok(Self::Forever), - _ => Err(format!("No game data for the game {name}")), - } - } -} - #[derive(Default)] struct GameTables { channels: ChannelSpells, diff --git a/crates/openlogs-wasm/src/lib.rs b/crates/openlogs-wasm/src/lib.rs index 54b6aa4..69a67d2 100644 --- a/crates/openlogs-wasm/src/lib.rs +++ b/crates/openlogs-wasm/src/lib.rs @@ -5,7 +5,8 @@ mod engine; use std::cell::RefCell; -pub use engine::{DataGame, Engine}; +pub use engine::Engine; +pub use openlogs_index::DataGame; use wasm_bindgen::prelude::*; thread_local! { diff --git a/crates/openlogs-wasm/tests/engine.rs b/crates/openlogs-wasm/tests/engine.rs index 0e8b55d..3648986 100644 --- a/crates/openlogs-wasm/tests/engine.rs +++ b/crates/openlogs-wasm/tests/engine.rs @@ -1081,6 +1081,14 @@ fn opening_a_forever_open_world_log_lists_its_combat_pull() { assert!(report["total"].as_u64().unwrap() > 0); } +#[test] +fn a_log_view_names_the_game_data_its_game_reads() { + const OPEN_WORLD: &str = + include_str!("../../openlogs-index/tests/fixtures/forever_open_world.txt"); + assert_eq!(open(OPEN_WORLD).1["dataGame"], "forever"); + assert_eq!(open(FIXTURE).1["dataGame"], "retail"); +} + #[test] fn a_forever_log_names_its_players_in_full() { const OPEN_WORLD: &str = diff --git a/ui/src/api/client.test.ts b/ui/src/api/client.test.ts index f9f5f8e..4ec8122 100644 --- a/ui/src/api/client.test.ts +++ b/ui/src/api/client.test.ts @@ -34,6 +34,7 @@ function view(id: string, logVersion: number | null = 22): LogView { logVersion, build: null, game: null, + dataGame: 'retail', advancedLogging: true, brokenLines: 0, brokenByEvent: {}, @@ -191,7 +192,7 @@ describe('opening logs', () => { const given: [string, string][] = []; fake.engine.setChannelSpells = async (json, game) => void given.push([json, game]); fake.engine.setSpellClasses = async (json, game) => void given.push([json, game]); - fake.engine.finishIndex = async (logId) => ({ ...view(logId), game: { kind: logId.startsWith('f') ? 'forever' : 'retail' } }); + fake.engine.finishIndex = async (logId) => ({ ...view(logId), game: { kind: logId.startsWith('f') ? 'forever' : 'retail' }, dataGame: logId.startsWith('f') ? 'forever' : 'retail' }); const api = createClient({ engine: () => fake.engine, dungeons: async () => null, @@ -215,7 +216,7 @@ describe('opening logs', () => { const fake = fakeEngine(); const given: string[] = []; fake.engine.setTalentTrees = async (json, game) => void given.push(`${json}:${game}`); - fake.engine.finishIndex = async (logId) => ({ ...view(logId), game: { kind: logId.startsWith('f') ? 'forever' : 'retail' } }); + fake.engine.finishIndex = async (logId) => ({ ...view(logId), game: { kind: logId.startsWith('f') ? 'forever' : 'retail' }, dataGame: logId.startsWith('f') ? 'forever' : 'retail' }); const api = createClient({ engine: () => fake.engine, dungeons: async () => null, @@ -234,8 +235,8 @@ describe('opening logs', () => { it('gives a Forever log reopened from its stored index the Forever tables', async () => { const db = memoryDatabase(); const forever = (engine: Engine) => { - engine.finishIndex = async (logId) => ({ ...view(logId), game: { kind: 'forever' } }); - engine.restoreIndex = async (_, logId) => ({ ...view(logId), game: { kind: 'forever' }, cacheHit: true }); + engine.finishIndex = async (logId) => ({ ...view(logId), game: { kind: 'forever' }, dataGame: 'forever' }); + engine.restoreIndex = async (_, logId) => ({ ...view(logId), game: { kind: 'forever' }, dataGame: 'forever', cacheHit: true }); }; const first = fakeEngine(); forever(first.engine); @@ -447,7 +448,7 @@ describe('following a log that grows', () => { const fake = fakeEngine(); const given: string[] = []; fake.engine.setSpellClasses = async (_, game) => void given.push(game); - fake.engine.refreshIndex = async (logId) => ({ ...view(logId), game: { kind: 'forever' } }); + fake.engine.refreshIndex = async (logId) => ({ ...view(logId), game: { kind: 'forever' }, dataGame: 'forever' }); const api = createClient({ engine: () => fake.engine, dungeons: async () => null, channelSpells: async () => null, spellClasses: async () => '{}', talentTrees: async () => null, db: memoryDatabase(), now: () => 1 }); const log = growable('today.txt', 0); await api.openLog(log); diff --git a/ui/src/api/client.ts b/ui/src/api/client.ts index a2202bb..087d080 100644 --- a/ui/src/api/client.ts +++ b/ui/src/api/client.ts @@ -1,8 +1,9 @@ import { type Engine, workerEngine } from '../engine/engine'; -import { type DataGame, channelSpellsJson, dataGameOf, dungeonsJson, spellClassesJson, talentTreesJson } from '../gameData'; +import { channelSpellsJson, dungeonsJson, spellClassesJson, talentTreesJson } from '../gameData'; import { t } from '../i18n/i18n'; import { browserDatabase, type Database } from './db'; import { fileGone, fileMissing, type LogSource, reopenHandle } from './logSource'; +import type { DataGame } from './types'; import { type RecentRecord, recentRecords, rememberLog } from './recent'; import type { Attribution, @@ -175,7 +176,7 @@ export function createClient({ engine: getEngine, dungeons, channelSpells, spell const view = await quietly(() => engine.restoreIndex(stored.json, source.id, source.name, source.size)); if (view) { await quietly(() => useIndex(key)); - await loadSpellTables(engine, dataGameOf(view.game)); + await loadSpellTables(engine, view.dataGame); return { view, key, followedBytes: 0 }; } } @@ -193,7 +194,7 @@ export function createClient({ engine: getEngine, dungeons, channelSpells, spell const view = await engine.finishIndex(source.id, source.name, source.size); const json = await engine.indexJson(); await quietly(() => storeIndex(key, json)); - await loadSpellTables(engine, dataGameOf(view.game)); + await loadSpellTables(engine, view.dataGame); return { view, key, followedBytes: source.size }; } @@ -268,7 +269,7 @@ export function createClient({ engine: getEngine, dungeons, channelSpells, spell } const view = await engine.refreshIndex(source.id, source.name, source.size, settleAll); // A log opened before its header was written learns its game only now. - await loadSpellTables(engine, dataGameOf(view.game)); + await loadSpellTables(engine, view.dataGame); await storeFollowed(engine, log, view, settleAll); return view; } finally { diff --git a/ui/src/api/types.ts b/ui/src/api/types.ts index c5d4980..cc79d68 100644 --- a/ui/src/api/types.ts +++ b/ui/src/api/types.ts @@ -10,6 +10,9 @@ export interface BossProgress { } /** The game a log comes from (mirrors `GameDto`). */ +/** The games with game data of their own; every other game reads retail's. */ +export type DataGame = 'retail' | 'forever'; + export type Game = { kind: 'retail' } | { kind: 'classicEra' } | { kind: 'forever' } | { kind: 'other'; projectId: number }; /** A completed key against its time limits (mirrors `TimerDto`). */ @@ -79,6 +82,8 @@ export interface LogView { build: string | null; /** `null` for logs whose header names no project. */ game: Game | null; + /** The game data the log's game reads. */ + dataGame: DataGame; advancedLogging: boolean; brokenLines: number; /** Unreadable lines by event name; lines without a readable name count only in `brokenLines`. */ diff --git a/ui/src/components/StartPage.test.tsx b/ui/src/components/StartPage.test.tsx index 5cb0817..5c29858 100644 --- a/ui/src/components/StartPage.test.tsx +++ b/ui/src/components/StartPage.test.tsx @@ -59,6 +59,7 @@ const LOG: LogView = { logVersion: 22, build: '12.1.0', game: { kind: 'retail' }, + dataGame: 'retail', advancedLogging: true, brokenLines: 0, brokenByEvent: {}, diff --git a/ui/src/components/overview/players.test.ts b/ui/src/components/overview/players.test.ts index 6dead98..48188d6 100644 --- a/ui/src/components/overview/players.test.ts +++ b/ui/src/components/overview/players.test.ts @@ -1,14 +1,14 @@ import { afterEach, describe, expect, it } from 'vitest'; -import { setCurrentGame } from '../../currentGame'; +import { setCurrentLog } from '../../currentGame'; import { shortName } from './players'; describe('player names', () => { - afterEach(() => setCurrentGame(null)); + afterEach(() => setCurrentLog(null)); it('shows a Forever name in full and a retail name by its first part', () => { - setCurrentGame({ kind: 'forever' }); + setCurrentLog({ game: { kind: 'forever' }, dataGame: 'forever' }); expect([shortName('Ravel-Ashwood-Normal-EU'), shortName('Wolf')]).toEqual(['Ravel Ashwood', 'Wolf']); - setCurrentGame({ kind: 'retail' }); + setCurrentLog({ game: { kind: 'retail' }, dataGame: 'retail' }); expect(shortName('Faelan-Emberfall-EU')).toBe('Faelan'); }); }); diff --git a/ui/src/currentGame.ts b/ui/src/currentGame.ts index d7e239e..bfb9f20 100644 --- a/ui/src/currentGame.ts +++ b/ui/src/currentGame.ts @@ -1,17 +1,23 @@ -import type { Game } from './api/types'; +import type { DataGame, Game, LogView } from './api/types'; -let game: Game | null = null; +let log: Pick | null = null; const listeners = new Set<() => void>(); -/** The game of the open log, which decides how names read and which spell icons show; the store keeps it in step. */ +/** The game of the open log, which decides how names read; the store keeps it in step. */ export function currentGame(): Game | null { - return game; + return log?.game ?? null; +} + +/** The game data of the open log, which decides which spell icons show. */ +export function currentDataGame(): DataGame { + return log?.dataGame ?? 'retail'; } /** Listeners hear only of another game, not of every refresh of the open log. */ -export function setCurrentGame(next: Game | null) { - const changed = JSON.stringify(next) !== JSON.stringify(game); - game = next; +export function setCurrentLog(next: Pick | null) { + const key = (value: typeof next) => JSON.stringify([value?.game ?? null, value?.dataGame ?? null]); + const changed = key(next) !== key(log); + log = next; if (changed) listeners.forEach((listener) => listener()); } diff --git a/ui/src/engine/engine.ts b/ui/src/engine/engine.ts index f6d6b05..c30d923 100644 --- a/ui/src/engine/engine.ts +++ b/ui/src/engine/engine.ts @@ -1,5 +1,5 @@ import type { LogView } from '../api/types'; -import type { DataGame } from '../gameData'; +import type { DataGame } from '../api/types'; import type { EngineMethod, EngineRequest, EngineResponse } from './protocol'; /** The analysis engine (Rust, as WebAssembly) in its Web Worker. It holds one log at a time. */ diff --git a/ui/src/gameData.test.ts b/ui/src/gameData.test.ts index 1ed1560..79e6f32 100644 --- a/ui/src/gameData.test.ts +++ b/ui/src/gameData.test.ts @@ -91,7 +91,7 @@ describe('game data tables', () => { return new Response('', { status: 404 }); }), ); - const { setCurrentGame } = await import('./currentGame'); + const { setCurrentLog } = await import('./currentGame'); const { iconTables, loadIconTables, spellIconName, subscribeIconTables } = await import('./gameData'); const bearForm = () => { const spells = iconTables().spells; @@ -100,29 +100,29 @@ describe('game data tables', () => { const notified = vi.fn(); subscribeIconTables(notified); - setCurrentGame({ kind: 'forever' }); + setCurrentLog({ game: { kind: 'forever' }, dataGame: 'forever' }); loadIconTables(); await vi.waitFor(() => expect(bearForm()).toBe('ability_racial_bearform')); notified.mockClear(); - setCurrentGame({ kind: 'retail' }); + setCurrentLog({ game: { kind: 'retail' }, dataGame: 'retail' }); expect(notified).toHaveBeenCalled(); await vi.waitFor(() => expect(bearForm()).toBe('retail_icon')); - setCurrentGame({ kind: 'forever' }); + setCurrentLog({ game: { kind: 'forever' }, dataGame: 'forever' }); expect(bearForm(), 'a loaded table is shown again at once').toBe('ability_racial_bearform'); }); it('leaves the icons alone when a refreshed log keeps its game', async () => { vi.stubGlobal('fetch', vi.fn(async () => new Response('', { status: 404 }))); - const { setCurrentGame } = await import('./currentGame'); + const { setCurrentLog } = await import('./currentGame'); const { iconTables, subscribeIconTables } = await import('./gameData'); - setCurrentGame({ kind: 'forever' }); + setCurrentLog({ game: { kind: 'forever' }, dataGame: 'forever' }); const shown = iconTables(); const notified = vi.fn(); subscribeIconTables(notified); - setCurrentGame({ kind: 'forever' }); + setCurrentLog({ game: { kind: 'forever' }, dataGame: 'forever' }); expect(notified).not.toHaveBeenCalled(); expect(iconTables()).toBe(shown); diff --git a/ui/src/gameData.ts b/ui/src/gameData.ts index b871f90..f62baec 100644 --- a/ui/src/gameData.ts +++ b/ui/src/gameData.ts @@ -1,5 +1,5 @@ -import type { Game, MapArtTable } from './api/types'; -import { currentGame, subscribeCurrentGame } from './currentGame'; +import type { DataGame, MapArtTable } from './api/types'; +import { currentDataGame, subscribeCurrentGame } from './currentGame'; /** Game data shipped next to the app in `game-data/`, written by `openlogs-cli export-game-data`. */ export interface GameDataManifest { @@ -18,14 +18,6 @@ export interface GameDataManifest { forever?: { build: string; spellIcons: number; channelSpells: number; spellClasses: number; talentTrees?: number }; } -/** The games with spell tables of their own. */ -export type DataGame = 'retail' | 'forever'; - -/** Forever has its own tables; every other game reads retail's. The engine follows the same rule (`DataGame::of`). */ -export function dataGameOf(game: Game | null): DataGame { - return game?.kind === 'forever' ? 'forever' : 'retail'; -} - /** Spell ID → icon name, as sorted parallel arrays. */ export interface SpellIcons { ids: Uint32Array; @@ -122,7 +114,7 @@ const listeners = new Set<() => void>(); const nextAttempt = new Map(); function publish() { - tables = { spells: spellIcons[dataGameOf(currentGame())], portraits, mapArt }; + tables = { spells: spellIcons[currentDataGame()], portraits, mapArt }; listeners.forEach((listener) => listener()); } @@ -140,7 +132,7 @@ function loadTable(table: string, loaded: boolean, read: () => Promise tableText('spell-icons.json', game), (text) => { spellIcons[game] = decodeSpellIcons(JSON.parse(text)); }); diff --git a/ui/src/store.test.ts b/ui/src/store.test.ts index 2bef106..1f28bca 100644 --- a/ui/src/store.test.ts +++ b/ui/src/store.test.ts @@ -62,6 +62,7 @@ const LOG: LogView = { logVersion: 22, build: '12.1.0', game: { kind: 'retail' }, + dataGame: 'retail', advancedLogging: true, brokenLines: 0, brokenByEvent: {}, diff --git a/ui/src/store.ts b/ui/src/store.ts index 74927f6..6945f87 100644 --- a/ui/src/store.ts +++ b/ui/src/store.ts @@ -53,7 +53,7 @@ import { replayClock } from './components/replay/replayClock'; import { t } from './i18n/i18n'; import { rowValue } from './components/filters/labels'; import { APP_VERSION } from './build'; -import { setCurrentGame } from './currentGame'; +import { setCurrentLog } from './currentGame'; import { followUpdate, type LiveNotice, liveNoticeOf } from './pulls/follow'; import { effectiveView, lanesOf } from './reportViews'; import { type FilterTab, isFilterTab, SIDES } from './scopeSides'; @@ -1889,5 +1889,5 @@ export const useApp = create()(derivingScope((set, get) => ({ }))); useApp.subscribe((state, previous) => { - if (state.log !== previous.log) setCurrentGame(state.log?.game ?? null); + if (state.log !== previous.log) setCurrentLog(state.log); }); diff --git a/ui/src/test/compareFixture.ts b/ui/src/test/compareFixture.ts index e3b33a3..4c1e6d1 100644 --- a/ui/src/test/compareFixture.ts +++ b/ui/src/test/compareFixture.ts @@ -82,6 +82,7 @@ export const compareLogFixture: LogView = { logVersion: 22, build: '12.1.0', game: { kind: 'retail' }, + dataGame: 'retail', advancedLogging: true, brokenLines: 0, brokenByEvent: {}, diff --git a/ui/src/test/runFixture.ts b/ui/src/test/runFixture.ts index 1512e5b..bdee858 100644 --- a/ui/src/test/runFixture.ts +++ b/ui/src/test/runFixture.ts @@ -56,6 +56,7 @@ export const runLogFixture: LogView = { logVersion: 22, build: '12.1.0', game: { kind: 'retail' }, + dataGame: 'retail', advancedLogging: true, brokenLines: 0, brokenByEvent: {}, From d724abdd3d883b23d1403a43b627cd63f8f3073f Mon Sep 17 00:00:00 2001 From: Shaydera Date: Fri, 20 Nov 2026 23:08:20 +0100 Subject: [PATCH 4/5] Read CSV columns through one helper --- .../openlogs-gamedata/src/boss_portraits.rs | 13 +++------ .../openlogs-gamedata/src/channel_spells.rs | 13 +++------ crates/openlogs-gamedata/src/csv_columns.rs | 16 ++++++++++ crates/openlogs-gamedata/src/dungeons.rs | 13 +++------ crates/openlogs-gamedata/src/lib.rs | 2 ++ crates/openlogs-gamedata/src/map_art.rs | 13 +++------ crates/openlogs-gamedata/src/spell_classes.rs | 13 +++------ crates/openlogs-gamedata/src/spell_icons.rs | 13 +++------ crates/openlogs-gamedata/src/talent_trees.rs | 29 ++++++++----------- .../openlogs-gamedata/tests/boss_portraits.rs | 4 +-- .../openlogs-gamedata/tests/channel_spells.rs | 6 ++-- crates/openlogs-gamedata/tests/dungeons.rs | 4 +-- crates/openlogs-gamedata/tests/map_art.rs | 6 ++-- .../openlogs-gamedata/tests/spell_classes.rs | 10 +++++-- crates/openlogs-gamedata/tests/spell_icons.rs | 6 ++-- 15 files changed, 76 insertions(+), 85 deletions(-) create mode 100644 crates/openlogs-gamedata/src/csv_columns.rs diff --git a/crates/openlogs-gamedata/src/boss_portraits.rs b/crates/openlogs-gamedata/src/boss_portraits.rs index 4ed3b01..8941cb6 100644 --- a/crates/openlogs-gamedata/src/boss_portraits.rs +++ b/crates/openlogs-gamedata/src/boss_portraits.rs @@ -6,6 +6,8 @@ use std::collections::{BTreeMap, HashMap}; use thiserror::Error; +use crate::csv_columns::{MissingColumn, column}; + use crate::icon_name::{icon_name_from_file, is_valid_icon_name}; /// The journal's generic silhouette: a boss without its own portrait gets the monogram instead. @@ -17,8 +19,8 @@ const PORTRAIT_PREFIX: &str = "ui-ej-boss-"; pub enum BossPortraitError { #[error("CSV error: {0}")] Csv(#[from] csv::Error), - #[error("CSV is missing the column {0}")] - MissingColumn(&'static str), + #[error(transparent)] + MissingColumn(#[from] MissingColumn), #[error("the exports hold no boss portrait")] Empty, } @@ -147,10 +149,3 @@ fn read_portrait_files(manifest: &[u8]) -> Result, BossPort } Ok(files) } - -fn column(headers: &csv::StringRecord, name: &'static str) -> Result { - headers - .iter() - .position(|header| header == name) - .ok_or(BossPortraitError::MissingColumn(name)) -} diff --git a/crates/openlogs-gamedata/src/channel_spells.rs b/crates/openlogs-gamedata/src/channel_spells.rs index 69e6f27..e8efbb5 100644 --- a/crates/openlogs-gamedata/src/channel_spells.rs +++ b/crates/openlogs-gamedata/src/channel_spells.rs @@ -2,6 +2,8 @@ use std::collections::HashMap; use thiserror::Error; +use crate::csv_columns::{MissingColumn, column}; + /// `SPELL_ATTR1_IS_CHANNELLED` and `SPELL_ATTR1_IS_SELF_CHANNELLED` of `SpellMisc.Attributes_1`. const CHANNEL_ATTRIBUTES: u32 = 0x4 | 0x40; @@ -9,8 +11,8 @@ const CHANNEL_ATTRIBUTES: u32 = 0x4 | 0x40; pub enum ChannelSpellError { #[error("CSV error: {0}")] Csv(#[from] csv::Error), - #[error("CSV is missing the column {0}")] - MissingColumn(&'static str), + #[error(transparent)] + MissingColumn(#[from] MissingColumn), #[error("JSON error: {0}")] Json(#[from] serde_json::Error), } @@ -115,10 +117,3 @@ impl ChannelSpells { Ok(Self { ids }) } } - -fn column(headers: &csv::StringRecord, name: &'static str) -> Result { - headers - .iter() - .position(|header| header == name) - .ok_or(ChannelSpellError::MissingColumn(name)) -} diff --git a/crates/openlogs-gamedata/src/csv_columns.rs b/crates/openlogs-gamedata/src/csv_columns.rs new file mode 100644 index 0000000..4770271 --- /dev/null +++ b/crates/openlogs-gamedata/src/csv_columns.rs @@ -0,0 +1,16 @@ +use thiserror::Error; + +/// A wago.tools export lacks a column a table is read from. +#[derive(Debug, Clone, Copy, PartialEq, Eq, Error)] +#[error("CSV is missing the column {0}")] +pub struct MissingColumn(pub &'static str); + +pub(crate) fn column( + headers: &csv::StringRecord, + name: &'static str, +) -> Result { + headers + .iter() + .position(|header| header == name) + .ok_or(MissingColumn(name)) +} diff --git a/crates/openlogs-gamedata/src/dungeons.rs b/crates/openlogs-gamedata/src/dungeons.rs index d973790..3efe3ff 100644 --- a/crates/openlogs-gamedata/src/dungeons.rs +++ b/crates/openlogs-gamedata/src/dungeons.rs @@ -6,6 +6,8 @@ use std::collections::{BTreeMap, HashMap, HashSet}; use serde::{Deserialize, Serialize}; use thiserror::Error; +use crate::csv_columns::{MissingColumn, column}; + /// `DungeonEncounter.DifficultyID` of a row that holds on every difficulty. const ANY_DIFFICULTY: u32 = 0; /// `DungeonEncounter.DifficultyID` of Mythic Keystone, the difficulty of M+ boss pulls. @@ -22,8 +24,8 @@ const IGNORED_ENCOUNTERS: [u32; 1] = [3463]; pub enum DungeonTableError { #[error("CSV error: {0}")] Csv(#[from] csv::Error), - #[error("CSV is missing the column {0}")] - MissingColumn(&'static str), + #[error(transparent)] + MissingColumn(#[from] MissingColumn), #[error("stored dungeon table is invalid: {0}")] Stored(#[from] serde_json::Error), #[error("the export holds no dungeon with a boss list")] @@ -255,10 +257,3 @@ fn time_limits(criteria: [u32; 3]) -> Vec { } limits } - -fn column(headers: &csv::StringRecord, name: &'static str) -> Result { - headers - .iter() - .position(|header| header == name) - .ok_or(DungeonTableError::MissingColumn(name)) -} diff --git a/crates/openlogs-gamedata/src/lib.rs b/crates/openlogs-gamedata/src/lib.rs index 0a1334c..9d985c4 100644 --- a/crates/openlogs-gamedata/src/lib.rs +++ b/crates/openlogs-gamedata/src/lib.rs @@ -3,6 +3,7 @@ mod boss_portraits; mod channel_spells; +mod csv_columns; mod curated; mod download; mod dungeons; @@ -18,6 +19,7 @@ mod talent_trees; pub use boss_portraits::{BossPortraitError, BossPortraitTable}; pub use channel_spells::{ChannelSpellError, ChannelSpells}; +pub use csv_columns::MissingColumn; pub use curated::{ ARENA_FRAMES_DIR, ArenaFrame, BOSS_EFFECTS_DIR, BossEffects, CONSUMABLES_FILE, Consumable, ConsumableKind, ConsumableList, CooldownCategory, CooldownList, CooldownSpell, Curated, diff --git a/crates/openlogs-gamedata/src/map_art.rs b/crates/openlogs-gamedata/src/map_art.rs index 232817e..ec464cd 100644 --- a/crates/openlogs-gamedata/src/map_art.rs +++ b/crates/openlogs-gamedata/src/map_art.rs @@ -8,6 +8,8 @@ use std::collections::{BTreeMap, HashMap, HashSet}; use serde::{Deserialize, Serialize}; use thiserror::Error; +use crate::csv_columns::{MissingColumn, column}; + /// `Map.InstanceType` of a raid. const RAID_INSTANCE: u32 = 2; @@ -15,8 +17,8 @@ const RAID_INSTANCE: u32 = 2; pub enum MapArtError { #[error("CSV error: {0}")] Csv(#[from] csv::Error), - #[error("CSV is missing the column {0}")] - MissingColumn(&'static str), + #[error(transparent)] + MissingColumn(#[from] MissingColumn), #[error("stored map art table is invalid: {0}")] Stored(#[from] serde_json::Error), #[error("the exports hold no map art or no boss pin")] @@ -269,10 +271,3 @@ fn read_pins(csv: &[u8]) -> Result, MapArtError> { } Ok(pins) } - -fn column(headers: &csv::StringRecord, name: &'static str) -> Result { - headers - .iter() - .position(|header| header == name) - .ok_or(MapArtError::MissingColumn(name)) -} diff --git a/crates/openlogs-gamedata/src/spell_classes.rs b/crates/openlogs-gamedata/src/spell_classes.rs index 1b57b28..03bde61 100644 --- a/crates/openlogs-gamedata/src/spell_classes.rs +++ b/crates/openlogs-gamedata/src/spell_classes.rs @@ -2,6 +2,8 @@ use std::collections::BTreeMap; use thiserror::Error; +use crate::csv_columns::{MissingColumn, column}; + /// The player class families of `SpellClassOptions.SpellClassSet` with their class IDs: mage 3, /// warrior 4, warlock 5, priest 6, druid 7, rogue 8, hunter and its pets 9, paladin 10, shaman 11, /// death knight 15, monk 53, warlock pets 57, demon hunter 107, evoker 224. Not @@ -32,8 +34,8 @@ const CROWD_CONTROL_AURAS: [u32; 8] = [5, 7, 12, 26, 27, 60, 298, 455]; pub enum SpellClassesError { #[error("CSV error: {0}")] Csv(#[from] csv::Error), - #[error("CSV is missing the column {0}")] - MissingColumn(&'static str), + #[error(transparent)] + MissingColumn(#[from] MissingColumn), #[error("the export lists no class spells")] Empty, #[error("JSON error: {0}")] @@ -197,10 +199,3 @@ fn undeltas(deltas: Vec) -> Vec { }) .collect() } - -fn column(headers: &csv::StringRecord, name: &'static str) -> Result { - headers - .iter() - .position(|header| header == name) - .ok_or(SpellClassesError::MissingColumn(name)) -} diff --git a/crates/openlogs-gamedata/src/spell_icons.rs b/crates/openlogs-gamedata/src/spell_icons.rs index 8e07166..47a0b40 100644 --- a/crates/openlogs-gamedata/src/spell_icons.rs +++ b/crates/openlogs-gamedata/src/spell_icons.rs @@ -2,14 +2,16 @@ use std::collections::HashMap; use thiserror::Error; +use crate::csv_columns::{MissingColumn, column}; + use crate::icon_name::{icon_name_from_file, is_valid_icon_name}; #[derive(Debug, Error)] pub enum SpellIconError { #[error("CSV error: {0}")] Csv(#[from] csv::Error), - #[error("CSV is missing the column {0}")] - MissingColumn(&'static str), + #[error(transparent)] + MissingColumn(#[from] MissingColumn), } /// Spell ID → zamimg icon name. @@ -120,10 +122,3 @@ pub(crate) fn read_icon_files(manifest: &[u8]) -> Result, S } Ok(files) } - -fn column(headers: &csv::StringRecord, name: &'static str) -> Result { - headers - .iter() - .position(|header| header == name) - .ok_or(SpellIconError::MissingColumn(name)) -} diff --git a/crates/openlogs-gamedata/src/talent_trees.rs b/crates/openlogs-gamedata/src/talent_trees.rs index d148d2e..f38a39e 100644 --- a/crates/openlogs-gamedata/src/talent_trees.rs +++ b/crates/openlogs-gamedata/src/talent_trees.rs @@ -3,6 +3,8 @@ use std::collections::{BTreeMap, HashMap, HashSet}; use serde::{Deserialize, Serialize}; use thiserror::Error; +use crate::csv_columns::{MissingColumn, column}; + use crate::specs::Role; use crate::spell_icons::{SpellIconError, read_icon_files}; @@ -16,8 +18,8 @@ const COLUMN_STARTS: [i64; 2] = [4000, 8000]; pub enum TalentTreesError { #[error("CSV error: {0}")] Csv(#[from] csv::Error), - #[error("CSV is missing the column {0}")] - MissingColumn(&'static str), + #[error(transparent)] + MissingColumn(#[from] MissingColumn), #[error("{0}")] Icons(#[from] SpellIconError), #[error("JSON error: {0}")] @@ -121,7 +123,7 @@ impl TalentTrees { let (node, tree) = (u32::try_from(node).ok()?, u32::try_from(tree).ok()?); class_trees .contains(&tree) - .then_some((node, (tree, column(x)))) + .then_some((node, (tree, tree_column(x)))) }) .collect(); let mut votes: HashMap<(u32, usize), BTreeMap> = HashMap::new(); @@ -267,7 +269,7 @@ impl TalentTrees { } } -fn column(x: i64) -> usize { +fn tree_column(x: i64) -> usize { COLUMN_STARTS.iter().filter(|&&start| x >= start).count() } @@ -280,7 +282,7 @@ fn class_of_mask(mask: u32) -> Option { fn classic_talent_tabs(talent: &[u8]) -> Result, TalentTreesError> { let mut reader = csv::Reader::from_reader(talent); let headers = reader.headers()?.clone(); - let tab_col = column_of(&headers, "TabID")?; + let tab_col = column(&headers, "TabID")?; let rank_cols: Vec = headers .iter() .enumerate() @@ -308,10 +310,10 @@ fn talent_tabs(talent_tab: &[u8]) -> Result, Talent let mut reader = csv::Reader::from_reader(talent_tab); let headers = reader.headers()?.clone(); let cols = [ - column_of(&headers, "ID")?, - column_of(&headers, "ClassMask")?, - column_of(&headers, "Name_lang")?, - column_of(&headers, "SpellIconID")?, + column(&headers, "ID")?, + column(&headers, "ClassMask")?, + column(&headers, "Name_lang")?, + column(&headers, "SpellIconID")?, ]; let mut tabs = Vec::new(); for record in reader.records() { @@ -354,7 +356,7 @@ fn signed( let headers = reader.headers()?.clone(); let mut cols = [0; N]; for (col, name) in cols.iter_mut().zip(names) { - *col = column_of(&headers, name)?; + *col = column(&headers, name)?; } let mut rows = Vec::new(); for record in reader.records() { @@ -373,10 +375,3 @@ fn signed( } Ok(rows) } - -fn column_of(headers: &csv::StringRecord, name: &'static str) -> Result { - headers - .iter() - .position(|header| header == name) - .ok_or(TalentTreesError::MissingColumn(name)) -} diff --git a/crates/openlogs-gamedata/tests/boss_portraits.rs b/crates/openlogs-gamedata/tests/boss_portraits.rs index 73d4a31..be64005 100644 --- a/crates/openlogs-gamedata/tests/boss_portraits.rs +++ b/crates/openlogs-gamedata/tests/boss_portraits.rs @@ -1,6 +1,6 @@ //! Boss portraits from trimmed real wago.tools exports. -use openlogs_gamedata::{BossPortraitError, BossPortraitTable}; +use openlogs_gamedata::{BossPortraitError, BossPortraitTable, MissingColumn}; const JOURNAL_ENCOUNTER: &[u8] = include_bytes!("fixtures/JournalEncounter.csv"); const JOURNAL_ENCOUNTER_CREATURE: &[u8] = include_bytes!("fixtures/JournalEncounterCreature.csv"); @@ -46,7 +46,7 @@ fn the_web_table_maps_encounters_to_portraits_and_unusable_exports_fail() { ); assert!(matches!( BossPortraitTable::from_csv(b"\n", JOURNAL_ENCOUNTER_CREATURE, MANIFEST), - Err(BossPortraitError::MissingColumn("ID")) + Err(BossPortraitError::MissingColumn(MissingColumn("ID"))) )); assert!(matches!( BossPortraitTable::from_csv( diff --git a/crates/openlogs-gamedata/tests/channel_spells.rs b/crates/openlogs-gamedata/tests/channel_spells.rs index 874d2e1..4df3338 100644 --- a/crates/openlogs-gamedata/tests/channel_spells.rs +++ b/crates/openlogs-gamedata/tests/channel_spells.rs @@ -1,4 +1,4 @@ -use openlogs_gamedata::{ChannelSpellError, ChannelSpells}; +use openlogs_gamedata::{ChannelSpellError, ChannelSpells, MissingColumn}; const SPELL_MISC: &str = "ID,Attributes_0,Attributes_1,DifficultyID,SpellID\n\ 1,0,872432772,0,5143\n\ @@ -40,6 +40,8 @@ fn the_web_table_lists_the_ids_in_order_as_differences_and_reads_back() { assert_eq!(ChannelSpells::from_json(&json).unwrap(), table()); assert!(matches!( ChannelSpells::from_csv(b"ID,DifficultyID,SpellID\n1,0,5\n"), - Err(ChannelSpellError::MissingColumn("Attributes_1")) + Err(ChannelSpellError::MissingColumn(MissingColumn( + "Attributes_1" + ))) )); } diff --git a/crates/openlogs-gamedata/tests/dungeons.rs b/crates/openlogs-gamedata/tests/dungeons.rs index f07dc0a..3d799a3 100644 --- a/crates/openlogs-gamedata/tests/dungeons.rs +++ b/crates/openlogs-gamedata/tests/dungeons.rs @@ -1,6 +1,6 @@ //! The dungeon table from trimmed real wago.tools exports. -use openlogs_gamedata::{DungeonBoss, DungeonTable, DungeonTableError, KeyTimer}; +use openlogs_gamedata::{DungeonBoss, DungeonTable, DungeonTableError, KeyTimer, MissingColumn}; const MAP_CHALLENGE_MODE: &[u8] = include_bytes!("fixtures/MapChallengeMode.csv"); const DUNGEON_ENCOUNTER: &[u8] = include_bytes!("fixtures/DungeonEncounter.csv"); @@ -115,7 +115,7 @@ fn time_limits_need_a_falling_ladder_and_decide_the_timer() { fn unusable_exports_are_rejected() { assert!(matches!( DungeonTable::from_csv(MAP_CHALLENGE_MODE, b"\n"), - Err(DungeonTableError::MissingColumn("ID")) + Err(DungeonTableError::MissingColumn(MissingColumn("ID"))) )); assert!(matches!( DungeonTable::from_csv(KEYS_HEADER.as_bytes(), ENCOUNTERS_HEADER.as_bytes()), diff --git a/crates/openlogs-gamedata/tests/map_art.rs b/crates/openlogs-gamedata/tests/map_art.rs index cc7ba81..10f9d6e 100644 --- a/crates/openlogs-gamedata/tests/map_art.rs +++ b/crates/openlogs-gamedata/tests/map_art.rs @@ -1,6 +1,6 @@ //! The replay's map art index from trimmed real wago.tools exports. -use openlogs_gamedata::{BossPin, MapArtError, MapArtTable}; +use openlogs_gamedata::{BossPin, MapArtError, MapArtTable, MissingColumn}; const UI_MAP_ASSIGNMENT: &[u8] = include_bytes!("fixtures/UiMapAssignment.csv"); const UI_MAP_GROUP_MEMBER: &[u8] = include_bytes!("fixtures/UiMapGroupMember.csv"); @@ -125,7 +125,7 @@ fn an_html_page_fails_with_a_missing_column() { MAP, JOURNAL_ENCOUNTER ), - Err(MapArtError::MissingColumn("UiMapID")) + Err(MapArtError::MissingColumn(MissingColumn("UiMapID"))) )); assert!(matches!( MapArtTable::from_csv( @@ -135,7 +135,7 @@ fn an_html_page_fails_with_a_missing_column() { MAP, b"\n" ), - Err(MapArtError::MissingColumn("ID")) + Err(MapArtError::MissingColumn(MissingColumn("ID"))) )); } diff --git a/crates/openlogs-gamedata/tests/spell_classes.rs b/crates/openlogs-gamedata/tests/spell_classes.rs index 7170adc..da2a350 100644 --- a/crates/openlogs-gamedata/tests/spell_classes.rs +++ b/crates/openlogs-gamedata/tests/spell_classes.rs @@ -1,6 +1,6 @@ //! Class and crowd-control spells from trimmed real wago.tools exports. -use openlogs_gamedata::{SpellClasses, SpellClassesError}; +use openlogs_gamedata::{MissingColumn, SpellClasses, SpellClassesError}; const SPELL_CLASS_OPTIONS: &[u8] = include_bytes!("fixtures/SpellClassOptions.csv"); const SPELL_EFFECT: &[u8] = include_bytes!("fixtures/SpellEffect.csv"); @@ -43,11 +43,15 @@ fn a_class_stun_is_crowd_control_and_a_damage_spell_is_not() { fn an_html_page_fails_with_a_missing_column() { assert!(matches!( SpellClasses::from_csv(b"\n", SPELL_EFFECT), - Err(SpellClassesError::MissingColumn("SpellClassSet")) + Err(SpellClassesError::MissingColumn(MissingColumn( + "SpellClassSet" + ))) )); assert!(matches!( SpellClasses::from_csv(SPELL_CLASS_OPTIONS, b"\n"), - Err(SpellClassesError::MissingColumn("EffectAura")) + Err(SpellClassesError::MissingColumn(MissingColumn( + "EffectAura" + ))) )); } diff --git a/crates/openlogs-gamedata/tests/spell_icons.rs b/crates/openlogs-gamedata/tests/spell_icons.rs index e29fc4a..292ab7d 100644 --- a/crates/openlogs-gamedata/tests/spell_icons.rs +++ b/crates/openlogs-gamedata/tests/spell_icons.rs @@ -1,4 +1,4 @@ -use openlogs_gamedata::{SpellIconError, SpellIconTable, is_valid_icon_name}; +use openlogs_gamedata::{MissingColumn, SpellIconError, SpellIconTable, is_valid_icon_name}; const MANIFEST: &str = "ID,FilePath,FileName\n\ 236205,Interface\\ICONS\\,Ability_Mage_ArcaneBarrage.blp\n\ @@ -54,7 +54,9 @@ fn the_web_table_lists_spells_in_order_and_names_each_icon_once() { ); assert!(matches!( SpellIconTable::from_csv(b"ID,DifficultyID,SpellID\n1,0,5\n", MANIFEST.as_bytes()), - Err(SpellIconError::MissingColumn("SpellIconFileDataID")) + Err(SpellIconError::MissingColumn(MissingColumn( + "SpellIconFileDataID" + ))) )); } From be9f06efe45c7f325769895b9ecc978a6884422e Mon Sep 17 00:00:00 2001 From: Shaydera Date: Fri, 20 Nov 2026 23:15:37 +0100 Subject: [PATCH 5/5] Keep each Forever talent set once in the index --- crates/openlogs-analysis/src/lib.rs | 3 ++- crates/openlogs-analysis/src/load.rs | 19 +++++++++++------ crates/openlogs-index/src/builder.rs | 23 +++++++++++++++------ crates/openlogs-index/src/combat.rs | 10 ++++----- crates/openlogs-index/src/model.rs | 21 +++++++++++++++---- crates/openlogs-index/tests/combat_pulls.rs | 15 +++++++------- crates/openlogs-index/tests/index_mini.rs | 4 ++-- crates/openlogs-index/tests/index_runs.rs | 4 ++-- crates/openlogs-wasm/src/engine.rs | 16 +++++++++----- 9 files changed, 76 insertions(+), 39 deletions(-) diff --git a/crates/openlogs-analysis/src/lib.rs b/crates/openlogs-analysis/src/lib.rs index 9f7c0cd..f3036c7 100644 --- a/crates/openlogs-analysis/src/lib.rs +++ b/crates/openlogs-analysis/src/lib.rs @@ -67,7 +67,8 @@ pub use interrupts::{ }; pub use links::AbilityLink; pub use load::{ - load_fight, load_fight_file, load_fight_slice, load_fight_slice_with, pair_melee_lines, + load_fight, load_fight_file, load_fight_slice, load_fight_slice_with, note_roster_talents, + pair_melee_lines, }; pub use meter::{Meter, MeterCategory, MeterEntry, MeterKey, MeterRow, meter}; pub use options::{FilterOption, OptionValue, SpellVariant, filter_options}; diff --git a/crates/openlogs-analysis/src/load.rs b/crates/openlogs-analysis/src/load.rs index 6b79920..6020b09 100644 --- a/crates/openlogs-analysis/src/load.rs +++ b/crates/openlogs-analysis/src/load.rs @@ -3,7 +3,7 @@ use std::fs::File; use std::io; use std::path::Path; -use openlogs_index::{FightSummary, MapBounds, Outcome, RosterEntry}; +use openlogs_index::{FightSummary, LogIndex, MapBounds, Outcome, RosterEntry}; use openlogs_parser::{ CombatEvent, CombatKind, EncounterEnd, EncounterStart, Event as LogEvent, HealVia, Lines, LogLine, Spell, Timestamp, parse_line, @@ -83,11 +83,18 @@ fn apply_roster(fight: &mut Fight, roster: &[RosterEntry]) { if entry.spec_id != 0 && fight.actors.get(id).spec_id.is_none() { fight.actors.set_spec(id, entry.spec_id); } - if !entry.talents.is_empty() { - fight - .talents - .entry(id) - .or_insert_with(|| entry.talents.clone()); + } +} + +/// A combat pull's talents come from `COMBATANT_INFO` before its range, which only the index +/// kept; talents logged inside the range win. +pub fn note_roster_talents(fight: &mut Fight, summary: &FightSummary, index: &LogIndex) { + for entry in &summary.roster { + let talents = index.talents_of(entry); + if let Some(id) = fight.actors.id(&entry.guid) + && !talents.is_empty() + { + fight.talents.entry(id).or_insert_with(|| talents.to_vec()); } } } diff --git a/crates/openlogs-index/src/builder.rs b/crates/openlogs-index/src/builder.rs index a094b6a..0dc8b04 100644 --- a/crates/openlogs-index/src/builder.rs +++ b/crates/openlogs-index/src/builder.rs @@ -53,6 +53,8 @@ pub struct IndexBuilder { zone_difficulty: u32, /// Spec of each player's latest `COMBATANT_INFO`, by GUID. last_specs: HashMap, + /// Position of each talent list in the index's `talent_sets`. + talent_set_ids: HashMap, u32>, markers: MarkerState, /// Latest bounds per `MAP_CHANGE` map ID; facts about the map, so never reset. map_bounds: BTreeMap, @@ -85,6 +87,7 @@ impl IndexBuilder { zone_instance_id: 0, zone_difficulty: 0, last_specs: HashMap::new(), + talent_set_ids: HashMap::new(), markers: MarkerState::default(), map_bounds: BTreeMap::new(), last_index: 0, @@ -177,11 +180,8 @@ impl IndexBuilder { Event::CombatantInfo(info) => { let known = KnownSpec { spec_id: info.spec_id, - talents: if self.index.flavor == Some(GameFlavor::Forever) { - info.talents().collect() - } else { - Vec::new() - }, + talent_set: (self.index.flavor == Some(GameFlavor::Forever)) + .then(|| self.talent_set(info.talents().collect())), }; if let Some(fight) = &mut self.open { add_combatant(&mut fight.summary.roster, info.guid, &known); @@ -329,6 +329,7 @@ impl IndexBuilder { warnings: self.index.warnings.clone(), fights, provisional, + talent_sets: self.index.talent_sets.clone(), } } @@ -912,6 +913,16 @@ impl IndexBuilder { } } + fn talent_set(&mut self, talents: Vec<(u32, u32)>) -> u32 { + if let Some(&set) = self.talent_set_ids.get(&talents) { + return set; + } + let set = self.index.talent_sets.len() as u32; + self.index.talent_sets.push(talents.clone()); + self.talent_set_ids.insert(talents, set); + set + } + fn list_combat(&mut self, summary: FightSummary) { self.last_combat_end = summary.end_offset; self.index.fights.push(summary); @@ -945,7 +956,7 @@ fn add_combatant(roster: &mut Vec, guid: &str, known: &KnownSpec) { guid: guid.to_string(), name: None, spec_id: known.spec_id, - talents: known.talents.clone(), + talent_set: known.talent_set, }); } } diff --git a/crates/openlogs-index/src/combat.rs b/crates/openlogs-index/src/combat.rs index 3342d9c..a57582c 100644 --- a/crates/openlogs-index/src/combat.rs +++ b/crates/openlogs-index/src/combat.rs @@ -7,11 +7,11 @@ use crate::model::{ COMBAT_QUIET_MICROS, CombatPull, DEAD_ENEMY_MEMORY_MICROS, FightSummary, Outcome, RosterEntry, }; -/// A player's spec and talents from their latest `COMBATANT_INFO`. -#[derive(Debug, Clone, Default)] +/// A player's spec and talent set from their latest `COMBATANT_INFO`. +#[derive(Debug, Clone, Copy, Default)] pub(crate) struct KnownSpec { pub(crate) spec_id: u32, - pub(crate) talents: Vec<(u32, u32)>, + pub(crate) talent_set: Option, } /// A combat pull still going on. @@ -186,7 +186,7 @@ impl OpenCombat { for entry in &mut summary.roster { if let Some(known) = specs.get(&entry.guid) { entry.spec_id = known.spec_id; - entry.talents.clone_from(&known.talents); + entry.talent_set = known.talent_set; } } self.summary @@ -199,7 +199,7 @@ impl OpenCombat { guid: player.guid.to_string(), name: player.name.map(str::to_string), spec_id: 0, - talents: Vec::new(), + talent_set: None, }); } } diff --git a/crates/openlogs-index/src/model.rs b/crates/openlogs-index/src/model.rs index 7f4e926..4a20489 100644 --- a/crates/openlogs-index/src/model.rs +++ b/crates/openlogs-index/src/model.rs @@ -4,7 +4,7 @@ use openlogs_parser::Timestamp; use serde::{Deserialize, Serialize}; /// Bumped whenever the index layout or its rules change; invalidates cached indexes. -pub const INDEX_FORMAT_VERSION: u32 = 18; +pub const INDEX_FORMAT_VERSION: u32 = 19; /// The combat log format this tool is built and tested against. pub const SUPPORTED_LOG_VERSION: u32 = 22; /// Lookback before `ENCOUNTER_START` that belongs to a fight (pre-pots, pre-casts). @@ -130,9 +130,20 @@ pub struct LogIndex { /// still being written: the open run, a left run and the entries after it that may join it. #[serde(default)] pub provisional: Vec, + /// `(node, rank)` talent lists, each once; roster entries refer to them by position. + #[serde(default, skip_serializing_if = "Vec::is_empty")] + pub talent_sets: Vec>, } impl LogIndex { + /// The `(node, rank)` talents of a roster entry; none when the index kept none. + pub fn talents_of(&self, entry: &RosterEntry) -> &[(u32, u32)] { + entry + .talent_set + .and_then(|set| self.talent_sets.get(set as usize)) + .map_or(&[], Vec::as_slice) + } + pub fn empty() -> Self { Self { format_version: INDEX_FORMAT_VERSION, @@ -147,6 +158,7 @@ impl LogIndex { warnings: Vec::new(), fights: Vec::new(), provisional: Vec::new(), + talent_sets: Vec::new(), } } } @@ -300,9 +312,10 @@ pub struct RosterEntry { /// `None` if the player never appeared in a combat event during the fight. pub name: Option, pub spec_id: u32, - /// `(node, rank)` of each talent; kept for Forever only, whose spec comes from them. - #[serde(default, skip_serializing_if = "Vec::is_empty")] - pub talents: Vec<(u32, u32)>, + /// Position of the player's talents in [`LogIndex::talent_sets`]; kept for Forever only, + /// whose spec comes from them. + #[serde(default, skip_serializing_if = "Option::is_none")] + pub talent_set: Option, } /// Display name of a difficulty ID; `None` for unknown IDs, which are shown raw. diff --git a/crates/openlogs-index/tests/combat_pulls.rs b/crates/openlogs-index/tests/combat_pulls.rs index a67f302..c8b99c6 100644 --- a/crates/openlogs-index/tests/combat_pulls.rs +++ b/crates/openlogs-index/tests/combat_pulls.rs @@ -458,7 +458,7 @@ fn talents_of_pulls(index: &openlogs_index::LogIndex) -> Vec> fight .roster .iter() - .map(|entry| (entry.guid.as_str(), entry.talents.clone())) + .map(|entry| (entry.guid.as_str(), index.talents_of(entry).to_vec())) .collect() }) .collect() @@ -475,18 +475,17 @@ fn a_forever_combat_pull_keeps_the_last_logged_talents() { vec![(FAELAN.guid, faelan), (PYRRIN.guid, vec![])], ] ); + assert_eq!( + index.talent_sets.len(), + 1, + "both pulls share one talent set" + ); } #[test] fn a_retail_index_keeps_no_talents() { let index = index_bytes(boss_then_trash(1).as_bytes()); - assert!( - index - .fights - .iter() - .flat_map(|fight| &fight.roster) - .all(|entry| entry.talents.is_empty()) - ); + assert!(index.talent_sets.is_empty()); } #[test] diff --git a/crates/openlogs-index/tests/index_mini.rs b/crates/openlogs-index/tests/index_mini.rs index b8a5360..38f8b8f 100644 --- a/crates/openlogs-index/tests/index_mini.rs +++ b/crates/openlogs-index/tests/index_mini.rs @@ -67,13 +67,13 @@ fn wipe_with_roster_boss_hp_and_prelude() { guid: "Player-4101-8E8C0182".into(), name: Some("Faelan-Emberfall-EU".into()), spec_id: 62, - talents: Vec::new(), + talent_set: None, }, RosterEntry { guid: "Player-4101-77D4A765".into(), name: Some("Pyrrin-Emberfall-EU".into()), spec_id: 105, - talents: Vec::new(), + talent_set: None, }, ] ); diff --git a/crates/openlogs-index/tests/index_runs.rs b/crates/openlogs-index/tests/index_runs.rs index 63009cb..8383e5e 100644 --- a/crates/openlogs-index/tests/index_runs.rs +++ b/crates/openlogs-index/tests/index_runs.rs @@ -121,13 +121,13 @@ fn a_run_is_indexed_with_its_key_its_roster_and_its_prelude() { guid: "Player-4101-8E8C0182".into(), name: Some("Faelan-Emberfall-EU".into()), spec_id: 62, - talents: Vec::new(), + talent_set: None, }, RosterEntry { guid: "Player-4101-77D4A765".into(), name: Some("Pyrrin-Emberfall-EU".into()), spec_id: 105, - talents: Vec::new(), + talent_set: None, }, ] ); diff --git a/crates/openlogs-wasm/src/engine.rs b/crates/openlogs-wasm/src/engine.rs index ca46724..b1a6500 100644 --- a/crates/openlogs-wasm/src/engine.rs +++ b/crates/openlogs-wasm/src/engine.rs @@ -2,7 +2,7 @@ use std::collections::BTreeSet; use openlogs_analysis::{ Actors, Fight, LANDED_MATCH_MS, assign_talent_specs, infer_classes, load_fight_slice, - load_fight_slice_with, + load_fight_slice_with, note_roster_talents, }; use openlogs_gamedata::{ChannelSpells, Curated, DungeonTable, SpellClasses, TalentTrees}; use openlogs_index::{DataGame, FightSummary, GameFlavor, Indexer, LogIndex}; @@ -199,7 +199,7 @@ impl Engine { ) -> Result<(), String> { let summary = self.summary(fight_index)?.clone(); let mut fight = load_fight_slice(part, base_offset, &summary); - ready_for_reports(&mut fight, self.index.flavor, self.tables()); + ready_for_reports(&mut fight, &summary, &self.index, self.tables()); self.fights.retain(|pulled| pulled.index != fight_index); self.fights.insert( 0, @@ -251,7 +251,7 @@ impl Engine { let mut fight = load_fight_slice_with(part, base_offset, summary, pass.actors.carried_over()); let tables = self.spell_tables.of_flavor(self.index.flavor); - ready_for_reports(&mut fight, self.index.flavor, tables); + ready_for_reports(&mut fight, summary, &self.index, tables); let mut cuts = PullCuts::new(&fight); for command in &mut pass.commands { command.add(fight_index, &fight, &self.curated, &mut cuts); @@ -515,9 +515,15 @@ struct LoadedPull { summary: FightSummary, } -fn ready_for_reports(fight: &mut Fight, flavor: Option, tables: &GameTables) { - fight.flavor = flavor; +fn ready_for_reports( + fight: &mut Fight, + summary: &FightSummary, + index: &LogIndex, + tables: &GameTables, +) { + fight.flavor = index.flavor; if !tables.talent_trees.is_empty() { + note_roster_talents(fight, summary, index); assign_talent_specs(fight, &tables.talent_trees); } infer_classes(fight, &tables.spell_classes);