diff --git a/Cargo.toml b/Cargo.toml index d4df157..a1ced99 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,7 @@ name = "xiv_craft_solver" version = "0.1.2" edition = "2021" -authors = ["谭俊健","Dandaedre"] +authors = ["谭俊健","Dandaedre","Vkyfox"] description = "Small XIV solver library in rust, with python and rust bindings" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/README.md b/README.md index 4d20cc2..7737c21 100644 --- a/README.md +++ b/README.md @@ -1,17 +1,71 @@ # xiv_craft_solver -A rust program for solving FFXIV craft recipe. **Only normal lv90 recipes with stars and 70/80 dur works.** +A rust program for solving FFXIV craft recipe. -## Usage +Originaly written by [RikaKagurasaka](https://github.com/RikaKagurasaka/xiv_craft_solver), +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 1. Download the latest release. 2. Unzip the file. 3. Edit the `craft.toml` file. 4. Run the program. -5. Wait for about 1 minute. +5. Wait for about 1-3 seconds. 6. Copy the output. 7. Import to other simulators. -#### Example -Note: The recipe data can be retrieved from [FFXIV Crafting Optimizer](https://yyyy.games/crafter/#/simulator) +## CLI +When building the CLI invocation is done with the following parameters +``` +Small XIV solver library in rust, with python and rust bindings + +Usage: ffcraft [OPTIONS] + +Options: + -r, --recipe-name + Name of the receipe [default: default_recipe] + -c, --character-name + Name of the character [default: default_character] + -f, --file-name + The ml file name [default: craft.toml] + -v, --verbose... + The verbose flag + -d, --depth + The depth of the first pass [default: 8] + -t, --threads + Thread counts, default is 4 [default: 4] + -D, --desperate + Desperate mode, will try to finish the craft above all + -l, --long + Long mode, will try to find more solutions, at the expense of time + -h, --help + Print help + -V, --version + Print version +``` +## Developpement +### Rust +Everything is located in the root & src. +You can build the program (CLI) with cargo build the following features are available +``cargo build --features=["fast","no_python","verbose"]`` +- The ``no_python`` will not build the lib (WIP, not fully implemented) +- The ``fast`` feature will not allow some under-optimisation to run (saving global run-time) +- The ``verbose`` feature will allow even more debug messages (They might not be shown depending on the verbosity level hoever) +#### Maturin +To build the python module, run ``maturin develop`` or ``maturin build`` then ``maturin install`` + +### Python +#### Developping the GUI +0. Activate the venv ``source .venv/bin/activate`` +1. Go to the ``python`` directory +2. Install the dev dependencies ``pip install -r requirements_dev.txt`` +3. Install the project (in editable mode) ``pip install -e .`` +4. Invoke the project (from anywhere) ``python -m ffcraft_solver`` +5. Edit the project and re-invoke it (no need to install / compile again) + + +#### Rust CLI Example +Note: The recipe data can be retrieved from a [FFXIV Crafting Optimizer](https://yyyy.games/crafter/#/simulator) with checking of **Custom Recipe** after selecting the recipe. ![img.png](img.png) ```toml @@ -43,9 +97,19 @@ max_cp = 602 ``` Solving... -Quality: 11126/12628 - ["muscleMemory", "manipulation", "veneration", "groundwork2", "basicSynth2", "prudentSynthesis", "prudentSynthesis", "prudentSynthesis", "prudentTouch", "prudentTouch", "manipulation", "innovation", "prudentTouch", "basicTouch", "standardTouch", "advancedTouch", "innovation", "prudentTouch", "basicTouch", "standardTouch", "advancedTouch", "innovation", "trainedFinesse", "trainedFinesse", "greatStrides", "byregotsBlessing", "basicSynth2"] + > SOLUTION [Least steps] < +Quality: [10941/10920] | Durability: [0/70] | Cp : [14/602] | Steps : 18 +["muscleMemory", "manipulation", "veneration", "wasteNot2", "groundwork", "delicateSynthesis", "basicSynth", "innovation", "preparatoryTouch", "preparatoryTouch", "preparatoryTouch", "preparatoryTouch", "greatStrides", "innovation", "basicTouch", "standardTouch", "greatStrides", "byregotsBlessing", "basicSynth2"] + > SOLUTION [Most durability] < +Quality: [10923/10920] | Durability: [15/70] | Cp : [4/602] | Steps : 22 +["muscleMemory", "manipulation", "veneration", "groundwork", "carefulSynthesis", "prudentTouch", "innovation", "prudentTouch", "prudentTouch", "prudentTouch", "prudentTouch", "manipulation", "innovation", "prudentTouch", "basicTouch", "standardTouch", "advancedTouch", "innovation", "prudentTouch", "basicTouch", "greatStrides", "byregotsBlessing", "basicSynth2"] + + > SOLUTION [Most quality] < +Quality: [12142/10920] | Durability: [-5/70] | Cp : [1/602] | Steps : 22 +["muscleMemory", "manipulation", "veneration", "wasteNot2", "groundwork", "carefulSynthesis", "basicTouch", "innovation", "preparatoryTouch", "basicTouch", "standardTouch", "advancedTouch", "innovation", "prudentTouch", "basicTouch", "standardTouch", "advancedTouch", "innovation", "prudentTouch", "trainedFinesse", "greatStrides", "byregotsBlessing", "basicSynth2"] + +Program finished successfully in 954ms Press enter to exit... ``` diff --git a/pyproject.toml b/pyproject.toml index e75ad35..e26bb76 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -2,13 +2,12 @@ requires = ["maturin>=0.14,<0.15"] build-backend = "maturin" -[project] +[project] # The rust bindings name = "xiv_craft_solver" requires-python = ">=3.7" +version = "0.0.4" classifiers = [ "Programming Language :: Rust", "Programming Language :: Python :: Implementation :: CPython", "Programming Language :: Python :: Implementation :: PyPy", -] - - +] \ No newline at end of file diff --git a/python/__ignore_setup.cfg b/python/__ignore_setup.cfg new file mode 100644 index 0000000..5681c80 --- /dev/null +++ b/python/__ignore_setup.cfg @@ -0,0 +1,39 @@ +[metadata] +platforms = unix, linux, cygwin, win32 +classifiers = + Programming Language :: Python :: 3 + Programming Language :: Python :: 3 :: Only + Programming Language :: Python :: 3.10 + Programming Language :: Python :: 3.9 + +[options] +packages = + ffcraft_solver + ffcraft_solver.modules +install_requires = + pyyaml>=6.0 +python_requires = >=3.9 +package_dir = + =src + +zip_safe = no + +[options.packages.find] +where = + = src + = src/ffcraft_solver + +[options.extras_require] +testing = + flake8>=4.0.1 + tox>=3.24.3 + pytest>=6.2.5 + pytest-cov>=2.12.1 + mypy>=0.910 + pyyaml>=6.0 + +[options.package_data] +slapping = py.typed + +[flake8] +max-line-length = 160 \ No newline at end of file diff --git a/python/pyproject.toml b/python/pyproject.toml new file mode 100644 index 0000000..0e3f93e --- /dev/null +++ b/python/pyproject.toml @@ -0,0 +1,38 @@ +[build-system] +requires = ["setuptools>=42.0", "wheel"] +build-backend = "setuptools.build_meta" + +[project] # The Python GUI +name = "ffcraft_solver" +authors = [ + {name="Vkyfox"}, + {name="Dandaedre"}, +] +requires-python = ">=3.7" +version = "0.0.4" +license = {text="Mozilla Public License Version 2.0"} +classifiers = [ + "Programming Language :: Rust", + "Programming Language :: Python :: Implementation :: CPython", + "Programming Language :: Python :: Implementation :: PyPy", +] + +[tool.pytest.ini_options] +addopts = "--cov=ffcraft_solver" +testpaths = [ + "tests", +] + +[tool.mypy] +mypy_path = "python" +check_untyped_defs = true +disallow_any_generics = true +ignore_missing_imports = true +no_implicit_optional = true +show_error_codes = true +strict_equality = true +warn_redundant_casts = true +warn_return_any = true +warn_unreachable = true +warn_unused_configs = true +no_implicit_reexport = true \ No newline at end of file diff --git a/python/requirements.txt b/python/requirements.txt new file mode 100644 index 0000000..d2a5867 --- /dev/null +++ b/python/requirements.txt @@ -0,0 +1,3 @@ +dearpygui==1.8.0 +PyYAML==6.0 +rich==13.3.1 diff --git a/python/requirements_dev.txt b/python/requirements_dev.txt new file mode 100644 index 0000000..a8b4c81 --- /dev/null +++ b/python/requirements_dev.txt @@ -0,0 +1,8 @@ +flake8==4.0.1 +tox==3.24.5 +pytest==7.1.1 +pytest-cov==3.0.0 +mypy==0.941 +dearpygui==1.8.0 +PyYAML==6.0 +rich==13.3.1 \ No newline at end of file diff --git a/python/src/ffcraft_solver/__init__.py b/python/src/ffcraft_solver/__init__.py new file mode 100644 index 0000000..8925872 --- /dev/null +++ b/python/src/ffcraft_solver/__init__.py @@ -0,0 +1,4 @@ +""" +A rust program for solving FFXIV craft recipe. + - ffcraft_solver +""" diff --git a/python/main.py b/python/src/ffcraft_solver/__main__.py similarity index 99% rename from python/main.py rename to python/src/ffcraft_solver/__main__.py index 76c2691..e624913 100644 --- a/python/main.py +++ b/python/src/ffcraft_solver/__main__.py @@ -1,13 +1,12 @@ import dearpygui.dearpygui as dpg -import loader -import rich import xiv_craft_solver as xcs +from ffcraft_solver.modules import loader +import rich dpg.create_context() dpg.configure_app(manual_callback_management=True) dpg.create_viewport(title='XIV Solver', width=500, height=700) - class User: name = 'NEW' food = '' diff --git a/configs/consumables.yaml b/python/src/ffcraft_solver/configs/consumables.yaml similarity index 100% rename from configs/consumables.yaml rename to python/src/ffcraft_solver/configs/consumables.yaml diff --git a/configs/recipes.yaml b/python/src/ffcraft_solver/configs/recipes.yaml similarity index 100% rename from configs/recipes.yaml rename to python/src/ffcraft_solver/configs/recipes.yaml diff --git a/configs/users.yaml b/python/src/ffcraft_solver/configs/users.yaml similarity index 100% rename from configs/users.yaml rename to python/src/ffcraft_solver/configs/users.yaml diff --git a/example.py b/python/src/ffcraft_solver/example.py similarity index 100% rename from example.py rename to python/src/ffcraft_solver/example.py diff --git a/python/example_dearpygui.py b/python/src/ffcraft_solver/example_dearpygui.py similarity index 100% rename from python/example_dearpygui.py rename to python/src/ffcraft_solver/example_dearpygui.py diff --git a/python/src/ffcraft_solver/modules/__init__.py b/python/src/ffcraft_solver/modules/__init__.py new file mode 100644 index 0000000..746130e --- /dev/null +++ b/python/src/ffcraft_solver/modules/__init__.py @@ -0,0 +1,3 @@ +""" +The modules in this folder are used to generate the GUI and parse the results +""" diff --git a/python/loader.py b/python/src/ffcraft_solver/modules/loader.py similarity index 74% rename from python/loader.py rename to python/src/ffcraft_solver/modules/loader.py index 3c9ea60..f847083 100644 --- a/python/loader.py +++ b/python/src/ffcraft_solver/modules/loader.py @@ -1,5 +1,13 @@ import rich import yaml +import os + +class DefaultConfig: + yaml_user = 'configs/users.yaml' + yaml_consumable = 'configs/consumables.yaml' + yaml_recipes = 'configs/recipes.yaml' + + class Loader: @@ -10,24 +18,29 @@ class Loader: self.foods_list = {' ': [[0, 0], [0, 0], [0, 0]]} self.pots_list = {' ': [[0, 0], [0, 0], [0, 0]]} self.recipes_list = {'NEW': [0, 0, 0]} + self.config = DefaultConfig() + try: - with open('../configs/users.yaml', 'r') as file: + with open(self.relative_import(self.config.yaml_user), 'r') as file: self.user_list.update(yaml.safe_load(file)) except FileNotFoundError as e: print(e) try: - with open('../configs/consumables.yaml', 'r') as file: + with open(self.relative_import(self.config.yaml_consumable), 'r') as file: loaded_file = yaml.safe_load(file) self.foods_list.update(loaded_file['Foods']) self.pots_list.update(loaded_file['Pots']) except FileNotFoundError as e: print(e) try: - with open('../configs/recipes.yaml', 'r') as file: + with open(self.relative_import(self.config.yaml_recipes), 'r') as file: self.recipes_list.update(yaml.safe_load(file)) - except FileNotFoundError as e: + except (FileNotFoundError,IsADirectoryError) as e: print(e) + def relative_import(self, path): + return (os.path.normpath(os.path.join(__file__,"../..",path))) + def get_users_dict(self) -> dict: return self.user_list diff --git a/python/src/ffcraft_solver/resources/ffcraft_solver.ico b/python/src/ffcraft_solver/resources/ffcraft_solver.ico new file mode 100644 index 0000000..3b9f0cf Binary files /dev/null and b/python/src/ffcraft_solver/resources/ffcraft_solver.ico differ diff --git a/python/src/ffcraft_solver/resources/ffcraft_solver.png b/python/src/ffcraft_solver/resources/ffcraft_solver.png new file mode 100644 index 0000000..60a51ef Binary files /dev/null and b/python/src/ffcraft_solver/resources/ffcraft_solver.png differ diff --git a/python/tox.ini b/python/tox.ini new file mode 100644 index 0000000..7fb9316 --- /dev/null +++ b/python/tox.ini @@ -0,0 +1,29 @@ +[tox] +minversion = 3.8.0 +envlist = py37, py38, py39, flake8, mypy +isolated_build = true + +[gh-actions] +python = + 3.7: py36, mypy, flake8 + 3.8: py38 + 3.9: py39 + +[testenv] +setenv = + PYTHONPATH = {toxinidir} +deps = + -r{toxinidir}/requirements_dev.txt +commands = + pytest --basetemp={envtmpdir} + +[testenv:flake8] +basepython = python3.10 +deps = flake8 +commands = flake8 src tests + +[testenv:mypy] +basepython = python3.10 +deps = + -r{toxinidir}/requirements_dev.txt +commands = mypy src