vky_refactor #7

Merged
Dandaedre merged 3 commits from vky_refactor into vky 2023-02-22 08:22:54 +01:00
19 changed files with 218 additions and 19 deletions

View File

@ -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

View File

@ -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 <RECIPE_NAME>
Name of the receipe [default: default_recipe]
-c, --character-name <CHARACTER_NAME>
Name of the character [default: default_character]
-f, --file-name <FILE_NAME>
The ml file name [default: craft.toml]
-v, --verbose...
The verbose flag
-d, --depth <DEPTH>
The depth of the first pass [default: 8]
-t, --threads <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...
```

View File

@ -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",
]
]

39
python/__ignore_setup.cfg Normal file
View File

@ -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

38
python/pyproject.toml Normal file
View File

@ -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

3
python/requirements.txt Normal file
View File

@ -0,0 +1,3 @@
dearpygui==1.8.0
PyYAML==6.0
rich==13.3.1

View File

@ -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

View File

@ -0,0 +1,4 @@
"""
A rust program for solving FFXIV craft recipe.
- ffcraft_solver
"""

View File

@ -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 = ''

View File

@ -0,0 +1,3 @@
"""
The modules in this folder are used to generate the GUI and parse the results
"""

View File

@ -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

Binary file not shown.

After

Width:  |  Height:  |  Size: 248 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 352 KiB

29
python/tox.ini Normal file
View File

@ -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