diff --git a/.run_status.toml b/.run_status.toml
index bb2f884..2488011 100644
--- a/.run_status.toml
+++ b/.run_status.toml
@@ -1,8 +1,8 @@
[last_run_clean]
run_status = "Success"
lines_parsed = 110
-coverage = 49.76
+coverage = 48.89
[last_run_clean.run_duration]
secs = 26
-nanos = 637749582
+nanos = 63691553
diff --git a/badges/coverage.svg b/badges/coverage.svg
index d697e70..0db759b 100644
--- a/badges/coverage.svg
+++ b/badges/coverage.svg
@@ -1 +1 @@
-
\ No newline at end of file
+
\ No newline at end of file
diff --git a/bin_efo/src/commands/entity_generic.rs b/bin_efo/src/commands/entity_generic.rs
index a85cb2c..18c109f 100644
--- a/bin_efo/src/commands/entity_generic.rs
+++ b/bin_efo/src/commands/entity_generic.rs
@@ -365,7 +365,8 @@ pub(crate) fn handle_create_entity(
entity.entity_type.to_shortest(),
entity.id.to_string(),
);
- // TODO: Rather bad
+ entity.update_metastats();
+ // TODO: Rather bad but faster that reloading without hashmaps
vec_entities.push(entity.clone());
entity.print_full(epoch_info);
@@ -495,6 +496,7 @@ fn handle_edit_entity(
};
helper_functions::update_common_values(&entity_args.common_args, position, &mut entity);
helper_functions::update_advanced_values(&entity_args.common_args, &mut entity, epoch_info)?;
+ entity.update_metastats();
entity.print_full(epoch_info);
// Only swap if a swap is needed
epoch_info.swap_entity(entity)?;
diff --git a/bin_efo/src/commands/epoch.rs b/bin_efo/src/commands/epoch.rs
index 1602f3c..e6d9daa 100644
--- a/bin_efo/src/commands/epoch.rs
+++ b/bin_efo/src/commands/epoch.rs
@@ -151,17 +151,20 @@ fn handle_diff(args: &cli_epoch::Diff) -> Result<(), AppError> {
///
/// This helper is internal to the `epoch` sub-command.
fn handle_log(args: &cli_epoch::Log, main_epoch: &mut EpochConfig) -> Result<(), AppError> {
- let limit = args.limit;
+ let context = args.context;
let start_id = &main_epoch.epoch_id;
- let mut list_id: Vec = main_epoch
- .list_existing_epochs
- .iter()
- .filter(|(id, _)| id <= &start_id)
- .map(|(id, _)| *id)
- .collect();
+ let mut list_id: Vec = main_epoch.list_existing_epochs.keys().copied().collect();
list_id.sort();
- main_epoch.log_elements(&list_id[..std::cmp::min(list_id.len(), limit)])?;
+ // list_id.reverse();
+ let pos = **list_id
+ .iter()
+ .find(|id| id == &start_id)
+ .ok_or(EpochError::EpochNotFound(start_id.to_string()))? as usize;
+
+ main_epoch.log_elements(
+ &list_id[(pos.saturating_sub(context))..std::cmp::min(pos + context + 1, list_id.len())],
+ )?;
Ok(())
}
diff --git a/bin_efo/src/commands/epoch/cli_epoch.rs b/bin_efo/src/commands/epoch/cli_epoch.rs
index 74f5c60..033f034 100644
--- a/bin_efo/src/commands/epoch/cli_epoch.rs
+++ b/bin_efo/src/commands/epoch/cli_epoch.rs
@@ -57,8 +57,8 @@ pub enum EpochCmd {
#[derive(Args, Debug)]
pub struct Log {
/// (Optional) Limit the number of entries shown.
- #[arg(short, long, default_value = "50")]
- pub limit: usize,
+ #[arg(short, long, default_value = "20")]
+ pub context: usize,
}
/// Switches to the specified epoch. The target can be an integer,
diff --git a/lib_efo/src/entity/implementations/accesors.rs b/lib_efo/src/entity/implementations/accesors.rs
index c5f1ccd..413d9bf 100644
--- a/lib_efo/src/entity/implementations/accesors.rs
+++ b/lib_efo/src/entity/implementations/accesors.rs
@@ -250,6 +250,11 @@ impl Entity {
&self.metadata.position
}
+ /// Defer the update of all stats
+ pub fn update_metastats(&mut self) {
+ self.stats.update();
+ }
+
/// Returns whether the entity match an optionnal identifier
pub fn match_identifier(&self, entity_identifier: &Option) -> bool {
match entity_identifier {
diff --git a/lib_efo/src/epoch/epoch_config.rs b/lib_efo/src/epoch/epoch_config.rs
index b5067d5..841a68f 100644
--- a/lib_efo/src/epoch/epoch_config.rs
+++ b/lib_efo/src/epoch/epoch_config.rs
@@ -15,8 +15,9 @@ use crate::{
EpochId, EpochIdentifier, EpochInfo, MAIN_NAME, SUBFOLDER_NAMING, SaveMode, TagList,
epoch_traits::ConfigWritable,
},
- stats,
+ stats::{self, Symbols},
};
+use colored::*;
use std::{
collections::HashMap,
fs::{read_to_string, remove_dir_all},
@@ -26,7 +27,7 @@ use std::{
use log::{info, warn};
use serde::{Deserialize, Serialize};
-use crate::{epoch::epoch_traits::Prettiable, error::EpochError};
+use crate::error::EpochError;
/// The file written to *.epochconfig* that tells the CLI which
/// epoch folder is the “current” one.
@@ -421,7 +422,36 @@ impl EpochConfig {
items_to_log.push(info);
}
}
- println!("{}", EpochInfo::as_table(items_to_log)?);
+
+ // TODO: Have this in a message and return a string
+ println!(
+ "{}",
+ "List of epoch, most recent shown first".bright_green()
+ );
+ // TODO: Make a method for this
+ for elt in items_to_log.iter() {
+ let star = if elt.epoch_id == self.epoch_id {
+ " "
+ } else {
+ " "
+ };
+ println!(
+ "{} {:>4} - {}{}{:10} {:50}",
+ star.green(),
+ elt.epoch_id.to_symbol().blue(),
+ " ".yellow(),
+ (elt.events.len()
+ + elt.characters.len()
+ + elt.towns.len()
+ + elt.calamities.len()
+ + elt.blockers.len())
+ .to_string()
+ .yellow(),
+ elt.tags.join(","),
+ elt.summary
+ )
+ }
+ // println!("{}", EpochInfo::as_table(items_to_log)?);
Ok(())
}
}
diff --git a/lib_efo/src/epoch/epoch_info.rs b/lib_efo/src/epoch/epoch_info.rs
index 8a2db4a..ce48a66 100644
--- a/lib_efo/src/epoch/epoch_info.rs
+++ b/lib_efo/src/epoch/epoch_info.rs
@@ -19,7 +19,7 @@ use crate::{
epoch_traits::{ConfigWritable, Prettiable},
},
error::EpochError,
- stats::{EntityType, Position, PositionIdentifier, TypedLink},
+ stats::{EntityType, Position, PositionIdentifier, Symbols, TypedLink},
};
/// The metadata file stored inside each epoch directory
@@ -378,3 +378,9 @@ impl EpochInfo {
}
}
}
+
+impl Symbols for EpochId {
+ fn to_symbol(&self) -> String {
+ format!("[ {:<2}]", self)
+ }
+}
diff --git a/lib_efo/src/stats.rs b/lib_efo/src/stats.rs
index 52cb12c..0275474 100644
--- a/lib_efo/src/stats.rs
+++ b/lib_efo/src/stats.rs
@@ -252,7 +252,6 @@ fn color_cell_categories(cell: CellStruct, value: &GenericStat) -> CellStruct {
impl OverallStats {
/// Create Stats with a given rng distribution
- // TODO(6): Use an iterator over the stat enum
pub(crate) fn create_rng(
rng: &RngLevel,
mut rng_t: &mut ThreadRng,
@@ -285,7 +284,8 @@ impl OverallStats {
}
/// Updates the inner meta values
- fn update(&mut self) {
+ // TODO: Force the use of this ?
+ pub fn update(&mut self) {
self.demographics =
(*(self.population + self.growth_rate + self.happiness - self.crime) / 4).into();
self.economy = (*(self.food + self.industry + self.trade + self.science) / 4).into();