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
3 changes: 2 additions & 1 deletion crates/openlogs-analysis/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
19 changes: 13 additions & 6 deletions crates/openlogs-analysis/src/load.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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());
}
}
}
Expand Down
13 changes: 4 additions & 9 deletions crates/openlogs-gamedata/src/boss_portraits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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,
}
Expand Down Expand Up @@ -147,10 +149,3 @@ fn read_portrait_files(manifest: &[u8]) -> Result<HashMap<u32, String>, BossPort
}
Ok(files)
}

fn column(headers: &csv::StringRecord, name: &'static str) -> Result<usize, BossPortraitError> {
headers
.iter()
.position(|header| header == name)
.ok_or(BossPortraitError::MissingColumn(name))
}
13 changes: 4 additions & 9 deletions crates/openlogs-gamedata/src/channel_spells.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@ 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;

#[derive(Debug, Error)]
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),
}
Expand Down Expand Up @@ -115,10 +117,3 @@ impl ChannelSpells {
Ok(Self { ids })
}
}

fn column(headers: &csv::StringRecord, name: &'static str) -> Result<usize, ChannelSpellError> {
headers
.iter()
.position(|header| header == name)
.ok_or(ChannelSpellError::MissingColumn(name))
}
16 changes: 16 additions & 0 deletions crates/openlogs-gamedata/src/csv_columns.rs
Original file line number Diff line number Diff line change
@@ -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<usize, MissingColumn> {
headers
.iter()
.position(|header| header == name)
.ok_or(MissingColumn(name))
}
13 changes: 4 additions & 9 deletions crates/openlogs-gamedata/src/dungeons.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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")]
Expand Down Expand Up @@ -255,10 +257,3 @@ fn time_limits(criteria: [u32; 3]) -> Vec<u32> {
}
limits
}

fn column(headers: &csv::StringRecord, name: &'static str) -> Result<usize, DungeonTableError> {
headers
.iter()
.position(|header| header == name)
.ok_or(DungeonTableError::MissingColumn(name))
}
2 changes: 2 additions & 0 deletions crates/openlogs-gamedata/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

mod boss_portraits;
mod channel_spells;
mod csv_columns;
mod curated;
mod download;
mod dungeons;
Expand All @@ -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,
Expand Down
13 changes: 4 additions & 9 deletions crates/openlogs-gamedata/src/map_art.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,17 @@ 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;

#[derive(Debug, Error)]
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")]
Expand Down Expand Up @@ -269,10 +271,3 @@ fn read_pins(csv: &[u8]) -> Result<BTreeMap<u32, BossPin>, MapArtError> {
}
Ok(pins)
}

fn column(headers: &csv::StringRecord, name: &'static str) -> Result<usize, MapArtError> {
headers
.iter()
.position(|header| header == name)
.ok_or(MapArtError::MissingColumn(name))
}
13 changes: 4 additions & 9 deletions crates/openlogs-gamedata/src/spell_classes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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}")]
Expand Down Expand Up @@ -197,10 +199,3 @@ fn undeltas(deltas: Vec<u32>) -> Vec<u32> {
})
.collect()
}

fn column(headers: &csv::StringRecord, name: &'static str) -> Result<usize, SpellClassesError> {
headers
.iter()
.position(|header| header == name)
.ok_or(SpellClassesError::MissingColumn(name))
}
13 changes: 4 additions & 9 deletions crates/openlogs-gamedata/src/spell_icons.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -120,10 +122,3 @@ pub(crate) fn read_icon_files(manifest: &[u8]) -> Result<HashMap<u32, String>, S
}
Ok(files)
}

fn column(headers: &csv::StringRecord, name: &'static str) -> Result<usize, SpellIconError> {
headers
.iter()
.position(|header| header == name)
.ok_or(SpellIconError::MissingColumn(name))
}
29 changes: 12 additions & 17 deletions crates/openlogs-gamedata/src/talent_trees.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand All @@ -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}")]
Expand Down Expand Up @@ -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<u32, u32>> = HashMap::new();
Expand Down Expand Up @@ -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()
}

Expand All @@ -280,7 +282,7 @@ fn class_of_mask(mask: u32) -> Option<u32> {
fn classic_talent_tabs(talent: &[u8]) -> Result<HashMap<u32, u32>, 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<usize> = headers
.iter()
.enumerate()
Expand Down Expand Up @@ -308,10 +310,10 @@ fn talent_tabs(talent_tab: &[u8]) -> Result<Vec<(u32, u32, String, u32)>, 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() {
Expand Down Expand Up @@ -354,7 +356,7 @@ fn signed<const N: usize>(
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() {
Expand All @@ -373,10 +375,3 @@ fn signed<const N: usize>(
}
Ok(rows)
}

fn column_of(headers: &csv::StringRecord, name: &'static str) -> Result<usize, TalentTreesError> {
headers
.iter()
.position(|header| header == name)
.ok_or(TalentTreesError::MissingColumn(name))
}
4 changes: 2 additions & 2 deletions crates/openlogs-gamedata/tests/boss_portraits.rs
Original file line number Diff line number Diff line change
@@ -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");
Expand Down Expand Up @@ -46,7 +46,7 @@ fn the_web_table_maps_encounters_to_portraits_and_unusable_exports_fail() {
);
assert!(matches!(
BossPortraitTable::from_csv(b"<!DOCTYPE html>\n", JOURNAL_ENCOUNTER_CREATURE, MANIFEST),
Err(BossPortraitError::MissingColumn("ID"))
Err(BossPortraitError::MissingColumn(MissingColumn("ID")))
));
assert!(matches!(
BossPortraitTable::from_csv(
Expand Down
6 changes: 4 additions & 2 deletions crates/openlogs-gamedata/tests/channel_spells.rs
Original file line number Diff line number Diff line change
@@ -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\
Expand Down Expand Up @@ -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"
)))
));
}
4 changes: 2 additions & 2 deletions crates/openlogs-gamedata/tests/dungeons.rs
Original file line number Diff line number Diff line change
@@ -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");
Expand Down Expand Up @@ -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"<!DOCTYPE html>\n"),
Err(DungeonTableError::MissingColumn("ID"))
Err(DungeonTableError::MissingColumn(MissingColumn("ID")))
));
assert!(matches!(
DungeonTable::from_csv(KEYS_HEADER.as_bytes(), ENCOUNTERS_HEADER.as_bytes()),
Expand Down
Loading
Loading