Updates coverage
Build Successful The build was successful
Gitea/epoch_forge/pipeline/head This commit looks good Details

This commit is contained in:
Dandaedre 2025-12-15 19:55:53 +01:00
parent b8d7029cc7
commit 7b2193fee1
5 changed files with 89 additions and 18 deletions

View File

@ -1,8 +1,8 @@
[last_run_clean]
run_status = "Success"
lines_parsed = 102
coverage = 47.96
lines_parsed = 108
coverage = 52.45
[last_run_clean.run_duration]
secs = 26
nanos = 496094925
nanos = 130055380

View File

@ -1 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="122" height="18" role="img" aria-label="test-coverage: 48%"><title>test-coverage: 48%</title><linearGradient id="bms-ccea4f7561c6b24b" x2="0" y2="100%"><stop offset="0" stop-color="#fff" stop-opacity=".7"/><stop offset=".1" stop-color="#aaa" stop-opacity=".1"/><stop offset=".9" stop-color="#000" stop-opacity=".3"/><stop offset="1" stop-color="#000" stop-opacity=".5"/></linearGradient><clipPath id="bmr-ccea4f7561c6b24b"><rect width="122" height="18" rx="4" fill="#fff"/></clipPath><g clip-path="url(#bmr-ccea4f7561c6b24b)"><rect width="87" height="18" fill="#555"/><rect x="87" width="35" height="18" fill="#97ca00"/><rect width="122" height="18" fill="url(#bms-ccea4f7561c6b24b)"/></g><g fill="#fff" text-anchor="middle" font-family="Verdana,Geneva,DejaVu Sans,sans-serif" text-rendering="geometricPrecision" font-size="110"><text aria-hidden="true" x="445" y="140" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="770">test-coverage</text><text x="445" y="130" transform="scale(.1)" fill="#fff" textLength="770">test-coverage</text><text aria-hidden="true" x="1035" y="140" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="250">48%</text><text x="1035" y="130" transform="scale(.1)" fill="#fff" textLength="250">48%</text></g></svg>
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="122" height="18" role="img" aria-label="test-coverage: 52%"><title>test-coverage: 52%</title><linearGradient id="bms-aa9f2da277165c95" x2="0" y2="100%"><stop offset="0" stop-color="#fff" stop-opacity=".7"/><stop offset=".1" stop-color="#aaa" stop-opacity=".1"/><stop offset=".9" stop-color="#000" stop-opacity=".3"/><stop offset="1" stop-color="#000" stop-opacity=".5"/></linearGradient><clipPath id="bmr-aa9f2da277165c95"><rect width="122" height="18" rx="4" fill="#fff"/></clipPath><g clip-path="url(#bmr-aa9f2da277165c95)"><rect width="87" height="18" fill="#555"/><rect x="87" width="35" height="18" fill="#97ca00"/><rect width="122" height="18" fill="url(#bms-aa9f2da277165c95)"/></g><g fill="#fff" text-anchor="middle" font-family="Verdana,Geneva,DejaVu Sans,sans-serif" text-rendering="geometricPrecision" font-size="110"><text aria-hidden="true" x="445" y="140" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="770">test-coverage</text><text x="445" y="130" transform="scale(.1)" fill="#fff" textLength="770">test-coverage</text><text aria-hidden="true" x="1035" y="140" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="250">52%</text><text x="1035" y="130" transform="scale(.1)" fill="#fff" textLength="250">52%</text></g></svg>

Before

Width:  |  Height:  |  Size: 1.3 KiB

After

Width:  |  Height:  |  Size: 1.3 KiB

View File

