Fix(Modularity) - Fixes the python module
This commit is contained in:
parent
775dc29f13
commit
e7bced1505
|
|
@ -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
|
||||
|
|
|
|||
26
README.md
26
README.md
|
|
@ -4,7 +4,8 @@ A rust program for solving FFXIV craft recipe.
|
|||
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)
|
||||
|
||||
## Usage
|
||||
### 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.
|
||||
|
|
@ -42,11 +43,28 @@ Options:
|
|||
-V, --version
|
||||
Print version
|
||||
```
|
||||
|
||||
## Python
|
||||
## 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``
|
||||
|
||||
#### Example
|
||||
### 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.
|
||||

|
||||
|
|
|
|||
|
|
@ -1,32 +1,13 @@
|
|||
[build-system]
|
||||
requires = ["maturin>=0.14,<0.15"] #,"setuptools>=42.0", "wheel"]
|
||||
build-backend = "maturin" #setuptools.build_meta
|
||||
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",
|
||||
]
|
||||
|
||||
[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
|
||||
]
|
||||
|
|
@ -1,10 +1,4 @@
|
|||
[metadata]
|
||||
name = ffcraft_solver
|
||||
description = A rust program for solving FFXIV craft recipe.
|
||||
author = Dandaedre & Vkyfox
|
||||
version = 0.0.4
|
||||
license = Mozilla Public License Version 2.0
|
||||
license_file = LICENSE
|
||||
platforms = unix, linux, cygwin, win32
|
||||
classifiers =
|
||||
Programming Language :: Python :: 3
|
||||
|
|
@ -26,8 +20,8 @@ zip_safe = no
|
|||
|
||||
[options.packages.find]
|
||||
where =
|
||||
= python
|
||||
= python/ffcraft_solver
|
||||
= src
|
||||
= src/ffcraft_solver
|
||||
|
||||
[options.extras_require]
|
||||
testing =
|
||||
|
|
@ -35,7 +29,7 @@ testing =
|
|||
tox>=3.24.3
|
||||
pytest>=6.2.5
|
||||
pytest-cov>=2.12.1
|
||||
mypy>==0.910
|
||||
mypy>=0.910
|
||||
pyyaml>=6.0
|
||||
|
||||
[options.package_data]
|
||||
|
|
@ -1,183 +0,0 @@
|
|||
import dearpygui.dearpygui as dpg
|
||||
import loader
|
||||
import rich
|
||||
import xiv_craft_solver as xcs
|
||||
|
||||
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 = ''
|
||||
pot = ''
|
||||
specialist = False
|
||||
initial_craftsmanship = 0
|
||||
initial_control = 0
|
||||
initial_cp = 0
|
||||
craftsmanship = 0
|
||||
control = 0
|
||||
cp = 0
|
||||
|
||||
def refresh_gui(self) -> True:
|
||||
self.compute_stats()
|
||||
dpg.set_value(user_combo, self.name)
|
||||
dpg.set_value(food_combo, self.food)
|
||||
dpg.set_value(pot_combo, self.pot)
|
||||
dpg.set_value(user_effective_stats, [self.craftsmanship, self.control, self.cp])
|
||||
return True
|
||||
|
||||
def compute_stats(self) -> list:
|
||||
food = []
|
||||
try:
|
||||
full_food = full_config.get_foods_dict()[self.food]
|
||||
# [[5, 120], [0, 0], [26, 82]]
|
||||
if user.initial_craftsmanship * full_food[0][0] / 100 > full_food[0][1]:
|
||||
food.append(full_food[0][1])
|
||||
else:
|
||||
food.append(round(user.initial_craftsmanship * full_food[0][0] / 100))
|
||||
if user.initial_control * full_food[1][0] / 100 > full_food[1][1]:
|
||||
food.append(full_food[1][1])
|
||||
else:
|
||||
food.append(round(user.initial_control * full_food[1][0] / 100))
|
||||
if user.initial_cp * full_food[2][0] / 100 > full_food[2][1]:
|
||||
food.append(full_food[2][1])
|
||||
else:
|
||||
food.append(round(user.initial_cp * full_food[2][0] / 100))
|
||||
except KeyError as _:
|
||||
food = [0, 0, 0]
|
||||
pass
|
||||
|
||||
pot = []
|
||||
try:
|
||||
full_pot = full_config.get_pots_dict()[self.pot]
|
||||
# [(0, 0), (0, 0), (6, 21)]
|
||||
if user.initial_craftsmanship * full_pot[0][0] / 100 > full_pot[0][1]:
|
||||
pot.append(full_pot[0][1])
|
||||
else:
|
||||
pot.append(round(user.initial_craftsmanship * full_pot[0][0] / 100))
|
||||
if user.initial_control * full_pot[1][0] / 100 > full_pot[1][1]:
|
||||
pot.append(full_pot[1][1])
|
||||
else:
|
||||
pot.append(round(user.initial_control * full_pot[1][0] / 100))
|
||||
if user.initial_cp * full_pot[2][0] / 100 > full_pot[2][1]:
|
||||
pot.append(full_pot[2][1])
|
||||
else:
|
||||
pot.append(round(user.initial_cp * full_pot[2][0] / 100))
|
||||
except KeyError as _:
|
||||
pot = [0, 0, 0]
|
||||
pass
|
||||
|
||||
if user.specialist:
|
||||
specialist = [20, 20, 15]
|
||||
else:
|
||||
specialist = [0, 0, 0]
|
||||
|
||||
self.craftsmanship = self.initial_craftsmanship + food[0] + pot[0] + specialist[0]
|
||||
self.control = self.initial_control + food[1] + pot[1] + specialist[1]
|
||||
self.cp = self.initial_cp + food[2] + pot[2] + specialist[2]
|
||||
|
||||
def set_initial_stats(self, _, app_data, __) -> list:
|
||||
self.initial_craftsmanship = app_data[0]
|
||||
self.initial_control = app_data[1]
|
||||
self.initial_cp = app_data[2]
|
||||
self.refresh_gui()
|
||||
return [self.initial_craftsmanship, self.initial_control, self.initial_cp]
|
||||
|
||||
def set_specialist(self, _, app_data, __) -> bool:
|
||||
if app_data:
|
||||
self.specialist = True
|
||||
else:
|
||||
self.specialist = False
|
||||
self.refresh_gui()
|
||||
return self.specialist
|
||||
|
||||
def set_food(self, _, app_data, __) -> str:
|
||||
self.food = app_data
|
||||
self.refresh_gui()
|
||||
return self.food
|
||||
|
||||
def set_pot(self, _, app_data, __) -> str:
|
||||
self.pot = app_data
|
||||
self.refresh_gui()
|
||||
return self.food
|
||||
|
||||
|
||||
class Recipe:
|
||||
name = ''
|
||||
quality = 0
|
||||
difficulty = 0
|
||||
durability = 0
|
||||
|
||||
def set_recipe_stats(self, _, app_data, __):
|
||||
self.quality = app_data[0]
|
||||
self.difficulty = app_data[1]
|
||||
self.durability = app_data[2]
|
||||
return self.quality, self.difficulty, self.durability
|
||||
|
||||
def get_recipe_stats(self):
|
||||
return self.quality, self.difficulty, self.durability
|
||||
|
||||
def set_recipe_name(self, _, app_data, __):
|
||||
self.name = app_data
|
||||
self.set_recipe_stats(0, full_config.get_recipes_dict()[self.name], 0)
|
||||
dpg.set_value(recipe_stats, self.get_recipe_stats())
|
||||
return self.name
|
||||
|
||||
|
||||
with dpg.window(label="Settings", width=500, height=700, no_resize=True, no_title_bar=True):
|
||||
user = User()
|
||||
recipe = Recipe()
|
||||
|
||||
full_config = loader.Loader()
|
||||
characters_names = full_config.get_users_names()
|
||||
foods_names = full_config.get_foods_names()
|
||||
pots_names = full_config.get_pots_names()
|
||||
recipe_names = full_config.get_recipes_names()
|
||||
|
||||
dpg.add_text("Character")
|
||||
user_combo = dpg.add_combo(items=characters_names, label="Your character")
|
||||
dpg.set_value(user_combo, "NEW")
|
||||
# TODO: Load 1rst user in users.yaml by default
|
||||
# TODO: Make NEW prompt for a name when saving
|
||||
user_stats = dpg.add_input_intx(size=3, label="Stats", tag="stats_tooltip", callback=user.set_initial_stats)
|
||||
with dpg.tooltip("stats_tooltip"):
|
||||
dpg.add_text("Craftsmanship / Control / CP")
|
||||
dpg.add_button(label="Save!", indent=282)
|
||||
specialist_checkbox = dpg.add_checkbox(label="Specialist", tag="specialist", callback=user.set_specialist)
|
||||
dpg.add_text(" ")
|
||||
user_effective_stats = dpg.add_input_intx(size=3, label="Effective stats", tag="effective_stats_tooltip", readonly=True)
|
||||
with dpg.tooltip("effective_stats_tooltip"):
|
||||
dpg.add_text("Craftsmanship / Control / CP")
|
||||
|
||||
dpg.add_separator()
|
||||
|
||||
dpg.add_text("Consumables")
|
||||
food_combo = dpg.add_combo(items=foods_names, label="Food", callback=user.set_food)
|
||||
pot_combo = dpg.add_combo(items=pots_names, label="Pot", callback=user.set_pot)
|
||||
|
||||
dpg.add_separator()
|
||||
|
||||
dpg.add_text("Recipe")
|
||||
recipe_combo = dpg.add_combo(items=recipe_names, label="Recipe", callback=recipe.set_recipe_name)
|
||||
dpg.set_value(recipe_combo, "NEW")
|
||||
recipe_stats = dpg.add_input_intx(size=3, label="Stats", tag="recipe_tooltip", callback=recipe.set_recipe_stats)
|
||||
with dpg.tooltip("recipe_tooltip"):
|
||||
dpg.add_text("Quality / Difficulty / Durability")
|
||||
# TODO: add a small grey text message if recipe matches a known recipe
|
||||
dpg.add_button(label="Save!", indent=282)
|
||||
|
||||
dpg.add_button(label="Solve!")
|
||||
dpg.add_collapsing_header(label="Result")
|
||||
|
||||
# TODO: add a log space at the bottom
|
||||
|
||||
dpg.setup_dearpygui()
|
||||
dpg.show_viewport()
|
||||
while dpg.is_dearpygui_running():
|
||||
jobs = dpg.get_callback_queue() # retrieves and clears queue
|
||||
dpg.run_callbacks(jobs)
|
||||
dpg.render_dearpygui_frame()
|
||||
dpg.start_dearpygui()
|
||||
dpg.destroy_context()
|
||||
|
|
@ -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
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
dearpygui==1.8.0
|
||||
PyYAML==6.0
|
||||
rich==13.3.1
|
||||
|
|
@ -3,5 +3,6 @@ tox==3.24.5
|
|||
pytest==7.1.1
|
||||
pytest-cov==3.0.0
|
||||
mypy==0.941
|
||||
pyyaml==6.0
|
||||
rich==12.0.1
|
||||
dearpygui==1.8.0
|
||||
PyYAML==6.0
|
||||
rich==13.3.1
|
||||
|
|
@ -1,12 +1,13 @@
|
|||
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)
|
||||
|
||||
dpg.set_viewport_large_icon("/home/dandaedre/Documents/Git/xiv_craft_solver/python/src/ffcraft_solver/resources/ffxiv_solver.ico")
|
||||
dpg.set_viewport_small_icon("/home/dandaedre/Documents/Git/xiv_craft_solver/python/src/ffcraft_solver/resources/ffxiv_solver.ico")
|
||||
|
||||
class User:
|
||||
name = 'NEW'
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
"""
|
||||
The modules in this folder are used to generate the GUI and parse the results
|
||||
"""
|
||||
|
|
@ -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 |
|
|
@ -1,5 +0,0 @@
|
|||
pyyaml==6.0
|
||||
rich==12.0.1
|
||||
pyparse~=1.1.7
|
||||
pyparsing[diagrams]~=3.0.7
|
||||
pytest==7.1.1
|
||||
Reference in New Issue