Skip to content

Commit

Permalink
🔀 Merge pull request #77 from rster2002/expand-state
Browse files Browse the repository at this point in the history
Expand state
  • Loading branch information
rster2002 committed Aug 10, 2024
2 parents 9feb1e6 + 414c7f2 commit 8d22f3b
Show file tree
Hide file tree
Showing 82 changed files with 1,681 additions and 555 deletions.
4 changes: 2 additions & 2 deletions src/modules/backpack/models/backpack.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use chrono::{DateTime, Utc};
use serde::Deserialize;
use serde::{Deserialize, Serialize};

use crate::backpack::models::backpack_entry::BackpackEntry;

#[derive(Debug, Deserialize, PartialEq)]
#[derive(Debug, Serialize, Deserialize, PartialEq, Clone)]
#[serde(rename_all = "PascalCase")]
pub struct Backpack {
#[serde(rename = "timestamp")]
Expand Down
4 changes: 2 additions & 2 deletions src/modules/backpack/models/backpack_entry.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use serde::Deserialize;
use serde::{Deserialize, Serialize};

use crate::modules::odyssey::Item;

#[derive(Debug, Deserialize, PartialEq)]
#[derive(Debug, Serialize, Deserialize, PartialEq, Clone)]
#[serde(rename_all = "PascalCase")]
pub struct BackpackEntry {
pub name: Item,
Expand Down
4 changes: 2 additions & 2 deletions src/modules/cargo/models/cargo.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use chrono::{DateTime, Utc};
use serde::Deserialize;
use serde::{Deserialize, Serialize};

use crate::logs::cargo_event::CargoEventVessel;
use crate::modules::cargo::models::cargo_entry::CargoEntry;

#[derive(Debug, Deserialize, PartialEq)]
#[derive(Debug, Serialize, Deserialize, PartialEq, Clone)]
#[serde(rename_all = "PascalCase")]
pub struct Cargo {
#[serde(rename = "timestamp")]
Expand Down
4 changes: 2 additions & 2 deletions src/modules/cargo/models/cargo_entry.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use serde::Deserialize;
use serde::{Deserialize, Serialize};

use crate::modules::trading::Commodity;

#[derive(Debug, Deserialize, PartialEq)]
#[derive(Debug, Serialize, Deserialize, PartialEq, Clone)]
#[serde(rename_all = "PascalCase")]
pub struct CargoEntry {
pub name: Commodity,
Expand Down
2 changes: 1 addition & 1 deletion src/modules/exobiology/models/genus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ impl Display for Genus {

impl Genus {
/// The minimum distance in meters required between two samples.
pub fn minimum_distance(&self) -> u16 {
pub fn minimum_distance(&self) -> u32 {
match self {
Genus::Aleoida => 150,
Genus::AmphoraPlant => 100,
Expand Down
27 changes: 23 additions & 4 deletions src/modules/exobiology/models/variant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ use std::str::FromStr;

use lazy_static::lazy_static;
use regex::Regex;
use serde::Serialize;
use serde::{Deserialize, Serialize};
use thiserror::Error;

use crate::from_str_deserialize_impl;
use crate::deserialize_in_order_impl;
use crate::modules::exobiology::{
Species, VariantColor, VariantColorError, VariantSource, VariantSourceError,
};

#[derive(Debug, Serialize, Clone, PartialEq)]
#[derive(Debug, Serialize, Clone, PartialEq, Eq)]
pub struct Variant {
pub species: Species,
pub color: VariantColor,
Expand Down Expand Up @@ -73,7 +73,26 @@ impl FromStr for Variant {
}
}

from_str_deserialize_impl!(Variant);
#[derive(Deserialize)]
struct VariantInput {
pub species: Species,
pub color: VariantColor,
}

impl From<VariantInput> for Variant {
fn from(value: VariantInput) -> Self {
Variant {
species: value.species,
color: value.color,
}
}
}

deserialize_in_order_impl!(
Variant =>
A # String,
B ! VariantInput,
);

impl Display for Variant {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
Expand Down
4 changes: 2 additions & 2 deletions src/modules/exobiology/models/variant_color.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
use std::fmt::{Display, Formatter};

use serde::Serialize;
use serde::{Deserialize, Serialize};
use thiserror::Error;

use crate::modules::exobiology::{Genus, Species, VariantSource};
use crate::modules::galaxy::StarClass;
use crate::modules::materials::Material;

#[derive(Debug, Serialize, Clone, PartialEq)]
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq)]
pub enum VariantColor {
Amethyst,
Aquamarine,
Expand Down
6 changes: 3 additions & 3 deletions src/modules/galaxy/functions/planet_distance.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/// Calculates the distance between two coords using the give planet radius, which can be given in
/// any scale (so you can use meters or kilometers and the result will use the same scale)
pub fn planet_distance(radius: f32, coord1: (f32, f32), coord2: (f32, f32)) -> f32 {
pub fn planet_distance(radius: f32, coord1: &(f32, f32), coord2: &(f32, f32)) -> f32 {
let difference_lat = (coord1.0 - coord2.0).to_radians();
let difference_long = (coord1.1 - coord2.1).to_radians();

Expand All @@ -21,8 +21,8 @@ mod tests {
fn distance_is_calculated_correctly() {
let distance = planet_distance(
6378100.0,
(52.262_42, 4.871_265_4),
(52.263_485, 4.873_533_2),
&(52.262_42, 4.871_265_4),
&(52.263_485, 4.873_533_2),
);

assert_eq!(distance, 194.70883);
Expand Down
4 changes: 2 additions & 2 deletions src/modules/journal/blocking/live_journal_dir_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ use crate::modules::shared::blocking::sync_blocker::SyncBlocker;
///
/// ```rust
/// # use std::env::current_dir;
/// use std::path::PathBuf;
/// use ed_journals::journal::auto_detect_journal_path;
/// use ed_journals::journal::blocking::LiveJournalDirReader;
///
/// let path = PathBuf::from("somePath");
/// let path = auto_detect_journal_path();
/// # let path = current_dir()
/// # .unwrap()
/// # .join("test-files")
Expand Down
2 changes: 1 addition & 1 deletion src/modules/journal/models/journal_event.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::journal::JournalEventKind;

#[derive(Debug)]
#[derive(Debug, Clone)]
pub struct JournalEvent {
/// Indicates whether the event was fired from a change in the journal directory or whether
/// it's an event from a log file other than the current one.
Expand Down
2 changes: 1 addition & 1 deletion src/modules/journal/models/journal_event_kind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::status::Status;

/// This event is fired from the [LiveJournalDirReader] when any change happens in the journal
/// directory and includes all the possible models that could have been updated.
#[derive(Debug, PartialEq)]
#[derive(Debug, Clone, PartialEq)]
// The large enum variant is allowed here as this is usually allocated by the reader anyway and
// adding another box here wouldn't be that useful. Also even though it's large, it's not huge.
#[allow(clippy::large_enum_variant)]
Expand Down
1 change: 1 addition & 0 deletions src/modules/journal/shared/journal_buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ impl LiveJournalBuffer {
is_live: true,
kind: JournalEventKind::StatusEvent(status),
}),
Err(ReadStatusFileError::Empty) => continue,
Err(error) => Err(error.into()),
});
}
Expand Down
10 changes: 5 additions & 5 deletions src/modules/logs/blocking/log_dir_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub struct LogDirReader {
dir: LogDir,
current_file: Option<LogFile>,
current_reader: Option<LogFileReader>,
is_live: bool,
reading_latest: bool,
failing: bool,
}

Expand All @@ -33,7 +33,7 @@ impl LogDirReader {
dir: LogDir::new(path.as_ref().to_path_buf()),
current_file: None,
current_reader: None,
is_live: false,
reading_latest: false,
failing: false,
}
}
Expand All @@ -46,7 +46,7 @@ impl LogDirReader {
}

pub fn is_reading_latest(&self) -> bool {
self.is_live
self.reading_latest
}

fn set_next_file(&mut self) -> Result<bool, LogDirReaderError> {
Expand All @@ -56,6 +56,8 @@ impl LogDirReader {
let length = files.len();

for (index, file) in files.into_iter().enumerate() {
self.reading_latest = length == index + 1;

let Some(current) = &self.current_file else {
self.set_current_file(file)?;
return Ok(true);
Expand All @@ -65,8 +67,6 @@ impl LogDirReader {
self.set_current_file(file)?;
return Ok(true);
}

self.is_live = length == index + 1;
}

Ok(is_empty)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@ use serde::{Deserialize, Serialize};

use crate::modules::exobiology::{Genus, Species, Variant};

#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq)]
#[serde(rename_all = "PascalCase")]
pub struct ScanOrganicEvent {
/// Possible values seem to be "Sample", "Analyze", "Log". It seems that the first scan for
/// a bio species uses `Sample`, then the second consists of two back to back events: one with
/// `Sample` and the one immediately after with `Analyze`. The contents seem to be the same. And
/// the third and last entry seems to be `Log`.
/// a bio species uses `Log`, then the second scan uses `Sample` The third one logs one `Sample`
/// entry and immediately followed with `Analyze`. The contents seem to be the same.
pub scan_type: ScanOrganicEventScanType,
pub genus: Genus,

Expand Down
23 changes: 23 additions & 0 deletions src/modules/logs/content/log_event_content/shipyard_buy_event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,41 +2,64 @@ use serde::{Deserialize, Serialize};

use crate::modules::ship::ShipType;

/// Fired when the player buys a new ship.
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
#[serde(rename_all = "PascalCase")]
pub struct ShipyardBuyEvent {
/// The ship type for the newly bought ship.
pub ship_type: ShipType,

/// The localized ship type for the newly bought ship.
#[serde(rename = "ShipType_Localised")]
pub ship_type_localized: Option<String>,

/// The amount of credits the player has spent on the new ship.
pub ship_price: u64,

/// What the player did with their current ship when buying the new ship.
#[serde(flatten)]
pub old_ship_action: ShipyardBuyEventOldShipAction,

/// The current market id the action was performed. This is also where the current ship will be
/// stored if the player choose to store their current ship.
#[serde(rename = "MarketID")]
pub market_id: u64,
}

/// The action that was performed for the player's current ship.
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
#[serde(untagged)]
pub enum ShipyardBuyEventOldShipAction {
/// Stored the player's current ship at the current location.
Store(ShipyardBuyEventStoreCurrentShip),

/// Sold the player's current ship.
Sell(ShipyardBuyEventSellCurrentShip),
}

/// Stored the player's current ship at the current location.
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
#[serde(rename_all = "PascalCase")]
pub struct ShipyardBuyEventStoreCurrentShip {
/// The ship type of the stored ship.
pub store_old_ship: ShipType,

/// The id of the stored ship.
#[serde(rename = "StoreShipID")]
pub store_ship_id: u64,
}

/// Sold the player's current ship.
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
#[serde(rename_all = "PascalCase")]
pub struct ShipyardBuyEventSellCurrentShip {
/// The ship type of the sold ship.
pub sell_old_ship: ShipType,

/// The id of the sold ship.
#[serde(rename = "SellShipID")]
pub sell_ship_id: u64,

/// The amount of credits that the ship was sold for.
pub sell_price: u64,
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,30 @@ use serde::{Deserialize, Serialize};

use crate::modules::ship::ShipType;

/// Fired when the player swaps between two ships they own.
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
#[serde(rename_all = "PascalCase")]
pub struct ShipyardSwapEvent {
/// The ship type for the retrieved ship.
pub ship_type: ShipType,

/// The localized ship type for the retrieved ship.
#[serde(rename = "ShipType_Localised")]
pub ship_type_localized: Option<String>,

/// The id of the ship that was retrieved.
#[serde(rename = "ShipID")]
pub ship_id: u64,

/// The type of the ship that was stored.
pub store_old_ship: ShipType,

/// The id of the ship that was stored.
#[serde(rename = "StoreShipID")]
pub store_ship_id: u64,

/// The current market id the action was performed. This is also where the current ship will be
/// stored.
#[serde(rename = "MarketID")]
pub market_id: u64,
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,39 @@ use serde::{Deserialize, Serialize};

use crate::modules::ship::ShipType;

/// Fired when the player starts a ship transfer between stations.
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
#[serde(rename_all = "PascalCase")]
pub struct ShipyardTransferEvent {
/// The type of the ship that is transferred.
pub ship_type: ShipType,

/// The localized name of the ship type that is transferred.
#[serde(rename = "ShipType_Localised")]
pub ship_type_localized: Option<String>,

/// The id of the ship that is transferred.
#[serde(rename = "ShipID")]
pub ship_id: u64,

/// The system the ship is transferred from.
pub system: String,

/// The market id the ship is transferred from.
#[serde(rename = "ShipMarketID")]
pub ship_market_id: u64,

/// The total distance in LY for the transfer.
pub distance: f32,

/// The cost of the transfer.
pub transfer_price: u64,

/// The time in seconds it takes for the transfer to complete.
pub transfer_time: u64,

/// The current market id where the action was performed. This is also where the ship will be
/// transferred to.
#[serde(rename = "MarketID")]
pub market_id: u64,
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use crate::ship::ShipModule;
use serde::{Deserialize, Serialize};

/// Fired when information about the player's stored modules is provided.
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
#[serde(rename_all = "PascalCase")]
pub struct StoredModulesEvent {
Expand All @@ -13,8 +15,7 @@ pub struct StoredModulesEvent {
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
#[serde(rename_all = "PascalCase")]
pub struct StoredModulesEventItem {
// TODO look into replacing this with an enum
pub name: String,
pub name: ShipModule,

#[serde(rename = "Name_Localised")]
pub name_localized: String,
Expand Down
Loading

0 comments on commit 8d22f3b

Please sign in to comment.