@ -143,12 +143,17 @@ pub fn update_advanced_values(
info!("Adding {} to {}{}", governor, entity.id, entity.name);
let governor =
epoch_info.find_entity_of_type(&Some(governor.clone()), &EntityType::Character)?;
entity.change_governor(stats::CharacterId(governor.id));
let old_gov = entity.change_governor(stats::CharacterId(governor.id));
let new_gov = governor.id;
// If there was a governor, tell it it's no longer the big boy in town
if let Some(gov) = old_gov {
epoch_info.del_from_links(*gov, &EntityType::Town, entity.id)?;
}
// Since I added a governor, I now need to add the link to the governor,
// note that if you add an entity to itself this will subtly break but the
// link usage being only for deletion, this breakage will not matter
// This double lookup is only done since the update is not done by the owning structure
epoch_info.add_to_links(governor.id, &EntityType::Character, entity.id)?;
epoch_info.add_to_links(new_gov, &EntityType::Character, entity.id)?;
} else if entity_args.no_governor
&& let Some(g) = entity.remove_governor()
{
@ -157,8 +162,14 @@ pub fn update_advanced_values(
}
if let Some(capital) = &entity_args.capital {
let capital = epoch_info.find_entity_of_type(&Some(capital.clone()), &EntityType::Town)?;
entity.change_capital(stats::TownId(capital.id));
epoch_info.add_to_links(capital.id, &EntityType::Town, entity.id)?;
let old_cap = entity.change_capital(stats::TownId(capital.id));
let new_cap = capital.id;
if let Some(cap) = old_cap {
epoch_info.del_from_links(*cap, &EntityType::Character, entity.id)?;
}
epoch_info.add_to_links(new_cap, &EntityType::Town, entity.id)?;
} else if entity_args.no_capital
&& let Some(c) = entity.remove_capital()
{

View File

@ -82,6 +82,24 @@ impl Entity {
self.stat_to_table(items)
}
/// Reset the temporary stats to a given base value.
///
/// Useful before performing an update: you can set the temporary stats to
/// whatever snapshot you want to start from (or `None` to clear it).
pub fn reset_temporary_stats_to(&mut self, other: Option<OverallStats>) {
self.temp_stats = other;
}
/// Return an immutable reference to the entity’s live statistics.
pub fn get_stats(&self) -> &OverallStats {
&self.stats
}
/// Return an immutable reference to the temporary statistics snapshot,
/// if one is currently stored.
pub fn get_temp_stats(&self) -> &Option<OverallStats> {
&self.temp_stats
}
/// Display the entity's statistics in a pretty table (same format as
/// `full_stats_to_table`).
///
@ -107,7 +125,6 @@ impl Entity {
///
/// # Returns
/// A `String` containing the formatted tree.
// TODO: Deref ids
pub fn to_pretty_tree(&self, epoch_info: &EpochInfo) -> String {
// Helper that prefixes a line with the correct amount of vertical bars.
pub(crate) fn indent(level: usize, line: &str) -> String {
@ -464,10 +481,10 @@ impl Entity {
}
}
/// Add a governor to the entity if the id exists
pub fn change_governor(&mut self, governor: stats::CharacterId) {
/// Add a governor to the entity if the id exists and return the old governor if it existed
pub fn change_governor(&mut self, governor: stats::CharacterId) -> Option<stats::CharacterId> {
debug!("Swapping the governor with {}", governor.to_symbol());
self.metadata.governor = Some(governor);
self.metadata.governor.replace(governor)
}
/// Remove the entity's governor and return it
pub fn remove_governor(&mut self) -> Option<stats::CharacterId> {
@ -475,9 +492,9 @@ impl Entity {
}
/// Add a governor to the entity if the id exists
pub fn change_capital(&mut self, capital: stats::TownId) {
pub fn change_capital(&mut self, capital: stats::TownId) -> Option<stats::TownId> {
debug!("Swapping the capital with {}", capital.to_symbol());
self.metadata.capital = Some(capital);
self.metadata.capital.replace(capital)
}
/// Remove the entity's governor and return it
pub fn remove_capital(&mut self) -> Option<stats::TownId> {

View File

@ -10,9 +10,12 @@
//! The world data and all event logs belong to the individual epoch
//! directories and are **not** part of this file.
use crate::epoch::{
EpochId, EpochIdentifier, EpochInfo, MAIN_NAME, SUBFOLDER_NAMING, SaveMode, TagList,
epoch_traits::ConfigWritable,
use crate::{
epoch::{
EpochId, EpochIdentifier, EpochInfo, MAIN_NAME, SUBFOLDER_NAMING, SaveMode, TagList,
epoch_traits::ConfigWritable,
},
stats,
};
use std::{
collections::HashMap,
@ -301,7 +304,12 @@ impl EpochConfig {
/// with the ID immediately following the current one. The actual logic
/// is deferred to the `EpochInfo -> World` subsystem.
pub fn compute_next(&mut self) -> Result<EpochInfo, EpochError> {
// unimplemented!()
// unimplemented!();
// Iter on events, increment time
// Iter on character, increment time
// create a new_towns_values vector, update it with base stats, then all events modifying underlying value
// create_new_character_base_v vector, do the same
// calculate the temps values (via function)
// TODO(1): Implement this
warn!("DEBUG LINE: COMPUTING NEXT EPOCH");
// New fake epoch
@ -312,6 +320,41 @@ impl EpochConfig {
Ok(new_epoch)
}
/// Update **all** temporary values of every entity in the current epoch.
///
/// # Safety
/// * The caller must guarantee that the current epoch is **loaded** and
/// its storage is still valid for the duration of the call.
/// * The function performs raw pointer arithmetic / `unsafe` reads/writes
/// on the internal data structures. No other thread may be mutably
/// borrowing the same data at the same time.
pub unsafe fn update_all_temporary_values(&mut self) {}
/// Reset **all** temporary values to the current live values.
///
/// # Safety
/// * The caller must ensure that the current epoch is loaded and that
/// no other mutable references to the same data exist.
/// * This method writes directly into the entity structs; any concurrent
/// access will lead to undefined behaviour.
pub unsafe fn reset_temporary_stats(&mut self) -> Result<(), EpochError> {
let current_epoch = self.try_load_current_as_mut()?;
current_epoch
.vec_entities_mut(&stats::EntityType::Town)
.iter_mut()
.for_each(|entity| entity.reset_temporary_stats_to(Some(entity.get_stats().clone())));
Ok(())
}
/// Update temporary values for every entity assuming the current epoch
/// is loaded.
///
/// # Safety
/// * Same as `update_all_temporary_values`: the current epoch must be
/// loaded and no other mutable references may exist.
pub unsafe fn update_temps(&mut self) {}
/// Insert a new epoch into the configuration and persist it.
///
/// The function creates the epoch's directory, writes its metadata,