Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion crates/openlogs-analysis/src/fight.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -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<ActorId>,
/// The log's game, which decides how player names are shown; `None` until the caller
/// that knows the log sets it.
pub flavor: Option<GameFlavor>,
}

impl Fight {
Expand Down
1 change: 1 addition & 0 deletions crates/openlogs-analysis/src/load.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions crates/openlogs-analysis/tests/support/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ impl FightBuilder {
heal_grants: Vec::new(),
delayed_hits: Vec::new(),
roster: BTreeSet::new(),
flavor: None,
},
}
}
Expand Down
10 changes: 10 additions & 0 deletions crates/openlogs-index/src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,16 @@ impl GameFlavor {
pub fn describe(flavor: Option<Self>) -> 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<Self>, 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.
Expand Down
25 changes: 25 additions & 0 deletions crates/openlogs-index/tests/player_names.rs
Original file line number Diff line number Diff line change
@@ -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"
);
}
}
7 changes: 2 additions & 5 deletions crates/openlogs-service/src/scope_dto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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
Expand All @@ -416,7 +413,7 @@ pub(crate) fn unit_name(fight: &Fight, unit: &UnitRef) -> (String, Option<u32>)
.get(*id)
.name
.as_deref()
.map(short)
.map(|name| GameFlavor::player_name(fight.flavor, name))
.unwrap_or_default(),
None,
),
Expand Down
1 change: 1 addition & 0 deletions crates/openlogs-service/src/test_fight.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ pub fn fight(actors: Actors, mut events: Vec<Event>) -> Fight {
heal_grants: Vec::new(),
delayed_hits: Vec::new(),
roster: BTreeSet::new(),
flavor: None,
}
}

Expand Down
11 changes: 8 additions & 3 deletions crates/openlogs-wasm/src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -474,6 +474,11 @@ struct LoadedPull {
summary: FightSummary,
}

fn ready_for_reports(fight: &mut Fight, flavor: Option<GameFlavor>, spell_classes: &SpellClasses) {
fight.flavor = flavor;
infer_classes(fight, spell_classes);
}

fn summary_of(index: &LogIndex, fight_index: u32) -> Result<&FightSummary, String> {
index
.fights
Expand Down
22 changes: 22 additions & 0 deletions crates/openlogs-wasm/tests/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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:?}");
}
14 changes: 14 additions & 0 deletions ui/src/components/overview/players.test.ts
Original file line number Diff line number Diff line change
@@ -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');
});
});
10 changes: 8 additions & 2 deletions ui/src/components/overview/players.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
12 changes: 12 additions & 0 deletions ui/src/currentGame.ts
Original file line number Diff line number Diff line change
@@ -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;
}
10 changes: 10 additions & 0 deletions ui/src/store.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => ({
Expand Down Expand Up @@ -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<LogView>();
let report: (bytesRead: number, totalBytes: number) => void = () => {};
Expand Down
5 changes: 5 additions & 0 deletions ui/src/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -1886,3 +1887,7 @@ export const useApp = create<Store>()(derivingScope((set, get) => ({
get().setReplayTime(ms);
},
})));

useApp.subscribe((state, previous) => {
if (state.log !== previous.log) setCurrentGame(state.log?.game ?? null);
});
Loading