diff --git a/Cargo.toml b/Cargo.toml
index e3e6c0e..f0d1f67 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -19,7 +19,7 @@ toml = "0.5.9"
clap = {version = "4.1.6", features = ["derive"]}
threadpool = "1.8.1"
# For python bindings TODO: make it optionnal
-pyo3 = { version = "0.18.0", features = ["extension-module"] }
+pyo3 = { version = "0.18.1", features= ["extension-module"]}
# [target.'cfg(not(no_python))'.dependencies]
# pyo3 = { version = "0.18.0", features = ["extension-module"] }
@@ -36,7 +36,8 @@ opt-level = 3
lto = true
[features]
-default = []
+extension-module = ["pyo3/extension-module"]
+default = ["extension-module"]
verbose = []
no_python = [] # Removes the python bindings
fast = [] # Remove some under optimisations that try to find other routes
@@ -48,4 +49,5 @@ crate-type = ["cdylib","rlib"]
[[bin]]
name = "xiv_csolver_cli"
-path = "src/bin/xiv_csolver.rs"
\ No newline at end of file
+path = "src/bin/xiv_csolver.rs"
+
diff --git a/Makefile.toml b/Makefile.toml
index cf4c53b..72dcc22 100644
--- a/Makefile.toml
+++ b/Makefile.toml
@@ -18,10 +18,11 @@ script = [
"twine upload releases/xiv_csolver_lib*.whl --repository gitea",
]
-[tasks.format]
-install_crate = "rustfmt"
-command = "cargo"
-args = ["fmt", "--", "--emit=files"]
+[tasks.fmt]
+script_runner = "@shell"
+script = [
+"cargo +nightly fmt -- --config format_code_in_doc_comments=true --config imports_granularity=Module"
+]
[tasks.testcov]
script_runner = "@shell"
@@ -29,7 +30,7 @@ ignore_errors = true
script = [
"mkdir -p coverage",
"mkdir -p coverage/html",
-"CARGO_INCREMENTAL=0 RUSTFLAGS='-Cinstrument-coverage' LLVM_PROFILE_FILE='llvm/cargo-test-%p-%m.profraw' cargo test",
+"CARGO_INCREMENTAL=0 RUSTFLAGS='-Cinstrument-coverage -Ccodegen-units=1 -Copt-level=0 -Coverflow-checks=off' LLVM_PROFILE_FILE='llvm/cargo-test-%p-%m.profraw' cargo test",
"grcov . --binary-path ./target/debug/deps/ -s . -t html --branch --ignore-not-existing --ignore '../*' --ignore '/*' -o coverage/html/"
]
diff --git a/README.md b/README.md
index fb2e1c4..0a64ce8 100644
--- a/README.md
+++ b/README.md
@@ -5,7 +5,7 @@ Originaly written by [RikaKagurasaka](https://github.com/RikaKagurasaka/xiv_craf
it now is widely improved and provides python bindings for a GUI (or anything else really)
-
+
### Basic RUST CLI Usage
Everything is done through the regular cargo interface
diff --git a/coverage/html/badges/flat.svg b/coverage/html/badges/flat.svg
index 6febf64..cbcfb5c 100644
--- a/coverage/html/badges/flat.svg
+++ b/coverage/html/badges/flat.svg
@@ -1,6 +1,6 @@
\ No newline at end of file
diff --git a/coverage/html/badges/flat_square.svg b/coverage/html/badges/flat_square.svg
index 9907885..36d4829 100644
--- a/coverage/html/badges/flat_square.svg
+++ b/coverage/html/badges/flat_square.svg
@@ -1,13 +1,13 @@
\ No newline at end of file
diff --git a/coverage/html/badges/for_the_badge.svg b/coverage/html/badges/for_the_badge.svg
index 7d6b58d..0cfc978 100644
--- a/coverage/html/badges/for_the_badge.svg
+++ b/coverage/html/badges/for_the_badge.svg
@@ -1,13 +1,13 @@
\ No newline at end of file
diff --git a/coverage/html/badges/plastic.svg b/coverage/html/badges/plastic.svg
index 209f476..68d3549 100644
--- a/coverage/html/badges/plastic.svg
+++ b/coverage/html/badges/plastic.svg
@@ -1,6 +1,6 @@
\ No newline at end of file
diff --git a/coverage/html/badges/social.svg b/coverage/html/badges/social.svg
index ccb1035..45c8c46 100644
--- a/coverage/html/badges/social.svg
+++ b/coverage/html/badges/social.svg
@@ -1,6 +1,6 @@
\ No newline at end of file
diff --git a/pyproject.toml b/pyproject.toml
index 5c2868e..19a619f 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -10,4 +10,7 @@ classifiers = [
"Programming Language :: Rust",
"Programming Language :: Python :: Implementation :: CPython",
"Programming Language :: Python :: Implementation :: PyPy",
-]
\ No newline at end of file
+]
+
+[tool.maturin]
+features = ["pyo3/extension-module"]
\ No newline at end of file
diff --git a/rustfmt.toml b/rustfmt.toml
new file mode 100644
index 0000000..44148a2
--- /dev/null
+++ b/rustfmt.toml
@@ -0,0 +1 @@
+reorder_imports = true
diff --git a/src/action.rs b/src/action.rs
index 9ff889f..0ae718d 100644
--- a/src/action.rs
+++ b/src/action.rs
@@ -2,7 +2,6 @@
//!
//! All actions are defined as Action, containing all methods to actively use it in a craft
//! while ActionBuilder is used only initally as a lazy_static setup
-//!
use crate::craft::Craft;
use crate::specs::{Buff, Success};
@@ -45,10 +44,10 @@ impl ActionBuilder {
/// use xiv_csolver_lib::action::ActionBuilder;
/// use xiv_csolver_lib::specs::Buff;
/// ActionBuilder::new("Muscle Memory")
- /// .cp(6)
- /// .progress(300)
- /// .buff(Some((Buff::MuscleMemory, 5)))
- /// .build();
+ /// .cp(6)
+ /// .progress(300)
+ /// .buff(Some((Buff::MuscleMemory, 5)))
+ /// .build();
/// ```
pub fn new(name: &str) -> Self {
let mut short_name = name.to_string();
@@ -145,9 +144,10 @@ impl Action {
}
/// Get the durability cost this action would have if used at this stage of the craft
/// This method accounts for the effects of **master mend** and **waste not**.
- pub fn get_durability_cost(&self, _craft: &Craft) -> u32 {
+ /// Note that not using i32 for durability from scratch is a desing choice
+ pub fn get_durability_cost(&self, _craft: &Craft) -> i32 {
if self == &ACTIONS.masters_mend {
- return 30;
+ return -30;
}
if self.dur == 0 || self.progress == 0 && self.quality == 0 {
return 0;
@@ -159,7 +159,7 @@ impl Action {
if dur < 5 {
dur = 5;
}
- dur
+ dur as i32
}
/// Get the progress effect this action would have if used at this stage of the craft
/// This method accounts for the effects of **groundwork** under 20 durability,
@@ -419,6 +419,7 @@ impl Default for ActionList {
.build(),
masters_mend: ActionBuilder::new("Master's Mend").cp(88).build(),
+ //masters_mend: ActionBuilder::new("Master's Mend").dur(-30).cp(88).build(),
waste_not: ActionBuilder::new("Waste Not")
.cp(56)
.buff(Some((Buff::WasteNot, 4)))
@@ -514,7 +515,7 @@ mod test {
assert_eq!(&ACTIONS.standard_touch.get_cp_cost(&craft), &18);
assert_eq!(&ACTIONS.advanced_touch.get_cp_cost(&craft), &18);
- assert_eq!(&ACTIONS.masters_mend.get_durability_cost(&craft), &30);
+ assert_eq!(&ACTIONS.masters_mend.get_durability_cost(&craft), &-30);
assert_eq!(&ACTIONS.byregot_blessing.get_quality(&craft), &420);
assert_eq!(&ACTIONS.byregot_blessing.can_use(&craft), &true);
diff --git a/src/bin/xiv_csolver.rs b/src/bin/xiv_csolver.rs
index c94c690..9549faf 100644
--- a/src/bin/xiv_csolver.rs
+++ b/src/bin/xiv_csolver.rs
@@ -30,7 +30,7 @@
//!
//! It is really recommended to set up a venv to handle the python development
//!
-//! All bindings and the explanation of how to use them can be found in the [`io`](crate::io) module.
+//! All bindings and the explanation of how to use them can be found in the [`io`](xiv_csolver_lib::io) module.
//!
//! ### Features
//!
diff --git a/src/craft.rs b/src/craft.rs
index 2a43a4d..9f4cd95 100644
--- a/src/craft.rs
+++ b/src/craft.rs
@@ -3,7 +3,6 @@
//! 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
//! will be done by cloning
-//!
use crate::action::Action;
use crate::specs::{Buff, BuffState, Recipe, Stats, Success};
@@ -211,14 +210,79 @@ impl<'a> Craft<'a> {
},
)
}
+
+ /// Create a "Three start" craft, testing only
+ pub fn three_star() -> Craft<'a> {
+ Self::new(
+ crate::specs::Recipe {
+ durability: 70,
+ progress: 3900,
+ quality: 10920,
+ progress_divider: 130,
+ quality_divider: 115,
+ progress_modifier: 80,
+ quality_modifier: 70,
+ },
+ crate::specs::Stats {
+ craftsmanship: 4041,
+ control: 3971,
+ max_cp: 595,
+ },
+ crate::io::Parameters {
+ threads: 8,
+ verbose: 2,
+ depth: 8,
+ desperate: false,
+ byregot_step: 10,
+ },
+ )
+ }
}
#[cfg(test)]
mod test {
- // use pretty_assertions::assert_eq;
+ use pretty_assertions::assert_eq;
// Struct Test
#[test]
pub fn struct_tests() {
- let _craft = crate::craft::Craft::default();
+ let craft = crate::craft::Craft::default().clone();
+ assert_eq!(craft.get_base_progression(), 22);
+ assert_eq!(craft.get_base_quality(), 55);
+
+ format!("{}", craft);
+ format!("{:?}", craft);
+ }
+
+ #[test]
+ pub fn test_craft() {
+ let mut craft = crate::craft::Craft::default();
+ craft.cp = 1000;
+ format!("{:?}", craft);
+ let mut craft2 = craft.run_action(&crate::action::ACTIONS.veneration).clone();
+
+ craft.run_action(&crate::action::ACTIONS.masters_mend);
+ craft.run_action(&crate::action::ACTIONS.masters_mend);
+ craft.run_action(&crate::action::ACTIONS.manipulation);
+ craft.run_action(&crate::action::ACTIONS.basic_touch);
+ craft.run_action(&crate::action::ACTIONS.basic_synthesis);
+ assert_eq!(craft.durability, 190);
+ craft.run_action(&crate::action::ACTIONS.masters_mend);
+ assert_eq!(craft.durability, 200);
+ craft.run_action(&crate::action::ACTIONS.masters_mend);
+ for _ in 0..10 {
+ craft.run_action(&crate::action::ACTIONS.basic_touch);
+ }
+
+ for _ in 0..3 {
+ craft.run_action(&crate::action::ACTIONS.masters_mend);
+ craft.run_action(&crate::action::ACTIONS.groundwork);
+ }
+ assert_eq!(craft.success, crate::craft::Success::Success);
+
+ for _ in 0..20 {
+ craft2.run_action(&crate::action::ACTIONS.preparatory_touch);
+ }
+ assert_eq!(craft2.durability, 0);
+ assert_eq!(craft2.success, crate::craft::Success::Failure);
}
}
diff --git a/src/io.rs b/src/io.rs
index 4c6e038..e4214b7 100644
--- a/src/io.rs
+++ b/src/io.rs
@@ -235,7 +235,26 @@ fn xiv_csolver_lib(_py: Python, m: &PyModule) -> PyResult<()> {
Ok(())
}
-///
+/// A test result, useful for debugging, all values are set to zero as per the
+/// [`default`](crate::io::SolverResult::default)
+/// ```
+/// # use xiv_csolver_lib::io::SolverResult;
+/// SolverResult {
+/// steps: 0,
+/// progression: 0,
+/// quality: 0,
+/// durability: 0,
+/// total_progression: 0,
+/// total_quality: 0,
+/// total_durability: 0,
+/// actions: vec!["Act1".to_string(), "Act2".to_string()],
+/// step1_solutions: 0,
+/// step2_solutions: 0,
+/// found_100_percent: false,
+/// cp: 0,
+/// total_cp: 0,
+/// };
+/// ```
#[cfg(not(feature = "no_python"))]
#[pyfunction]
pub fn test_result() -> SolverResult {
@@ -273,6 +292,7 @@ use crate::{solve_craft, Recipe, Stats};
/// crafting_feeder = FeedingClass()
/// rich.inspect(xiv_csolver_lib.solve_from_python(crafting_feeder))
/// ```
+
#[cfg(not(feature = "no_python"))]
#[pyfunction]
pub fn solve_from_python(py: Python<'_>, values: &PyAny) -> PyResult