Implements a part of the scenarios

This commit is contained in:
Dandaedre 2025-02-18 22:59:42 +01:00
parent dfa806acef
commit 3af43de27e
Signed by: Dandaedre
GPG Key ID: 440C6592E8A26D99
3 changed files with 44 additions and 13 deletions

View File

@ -29,7 +29,7 @@ pub trait ViewTable {
fn index_of_interest_points(&self) -> Vec<usize>;
/// Interrogate the FinalRepresentation to find interesting elements
fn find_points_of_interest(&self, representation: &Self::InterestElementList);
fn find_points_of_interest(representation: &Self::InterestElementList) -> Self;
// An alternative, non Self::Typed way of doing since there is only one usage for now
// fn find_points_of_interest(&self, representation: &impl FinalRepresentation);
}
@ -241,7 +241,7 @@ pub trait Scenario {
// fn refine_recipes(&self);
/// Generate the final list type
fn generate_refined_recipes(&self) -> Self::FinalListType;
fn generate_refined_recipes(&self) -> Result<Self::FinalListType, EquipementError>;
/// Gather the selected view tables
/// All the inner generation is done gradually and populate all section to finally generate the views

View File

@ -9,10 +9,13 @@
#![allow(dead_code)]
use crate::weaponry_structs::Equipement;
use crate::weaponry_structs::InitialEquipementList;
use crate::weaponry_structs::equipement_structs::InnerEquipementStats;
use crate::{
error::{EquipementError, FatalEquipementError},
interfaces::{RecipeDatabase, Scenario, ViewTable},
weaponry_structs::equipement_structs::InnerEquipementStats,
interfaces::{RecipeCollection, RecipeDatabase, Scenario, ViewTable},
weaponry_structs::equipement_structs::{EqFinishing, EqMaterial, EqNature, EqShape},
};
use super::equipement_advanced_repr::RefinedEquipementList;
@ -54,7 +57,7 @@ impl ViewTable for ViewtableMock {
todo!()
}
fn find_points_of_interest(&self, representation: &Self::InterestElementList) {
fn find_points_of_interest(representation: &Self::InterestElementList) -> Self {
let _ = representation;
todo!()
}
@ -67,6 +70,22 @@ pub struct CrossRecipeScenario {
config: ConfigMock,
}
/// Automatically deserialize into an equipement
// TODO: This macro only exists because no blanket implementation or function does this *relatively* easy step
macro_rules! deserde_into_equipement {
( $db:expr, $name:expr, $type:ident) => {
InitialEquipementList::from_vectored(
$db.serialize_vec_from_table::<InnerEquipementStats>(
"Equipement",
Some(&format!("CATEGORY == {}", $name)),
)?
.into_iter()
.map(|eq| $type { stats: eq }.into())
.collect::<Vec<Equipement>>(),
)
};
}
impl Scenario for CrossRecipeScenario {
type DatabaseType = DatabaseMock;
type ViewTableType = ViewtableMock;
@ -84,15 +103,27 @@ impl Scenario for CrossRecipeScenario {
})
}
fn generate_refined_recipes(&self) -> Self::FinalListType {
let _all_parts = &self
.database
.serialize_vec_from_table::<InnerEquipementStats>("bob", Some("CATEGOTY == 'Bobitty'"));
todo!()
fn generate_refined_recipes(&self) -> Result<Self::FinalListType, EquipementError> {
// TODO: Depending on config, a different filter might be given here
let eq_shape = deserde_into_equipement!(self.database, "Shape", EqShape);
let eq_material = deserde_into_equipement!(self.database, "Material", EqMaterial);
let eq_nature = deserde_into_equipement!(self.database, "Nature", EqNature);
let eq_finishing = deserde_into_equipement!(self.database, "Finishing", EqFinishing);
// No op, just clarity
// TODO: Depending on config this step might differ
let mut f_list = eq_shape;
f_list.combine_all(&eq_material);
f_list.combine_all(&eq_nature);
f_list.combine_all(&eq_finishing);
// This oneline is neat
Ok(f_list.into())
}
fn generate_view_tables(&self, equipement_list: Self::FinalListType) -> Self::ViewTableType {
let _ = equipement_list;
todo!()
// TODO: Change this depending on the config ? or maybe a scenario is inerently tied to a viewtable ?
// The polymorphism will depend on many factors not yet known :(
Self::ViewTableType::find_points_of_interest(&equipement_list)
}
}

View File

@ -21,7 +21,7 @@ impl ViewTable for EquipementFullView {
todo!()
}
fn find_points_of_interest(&self, representation: &Self::InterestElementList) {
fn find_points_of_interest(representation: &Self::InterestElementList) -> Self {
let _ = representation;
todo!()
}