Switch pub to super only

This commit is contained in:
Dandaedre 2024-06-24 04:46:50 +02:00
parent 6b303294f1
commit ed34e2bf60
12 changed files with 146 additions and 143 deletions

View File

@ -13,8 +13,6 @@ console = "0.15.8"
csv = "1.3.0"
debug_print = "1.0.0"
dynfmt = { version = "0.1.5", features = ["curly"] }
enum_dispatch = "0.3.13"
futures = "0.3.30"
glob = "0.3.1"
indexmap = "2.2.6"
indicatif = "0.17.8"

View File

@ -30,41 +30,41 @@ use crate::Config;
#[derive(Args, Debug, Clone)]
// #[command(after_)]
/// The configuration struct for the PdfMaker
pub(crate) struct MakeConfig {
pub(super) struct MakeConfig {
/// The filename to compile
pub(crate) filename: String,
pub(super) filename: String,
/// Special target
#[arg(short, long, help = format!("Build with a special target. {}", HELP_BUILD_TARGET_LIST.as_str()))]
pub(crate) target: Option<MakeTargets>,
pub(super) target: Option<MakeTargets>,
/// The verbosity level
#[arg(short, long, default_value = "warning", help = format!("The verbosity level. {}",HELP_VERBOSITY_LEVEL.as_str()))]
pub(crate) verbosity: VerboseLevel,
pub(super) verbosity: VerboseLevel,
/// The progress bar style
#[arg(short, long, default_value = "class", help = format!("The progress bar style. {}",HELP_BLOCK_SELECTION.as_str()))]
pub(crate) pbar: String,
pub(super) pbar: String,
/// switch to non interactive mode
#[arg(short = 'N', long, default_value_t = false)]
pub(crate) non_interactive: bool,
pub(super) non_interactive: bool,
/// Select only these targets
#[arg(short, long, value_name = "FILE", group = "select")]
pub(crate) only: Vec<String>,
pub(super) only: Vec<String>,
/// Deselect these targets
#[arg(short, long, value_name = "FILE", group = "select")]
pub(crate) no: Vec<String>,
pub(super) no: Vec<String>,
/// Wether to add the initial and final context
#[arg(short = 'C', long, action = clap::ArgAction::SetFalse)]
pub(crate) no_context: bool,
pub(super) no_context: bool,
}
/// Make a pdf spawning a subprocess
pub(crate) fn make_pdf(args: &MakeConfig, _config: &Config) -> Result<()> {
pub(super) fn make_pdf(args: &MakeConfig, _config: &Config) -> Result<()> {
let Ok(Some(_)) = BLOCK_PROGRESSION.get_key(&args.pbar) else {
panic!(
"Progressbar {} doesn't exists. Use one of the following {:?}",
@ -105,6 +105,7 @@ async fn launch_subprocess(
let mut status = Status::zero();
let started = Instant::now();
let mut last_total_duration = Duration::from_secs(0);
let mut current_run = BuildInfo::new(args);
let last_run = BuildInfo::load(args);
@ -179,8 +180,16 @@ async fn launch_subprocess(
continue;
}
};
checkline(args, s, &mut status, &mut current_run, &started, &pb)
.expect("Error while checking line");
checkline(
args,
s,
&mut status,
&mut current_run,
&started,
&pb,
&mut last_total_duration,
)
.expect("Error while checking line");
} else {
break;
}
@ -201,6 +210,7 @@ fn checkline(
run: &mut BuildInfo,
started: &Instant,
pb: &ProgressBar,
last_total_duration: &mut Duration,
) -> Result<()> {
// Match the line to guess what is happening
let mut lex = LineType::lexer(orginal_line);
@ -217,8 +227,8 @@ fn checkline(
// LineType::StartingSequence => todo!(),
// LineType::EndSequence => todo!(),
// LineType::MPSConverter => todo!(),
ref a @ LineType::Chapter(ref chap) => {
run.add_lap(started, chap);
ref a @ LineType::Chapter(_) => {
run.add_lap(started, last_total_duration);
a
}
LineType::MissingReferencePrs => &LineType::MissingReference(orginal_line.to_string()),

View File

@ -25,7 +25,7 @@ static CHAPT_REGEX: LazyLock<Regex> =
LazyLock::new(|| Regex::new(r#" *\\chapter\*?\{"?([^\}]+)\}"?"#).unwrap());
/// The info returned by a make_file
pub(crate) struct BuilderParseResult {
pub(super) struct BuilderParseResult {
/// The new name
pub(super) new_name: String,
@ -34,7 +34,7 @@ pub(crate) struct BuilderParseResult {
}
/// Make the (new/purged) target file and return (name,chapter_list)
pub(crate) fn make_file(args: &MakeConfig) -> BuilderParseResult {
pub(super) fn make_file(args: &MakeConfig) -> BuilderParseResult {
let path = target_name(&args.filename);
let m = make_ignore_targets(args);
let mut f = File::open(&args.filename).expect("The file doesn't exist");
@ -127,7 +127,7 @@ fn add_checker(check: &str, dict_entries: &IndexMap<String, String>, args: &Make
false
}
/// List all chapters targetable by ignore and only
pub(crate) fn make_list(args: &MakeConfig) {
pub(super) fn make_list(args: &MakeConfig) {
let m = make_ignore_targets(args);
println!("The ignore targets are the following:");
println!("{:#?}", m);
@ -150,7 +150,7 @@ fn make_ignore_targets(args: &MakeConfig) -> IndexMap<String, String> {
}
/// Create a target name, by appending _build to it
pub(crate) fn target_name(target: &str) -> PathBuf {
pub(super) fn target_name(target: &str) -> PathBuf {
let target = Path::new(target);
let mut target_oss = target.file_stem().unwrap().to_owned();
target_oss.push("_build.tex");
@ -158,7 +158,7 @@ pub(crate) fn target_name(target: &str) -> PathBuf {
}
/// Create a target suffix and by append _build
pub(crate) fn target_pref(target: &str) -> String {
pub(super) fn target_pref(target: &str) -> String {
let target = Path::new(target);
let target_oss = target.file_stem().unwrap().to_owned();
let v = format!("{:?}", target_oss);
@ -166,7 +166,7 @@ pub(crate) fn target_pref(target: &str) -> String {
}
/// Try to add a simplified entry to a list
pub(crate) fn simplify_add(
pub(super) fn simplify_add(
entry: String,
dict_entries: &mut IndexMap<String, String>,
) -> Result<()> {
@ -211,7 +211,7 @@ pub(crate) fn simplify_add(
}
/// Make the glossaries
pub(crate) fn make_glossaries(args: &MakeConfig) {
pub(super) fn make_glossaries(args: &MakeConfig) {
use std::str;
// let name = format!("{:?}", target_name(&args.filename));
// let name = &name[1..name.len() - 1];
@ -240,17 +240,17 @@ pub(crate) fn make_glossaries(args: &MakeConfig) {
}
/// Make the working directory clean, by eliminating all temporary files
pub(crate) fn make_clean(args: &MakeConfig) {
pub(super) fn make_clean(args: &MakeConfig) {
let _ = args;
// let target = format!("{:?}", Path::new(&args.filename).file_stem().unwrap());
let target = target_pref(&args.filename);
let list_suff = [
".aux", ".glg", ".glo", ".gls", ".ist", ".log", ".out", ".toc", ".pdf",
".aux", ".glg", ".glo", ".gls", ".ist", ".log", ".out", ".toc", ".pdf", ".dvi", ".fls",
];
let mut cmd = Command::new("rm");
for s in list_suff {
// The most ghetto *** I've done so far
cmd.arg(format!("{}{}", &target, s));
// cmd.arg(format!("{}{}", &target, s));
cmd.arg(format!("{}_build{}", &target, s));
}
cmd.arg(format!("{}_build{}", &target, ".tex"));

View File

@ -24,21 +24,21 @@ static STR_TO_BUILD_TARGET: phf::Map<&'static str, MakeTargets> = phf_map! {
};
/// List all blocktype
pub(crate) static HELP_BLOCK_SELECTION: LazyLock<String> = LazyLock::new(|| {
pub(super) static HELP_BLOCK_SELECTION: LazyLock<String> = LazyLock::new(|| {
let mut targets = BLOCK_PROGRESSION.keys().collect::<Vec<&String>>();
targets.sort();
format!("{:?}", targets)
});
/// List all targets
pub(crate) static HELP_VERBOSITY_LEVEL: LazyLock<String> = LazyLock::new(|| {
pub(super) static HELP_VERBOSITY_LEVEL: LazyLock<String> = LazyLock::new(|| {
let mut targets = STR_TO_VERBOSITY.values().collect::<Vec<&VerboseLevel>>();
targets.sort();
format!("{:?}", targets)
});
/// List all targets
pub(crate) static HELP_BUILD_TARGET_LIST: LazyLock<String> = LazyLock::new(|| {
pub(super) static HELP_BUILD_TARGET_LIST: LazyLock<String> = LazyLock::new(|| {
let targets = STR_TO_BUILD_TARGET.values().collect::<Vec<&MakeTargets>>();
format!("{:?}", targets)
});
@ -70,7 +70,7 @@ impl From<&str> for MakeTargets {
}
/// All progress bar styles
pub(crate) static BLOCK_PROGRESSION: LazyLock<HashMap<String, String>> = LazyLock::new(|| {
pub(super) static BLOCK_PROGRESSION: LazyLock<HashMap<String, String>> = LazyLock::new(|| {
let mut m = HashMap::new();
m.insert("class".to_string(), "#>-".to_string());
m.insert("cargo".to_string(), "#> ".to_string());

View File

@ -13,49 +13,49 @@ use console::Style;
use crate::{makepdf::MakeConfig, makepdf_functions::BuilderParseResult};
/// Color Scheme for the NORMAL level
pub(crate) static COL_NORMAL: LazyLock<Style> = LazyLock::new(Style::new);
pub(super) static COL_NORMAL: LazyLock<Style> = LazyLock::new(Style::new);
/// Color Scheme for the MISC level
pub(crate) static COL_MISC: LazyLock<Style> = LazyLock::new(|| Style::new().color256(44));
pub(super) static COL_MISC: LazyLock<Style> = LazyLock::new(|| Style::new().color256(44));
/// Color Scheme for the BOX level
pub(crate) static COL_BOX: LazyLock<Style> = LazyLock::new(|| Style::new().color256(37));
pub(super) static COL_BOX: LazyLock<Style> = LazyLock::new(|| Style::new().color256(37));
/// Color Scheme for the CONTEXT level
pub(crate) static COL_CONTEXT: LazyLock<Style> = LazyLock::new(|| Style::new().color256(30));
pub(super) static COL_CONTEXT: LazyLock<Style> = LazyLock::new(|| Style::new().color256(30));
/// Color Scheme for the INFO level
pub(crate) static COL_INFO: LazyLock<Style> = LazyLock::new(|| Style::new().color256(2));
pub(super) static COL_INFO: LazyLock<Style> = LazyLock::new(|| Style::new().color256(2));
/// Color Scheme for the WARNING level
pub(crate) static COL_WARNING: LazyLock<Style> = LazyLock::new(|| Style::new().color256(166));
pub(super) static COL_WARNING: LazyLock<Style> = LazyLock::new(|| Style::new().color256(166));
/// Color Scheme for the ERROR level
#[allow(dead_code)]
pub(crate) static COL_ERROR: LazyLock<Style> = LazyLock::new(|| Style::new().color256(52));
pub(super) static COL_ERROR: LazyLock<Style> = LazyLock::new(|| Style::new().color256(52));
/// Color Scheme for the CRITICAL level
pub(crate) static COL_CRITICAL: LazyLock<Style> = LazyLock::new(|| Style::new().color256(1));
pub(super) static COL_CRITICAL: LazyLock<Style> = LazyLock::new(|| Style::new().color256(1));
/// Color Scheme for the UNCATCHABLE level
pub(crate) static COL_UNCATCHABLE: LazyLock<Style> =
pub(super) static COL_UNCATCHABLE: LazyLock<Style> =
LazyLock::new(|| Style::new().color256(124).bold());
/// Filler box for the [MISC] text box
pub(crate) static TXT_MISC: LazyLock<String> =
pub(super) static TXT_MISC: LazyLock<String> =
LazyLock::new(|| format!("{}", COL_MISC.apply_to(&"[MISC]")));
/// Filler box for the [BOXX] text box
pub(crate) static TXT_BOXX: LazyLock<String> =
pub(super) static TXT_BOXX: LazyLock<String> =
LazyLock::new(|| format!("{}", COL_BOX.apply_to(&"[BOXX]")));
/// Filler box for the [CNTX] text box
pub(crate) static TXT_CNTX: LazyLock<String> =
pub(super) static TXT_CNTX: LazyLock<String> =
LazyLock::new(|| format!("{}", COL_CONTEXT.apply_to(&"[CNTX]")));
/// Filler box for the [INFO] text box
pub(crate) static TXT_INFO: LazyLock<String> =
pub(super) static TXT_INFO: LazyLock<String> =
LazyLock::new(|| format!("{}", COL_INFO.apply_to(&"[INFO]")));
/// Filler box for the [WARN] text box
pub(crate) static TXT_WARN: LazyLock<String> =
pub(super) static TXT_WARN: LazyLock<String> =
LazyLock::new(|| format!("{}", COL_WARNING.apply_to(&"[WARN]")));
/// Filler box for the [CRIT] text box
pub(crate) static TXT_CRIT: LazyLock<String> =
pub(super) static TXT_CRIT: LazyLock<String> =
LazyLock::new(|| format!("{}", COL_CRITICAL.apply_to(&"[CRIT]")));
/// Filler box for the [ERRR] text box
pub(crate) static TXT_ERRR: LazyLock<String> =
pub(super) static TXT_ERRR: LazyLock<String> =
LazyLock::new(|| format!("{}", COL_CRITICAL.apply_to(&"[ERRR]")));
/// Filler box for the [UKNW] text box
pub(crate) static TXT_UKNW: LazyLock<String> =
pub(super) static TXT_UKNW: LazyLock<String> =
LazyLock::new(|| format!("{}", COL_UNCATCHABLE.apply_to(&"[UKNW]")));
/// The verbosity level
@ -83,7 +83,7 @@ pub enum VerboseLevel {
/// List of all alternative targets
#[derive(Debug, Clone)]
pub(crate) enum MakeTargets {
pub(super) enum MakeTargets {
/// Make all targets
All,
/// Make a list of all optionals
@ -96,7 +96,7 @@ pub(crate) enum MakeTargets {
/// Keeps tracks of the stats of the last(s) run to offer accurate estimation
#[derive(Serialize, Deserialize)]
pub(crate) struct BuildInfo {
pub(super) struct BuildInfo {
/// File parsed
pub filename: String,
/// Options Selected
@ -126,7 +126,7 @@ impl BuildInfo {
}
/// Load a run from file
pub(crate) fn load(args: &MakeConfig) -> Self {
pub(super) fn load(args: &MakeConfig) -> Self {
let mut file = match std::fs::File::open(".last_run.toml") {
Ok(f) => f,
Err(_) => return Self::empty_guess(args),
@ -149,23 +149,18 @@ impl BuildInfo {
}
/// Save the last run info
pub(crate) fn save(&self) {
pub(super) fn save(&self) {
let mut file = std::fs::File::create(".last_run.toml").unwrap();
file.write_all(toml::to_string(&self).unwrap().as_bytes())
.unwrap();
}
/// Add a level to a chapter
pub(crate) fn add_lap(&mut self, started: &Instant, chap: &String) {
let _ = chap;
let a = if let Some(t) = self.time_spent.last() {
t
} else {
&Duration::from_secs(0)
};
/// Add a level to a chapter, and return the new total duration
pub(super) fn add_lap(&mut self, started: &Instant, last_total: &mut Duration) {
let total = started.elapsed();
self.time_spent
.push(started.elapsed().checked_sub(*a).unwrap());
.push(total.checked_sub(*last_total).unwrap());
*last_total = total;
}
}
// [7] [8]
@ -177,7 +172,7 @@ impl BuildInfo {
// #[allow(unused)]
#[derive(Debug, Logos, PartialEq)]
#[logos(skip r"[) ]+")]
pub(crate) enum LineType {
pub(super) enum LineType {
/// The tex building mode : entering extended mode
#[regex("entering[_ ]extended[_ ]mode")]
Mode,
@ -326,7 +321,7 @@ pub(crate) enum LineType {
impl LineType {
/// Decides all verbose levels, for output
pub(crate) fn vlvl(&self) -> VerboseLevel {
pub(super) fn vlvl(&self) -> VerboseLevel {
match &self {
LineType::Mode => VerboseLevel::Misc,
LineType::Info(_) => VerboseLevel::Misc,
@ -376,20 +371,20 @@ fn split_by(delim: &str, text: &str) -> Option<(String, String)> {
}
#[derive(Debug)]
/// The current status of a run, holding all final info
pub(crate) struct Status {
pub(super) struct Status {
/// Number of encountered info (mainly o/ufull)
pub(crate) info: usize,
pub(super) info: usize,
/// Number of warnings, mainly label/reference rerun
pub(crate) warnings: usize,
pub(super) warnings: usize,
/// Only makes sense with non-interactie builds
pub(crate) errors: usize,
pub(super) errors: usize,
// /// List of all recoverable
// pub(crate) v_errors: Vec<String>,
// pub(super) v_errors: Vec<String>,
}
impl Status {
/// Initialize a new status
pub(crate) fn zero() -> Self {
pub(super) fn zero() -> Self {
Self {
info: 0,
warnings: 0,
@ -398,7 +393,7 @@ impl Status {
}
/// Print a pretty message
pub(crate) fn print(
pub(super) fn print(
&self,
args: &MakeConfig,
run_info: &BuildInfo,

View File

@ -10,7 +10,7 @@ use std::{iter::Cycle, vec::IntoIter};
/// Fitness mode
#[derive(Debug, Clone, Copy)]
pub(crate) enum Mode {
pub(super) enum Mode {
/// A positive fitness, looking for stats the creature has affinity with
Positive,
/// A negative fitness, looking for stats the creature has no affinity with
@ -18,7 +18,7 @@ pub(crate) enum Mode {
}
/// Find all the fits for the solution (algo1)
pub(crate) fn find_all_fits(
pub(super) fn find_all_fits(
statmatrix: &mut CharacCharMatrix,
mut sw: Cycle<IntoIter<AffName>>,
mode: Mode,
@ -55,7 +55,7 @@ pub(crate) fn find_all_fits(
}
// /// Find all the fits for the solution (algo1)
// pub(crate) fn find_all_negative_fits(
// pub(super) fn find_all_negative_fits(
// statmatrix: &mut CharacCharMatrix,
// mut sw: Cycle<IntoIter<AffName>>,
// ) -> Result<()> {

View File

@ -12,7 +12,7 @@ type Affinity = f64;
#[derive(Serialize, Deserialize, Debug)]
/// A row representing the creature affinity for a stat
pub(crate) struct CreatureCharacteristicsAffinity {
pub(super) struct CreatureCharacteristicsAffinity {
/// A list of witch stats are desired and at witch level
affinity: Vec<Affinity>,
}
@ -43,7 +43,7 @@ impl CreatureCharacteristicsAffinity {
#[derive(Debug)]
/// A single creature with the needed fields to handle affinity selection
pub(crate) struct Creature {
pub(super) struct Creature {
/// The name of the creature
name: String,
/// The list of affinity desired
@ -58,31 +58,31 @@ pub(crate) struct Creature {
impl Creature {
/// Get the underlying name
pub(crate) fn get_name(&self) -> &str {
pub(super) fn get_name(&self) -> &str {
&self.name
}
/// The list of affinities
#[allow(dead_code)]
pub(crate) fn get_affinities(&self) -> &CreatureCharacteristicsAffinity {
pub(super) fn get_affinities(&self) -> &CreatureCharacteristicsAffinity {
&self.affinities
}
/// The list of selected characs
#[allow(dead_code)]
pub(crate) fn get_selected(&self) -> &Vec<AffName> {
pub(super) fn get_selected(&self) -> &Vec<AffName> {
&self.selected_affinities
}
/// The list of selected negative characs
#[allow(dead_code)]
pub(crate) fn get_negative_selected(&self) -> &Vec<AffName> {
pub(super) fn get_negative_selected(&self) -> &Vec<AffName> {
&self.selected_negative_affinities
}
/// The list of all selected characs
#[allow(dead_code)]
pub(crate) fn get_all_selected(&self) -> Vec<AffName> {
pub(super) fn get_all_selected(&self) -> Vec<AffName> {
let mut v = self.selected_affinities.clone();
v.extend(&self.selected_negative_affinities);
v
@ -140,12 +140,12 @@ fn fit(value: Affinity, _vaff: &[Affinity]) -> Fit {
impl Creature {
/// Return the fit of a stat
pub(crate) fn fit(&self, stat: AffName) -> Fit {
pub(super) fn fit(&self, stat: AffName) -> Fit {
fit(self.get_stat(stat), &self.affinities.affinity)
}
/// Return the negative fitness of a stat
pub(crate) fn negative_fit(&self, stat: AffName) -> Fit {
pub(super) fn negative_fit(&self, stat: AffName) -> Fit {
fit(self.get_stat(stat), &self.affinities.affinity)
}
/// Get the stat associated to the given affinity
@ -195,7 +195,7 @@ impl TryFrom<StringRecord> for CreatureCharacteristicsAffinity {
/// The names of all affinities (essentialy a list of characteristics)
#[allow(clippy::missing_docs_in_private_items)]
#[derive(Deserialize, Serialize, Debug, Clone, Copy, PartialEq, Eq)]
pub(crate) enum AffName {
pub(super) enum AffName {
F,
Ag,
Per,
@ -208,7 +208,7 @@ pub(crate) enum AffName {
impl AffName {
/// Return the list of stats as iterable
pub(crate) fn as_iter() -> impl Iterator<Item = AffName> {
pub(super) fn as_iter() -> impl Iterator<Item = AffName> {
[
AffName::F,
AffName::Ag,
@ -226,11 +226,11 @@ impl AffName {
/// A creature id in the vector of creatures
#[derive(Debug, Clone, Copy, PartialEq)]
pub(crate) struct CreatureVecId(usize);
pub(super) struct CreatureVecId(usize);
/// A creature id in the inner vector
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub(crate) struct CreatureInnerId(usize);
pub(super) struct CreatureInnerId(usize);
impl CreatureInnerId {
/// Get the underlying Inner Id
@ -263,7 +263,7 @@ impl From<usize> for CreatureVecId {
/// A matrix representing: List of characteristics and associated list of creatures
/// All math is done at this level to avoid cost
/// Right now the index of every creature is used in the matrix, but a references could be used instead
pub(crate) struct CharacCharMatrix {
pub(super) struct CharacCharMatrix {
/// The inner vector structure, used to access rapidly the underlying affinities
inner: Vec<Vec<(CreatureVecId, Affinity)>>,
/// The list of creatures refered to by the inner structure
@ -279,7 +279,7 @@ impl CharacCharMatrix {
/// Find a creature having an affinity for the given stat
/// Returns the id in the inner struct
pub(crate) fn find_creature_for_stat_with_fit(
pub(super) fn find_creature_for_stat_with_fit(
&self,
stat: AffName,
fit_level: &Fit,
@ -294,7 +294,7 @@ impl CharacCharMatrix {
/// Find a create with a negative fit for a stat
/// Returns the id in the inner struct
pub(crate) fn find_creature_for_stat_with_negative_fit(
pub(super) fn find_creature_for_stat_with_negative_fit(
&self,
stat: AffName,
fit_level: &Fit,
@ -307,28 +307,28 @@ impl CharacCharMatrix {
Err(anyhow!("Coudln't find a match at the given negative fit"))
}
/// Get a creature by Id
pub(crate) fn get_creature(&self, id: CreatureVecId) -> &Creature {
pub(super) fn get_creature(&self, id: CreatureVecId) -> &Creature {
&self.creatures[id.id()]
}
/// Get a mutable reference to the creature by Id
pub(crate) fn get_mut_creature(&mut self, id: CreatureVecId) -> &mut Creature {
pub(super) fn get_mut_creature(&mut self, id: CreatureVecId) -> &mut Creature {
&mut self.creatures[id.id()]
}
/// Get the creature name
#[allow(dead_code)]
pub(crate) fn creature_name(&self, id: CreatureVecId) -> &String {
pub(super) fn creature_name(&self, id: CreatureVecId) -> &String {
&self.get_creature(id).name
}
/// Get the creature name from it's inner value
#[allow(dead_code)]
pub(crate) fn inner_creature(&self, id: CreatureInnerId, stat: AffName) -> &Creature {
pub(super) fn inner_creature(&self, id: CreatureInnerId, stat: AffName) -> &Creature {
&self.creatures[self.to_vec_id(id, stat).id()]
}
/// Adds the affinity given to a creature
pub(crate) fn add_affinity_to_creature(
pub(super) fn add_affinity_to_creature(
&mut self,
id: CreatureVecId,
stat: AffName,
@ -371,7 +371,7 @@ impl CharacCharMatrix {
}
/// Show the list of solutions chosen for each creature
pub(crate) fn print_solutions(&self) {
pub(super) fn print_solutions(&self) {
for creature in self.creatures.iter() {
println!(
"[{}] Les Caractéristiques maximum à la création : {:?} (7), {:?} (7), {:?} (5)",
@ -384,24 +384,24 @@ impl CharacCharMatrix {
}
/// Print all stat weights
pub(crate) fn print_weights(&self) {
pub(super) fn print_weights(&self) {
for creature in self.creatures.iter() {
println!("[{}] {}", creature.name, creature.affinities);
}
}
/// Gives the size of the loop needed to fill all negative characteristics
pub(crate) fn size_unfited_loop(&self) -> usize {
pub(super) fn size_unfited_loop(&self) -> usize {
self.creatures.len()
}
/// Gives the size of the loop needed to fill all characteristics
pub(crate) fn size_loop(&self) -> usize {
pub(super) fn size_loop(&self) -> usize {
self.creatures.len() * 2
}
/// Get the length of the affinity vector related to the given stat
pub(crate) fn get_len_affinity(&self, stat: AffName) -> usize {
pub(super) fn get_len_affinity(&self, stat: AffName) -> usize {
self.get_affinity(stat).len()
}
@ -411,14 +411,14 @@ impl CharacCharMatrix {
}
/// Find the id in the vector associated to the inner id
pub(crate) fn to_vec_id(&self, creature_id: CreatureInnerId, stat: AffName) -> CreatureVecId {
pub(super) fn to_vec_id(&self, creature_id: CreatureInnerId, stat: AffName) -> CreatureVecId {
self.inner[stat as usize][creature_id.id()].0
}
#[deprecated]
#[allow(dead_code)]
/// Find the inner id associated to the creature_id give
pub(crate) fn to_inner_id(&self, creature_id: CreatureVecId, stat: AffName) -> CreatureInnerId {
pub(super) fn to_inner_id(&self, creature_id: CreatureVecId, stat: AffName) -> CreatureInnerId {
// let a = &self.[creature_id.id()];
self.inner[stat as usize]
.iter()
@ -430,36 +430,36 @@ impl CharacCharMatrix {
// /// Consume the config object to add it to the CharacStatMatrix
// #[deprecated]
// pub(crate) fn add_config(&mut self, config: StatConfig) {
// pub(super) fn add_config(&mut self, config: StatConfig) {
// self.config = config;
// }
/// Get the level of verbosity
pub(crate) fn verbose(&self) -> bool {
pub(super) fn verbose(&self) -> bool {
self.config.verbosity
}
/// Get a reference to the active config
#[allow(dead_code)]
pub(crate) fn get_config(&self) -> &StatConfig {
pub(super) fn get_config(&self) -> &StatConfig {
&self.config
}
/// Sort the underlying data
pub(crate) fn sort(&mut self) {
pub(super) fn sort(&mut self) {
for v in self.inner.iter_mut() {
v.sort_unstable_by(|(_, v1), (_, v2)| v1.total_cmp(v2))
}
}
/// Sort the underlying data in the reverse order
pub(crate) fn reverse_sort(&mut self) {
pub(super) fn reverse_sort(&mut self) {
for v in self.inner.iter_mut() {
v.sort_unstable_by(|(_, v1), (_, v2)| v2.total_cmp(v1))
}
}
/// Remove the creature to avoid doing incessant lookups
pub(crate) fn remove_creature_from_stat(
pub(super) fn remove_creature_from_stat(
&mut self,
creature_id: CreatureInnerId,
stat: AffName,

View File

@ -5,7 +5,7 @@ use std::{iter::Cycle, vec::IntoIter};
use crate::stat_io::AffName;
/// How much a solution fits the algorithm, or how much a solution fits a creature
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Copy, Clone)]
pub(crate) enum Fit {
pub(super) enum Fit {
/// Weakest fit, can't be used
VeryWeak,
/// Weak fit, shouldn't be used
@ -19,7 +19,7 @@ pub(crate) enum Fit {
}
impl Fit {
/// Lower the fitness by one, with an optionnal maximum
pub(crate) fn lower(&self, min: Option<Fit>) -> Option<Fit> {
pub(super) fn lower(&self, min: Option<Fit>) -> Option<Fit> {
let f = match self {
Fit::VeryWeak => None,
Fit::Weak => Some(Fit::VeryWeak),
@ -34,7 +34,7 @@ impl Fit {
}
/// Raise the fitness level by one, with an optionnal maximum
pub(crate) fn upper(&self, min: Option<Fit>) -> Option<Fit> {
pub(super) fn upper(&self, min: Option<Fit>) -> Option<Fit> {
let f = match self {
Fit::VeryWeak => Some(Fit::Weak),
Fit::Weak => Some(Fit::Medium),
@ -53,13 +53,13 @@ type StatWeightsTuple = Vec<(AffName, usize)>;
/// The statweights, holding looping methods
#[derive(Debug)]
pub(crate) struct StatWeightList {
pub(super) struct StatWeightList {
/// The list of all affinities
weights: Vec<AffName>,
}
impl StatWeightList {
/// Iterate over all affinites to fill, endlessly
pub(crate) fn iter_cycle(self) -> Cycle<IntoIter<AffName>> {
pub(super) fn iter_cycle(self) -> Cycle<IntoIter<AffName>> {
self.weights.into_iter().cycle()
}
}

View File

@ -15,17 +15,17 @@ use crate::{
#[derive(Args, Debug, Clone)]
/// The configuration struct for the StatSolver
pub(crate) struct StatConfig {
pub(super) struct StatConfig {
// #[arg(default_value_t: "data/Book1.csv")]
/// The path where the data to analyse is
pub(crate) config_path: String,
pub(super) config_path: String,
/// The verbosity level
#[arg(short, long, default_value_t = false)]
pub(crate) verbosity: bool,
pub(super) verbosity: bool,
}
/// Main solver function, in charge of selecting algorithms and handling all program flow
pub(crate) fn stat_solver(args: &StatConfig, config: &Config) -> Result<()> {
pub(super) fn stat_solver(args: &StatConfig, config: &Config) -> Result<()> {
let _ = config;
let mut statmatrix = load_stat_records(&args.config_path, args.clone()).unwrap();
solution_from_empty(&mut statmatrix).unwrap();

View File

@ -11,38 +11,38 @@ use regex_static::once_cell::sync::Lazy;
#[allow(dead_code)]
#[derive(Deserialize)]
/// The Craft configs
pub(crate) struct Craft {
pub(super) struct Craft {
/// The food header string formatter
pub(crate) header_food: String,
pub(super) header_food: String,
/// The alchemy header string formatter
pub(crate) header_alchemy: String,
pub(super) header_alchemy: String,
/// The forge header string formatter
pub(crate) header_forge: String,
pub(super) header_forge: String,
/// The mtrap header string formatter
pub(crate) header_mtrap: String,
pub(super) header_mtrap: String,
/// The weapons header string formatter
pub(crate) header_weapons: String,
pub(super) header_weapons: String,
/// The armors header string formatter
pub(crate) header_armors: String,
pub(super) header_armors: String,
/// The gadgets header string formatter
pub(crate) header_gadgets: String,
pub(super) header_gadgets: String,
/// The potions header string formatter
pub(crate) header_potions: String,
pub(super) header_potions: String,
/// The traps header string formatter
pub(crate) header_traps: String,
pub(super) header_traps: String,
/// The table end string formatter
pub(crate) end: String,
pub(super) end: String,
/// The long table end string formatter
pub(crate) end_long: String,
pub(super) end_long: String,
/// The long sideways table end string formatter
pub(crate) end_long_side: String,
pub(super) end_long_side: String,
/// The no_headers table end string formatter
pub(crate) end_empty: String,
pub(super) end_empty: String,
}
/// Configuration options for processing TSV files and generating LaTeX tables.
#[derive(Debug, Args)]
pub(crate) struct TableArgs {
pub(super) struct TableArgs {
/// A boolean indicating whether to generate LaTeX code and write it to an output file
/// (if true) or just print the generated code to stdout
#[arg(short)]
@ -102,7 +102,7 @@ pub enum TableTargets {
}
/// A mapping of string names to target types.
pub(crate) static STR_TO_TARGET_FULL: phf::Map<&'static str, TableTargets> = phf_map! {
pub(super) static STR_TO_TARGET_FULL: phf::Map<&'static str, TableTargets> = phf_map! {
"cls" => TableTargets::Classes,
"fud" => TableTargets::Food,
"alc" => TableTargets::Alchemy,
@ -116,11 +116,11 @@ pub(crate) static STR_TO_TARGET_FULL: phf::Map<&'static str, TableTargets> = phf
};
/// The regex for finding and replacing all stars with a custom DD
pub(crate) static RE_STARS: Lazy<Regex> = regex_static::lazy_regex!(r"★+");
pub(super) static RE_STARS: Lazy<Regex> = regex_static::lazy_regex!(r"★+");
/// The regex for finding and replacing all +/- stars with a custom DD
pub(crate) static RE_PLUS_STARS: Lazy<Regex> = regex_static::lazy_regex!(r"([\+-])(★+)");
pub(super) static RE_PLUS_STARS: Lazy<Regex> = regex_static::lazy_regex!(r"([\+-])(★+)");
/// The regex for finding all (+/-) and replacing them with mathmode
pub(crate) static RE_MATHS: Lazy<Regex> = regex_static::lazy_regex!(r"\([\+-]+\)");
pub(super) static RE_MATHS: Lazy<Regex> = regex_static::lazy_regex!(r"\([\+-]+\)");
impl From<&str> for TableGenerationTarget {
fn from(value: &str) -> Self {

View File

@ -13,7 +13,7 @@ use std::{
#[derive(Debug, Deserialize)]
#[serde(rename_all = "PascalCase")]
/// A single row in a martial class tsv file
pub(crate) struct RecordClass {
pub(super) struct RecordClass {
/// The name of a technique.
pub technique: String,
/// The level or rank of a technique
@ -66,18 +66,18 @@ impl WriteRow for RecordClass {
}
}
/// Represents the whole Classes Array, with a vec for every tier
pub(crate) struct ClassesArray {
pub(super) struct ClassesArray {
/// Every tier held as a vec of vec of rows
pub tiers: Vec<Vec<RecordClass>>,
}
/// Trait needed to be writable as a LaTex table
pub(crate) trait WriteTable {
pub(super) trait WriteTable {
/// Takes a config and writes to a string the representation of the Array
fn write_table(&self, config: &Config) -> Result<String>;
}
/// Trait needed to be writable as a LaTex table
pub(crate) trait WriteRow {
pub(super) trait WriteRow {
/// Write the header of the LaTex table
fn write_header(
&self,
@ -102,7 +102,7 @@ pub(crate) trait WriteRow {
}
/// This table stores it's row types
pub(crate) trait TypedRow {
pub(super) trait TypedRow {
/// Get the row type of the table
fn get_type(&self) -> &TableTargets;
}
@ -127,7 +127,7 @@ impl WriteTable for ClassesArray {
}
/// Represents the whole Craft Array, with a vec for every tier
pub(crate) struct GenericArray<RecordType>
pub(super) struct GenericArray<RecordType>
where
RecordType: WriteRow,
{
@ -231,7 +231,7 @@ const NO_STRING: &String = &String::new();
/// This type is used to represent strings in LaTeX tables, where certain characters need to be escaped or replaced with special commands.
#[derive(Deserialize)]
pub(crate) struct CleanString(String);
pub(super) struct CleanString(String);
impl fmt::Debug for CleanString {
#[inline]

View File

@ -232,7 +232,7 @@ fn read_generic_tsv(filename: &Path, craft_type: &TableTargets) -> Result<Box<dy
///
/// This function takes in a Table object and returns its contents as a formatted string,
/// which can be used to generate LaTeX code or perform other operations on the data.
pub(crate) fn tsv_to_string(tsv: Box<dyn WriteTable>, config: &Config) -> Result<String> {
pub(super) fn tsv_to_string(tsv: Box<dyn WriteTable>, config: &Config) -> Result<String> {
tsv.write_table(config)
}
// /// Reads a TSV file into a table.