Rewrote a lot of code because recipes are not 3 values but 7
Added text area to save as (save still not implemented) Created logger and solver
This commit is contained in:
parent
7a8dca2f06
commit
4015bda699
|
|
@ -1,14 +1,15 @@
|
|||
import dearpygui.dearpygui as dpg
|
||||
import xiv_craft_solver as xcs
|
||||
from ffcraft_solver.modules import loader
|
||||
from ffcraft_solver.modules import loader, log, solver
|
||||
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'
|
||||
name = ' '
|
||||
food = ''
|
||||
pot = ''
|
||||
specialist = False
|
||||
|
|
@ -25,13 +26,16 @@ class User:
|
|||
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])
|
||||
if self.name != ' ':
|
||||
dpg.set_value(save_user_as, self.name)
|
||||
else:
|
||||
dpg.set_value(save_user_as, '')
|
||||
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:
|
||||
|
|
@ -51,7 +55,6 @@ class User:
|
|||
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:
|
||||
|
|
@ -77,6 +80,8 @@ class User:
|
|||
self.control = self.initial_control + food[1] + pot[1] + specialist[1]
|
||||
self.cp = self.initial_cp + food[2] + pot[2] + specialist[2]
|
||||
|
||||
return [self.craftsmanship, self.control, self.cp]
|
||||
|
||||
def set_initial_stats(self, _, app_data, __) -> list:
|
||||
self.initial_craftsmanship = app_data[0]
|
||||
self.initial_control = app_data[1]
|
||||
|
|
@ -102,30 +107,79 @@ class User:
|
|||
self.refresh_gui()
|
||||
return self.food
|
||||
|
||||
def set_name_combo(self, _, app_data, __) -> str:
|
||||
self.name = app_data
|
||||
self.set_initial_stats(0, full_config.get_users_dict()[self.name], None)
|
||||
dpg.set_value(user_stats, [self.initial_craftsmanship, self.initial_control, self.initial_cp])
|
||||
return self.name
|
||||
|
||||
|
||||
class Recipe:
|
||||
name = ''
|
||||
name = ' '
|
||||
progress = 0
|
||||
quality = 0
|
||||
difficulty = 0
|
||||
durability = 0
|
||||
quality_difficulty = 0
|
||||
progress_difficulty = 0
|
||||
quality_extra_difficulty = 0
|
||||
progress_extra_difficulty = 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 refresh_gui(self):
|
||||
dpg.set_value(recipe_stats, self.get_recipe_stats()[0:3])
|
||||
dpg.set_value(advanced_recipe_stats, self.get_recipe_stats()[3:7])
|
||||
if self.name != ' ':
|
||||
dpg.set_value(save_recipe_as, self.name)
|
||||
else:
|
||||
dpg.set_value(save_recipe_as, '')
|
||||
|
||||
def get_recipe_stats(self):
|
||||
return self.quality, self.difficulty, self.durability
|
||||
def set_recipe_stats(self, tag, app_data, _) -> list[int, int, int, int, int, int, int]:
|
||||
stats = [0, 0, 0]
|
||||
advanced_stats = [0, 0, 0, 0]
|
||||
|
||||
if tag == 'recipe_tooltip':
|
||||
stats = app_data
|
||||
advanced_stats = dpg.get_value(advanced_recipe_stats)
|
||||
elif tag == 'advanced_recipe_tooltip':
|
||||
stats = dpg.get_value(recipe_stats)
|
||||
advanced_stats = app_data
|
||||
elif tag == 0:
|
||||
stats = [app_data[0], app_data[1], app_data[2]]
|
||||
advanced_stats = [app_data[3], app_data[4], app_data[5], app_data[6]]
|
||||
else:
|
||||
print('Log: Something went very wrong in recipe stat assignment.')
|
||||
|
||||
self.progress = stats[0]
|
||||
self.quality = stats[1]
|
||||
self.durability = stats[2]
|
||||
self.progress_difficulty = advanced_stats[0]
|
||||
self.quality_difficulty = advanced_stats[1]
|
||||
self.progress_extra_difficulty = advanced_stats[2]
|
||||
self.quality_extra_difficulty = advanced_stats[3]
|
||||
|
||||
return [self.progress, self.quality, self.durability, self.progress_difficulty, self.quality_difficulty,
|
||||
self.progress_extra_difficulty, self.quality_extra_difficulty]
|
||||
|
||||
def get_recipe_stats(self) -> list[int, int, int, int, int, int, int]:
|
||||
return [self.progress, self.quality, self.durability, self.progress_difficulty, self.quality_difficulty,
|
||||
self.progress_extra_difficulty, self.quality_extra_difficulty]
|
||||
|
||||
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())
|
||||
self.refresh_gui()
|
||||
return self.name
|
||||
|
||||
def get_recipe_name(self) -> str:
|
||||
return self.name
|
||||
|
||||
|
||||
def request_solve(self):
|
||||
solve = solver.Solver(user, recipe)
|
||||
solve.solve()
|
||||
|
||||
|
||||
with dpg.window(label="Settings", width=500, height=700, no_resize=True, no_title_bar=True, no_move=True):
|
||||
# Initialization of all our classes
|
||||
user = User()
|
||||
recipe = Recipe()
|
||||
|
||||
|
|
@ -135,42 +189,63 @@ with dpg.window(label="Settings", width=500, height=700, no_resize=True, no_titl
|
|||
pots_names = full_config.get_pots_names()
|
||||
recipe_names = full_config.get_recipes_names()
|
||||
|
||||
loggers = log.Loggers()
|
||||
|
||||
# Start of GUI drawing
|
||||
# CHARACTER
|
||||
dpg.add_text("Character")
|
||||
user_combo = dpg.add_combo(items=characters_names, label="Your character")
|
||||
dpg.set_value(user_combo, "NEW")
|
||||
user_combo = dpg.add_combo(items=characters_names, label="Your character", callback=user.set_name_combo)
|
||||
dpg.set_value(user_combo, " ")
|
||||
# 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(" ")
|
||||
with dpg.group(horizontal=True):
|
||||
save_user_as = dpg.add_input_text(hint='Save as...')
|
||||
dpg.add_button(label="Save!")
|
||||
# TODO: Can't save if value == ' '
|
||||
|
||||
# EFFECTIVE STATS
|
||||
dpg.add_separator()
|
||||
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")
|
||||
# MODIFIERS
|
||||
dpg.add_text("Modifiers")
|
||||
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)
|
||||
specialist_checkbox = dpg.add_checkbox(label="Specialist", tag="specialist", callback=user.set_specialist)
|
||||
|
||||
# RECIPE
|
||||
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")
|
||||
dpg.set_value(recipe_combo, " ")
|
||||
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")
|
||||
dpg.add_text("Progress / Quality / Durability")
|
||||
advanced_recipe_stats = dpg.add_input_intx(
|
||||
size=4, label="Advanced stats", tag="advanced_recipe_tooltip", callback=recipe.set_recipe_stats
|
||||
)
|
||||
with dpg.tooltip("advanced_recipe_tooltip"):
|
||||
dpg.add_text("Progress / Quality difficulty // Progress / Quality extra difficulty")
|
||||
# TODO: add a log if recipe matches a known recipe
|
||||
dpg.add_button(label="Save!", indent=282)
|
||||
with dpg.group(horizontal=True):
|
||||
save_recipe_as = dpg.add_input_text(hint='Save as...')
|
||||
dpg.add_button(label="Save!", callback=request_solve)
|
||||
# TODO: Can't save if value == ' '
|
||||
|
||||
# SOLVE
|
||||
dpg.add_separator()
|
||||
dpg.add_button(label="Solve!")
|
||||
dpg.add_text()
|
||||
dpg.add_collapsing_header(label="Result")
|
||||
|
||||
# TODO: add a log space at the bottom
|
||||
# LOG
|
||||
log_window = dpg.add_input_text(multiline=True, default_value=loggers.log, height=50, width=500,
|
||||
tab_input=True, pos=[0, 642], tracked=True)
|
||||
|
||||
dpg.setup_dearpygui()
|
||||
dpg.show_viewport()
|
||||
|
|
|
|||
|
|
@ -1,3 +1,8 @@
|
|||
# Name: [Quality, difficulty, durability]
|
||||
Grade 7 Tincture of Strength: [12628, 5060, 70]
|
||||
Grade 5 Strength Alkahest: [6200, 1300, 35]
|
||||
# Name: [Progress, quality, durability, progress difficulty, quality difficulty, extra progress difficulty, extra quality difficulty]
|
||||
# as can be found on other solver websites, such as https://yyyy.games/crafter/index.html#/simulator and checking custom recipe.
|
||||
# The language option is the second menu to the left from the top-right hand corner.
|
||||
# If this seems super convoluted, and you'd rather it was just the three in-game values, know that me too.
|
||||
# Unfortunately that is how Square Enix chose to make crafting work in FFXIV.
|
||||
|
||||
Grade 7 Tincture of Strength: [5060, 12628, 70, 130, 115, 80, 70]
|
||||
Grade 5 Strength Alkahest: [1300, 6200, 40, 123, 107, 100, 100]
|
||||
|
|
@ -7,7 +7,7 @@ rich.inspect(xiv_craft_solver.test_result())
|
|||
rich.inspect(xiv_craft_solver.test_result())
|
||||
|
||||
|
||||
class feedMeDaddy:
|
||||
class FeedMeDaddy:
|
||||
durability = 70
|
||||
progress = 3900
|
||||
quality = 10920
|
||||
|
|
@ -27,6 +27,6 @@ class feedMeDaddy:
|
|||
verbose = 0
|
||||
|
||||
|
||||
el_daddy=feedMeDaddy()
|
||||
el_daddy = FeedMeDaddy()
|
||||
rich.inspect(xiv_craft_solver.solve_from_python(el_daddy))
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,11 @@
|
|||
import rich
|
||||
import yaml
|
||||
import os
|
||||
# from xiv_craft_solver.modules import log
|
||||
|
||||
|
||||
# loggers = log.Loggers()
|
||||
|
||||
|
||||
class DefaultConfig:
|
||||
yaml_user = 'configs/users.yaml'
|
||||
|
|
@ -8,16 +13,14 @@ class DefaultConfig:
|
|||
yaml_recipes = 'configs/recipes.yaml'
|
||||
|
||||
|
||||
|
||||
|
||||
class Loader:
|
||||
# TODO: create folder/file if missing when clicking "save"
|
||||
# TODO: log any missing file(s) or the whole folder
|
||||
def __init__(self):
|
||||
self.user_list = {'NEW': [0, 0, 0]}
|
||||
self.user_list = {' ': [0, 0, 0]}
|
||||
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.recipes_list = {' ': [0, 0, 0, 0, 0, 0, 0]}
|
||||
self.config = DefaultConfig()
|
||||
|
||||
try:
|
||||
|
|
@ -25,6 +28,7 @@ class Loader:
|
|||
self.user_list.update(yaml.safe_load(file))
|
||||
except FileNotFoundError as e:
|
||||
print(e)
|
||||
|
||||
try:
|
||||
with open(self.relative_import(self.config.yaml_consumable), 'r') as file:
|
||||
loaded_file = yaml.safe_load(file)
|
||||
|
|
@ -32,16 +36,19 @@ class Loader:
|
|||
self.pots_list.update(loaded_file['Pots'])
|
||||
except FileNotFoundError as e:
|
||||
print(e)
|
||||
|
||||
try:
|
||||
with open(self.relative_import(self.config.yaml_recipes), 'r') as file:
|
||||
self.recipes_list.update(yaml.safe_load(file))
|
||||
except (FileNotFoundError,IsADirectoryError) as e:
|
||||
except (FileNotFoundError, IsADirectoryError) as e:
|
||||
print(e)
|
||||
|
||||
def relative_import(self, path):
|
||||
return (os.path.normpath(os.path.join(__file__,"../..",path)))
|
||||
@staticmethod
|
||||
def relative_import(path):
|
||||
return os.path.normpath(os.path.join(__file__, "../..", path))
|
||||
|
||||
def get_users_dict(self) -> dict:
|
||||
# loggers + 'Loaded user dictionary from users.yaml'
|
||||
return self.user_list
|
||||
|
||||
def get_users_names(self) -> list:
|
||||
|
|
|
|||
|
|
@ -0,0 +1,24 @@
|
|||
from datetime import datetime
|
||||
|
||||
|
||||
class Loggers:
|
||||
def __init__(self):
|
||||
timestamp = self.get_timestamp()
|
||||
self.log = f"{timestamp} Log initialised."
|
||||
|
||||
def __add__(self, other: str) -> str:
|
||||
timestamp = self.get_timestamp()
|
||||
self.log += '\n' + timestamp + ' ' + other
|
||||
return self.log
|
||||
|
||||
# noinspection PyMethodMayBeStatic
|
||||
def get_timestamp(self) -> str:
|
||||
now = datetime.now()
|
||||
almost_timestamp = str(now.time())
|
||||
timestamp = almost_timestamp.rsplit('.')
|
||||
return f'[{timestamp[0]}]'
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
loggers = Loggers()
|
||||
print(loggers.log)
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
import xiv_craft_solver
|
||||
from __main__ import User, Recipe
|
||||
|
||||
|
||||
class Solver:
|
||||
def __init__(self, user: User, recipe: Recipe):
|
||||
self.durability = recipe.durability
|
||||
self.progress = recipe.progress
|
||||
self.quality = recipe.quality
|
||||
self.progress_divider = recipe.progress_difficulty
|
||||
self.quality_divider = recipe.quality_difficulty
|
||||
self.progress_modifier = recipe.extra_progress_difficulty
|
||||
self.quality_modifier = recipe.extra_quality_difficulty
|
||||
|
||||
self.craftsmanship = user.craftsmanship
|
||||
self.control = user.control
|
||||
self.max_cp = user.cp
|
||||
|
||||
self.depth = 10
|
||||
self.byregot_step = 10
|
||||
self.desperate = False
|
||||
self.threads = 8
|
||||
self.verbose = 0
|
||||
|
||||
def solve(self) -> str:
|
||||
return xiv_craft_solver.solve_from_python(self)
|
||||
Reference in New Issue