Probable fix of all the links
Build Successful The build was successful
Gitea/epoch_forge/pipeline/head This commit looks good Details

This commit is contained in:
Dandaedre 2025-12-16 03:18:11 +01:00
parent ce448ede1d
commit 26ebe715d0
7 changed files with 100 additions and 91 deletions

View File

@ -1,8 +1,8 @@
[last_run_clean]
run_status = "Success"
lines_parsed = 108
coverage = 52.45
lines_parsed = 110
coverage = 49.76
[last_run_clean.run_duration]
secs = 26
nanos = 130055380
nanos = 637749582

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: 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>
<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: 50%"><title>test-coverage: 50%</title><linearGradient id="bms-8fc2dc264327201c" 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-8fc2dc264327201c"><rect width="122" height="18" rx="4" fill="#fff"/></clipPath><g clip-path="url(#bmr-8fc2dc264327201c)"><rect width="87" height="18" fill="#555"/><rect x="87" width="35" height="18" fill="#97ca00"/><rect width="122" height="18" fill="url(#bms-8fc2dc264327201c)"/></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">50%</text><text x="1035" y="130" transform="scale(.1)" fill="#fff" textLength="250">50%</text></g></svg>

Before

Width:  |  Height:  |  Size: 1.3 KiB

After

Width:  |  Height:  |  Size: 1.3 KiB

View File

