-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
108 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
use std::path::Path; | ||
use thiserror::Error; | ||
use tokio::fs; | ||
use crate::modules::shared::asynchronous::live_json_file_watcher::LiveJsonFileWatcher; | ||
|
||
pub type ShipLockerFileWatcher = LiveJsonFileWatcher<ShipLocker>; | ||
pub use crate::modules::shared::asynchronous::live_json_file_watcher::LiveJsonFileWatcherError as ShipLockerFileWatcherError; | ||
use crate::ship_locker::ShipLocker; | ||
|
||
pub async fn read_ship_locker_file<P: AsRef<Path>>(path: P) -> Result<ShipLocker, ReadShipLockerFileError> { | ||
Ok(serde_json::from_str(&fs::read_to_string(path) | ||
.await?)?) | ||
} | ||
|
||
#[derive(Debug, Error)] | ||
pub enum ReadShipLockerFileError { | ||
#[error(transparent)] | ||
IO(#[from] std::io::Error), | ||
|
||
#[error("Failed to parse ship locker file: {0}")] | ||
SerdeJson(#[from] serde_json::Error), | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
use std::fs; | ||
use std::path::Path; | ||
use thiserror::Error; | ||
use crate::modules::shared::blocking::live_json_file_watcher::LiveJsonFileWatcher; | ||
|
||
pub type ShipLockerFileWatcher = LiveJsonFileWatcher<ShipLocker>; | ||
pub use crate::modules::shared::blocking::live_json_file_watcher::LiveJsonFileWatcherError as ShipLockerFileWatcherError; | ||
use crate::ship_locker::ShipLocker; | ||
|
||
pub fn read_ship_locker_file<P: AsRef<Path>>(path: P) -> Result<ShipLocker, ReadShipLockerFileError> { | ||
Ok(serde_json::from_str(&fs::read_to_string(path)?)?) | ||
} | ||
|
||
#[derive(Debug, Error)] | ||
pub enum ReadShipLockerFileError { | ||
#[error(transparent)] | ||
IO(#[from] std::io::Error), | ||
|
||
#[error("Failed to parse ship locker file: {0}")] | ||
SerdeJson(#[from] serde_json::Error), | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use std::env::current_dir; | ||
use crate::ship_locker::blocking::read_ship_locker_file; | ||
|
||
#[test] | ||
fn backpack_file_is_parsed_correctly() { | ||
let path = current_dir() | ||
.unwrap() | ||
.join("test-files") | ||
.join("json") | ||
.join("ShipLocker.json"); | ||
|
||
let result = read_ship_locker_file(&path); | ||
|
||
dbg!(&result); | ||
|
||
assert!(result.is_ok()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
mod models; | ||
pub mod blocking; | ||
|
||
#[cfg(feature = "asynchronous")] | ||
pub mod asynchronous; | ||
|
||
pub use models::ship_locker::ShipLocker; | ||
pub use models::ship_locker_entry::ShipLockerEntry; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
pub mod ship_locker; | ||
pub mod ship_locker_entry; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
use chrono::{DateTime, Utc}; | ||
use serde::Deserialize; | ||
use crate::ship_locker::ShipLockerEntry; | ||
|
||
#[derive(Debug, Deserialize, PartialEq)] | ||
#[serde(rename_all = "PascalCase")] | ||
pub struct ShipLocker { | ||
#[serde(rename = "timestamp")] | ||
pub timestamp: DateTime<Utc>, | ||
|
||
#[serde(rename = "event")] | ||
pub event: String, | ||
pub items: Vec<ShipLockerEntry>, | ||
pub components: Vec<ShipLockerEntry>, | ||
pub consumables: Vec<ShipLockerEntry>, | ||
pub data: Vec<ShipLockerEntry>, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
use serde::Deserialize; | ||
use crate::models::odyssey::item::Item; | ||
|
||
#[derive(Debug, Deserialize, PartialEq)] | ||
#[serde(rename_all = "PascalCase")] | ||
pub struct ShipLockerEntry { | ||
pub name: Item, | ||
|
||
#[serde(rename = "Name_Localised")] | ||
pub name_localized: Option<String>, | ||
|
||
#[serde(rename = "OwnerID")] | ||
pub owner_id: u64, | ||
pub count: u16, | ||
} |