diff --git a/crates/openlogs-analysis/src/fight.rs b/crates/openlogs-analysis/src/fight.rs index fedf9bc..d408e95 100644 --- a/crates/openlogs-analysis/src/fight.rs +++ b/crates/openlogs-analysis/src/fight.rs @@ -1,6 +1,6 @@ use std::collections::{BTreeMap, BTreeSet}; -use openlogs_index::{MapBounds, Outcome}; +use openlogs_index::{GameFlavor, MapBounds, Outcome}; pub use openlogs_parser::{AuraAction, AuraType, DamageVia}; use crate::actors::{ActorId, ActorKind, Actors, NOBODY}; @@ -56,6 +56,9 @@ pub struct Fight { /// The index's roster: players with `COMBATANT_INFO` in a boss pull or run, the players /// who fought in a combat pull. pub roster: BTreeSet, + /// The log's game, which decides how player names are shown; `None` until the caller + /// that knows the log sets it. + pub flavor: Option, } impl Fight { diff --git a/crates/openlogs-analysis/src/load.rs b/crates/openlogs-analysis/src/load.rs index e7de0df..e920a2e 100644 --- a/crates/openlogs-analysis/src/load.rs +++ b/crates/openlogs-analysis/src/load.rs @@ -260,6 +260,7 @@ impl FightBuilder { heal_grants: Vec::new(), delayed_hits: Vec::new(), roster: BTreeSet::new(), + flavor: None, }, last_power: HashMap::new(), last_t: i32::MIN, diff --git a/crates/openlogs-analysis/tests/support/mod.rs b/crates/openlogs-analysis/tests/support/mod.rs index 34059eb..d283071 100644 --- a/crates/openlogs-analysis/tests/support/mod.rs +++ b/crates/openlogs-analysis/tests/support/mod.rs @@ -48,6 +48,7 @@ impl FightBuilder { heal_grants: Vec::new(), delayed_hits: Vec::new(), roster: BTreeSet::new(), + flavor: None, }, } } diff --git a/crates/openlogs-index/src/model.rs b/crates/openlogs-index/src/model.rs index 0d6710e..da15118 100644 --- a/crates/openlogs-index/src/model.rs +++ b/crates/openlogs-index/src/model.rs @@ -63,6 +63,16 @@ impl GameFlavor { pub fn describe(flavor: Option) -> String { flavor.map_or_else(|| "Unknown game".to_string(), Self::name) } + + /// A player's name as shown, from the logged `Name-Realm-Region`. A Forever name may itself + /// contain `-` ("Ravel-Ashwood-Normal-EU" is "Ravel Ashwood"); elsewhere the first part. + pub fn player_name(flavor: Option, logged: &str) -> String { + let parts: Vec<&str> = logged.split('-').collect(); + match flavor { + Some(Self::Forever) if parts.len() > 2 => parts[..parts.len() - 2].join(" "), + _ => parts[0].to_string(), + } + } } /// Difficulty ID of Mythic+ (Mythic Keystone) dungeons; run entries carry it too. diff --git a/crates/openlogs-index/tests/player_names.rs b/crates/openlogs-index/tests/player_names.rs new file mode 100644 index 0000000..2d90e49 --- /dev/null +++ b/crates/openlogs-index/tests/player_names.rs @@ -0,0 +1,25 @@ +use openlogs_index::GameFlavor; + +#[test] +fn a_forever_player_name_is_everything_before_realm_and_region() { + let forever = Some(GameFlavor::Forever); + assert_eq!( + GameFlavor::player_name(forever, "Ravel-Ashwood-Normal-EU"), + "Ravel Ashwood" + ); + assert_eq!( + GameFlavor::player_name(forever, "Rexxar-Normal-EU"), + "Rexxar" + ); + assert_eq!(GameFlavor::player_name(forever, "Wolf"), "Wolf"); +} + +#[test] +fn a_retail_player_name_is_its_first_part() { + for flavor in [Some(GameFlavor::Retail), None] { + assert_eq!( + GameFlavor::player_name(flavor, "Faelan-Emberfall-EU"), + "Faelan" + ); + } +} diff --git a/crates/openlogs-service/src/scope_dto.rs b/crates/openlogs-service/src/scope_dto.rs index 871f916..2f884f5 100644 --- a/crates/openlogs-service/src/scope_dto.rs +++ b/crates/openlogs-service/src/scope_dto.rs @@ -3,6 +3,7 @@ use openlogs_analysis::{ FilterOption, MissType, Misses, OptionValue, RowKey, Scope, ScopeMetric, Side, SpellId, UnitRef, }; +use openlogs_index::GameFlavor; use serde::{Deserialize, Serialize}; use crate::overview_dto::{PlayerRef, player_ref}; @@ -394,10 +395,6 @@ impl DimensionDto { } } -fn short(name: &str) -> String { - name.split('-').next().unwrap_or(name).to_string() -} - fn instance_number(fight: &Fight, id: ActorId) -> u32 { let name = &fight.actors.get(id).name; fight @@ -416,7 +413,7 @@ pub(crate) fn unit_name(fight: &Fight, unit: &UnitRef) -> (String, Option) .get(*id) .name .as_deref() - .map(short) + .map(|name| GameFlavor::player_name(fight.flavor, name)) .unwrap_or_default(), None, ), diff --git a/crates/openlogs-service/src/test_fight.rs b/crates/openlogs-service/src/test_fight.rs index 8deea61..52617de 100644 --- a/crates/openlogs-service/src/test_fight.rs +++ b/crates/openlogs-service/src/test_fight.rs @@ -48,6 +48,7 @@ pub fn fight(actors: Actors, mut events: Vec) -> Fight { heal_grants: Vec::new(), delayed_hits: Vec::new(), roster: BTreeSet::new(), + flavor: None, } } diff --git a/crates/openlogs-wasm/src/engine.rs b/crates/openlogs-wasm/src/engine.rs index 13a7dab..85052c3 100644 --- a/crates/openlogs-wasm/src/engine.rs +++ b/crates/openlogs-wasm/src/engine.rs @@ -4,7 +4,7 @@ use openlogs_analysis::{ Actors, Fight, LANDED_MATCH_MS, infer_classes, load_fight_slice, load_fight_slice_with, }; use openlogs_gamedata::{ChannelSpells, Curated, DungeonTable, SpellClasses}; -use openlogs_index::{FightSummary, Indexer, LogIndex}; +use openlogs_index::{FightSummary, GameFlavor, Indexer, LogIndex}; use openlogs_service::auras_dto::AuraKindDto; use openlogs_service::casts_dto::CastsReportDto; use openlogs_service::log_dto::log_view; @@ -159,7 +159,7 @@ impl Engine { ) -> Result<(), String> { let summary = self.summary(fight_index)?.clone(); let mut fight = load_fight_slice(part, base_offset, &summary); - infer_classes(&mut fight, &self.spell_classes); + ready_for_reports(&mut fight, self.index.flavor, &self.spell_classes); self.fights.retain(|pulled| pulled.index != fight_index); self.fights.insert( 0, @@ -210,7 +210,7 @@ impl Engine { let summary = summary_of(&self.index, fight_index)?; let mut fight = load_fight_slice_with(part, base_offset, summary, pass.actors.carried_over()); - infer_classes(&mut fight, &self.spell_classes); + ready_for_reports(&mut fight, self.index.flavor, &self.spell_classes); let mut cuts = PullCuts::new(&fight); for command in &mut pass.commands { command.add(fight_index, &fight, &self.curated, &mut cuts); @@ -474,6 +474,11 @@ struct LoadedPull { summary: FightSummary, } +fn ready_for_reports(fight: &mut Fight, flavor: Option, spell_classes: &SpellClasses) { + fight.flavor = flavor; + infer_classes(fight, spell_classes); +} + fn summary_of(index: &LogIndex, fight_index: u32) -> Result<&FightSummary, String> { index .fights diff --git a/crates/openlogs-wasm/tests/engine.rs b/crates/openlogs-wasm/tests/engine.rs index cdd1eff..2ceb80d 100644 --- a/crates/openlogs-wasm/tests/engine.rs +++ b/crates/openlogs-wasm/tests/engine.rs @@ -965,3 +965,25 @@ fn opening_a_forever_open_world_log_lists_its_combat_pull() { ); assert!(report["total"].as_u64().unwrap() > 0); } + +#[test] +fn a_forever_log_names_its_players_in_full() { + const OPEN_WORLD: &str = + include_str!("../../openlogs-index/tests/fixtures/forever_open_world.txt"); + let (mut engine, view) = open(OPEN_WORLD); + let pull = view["fights"][0]["index"].as_u64().unwrap() as u32; + load(&mut engine, OPEN_WORLD, pull); + let scope = json!({ "perspective": "friendly", "source": [], "target": [], "ability": [] }); + let breakdown = call( + &engine, + "breakdown_report", + json!({ "fightIndex": pull, "filter": whole_pull(), "scope": scope, "metric": "damageDone", "group": "source" }), + ); + let names: Vec<_> = breakdown["rows"] + .as_array() + .unwrap() + .iter() + .map(|row| row["name"].as_str().unwrap()) + .collect(); + assert!(names.contains(&"Ravel Ashwood"), "{names:?}"); +} diff --git a/ui/src/components/overview/players.test.ts b/ui/src/components/overview/players.test.ts new file mode 100644 index 0000000..6dead98 --- /dev/null +++ b/ui/src/components/overview/players.test.ts @@ -0,0 +1,14 @@ +import { afterEach, describe, expect, it } from 'vitest'; +import { setCurrentGame } from '../../currentGame'; +import { shortName } from './players'; + +describe('player names', () => { + afterEach(() => setCurrentGame(null)); + + it('shows a Forever name in full and a retail name by its first part', () => { + setCurrentGame({ kind: 'forever' }); + expect([shortName('Ravel-Ashwood-Normal-EU'), shortName('Wolf')]).toEqual(['Ravel Ashwood', 'Wolf']); + setCurrentGame({ kind: 'retail' }); + expect(shortName('Faelan-Emberfall-EU')).toBe('Faelan'); + }); +}); diff --git a/ui/src/components/overview/players.ts b/ui/src/components/overview/players.ts index a8f5bf9..4cd06e0 100644 --- a/ui/src/components/overview/players.ts +++ b/ui/src/components/overview/players.ts @@ -1,12 +1,18 @@ import type { PlayerRef, QuickOverview, Role } from '../../api/types'; +import { currentGame } from '../../currentGame'; import { formatEventTime } from '../../i18n/format'; import { t } from '../../i18n/i18n'; export const ROLE_ORDER: (Role | null)[] = ['tank', 'healer', 'damage', null]; -/** "Faelan-Emberfall-EU" → "Faelan"; character names cannot contain hyphens. */ +/** + * A player's name from the logged `Name-Realm-Region`: "Faelan-Emberfall-EU" → "Faelan". A Forever name + * may itself contain `-`: "Ravel-Ashwood-Normal-EU" → "Ravel Ashwood". Keep in step with the service's + * `GameFlavor::player_name`. + */ export function shortName(name: string): string { - return name.split('-')[0]; + const parts = name.split('-'); + return currentGame()?.kind === 'forever' && parts.length > 2 ? parts.slice(0, -2).join(' ') : parts[0]; } export function classColor(token: string | null): string { diff --git a/ui/src/currentGame.ts b/ui/src/currentGame.ts new file mode 100644 index 0000000..365f198 --- /dev/null +++ b/ui/src/currentGame.ts @@ -0,0 +1,12 @@ +import type { Game } from './api/types'; + +let game: Game | null = null; + +/** The game of the open log, which decides how names read; the store keeps it in step. */ +export function currentGame(): Game | null { + return game; +} + +export function setCurrentGame(next: Game | null) { + game = next; +} diff --git a/ui/src/store.test.ts b/ui/src/store.test.ts index 3a2276e..2bef106 100644 --- a/ui/src/store.test.ts +++ b/ui/src/store.test.ts @@ -21,6 +21,7 @@ import { targetDetailFixture, } from './test/reportFixtures'; import { eventsPageFixture, timelineFixture } from './test/viewFixtures'; +import { currentGame } from './currentGame'; import { type FightTab, initialState, useApp } from './store'; vi.mock('./api/client', () => ({ @@ -133,6 +134,15 @@ describe('logs and pulls', () => { expect(useApp.getState().view).toEqual({ kind: 'start' }); }); + it('opening a log sets the game its names follow', async () => { + const forever: LogView = { ...LOG, game: { kind: 'forever' } }; + vi.mocked(api.openLog).mockResolvedValueOnce(forever); + await useApp.getState().openLog(chosen(forever)); + expect(currentGame()).toEqual({ kind: 'forever' }); + await useApp.getState().openLog(chosen(LOG)); + expect(currentGame()).toEqual(LOG.game); + }); + it('shows the indexing progress while a log opens', async () => { const indexed = deferred(); let report: (bytesRead: number, totalBytes: number) => void = () => {}; diff --git a/ui/src/store.ts b/ui/src/store.ts index ba3c939..74927f6 100644 --- a/ui/src/store.ts +++ b/ui/src/store.ts @@ -53,6 +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 { followUpdate, type LiveNotice, liveNoticeOf } from './pulls/follow'; import { effectiveView, lanesOf } from './reportViews'; import { type FilterTab, isFilterTab, SIDES } from './scopeSides'; @@ -1886,3 +1887,7 @@ export const useApp = create()(derivingScope((set, get) => ({ get().setReplayTime(ms); }, }))); + +useApp.subscribe((state, previous) => { + if (state.log !== previous.log) setCurrentGame(state.log?.game ?? null); +});