Addentum(Doc) - Adds more documentation

This commit is contained in:
Dandaedre 2023-03-02 17:45:03 +01:00
parent 0c5ed39573
commit a5c196b764
5 changed files with 88 additions and 32 deletions

View File

@ -15,6 +15,7 @@
🟩 (CLI) Rework the parameters and return structs to only have one ref each 🟩 (CLI) Rework the parameters and return structs to only have one ref each
### Features ### Features
🟩 (GUI) Refactor code 🟩 (GUI) Refactor code
🟩 (GUI) Restore GUI state
# Roadmap # Roadmap
## v1.0.0 ## v1.0.0

View File

@ -10,7 +10,7 @@ use lazy_static::lazy_static;
use std::fmt::Debug; use std::fmt::Debug;
/// Hold an action for the solver to try using /// Hold an action for the solver to try using
/// ///
/// It will be used heavily to try/discard actions durin craft /// It will be used heavily to try/discard actions durin craft
pub struct Action { pub struct Action {
/// The action name, in a human readable format, it will be used to generate a short_name /// The action name, in a human readable format, it will be used to generate a short_name
@ -30,7 +30,7 @@ pub struct Action {
} }
/// Builds an action based on an action /// Builds an action based on an action
/// ///
/// Made to initialize lazy_static and nothing more /// Made to initialize lazy_static and nothing more
pub struct ActionBuilder { pub struct ActionBuilder {
action: Action, action: Action,
@ -39,7 +39,7 @@ pub struct ActionBuilder {
impl ActionBuilder { impl ActionBuilder {
/// Base creator, takes a name and initialize an empty action with the short_name /// Base creator, takes a name and initialize an empty action with the short_name
/// and name setup and default values for all other fields /// and name setup and default values for all other fields
/// ///
/// # Examples /// # Examples
/// ``` /// ```
/// use xiv_csolver_lib::action::ActionBuilder; /// use xiv_csolver_lib::action::ActionBuilder;
@ -99,8 +99,8 @@ impl ActionBuilder {
self self
} }
/// Makes an action add a buff for certain number of actions /// Makes an action add a buff for certain number of actions
/// The buffs available are defined in [specs.rs](xiv_csolver::specs::Buff) /// The buffs available are defined in [specs.rs](crate::specs::Buff)
/// ///
/// `` /// ``
/// (self.recipe.progress as f32 - self.progression as f32) / self.get_base_progression() as f32; /// (self.recipe.progress as f32 - self.progression as f32) / self.get_base_progression() as f32;
/// `` /// ``
@ -126,8 +126,8 @@ impl PartialEq for Action {
} }
} }
/// A craft action, after compilation (with lazy_static) /// A craft action, after compilation (with lazy_static)
// no other actions should be created // no other actions should be created
impl Action { impl Action {
/// Get the printable name of the action /// Get the printable name of the action
pub fn get_name(&self) -> String { pub fn get_name(&self) -> String {
@ -184,7 +184,7 @@ impl Action {
(prog * mult).floor() as u32 (prog * mult).floor() as u32
} }
/// Get the quality effect this action would have if used at this stage of the craft. /// Get the quality effect this action would have if used at this stage of the craft.
/// This method account for the **inner quiet** stacking effect, **innovation** and **great strides** /// This method account for the **inner quiet** stacking effect, **innovation** and **great strides**
pub fn get_quality(&self, _craft: &Craft) -> u32 { pub fn get_quality(&self, _craft: &Craft) -> u32 {
let mut qual = self.quality as f64; let mut qual = self.quality as f64;
@ -210,12 +210,12 @@ impl Action {
} }
/// Returns a bool representing if this action **can** be used, note that this does only account /// Returns a bool representing if this action **can** be used, note that this does only account
/// for the game limitations and not viability limitation /// for the game limitations and not viability limitation
/// ///
/// # Improvements /// # Improvements
/// This function could easily prune useless actions by considering them not available. /// This function could easily prune useless actions by considering them not available.
/// Doing so could stop early refresh of buffs and spam of observe and such. /// Doing so could stop early refresh of buffs and spam of observe and such.
/// However some of such "optimisations" could just plain hurt the craft by forbidding a *seemingly* /// However some of such "optimisations" could just plain hurt the craft by forbidding a *seemingly*
/// useless action. The "bruteforce" method being easily computatble on a modern computer, such /// useless action. The "bruteforce" method being easily computatble on a modern computer, such
/// optimisations arent warrented and left to aother time. /// optimisations arent warrented and left to aother time.
pub fn can_use(&self, _craft: &Craft) -> bool { pub fn can_use(&self, _craft: &Craft) -> bool {
if self.get_cp_cost(_craft) > _craft.cp as u32 { if self.get_cp_cost(_craft) > _craft.cp as u32 {
@ -318,27 +318,25 @@ pub struct ActionList {
/// Success Rate: 100% /// Success Rate: 100%
/// Available only when Inner Quiet stack size is 10. /// Available only when Inner Quiet stack size is 10.
pub trained_finesse: Action, pub trained_finesse: Action,
/// Restores item durability by 30. /// Restores item durability by 30.
pub masters_mend: Action, pub masters_mend: Action,
// Restores item durability by 60. // Restores item durability by 60.
// pub masters_mend_2: Action, // pub masters_mend_2: Action,
/// Reduces loss of durability by 50% for the next four steps.
/// Reduces loss of durability by 50% for the next four steps.
pub waste_not: Action, pub waste_not: Action,
/// Reduces loss of durability by 50% for the next eight steps. /// Reduces loss of durability by 50% for the next eight steps.
pub waste_not_ii: Action, pub waste_not_ii: Action,
/// Restores 5 points of durability after each step for the next eight steps. /// Restores 5 points of durability after each step for the next eight steps.
pub manipulation: Action, pub manipulation: Action,
/// Increases efficiency of Synthesis actions by 50% for the next four steps. /// Increases efficiency of Synthesis actions by 50% for the next four steps.
pub veneration: Action, pub veneration: Action,
/// Increases the efficiency of next Touch action by 100%. /// Increases the efficiency of next Touch action by 100%.
/// Effect active for three steps. /// Effect active for three steps.
pub great_strides: Action, pub great_strides: Action,
/// Increases efficiency of Touch actions by 50% for the next four steps. /// Increases efficiency of Touch actions by 50% for the next four steps.
pub innovation: Action, pub innovation: Action,
// Do nothing for one step.
// Do nothing for one step.
//pub observe: Action, //pub observe: Action,
// Increases progress. // Increases progress.
// Efficiency: 200% // Efficiency: 200%
@ -453,6 +451,6 @@ impl Default for ActionList {
} }
lazy_static! { lazy_static! {
/// Initialize a static pseudo &Craft: ACTIONS /// Initialize a static pseudo &Craft: ACTIONS
pub static ref ACTIONS: ActionList = ActionList::default(); pub static ref ACTIONS: ActionList = ActionList::default();
} }

View File

@ -1,16 +1,16 @@
//! Module containing everything to create a craft and all methods to get the current state of the craft //! Module containing everything to create a craft and all methods to get the current state of the craft
//! //!
//! A craft represent the state of the recipe with a vector of actions applied to it. //! A craft represent the state of the recipe with a vector of actions applied to it.
//! Applying actions to it will make the craft progress, while branching and trying other actions //! Applying actions to it will make the craft progress, while branching and trying other actions
//! will be done by cloning //! will be done by cloning
//! //!
use crate::action::Action; use crate::action::Action;
use crate::specs::{Buff, BuffState, Recipe, Stats, Success}; use crate::specs::{Buff, BuffState, Recipe, Stats, Success};
use crate::Parameters; use crate::Parameters;
use std::fmt::{Debug, Display, Formatter}; use std::fmt::{Debug, Display, Formatter};
/// The craft structure, note that there is no standard way of backtracking /// The craft structure, note that there is no standard way of backtracking
/// and a traditional branching method is applied when solving. /// and a traditional branching method is applied when solving.
#[derive(Clone)] #[derive(Clone)]
pub struct Craft<'a> { pub struct Craft<'a> {
@ -32,7 +32,7 @@ pub struct Craft<'a> {
pub cp: i32, pub cp: i32,
/// Wether the craft has succeded, is pending sucess, or failed /// Wether the craft has succeded, is pending sucess, or failed
pub success: Success, pub success: Success,
/// The vector of action already applied, structs are used for the vector since /// The vector of action already applied, structs are used for the vector since
/// static references are used and therefore take no additional memory at runtime /// static references are used and therefore take no additional memory at runtime
pub actions: Vec<&'a Action>, pub actions: Vec<&'a Action>,
/// The parameters used for the craft /// The parameters used for the craft
@ -60,7 +60,7 @@ impl<'a> Craft<'a> {
} }
/// How much progression will be done by an action with 100 efficiency and no buffs /// How much progression will be done by an action with 100 efficiency and no buffs
/// This function is mainly used to know wether or not the craft will finish in /// This function is mainly used to know wether or not the craft will finish in
/// 1, 1.2 or 2.0 actions. /// 1, 1.2 or 2.0 actions.
pub fn get_base_progression(&self) -> u32 { pub fn get_base_progression(&self) -> u32 {
let base_value = (self.stats.craftsmanship as f64 / 10.0) let base_value = (self.stats.craftsmanship as f64 / 10.0)
@ -69,7 +69,7 @@ impl<'a> Craft<'a> {
(base_value * (self.recipe.progress_modifier as f64 / 100.0) as f64).floor() as u32 (base_value * (self.recipe.progress_modifier as f64 / 100.0) as f64).floor() as u32
} }
/// How much quality will the crafter generate with one action with 100 efficiency and no buffs /// How much quality will the crafter generate with one action with 100 efficiency and no buffs
/// This function is usually called by [`run_action`](crate::craft::Craft::run_action) /// This function is usually called by [`run_action`](crate::craft::Craft::run_action)
/// wich will then apply all needed buff and progress the craft /// wich will then apply all needed buff and progress the craft
pub fn get_base_quality(&self) -> u32 { pub fn get_base_quality(&self) -> u32 {
let base_value = (self.stats.control as f64 / 10.0) let base_value = (self.stats.control as f64 / 10.0)

View File

@ -1,7 +1,7 @@
//! The main IO module //! The main IO module
//! For now it contains the python bindings, the Args bindings (for clap) and the struct //! For now it contains the python bindings, the Args bindings (for clap) and the struct
//! needed to hold all parameters needed at runtime //! needed to hold all parameters needed at runtime
//! //!
//! Moving the bindings and making them non mandatory is a WIP //! Moving the bindings and making them non mandatory is a WIP
use crate::Craft; use crate::Craft;
@ -169,7 +169,7 @@ impl SolverResult {
#[pymethods] #[pymethods]
impl SolverResult { impl SolverResult {
/// Default method to create an empty solution, only used for debug purposes /// Default method to create an empty solution, only used for debug purposes
/// to test wether the import worked /// to test wether the import worked
/// ```py /// ```py
/// import xiv_csolver_lib /// import xiv_csolver_lib
@ -250,7 +250,7 @@ use crate::{solve_craft, Recipe, Stats};
/// The values are all obtained by a `&PyAny`, wich must guaranty that several attributes are /// The values are all obtained by a `&PyAny`, wich must guaranty that several attributes are
/// accesible by `__getattr__` /// accesible by `__getattr__`
/// ///
/// ```py /// ```python
/// import xiv_craft_solver, rich /// import xiv_craft_solver, rich
/// ///
/// class FeedingClass: /// class FeedingClass:

View File

@ -4,55 +4,103 @@ use std::fmt::Debug;
use strum_macros::EnumIter; use strum_macros::EnumIter;
/// The recipe to craft /// The recipe to craft
/// On some websites the fields are instead called
/// [Progress, quality, durability, progress difficulty, quality difficulty, extra progress difficulty, extra quality difficulty]
#[derive(Debug, Clone, Copy)] #[derive(Debug, Clone, Copy)]
pub struct Recipe { pub struct Recipe {
/// The craft durability (also called solidity) /// The recipe durability (also called solidity) (35, 40, 70 or 80 usually)
pub durability: u32, pub durability: u32,
/// The total recipe progress needed
pub progress: u32, pub progress: u32,
/// The total recipe quality
pub quality: u32, pub quality: u32,
/// How much the progress is hard to set,
/// it's an (hidden) extra progress multiplier,
/// inflicting a -10% to -30% to starred recipes
/// Also called `progress_difficulty`
pub progress_divider: u32, pub progress_divider: u32,
/// The same (hidden) difficulty multiplier, for quality
/// Also called `progress_difficulty`
pub quality_divider: u32, pub quality_divider: u32,
/// Modifies how much the base stats are affecting the craft progress
/// Also called `progress_extra_difficulty`
pub progress_modifier: u32, pub progress_modifier: u32,
/// Modifies how much the base stats are affectif the craft quality
/// Also called `quality_extra_difficulty`
pub quality_modifier: u32, pub quality_modifier: u32,
} }
/// The craftsman stats
#[derive(Debug, Clone, Copy)] #[derive(Debug, Clone, Copy)]
pub struct Stats { pub struct Stats {
/// The craftsmanship, influences the progress
pub craftsmanship: u32, pub craftsmanship: u32,
/// The control, inluences the quality
pub control: u32, pub control: u32,
/// The amount of cp, ressource used for actions
pub max_cp: u32, pub max_cp: u32,
} }
/// The buffs available for the crafter
#[derive(Debug, Clone, Copy, PartialEq, EnumIter)] #[derive(Debug, Clone, Copy, PartialEq, EnumIter)]
pub enum Buff { pub enum Buff {
/// Gain a stack of Inner Quiet with every increase in quality, up to a maximum of 10.
/// Grants a 10% bonus to the efficiency of Touch actions for each stack.
InnerQuiet, InnerQuiet,
/// Reduces loss of durability by 50%.
WasteNot, WasteNot,
/// Increases the efficiency of next Touch action by 100%.
GreatStrides, GreatStrides,
/// Increases efficiency of Touch actions by 50%.
Innovation, Innovation,
/// Increases efficiency of Synthesis actions by 50%.
Veneration, Veneration,
/// Restores 5 points of durability after each step.
Manipulation, Manipulation,
/// Increases progress.
/// Efficiency: 300%
/// Success Rate: 100%
/// Additional Effect: Efficiency of your next Synthesis action is increased by 100%
/// Available only on the first step.
/// Additional effect is active for five steps.
MuscleMemory, MuscleMemory,
// v Hidden v // v Hidden v
/// (Hidden) Combo with Standart touch costs 18 cp.
BasicTouch, BasicTouch,
/// (Hidden) Combo with Advanced touch costs 18 cp.
StandardTouch, StandardTouch,
/// (Hidden) Do nothing for one step.
Observe, Observe,
} }
/// Keeps track of all the durations remaining on all buffs
/// Also called buff tracker in the docs
#[derive(Debug, Clone, Copy)] #[derive(Debug, Clone, Copy)]
pub struct BuffState { pub struct BuffState {
/// Caps at 10 for a 100% extra efficiency in quality increase
pub inner_quiet: u8, pub inner_quiet: u8,
/// Lasts for four steps if Waste not was used, height if Waste Not II was.
pub waste_not: u8, pub waste_not: u8,
/// Effect active for three steps, dissipates after a quality action is used.
pub great_strides: u8, pub great_strides: u8,
/// Lasts four steps
pub innovation: u8, pub innovation: u8,
/// Lasts four steps.
pub veneration: u8, pub veneration: u8,
/// Lasts height steps
pub manipulation: u8, pub manipulation: u8,
/// Lasts five steps, dissipate after a progression action is used.
pub muscle_memory: u8, pub muscle_memory: u8,
/// Lasts one step
pub basic_touch: u8, pub basic_touch: u8,
/// Lasts one step
pub standard_touch: u8, pub standard_touch: u8,
/// Lasts one step
pub observe: u8, pub observe: u8,
} }
impl BuffState { impl BuffState {
/// Default state of buffs (all at zero) as per the beggining of craft
pub fn default() -> Self { pub fn default() -> Self {
Self { Self {
inner_quiet: 0, inner_quiet: 0,
@ -68,6 +116,7 @@ impl BuffState {
} }
} }
/// Remove the given buff from the buff tracker
pub fn remove(&mut self, buff: Buff) { pub fn remove(&mut self, buff: Buff) {
match buff { match buff {
Buff::InnerQuiet => self.inner_quiet = 0, Buff::InnerQuiet => self.inner_quiet = 0,
@ -83,6 +132,8 @@ impl BuffState {
} }
} }
/// Apply the given buff to the buff tracker for `value` steps
/// In the case of Inner Quiet, it inseads adds one to the stack counter
pub fn apply(&mut self, buff: Buff, value: u8) { pub fn apply(&mut self, buff: Buff, value: u8) {
match buff { match buff {
Buff::InnerQuiet => { Buff::InnerQuiet => {
@ -104,6 +155,7 @@ impl BuffState {
} }
} }
/// Tick downs the remaining duration of all buffs, if up
pub fn tick(&mut self) { pub fn tick(&mut self) {
if self.waste_not > 0 { if self.waste_not > 0 {
self.waste_not -= 1; self.waste_not -= 1;
@ -132,9 +184,14 @@ impl BuffState {
} }
} }
/// State the craft is in, used to keep track of wether the craft
/// is to be worked on, added to the success vector or discarded
#[derive(Debug, Clone, Copy, PartialEq)] #[derive(Debug, Clone, Copy, PartialEq)]
pub enum Success { pub enum Success {
/// Pending success and therefor still ongoing
Pending, Pending,
/// Finised, not ongoing and finished without breaking (Doens't take quality into account)
Success, Success,
/// Finised because of lack of remaining durability
Failure, Failure,
} }