ed_journals/
lib.rs

1#![cfg_attr(docsrs, feature(doc_cfg))]
2
3//! # ED Journals
4//!
5//! This library provides models and utilities to work with Elite Dangerous journal files.
6//!
7//! > **Warning** this project is currently in beta, which means that it is very much work in progress. Breaking
8//! > changes are likely to happen.
9//!
10//! ## Where to start
11//!
12//! This library contains quite a large number of modules that each cover a different part of the
13//! game, but there are a couple of modules that are important to point out:
14//!
15//! * The [logs] module contains readers and models for reading the `Journal.log` files that are
16//!   stored in the games journal directory.
17//! * [State](state) can be used to turn the logs from the `Journal.log` files into a single state that can
18//!   then be queried and used to figure out the current or previous state of the game.
19//! * The [journal] module can be used to interact with the whole journal directory and can watch
20//!   the directory as a whole for changes.
21
22pub use modules::backpack;
23pub use modules::cargo;
24pub use modules::civilization;
25pub use modules::commander;
26pub use modules::exobiology;
27pub use modules::exploration;
28pub use modules::galaxy;
29pub use modules::io;
30pub use modules::journal;
31pub use modules::logs;
32pub use modules::market;
33pub use modules::materials;
34pub use modules::mixed;
35pub use modules::modules_info;
36pub use modules::nav_route;
37pub use modules::odyssey;
38pub use modules::outfitting;
39pub use modules::partials;
40pub use modules::ship;
41pub use modules::ship_locker;
42pub use modules::shipyard;
43pub use modules::state;
44pub use modules::station;
45pub use modules::status;
46pub use modules::thargoid;
47pub use modules::trading;
48
49mod modules;
50
51#[cfg(test)]
52mod tests {
53    use crate::logs::LogDir;
54    use crate::logs::LogEventContent;
55    use std::env::current_dir;
56    use std::path::PathBuf;
57
58    pub fn test_root() -> PathBuf {
59        PathBuf::from("./test-files")
60    }
61
62    #[test]
63    fn test_journals_are_parsed_correctly() {
64        let dir_path = current_dir().unwrap().join("test-files").join("journals");
65
66        let log_dir = LogDir::new(dir_path);
67
68        let logs = log_dir.journal_logs().unwrap();
69
70        assert!(logs.len() > 10);
71
72        let mut file_header_count = 0;
73        let mut entry_count = 0;
74
75        for journal in &logs {
76            let mut found_file_header = false;
77            let reader = journal.create_blocking_reader().unwrap();
78
79            for entry in reader {
80                entry_count += 1;
81
82                if let LogEventContent::FileHeader(_) = entry.unwrap().content {
83                    found_file_header = true;
84                    file_header_count += 1;
85                }
86            }
87        }
88
89        dbg!(file_header_count);
90        dbg!(entry_count);
91
92        // assert_eq!(logs.len(), file_header_count);
93    }
94}