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
12 changes: 7 additions & 5 deletions crates/openlogs-service/src/auras_dto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use openlogs_analysis::{
use serde::{Deserialize, Serialize};

use crate::overview_dto::{PlayerRef, SpellRef};
use crate::refs::Refs;
use crate::refs::{Refs, shown};
use crate::scope_dto::{DimensionDto, RowKeyDto, key_dto};

#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)]
Expand Down Expand Up @@ -92,9 +92,11 @@ pub struct AurasReportDto {
pub spells: BTreeMap<SpellId, SpellRef>,
}

fn holder_dto(refs: &mut Refs, holder: &AuraHolder) -> AuraHolderDto {
fn holder_dto(fight: &Fight, refs: &mut Refs, holder: &AuraHolder) -> AuraHolderDto {
AuraHolderDto {
name: holder.name.clone(),
name: holder
.player
.map_or_else(|| holder.name.clone(), |p| shown(fight, p, &holder.name)),
player: holder.player.map(|p| refs.player(p)),
}
}
Expand Down Expand Up @@ -127,15 +129,15 @@ pub fn auras_report_dto(
name,
spell_id: refs.spell(fight, row.spell),
spell_ids: row.spells.iter().map(|&s| refs.spell(fight, s)).collect(),
holder: row.holder.as_ref().map(|h| holder_dto(&mut refs, h)),
holder: row.holder.as_ref().map(|h| holder_dto(fight, &mut refs, h)),
sources: row.sources.iter().map(|&p| refs.player(p)).collect(),
applications: row.applications,
uptime: row.uptime,
lanes: row
.lanes
.iter()
.map(|lane| AuraLaneDto {
holder: holder_dto(&mut refs, &lane.holder),
holder: holder_dto(fight, &mut refs, &lane.holder),
spell_id: refs.spell(fight, lane.spell),
spell_ids: lane.spells.iter().map(|&s| refs.spell(fight, s)).collect(),
sources: lane.sources.iter().map(|&p| refs.player(p)).collect(),
Expand Down
2 changes: 1 addition & 1 deletion crates/openlogs-service/src/compare_dto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ mod tests {
let faelan = &dto.players[0];
assert_eq!(
(faelan.player.name.as_str(), faelan.player.spec_id),
("Faelan-Emberfall-EU", Some(62))
("Faelan", Some(62))
);
assert_eq!(
faelan.player.actor_id, faelan_a,
Expand Down
36 changes: 15 additions & 21 deletions crates/openlogs-service/src/detail_dto.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::collections::{BTreeMap, BTreeSet};
use std::collections::BTreeMap;

use openlogs_analysis::{
AbilityDetail, ActorId, ActorKind, EnemyGroup, Fight, SpellId, TargetDetail,
Expand All @@ -7,6 +7,7 @@ use serde::Serialize;

use crate::overview_dto::{PlayerRef, player_ref};
use crate::player_dto::MetricDto;
use crate::refs::{logged_name, shown};
use crate::report_dto::PlayerAmount;

#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize)]
Expand Down Expand Up @@ -50,8 +51,8 @@ pub struct AbilityDetailDto {
pub dead: Vec<[i32; 2]>,
/// Names of the units in `hits`, keyed by actor id.
pub target_names: BTreeMap<ActorId, String>,
/// Names in `target_names` that belong to players; only these are shortened in the UI.
pub player_targets: Vec<String>,
/// The shown name of each player in `target_names`; other units are shown as logged.
pub shown_names: BTreeMap<String, String>,
}

pub fn ability_detail_dto(
Expand All @@ -60,25 +61,15 @@ pub fn ability_detail_dto(
metric: MetricDto,
) -> AbilityDetailDto {
let info = fight.spells.get(&detail.spell);
let target_names = detail
let target_names: BTreeMap<ActorId, String> = detail
.hits
.iter()
.map(|hit| {
let actor = fight.actors.get(hit.target);
(
hit.target,
actor.name.clone().unwrap_or_else(|| actor.guid.clone()),
)
})
.map(|hit| (hit.target, logged_name(fight, hit.target).to_owned()))
.collect();
let player_targets: BTreeSet<String> = detail
.hits
let shown_names = target_names
.iter()
.filter(|hit| fight.actors.get(hit.target).kind == ActorKind::Player)
.map(|hit| {
let actor = fight.actors.get(hit.target);
actor.name.clone().unwrap_or_else(|| actor.guid.clone())
})
.filter(|&(&id, _)| fight.actors.get(id).kind == ActorKind::Player)
.map(|(&id, logged)| (logged.clone(), shown(fight, id, logged)))
.collect();
AbilityDetailDto {
player: player_ref(fight, detail.player),
Expand Down Expand Up @@ -117,7 +108,7 @@ pub fn ability_detail_dto(
uptime: detail.uptime,
dead: detail.dead.iter().map(|&(a, b)| [a, b]).collect(),
target_names,
player_targets: player_targets.into_iter().collect(),
shown_names,
}
}

Expand Down Expand Up @@ -240,7 +231,7 @@ mod tests {
use crate::test_fight::{PLAYER_FLAGS, fight, heal_event, unit};

#[test]
fn only_players_are_listed_as_player_targets() {
fn only_player_targets_get_a_shown_name() {
let mut actors = Actors::new();
let priest = unit(&mut actors, "Player-1", "Ulvara-Emberfall-EU", PLAYER_FLAGS);
actors.set_spec(priest, 256);
Expand All @@ -265,7 +256,10 @@ mod tests {
)
.unwrap();
let dto = ability_detail_dto(&fight, &detail, MetricDto::Healing);
assert_eq!(dto.player_targets, vec!["Faelan-Emberfall-EU".to_string()]);
assert_eq!(
dto.shown_names,
BTreeMap::from([("Faelan-Emberfall-EU".to_string(), "Faelan".to_string())])
);
assert!(dto.target_names.values().any(|name| name == "Ky-Veth Ward"));
}
}
2 changes: 1 addition & 1 deletion crates/openlogs-service/src/meter_dto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ mod tests {
);
assert_eq!(
json["units"],
json!({ hunter.to_string(): "Brannoc-Emberfall-EU", wolf.to_string(): "Wolf" })
json!({ hunter.to_string(): "Brannoc", wolf.to_string(): "Wolf" })
);
let taken = meter(&fight, &filter, MeterCategory::DamageTaken, Some(hunter));
assert_eq!(
Expand Down
21 changes: 10 additions & 11 deletions crates/openlogs-service/src/overview_dto.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
use std::collections::BTreeMap;

use openlogs_analysis::{
ActorId, ContextItem, ContextState, Death, DeathContext, Fight, Hit, NO_SPELL, NOBODY,
PhaseKind, QuickOverview, SpellId, listed_player,
ActorId, ContextItem, ContextState, Death, DeathContext, Fight, Hit, NO_SPELL, PhaseKind,
QuickOverview, SpellId, listed_player,
};
use openlogs_gamedata::{ConsumableKind, CooldownCategory, Curated, Role};
use serde::Serialize;

use crate::refs::name_of;

#[derive(Debug, Clone, PartialEq, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct QuickOverviewDto {
Expand Down Expand Up @@ -265,11 +267,6 @@ fn note_spell(
spells.entry(id).or_insert(SpellRef { name });
}

fn actor_name(fight: &Fight, id: ActorId) -> String {
let actor = fight.actors.get(id);
actor.name.clone().unwrap_or_else(|| actor.guid.clone())
}

/// The death context without absorb shields: the overview's death list and the player page's
/// death sentence do not show rotational shields; only the death recap lists them.
pub(crate) fn without_shields(curated: &Curated, context: &[DeathContext]) -> Vec<DeathContext> {
Expand Down Expand Up @@ -359,7 +356,7 @@ pub(crate) fn hit_dto(
HitDto {
t: hit.t,
spell_id: hit.spell,
source_name: (hit.source != NOBODY).then(|| actor_name(fight, hit.source)),
source_name: name_of(fight, hit.source),
amount: hit.amount,
overkill: hit.overkill,
environmental: hit.environmental,
Expand Down Expand Up @@ -391,7 +388,7 @@ pub fn death_dto(
let context = context_dtos(fight, curated, context, spells);
DeathDto {
player: death.player,
player_name: actor_name(fight, death.player),
player_name: name_of(fight, death.player).unwrap_or_default(),
t: death.t,
killing_blow,
damage_last_5s,
Expand Down Expand Up @@ -574,7 +571,7 @@ pub fn player_ref(fight: &Fight, id: ActorId) -> PlayerRef {
let class = actor.class().and_then(openlogs_gamedata::class);
PlayerRef {
actor_id: id,
name: actor.name.clone().unwrap_or_else(|| actor.guid.clone()),
name: name_of(fight, id).unwrap_or_default(),
spec_id: actor.spec_id,
spec_name: crate::player_dto::spec_name(fight, id),
spec_icon: spec.map(|s| s.icon.to_string()),
Expand All @@ -586,7 +583,9 @@ pub fn player_ref(fight: &Fight, id: ActorId) -> PlayerRef {

#[cfg(test)]
mod tests {
use openlogs_analysis::{Actors, Attribution, Event, EventKind, ReportFilter, SpellInfo};
use openlogs_analysis::{
Actors, Attribution, Event, EventKind, NOBODY, ReportFilter, SpellInfo,
};

use super::*;
use crate::test_fight::{PLAYER_FLAGS, fight, unit};
Expand Down
5 changes: 2 additions & 3 deletions crates/openlogs-service/src/player_dto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use serde::{Deserialize, Serialize};
use crate::overview_dto::{
ContextDto, HitDto, PlayerRef, SpellRef, context_dtos, player_ref, without_shields,
};
use crate::refs::shown_name;
use crate::report_dto::{
AbilityRowDto, AttributionDto, BuffShareDto, Names, PlayerAmount, TakenSpellDto, TargetShareDto,
};
Expand Down Expand Up @@ -314,9 +315,7 @@ pub fn player_detail_dto(
killing_blow: death.killing_blow.map(|hit| HitDto {
t: hit.t,
spell_id: names.spell(hit.spell),
source_name: (hit.source != NOBODY)
.then(|| fight.actors.get(hit.source).name.clone())
.flatten(),
source_name: shown_name(fight, hit.source),
amount: hit.amount,
overkill: hit.overkill,
environmental: hit.environmental,
Expand Down
2 changes: 1 addition & 1 deletion crates/openlogs-service/src/recap_dto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ mod tests {
serde_json::Value::Null
);
assert_eq!(death["events"][1]["sourceName"], "Stormstream Totem");
assert_eq!(death["events"][1]["sourceOwnerName"], "Mulgar-Emberfall-EU");
assert_eq!(death["events"][1]["sourceOwnerName"], "Mulgar");
assert_eq!(
death["lethalBurst"],
serde_json::json!({ "spellId": 1302982, "count": 2, "windowMs": 1009 })
Expand Down
60 changes: 55 additions & 5 deletions crates/openlogs-service/src/refs.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::collections::BTreeMap;

use openlogs_analysis::{ActorId, Fight, NOBODY, SpellId};
use openlogs_analysis::{ActorId, ActorKind, Fight, NOBODY, SpellId};
use openlogs_index::GameFlavor;

use crate::overview_dto::{PlayerRef, SpellRef, player_ref};

Expand Down Expand Up @@ -39,9 +40,58 @@ impl Refs {
}
}

/// The name the UI shows for a unit's `logged` name: a player's as its game shows it, any other
/// unit's as logged.
pub(crate) fn shown(fight: &Fight, id: ActorId, logged: &str) -> String {
if fight.actors.get(id).kind == ActorKind::Player {
GameFlavor::player_name(fight.flavor, logged)
} else {
logged.to_owned()
}
}

/// The shown name; `None` when the log named nobody or a unit without a name.
pub(crate) fn shown_name(fight: &Fight, id: ActorId) -> Option<String> {
if id == NOBODY {
return None;
}
let logged = fight.actors.get(id).name.as_deref()?;
Some(shown(fight, id, logged))
}

/// The logged name, or the GUID of a unit without a name.
pub(crate) fn logged_name(fight: &Fight, id: ActorId) -> &str {
let actor = fight.actors.get(id);
actor.name.as_deref().unwrap_or(&actor.guid)
}

/// The shown name, or the shown GUID of a unit without a name; `None` for nobody.
pub(crate) fn name_of(fight: &Fight, id: ActorId) -> Option<String> {
(id != NOBODY).then(|| {
let actor = fight.actors.get(id);
actor.name.clone().unwrap_or_else(|| actor.guid.clone())
})
(id != NOBODY).then(|| shown(fight, id, logged_name(fight, id)))
}

#[cfg(test)]
mod tests {
use openlogs_analysis::Actors;

use super::*;
use crate::test_fight::{PLAYER_FLAGS, fight, unit};

#[test]
fn players_are_shown_by_their_game_and_other_units_as_logged() {
let mut actors = Actors::new();
let ravel = unit(
&mut actors,
"Player-1",
"Ravel-Ashwood-Normal-EU",
PLAYER_FLAGS,
);
let ward = unit(&mut actors, "Creature-0-1-1-1-9-01", "Ky-Veth Ward", 0xa18);
let mut fight = fight(actors, Vec::new());
fight.flavor = Some(GameFlavor::Forever);

assert_eq!(player_ref(&fight, ravel).name, "Ravel Ashwood");
assert_eq!(name_of(&fight, ravel).as_deref(), Some("Ravel Ashwood"));
assert_eq!(name_of(&fight, ward).as_deref(), Some("Ky-Veth Ward"));
}
}
19 changes: 14 additions & 5 deletions crates/openlogs-service/src/replay_dto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use openlogs_index::MapBounds;
use serde::Serialize;

use crate::overview_dto::{PhaseDto, PhaseKindDto, PlayerRef, SpellRef};
use crate::refs::Refs;
use crate::refs::{Refs, shown};

#[derive(Debug, Clone, PartialEq, Serialize)]
#[serde(rename_all = "camelCase")]
Expand Down Expand Up @@ -272,7 +272,7 @@ pub fn replay_dto(fight: &Fight, replay: &Replay, advanced_logging: bool) -> Rep
duration_ms: replay.duration_ms,
roster,
spells,
units: replay.units.iter().map(unit_dto).collect(),
units: replay.units.iter().map(|u| unit_dto(fight, u)).collect(),
tracks: replay.tracks.iter().map(track_dto).collect(),
health: replay.health.iter().map(health_dto).collect(),
power: replay
Expand Down Expand Up @@ -340,10 +340,10 @@ pub fn replay_dto(fight: &Fight, replay: &Replay, advanced_logging: bool) -> Rep
}
}

fn unit_dto(unit: &ReplayUnit) -> ReplayUnitDto {
fn unit_dto(fight: &Fight, unit: &ReplayUnit) -> ReplayUnitDto {
ReplayUnitDto {
actor: unit.actor,
name: unit.name.clone(),
name: shown(fight, unit.actor, &unit.name),
kind: match unit.kind {
UnitKind::Player => UnitKindDto::Player,
UnitKind::Pet => UnitKindDto::Pet,
Expand Down Expand Up @@ -591,7 +591,16 @@ mod tests {

assert_eq!(json["advancedLogging"], true);
assert_eq!(json["encounterId"], 3492);
assert_eq!(json["roster"][0]["name"], "Faelan-Emberfall-EU");
assert_eq!(json["roster"][0]["name"], "Faelan");
let unit_name = |actor: ActorId| {
dto.units
.iter()
.find(|u| u.actor == actor)
.unwrap()
.name
.clone()
};
assert_eq!(unit_name(mage), "Faelan");
assert_eq!(json["spells"]["44425"]["name"], "Arcane Barrage");
assert_eq!(json["casts"][0]["spellId"], 44425);
assert_eq!(
Expand Down
13 changes: 2 additions & 11 deletions crates/openlogs-service/src/scope_dto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ 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};
use crate::refs::shown_name;

#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
Expand Down Expand Up @@ -407,16 +407,7 @@ fn instance_number(fight: &Fight, id: ActorId) -> u32 {

pub(crate) fn unit_name(fight: &Fight, unit: &UnitRef) -> (String, Option<u32>) {
match unit {
UnitRef::Player(id) => (
fight
.actors
.get(*id)
.name
.as_deref()
.map(|name| GameFlavor::player_name(fight.flavor, name))
.unwrap_or_default(),
None,
),
UnitRef::Player(id) => (shown_name(fight, *id).unwrap_or_default(), None),
UnitRef::Pet { name, .. } | UnitRef::Unit(name) => (name.clone(), None),
UnitRef::Instance(id) => (
fight.actors.get(*id).name.clone().unwrap_or_default(),
Expand Down
Loading
Loading