@ -392,8 +392,9 @@ fn handle_delete_entity(
.ok_or(EpochError::EntityNotFound(*e_type, entity_identifier))?;
let entity = vec_entities.swap_remove(index);
entity.remove_all_links(epoch_info)?;
// TODO: Clean all the links from it's presence
// for l in entity.links(){
// // Figure out what the link is
// // Delete either a governor or capital

View File

@ -148,77 +148,30 @@ pub fn update_advanced_values(
entity: &mut Entity,
epoch_info: &mut EpochInfo,
) -> Result<(), EpochError> {
if let Some(governor) = &entity_args.governor {
let AddingDoneStruct { old_id, new_id } = add_entity(
entity,
epoch_info,
governor,
&EntityType::Character,
stats::Role::Govern,
)?;
remove_link_from_old(
entity,
epoch_info,
old_id,
stats::Role::Govern,
&EntityType::Character,
);
add_link_to_new(
entity,
epoch_info,
new_id,
stats::Role::Govern,
&EntityType::Character,
)?;
} else if entity_args.no_governor
&& let Some(old_gov) = entity.remove_governor()
{
remove_link_from_old(
entity,
epoch_info,
Some(*old_gov),
stats::Role::Govern,
&EntityType::Character,
);
}
update_link(
entity_args.governor.as_ref(),
entity_args.no_governor,
|e| e.remove_governor().map(|i| *i),
add_entity,
entity,
epoch_info,
stats::Role::Govern,
&EntityType::Character,
)?;
if let Some(capital) = &entity_args.capital {
info!("About to add");
let AddingDoneStruct { old_id, new_id } = add_entity(
entity,
epoch_info,
capital,
&EntityType::Town,
stats::Role::Capital,
)?;
remove_link_from_old(
entity,
epoch_info,
old_id,
stats::Role::Capital,
&EntityType::Town,
);
add_link_to_new(
entity,
epoch_info,
new_id,
stats::Role::Capital,
&EntityType::Town,
)?;
} else if entity_args.no_capital
&& let Some(capital) = entity.remove_capital()
{
remove_link_from_old(
entity,
epoch_info,
Some(*capital),
stats::Role::Capital,
&EntityType::Town,
);
}
update_link(
entity_args.capital.as_ref(),
entity_args.no_capital,
|e| e.remove_capital().map(|i| *i),
add_entity,
entity,
epoch_info,
stats::Role::Capital,
&EntityType::Town,
)?;
Ok(())
}
/// Update a single “link” (governor, capital, …) in a DRY way.
///
/// * `opt_new` – `Some(&T)` if the caller supplied a new value, `None` otherwise.
@ -253,20 +206,12 @@ where
) -> Result<AddingDoneStruct, EpochError>,
{
if let Some(new_val) = opt_new {
// 1️⃣ add the new entity
let AddingDoneStruct { old_id, new_id } =
add_new(entity, epoch_info, new_val, etype, role)?;
// 2️⃣ unlink the old one (if any)
remove_link_from_old(entity, epoch_info, old_id, role, etype);
// 3️⃣ link the new one
add_link_to_new(entity, epoch_info, new_id, role, etype)?;
} else if no_flag {
// only remove the old link if we are allowed to
if let Some(old_id) = remove_old(entity) {
remove_link_from_old(entity, epoch_info, Some(old_id), role, etype);
}
} else if no_flag && let Some(old_id) = remove_old(entity) {
remove_link_from_old(entity, epoch_info, Some(old_id), role, etype);
}
Ok(())

View File

@ -19,7 +19,7 @@ use uuid::Uuid;
use crate::{
error::EpochError,
stats::{EntityType, MetaStats, OverallStats},
stats::{self, EntityType, MetaStats, OverallStats, Symbols, TypedLink},
};
pub mod implementations;
@ -80,7 +80,40 @@ pub struct Entity {
/// Limits that clamp any stat changes caused by the entity's effect.
effect_bounds: EffectBounds,
}
impl Entity {}
impl Entity {
/// Iterate over all the links and do the appropriate action
pub fn remove_all_links(
&self,
epoch_info: &mut crate::epoch::EpochInfo,
) -> Result<(), EpochError> {
for TypedLink {
other_id,
role,
other_type,
} in &self.metadata.links
{
let entity: &mut Entity =
epoch_info.find_entity_strict_as_mut(*other_id, Some(*other_type))?;
let id = match role {
stats::Role::Govern => entity.remove_governor().map(|i| *i),
stats::Role::Capital => entity.remove_capital().map(|i| *i),
stats::Role::Undefined => None,
};
// TODO: Add the other way cleaning, not useful for now but if ever links can be two way,
// it needs to be done
log::info!(
"Removed entity {}{} [{}] from {}{}{} -> {id:?}",
other_id.to_symbol(),
other_type.to_symbol(),
role.to_symbol(),
entity.name,
entity.id.to_symbol(),
entity.entity_type.to_symbol()
);
}
Ok(())
}
}
/// Limits for the maximum and minimum value that an effect may
/// modify a statistic. The bounds are applied after the effect has

View File

@ -244,18 +244,18 @@ fn full_entity() -> Entity {
links: vec![
stats::TypedLink::new(
Uuid::from_u128_le(1212),
stats::Role::Govern,
EntityType::Character,
stats::Role::Capital,
EntityType::Town,
),
stats::TypedLink::new(
Uuid::from_u128_le(121),
stats::Role::Govern,
EntityType::Character,
stats::Role::Capital,
EntityType::Town,
),
stats::TypedLink::new(
Uuid::from_u128_le(121),
stats::Role::Govern,
EntityType::Character,
stats::Role::Capital,
EntityType::Town,
),
],
reach: stats::Reach::Global,

View File

@ -251,6 +251,36 @@ impl EpochInfo {
))
}
}
/// Find an entity from an Uuid
// TODO: Siplify this with the better iterator
pub fn find_entity_strict_as_mut(
&mut self,
id: Uuid,
strict: Option<EntityType>,
) -> Result<&mut Entity, EpochError> {
let predicate = |entity: &&mut Entity| entity.id == id;
if let Some(e_type) = strict {
self.vec_entities_mut(&e_type)
.iter_mut()
.find(|entity| entity.id == id)
.ok_or(EpochError::EntityNotFound(
e_type,
Some(EntityIdentifier::Id(id.to_string())),
))
} else {
self.events
.iter_mut()
.find(predicate)
.or(self.characters.iter_mut().find(predicate))
.or(self.towns.iter_mut().find(predicate))
.or(self.blockers.iter_mut().find(predicate))
.or(self.calamities.iter_mut().find(predicate))
.ok_or(EpochError::EntityNotFound(
EntityType::Player,
Some(EntityIdentifier::Id(id.to_string())),
))
}
}
/// Returns a slice over the entities of the requested type from the given `EpochInfo`.
///
/// The function matches the supplied `e_type` to the appropriate collection