From 198c59044290b0ec4784b1c0db3d0fc7dd00bb6a Mon Sep 17 00:00:00 2001 From: vicky Date: Wed, 22 Feb 2023 09:56:56 +0100 Subject: [PATCH 1/9] minor todo rewriting --- python/main.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/python/main.py b/python/main.py index 76c2691..bdb884f 100644 --- a/python/main.py +++ b/python/main.py @@ -126,7 +126,7 @@ class Recipe: return self.name -with dpg.window(label="Settings", width=500, height=700, no_resize=True, no_title_bar=True): +with dpg.window(label="Settings", width=500, height=700, no_resize=True, no_title_bar=True, no_move=True): user = User() recipe = Recipe() @@ -165,7 +165,7 @@ with dpg.window(label="Settings", width=500, height=700, no_resize=True, no_titl 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 + # TODO: add a log if recipe matches a known recipe dpg.add_button(label="Save!", indent=282) dpg.add_button(label="Solve!") From 4015bda699a766420d7508a50b56201570cf340d Mon Sep 17 00:00:00 2001 From: vicky Date: Wed, 22 Feb 2023 15:18:52 +0100 Subject: [PATCH 2/9] 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 --- python/src/ffcraft_solver/__main__.py | 129 ++++++++++++++---- .../src/ffcraft_solver/configs/recipes.yaml | 11 +- python/src/ffcraft_solver/example.py | 4 +- python/src/ffcraft_solver/modules/loader.py | 21 ++- python/src/ffcraft_solver/modules/log.py | 24 ++++ python/src/ffcraft_solver/modules/solver.py | 26 ++++ 6 files changed, 176 insertions(+), 39 deletions(-) create mode 100644 python/src/ffcraft_solver/modules/log.py create mode 100644 python/src/ffcraft_solver/modules/solver.py diff --git a/python/src/ffcraft_solver/__main__.py b/python/src/ffcraft_solver/__main__.py index 41485a2..5b686a5 100644 --- a/python/src/ffcraft_solver/__main__.py +++ b/python/src/ffcraft_solver/__main__.py @@ -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() diff --git a/python/src/ffcraft_solver/configs/recipes.yaml b/python/src/ffcraft_solver/configs/recipes.yaml index 50aa10d..2c1c096 100644 --- a/python/src/ffcraft_solver/configs/recipes.yaml +++ b/python/src/ffcraft_solver/configs/recipes.yaml @@ -1,3 +1,8 @@ -# Name: [Quality, difficulty, durability] -Grade 7 Tincture of Strength: [12628, 5060, 70] -Grade 5 Strength Alkahest: [6200, 1300, 35] \ No newline at end of file +# 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] \ No newline at end of file diff --git a/python/src/ffcraft_solver/example.py b/python/src/ffcraft_solver/example.py index a9c19ec..9b55efe 100644 --- a/python/src/ffcraft_solver/example.py +++ b/python/src/ffcraft_solver/example.py @@ -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)) diff --git a/python/src/ffcraft_solver/modules/loader.py b/python/src/ffcraft_solver/modules/loader.py index f847083..f527184 100644 --- a/python/src/ffcraft_solver/modules/loader.py +++ b/python/src/ffcraft_solver/modules/loader.py @@ -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: diff --git a/python/src/ffcraft_solver/modules/log.py b/python/src/ffcraft_solver/modules/log.py new file mode 100644 index 0000000..ccb2d7b --- /dev/null +++ b/python/src/ffcraft_solver/modules/log.py @@ -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) diff --git a/python/src/ffcraft_solver/modules/solver.py b/python/src/ffcraft_solver/modules/solver.py new file mode 100644 index 0000000..2ff5fad --- /dev/null +++ b/python/src/ffcraft_solver/modules/solver.py @@ -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) From 67b67712cff8d8ce7464fe7ac908c635737466e8 Mon Sep 17 00:00:00 2001 From: vicky Date: Wed, 22 Feb 2023 21:42:23 +0100 Subject: [PATCH 3/9] resolved module loading problems, started work on getting solutions out of rust --- python/src/ffcraft_solver/__main__.py | 151 ++++++++++---------- python/src/ffcraft_solver/modules/loader.py | 6 +- python/src/ffcraft_solver/modules/solver.py | 26 +++- 3 files changed, 102 insertions(+), 81 deletions(-) diff --git a/python/src/ffcraft_solver/__main__.py b/python/src/ffcraft_solver/__main__.py index 5b686a5..eae79d3 100644 --- a/python/src/ffcraft_solver/__main__.py +++ b/python/src/ffcraft_solver/__main__.py @@ -3,10 +3,6 @@ import xiv_craft_solver as xcs 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 = ' ' @@ -173,85 +169,90 @@ class Recipe: return self.name -def request_solve(self): - solve = solver.Solver(user, recipe) - solve.solve() +def request_solve() -> True: + solver.Solver(user, recipe) + return True -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() +if __name__ == '__main__': + dpg.create_context() + dpg.configure_app(manual_callback_management=True) + dpg.create_viewport(title='XIV Solver', width=500, height=700) - 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() + 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() - loggers = log.Loggers() + 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() - # Start of GUI drawing - # CHARACTER - dpg.add_text("Character") - 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 - 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") - 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 == ' ' + loggers = log.Loggers() - # 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() + # Start of GUI drawing + # CHARACTER + dpg.add_text("Character") + 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 + 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") + 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 == ' ' - # 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) + # 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() - # 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, " ") - 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("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 - 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 == ' ' + # 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) - # SOLVE - dpg.add_separator() - dpg.add_button(label="Solve!") - dpg.add_text() - dpg.add_collapsing_header(label="Result") + # 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, " ") + 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("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 + 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 == ' ' - # 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) + # SOLVE + dpg.add_separator() + dpg.add_button(label="Solve!", callback=request_solve) + dpg.add_text() + dpg.add_collapsing_header(label="Result") -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() + # 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() + 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() diff --git a/python/src/ffcraft_solver/modules/loader.py b/python/src/ffcraft_solver/modules/loader.py index f527184..04a7764 100644 --- a/python/src/ffcraft_solver/modules/loader.py +++ b/python/src/ffcraft_solver/modules/loader.py @@ -1,10 +1,10 @@ import rich import yaml import os -# from xiv_craft_solver.modules import log +from ffcraft_solver.modules import log -# loggers = log.Loggers() +loggers = log.Loggers() class DefaultConfig: @@ -48,7 +48,7 @@ class Loader: return os.path.normpath(os.path.join(__file__, "../..", path)) def get_users_dict(self) -> dict: - # loggers + 'Loaded user dictionary from users.yaml' + loggers + 'Loaded user dictionary from users.yaml' return self.user_list def get_users_names(self) -> list: diff --git a/python/src/ffcraft_solver/modules/solver.py b/python/src/ffcraft_solver/modules/solver.py index 2ff5fad..56d835f 100644 --- a/python/src/ffcraft_solver/modules/solver.py +++ b/python/src/ffcraft_solver/modules/solver.py @@ -1,5 +1,6 @@ +import rich import xiv_craft_solver -from __main__ import User, Recipe +from ffcraft_solver.__main__ import User, Recipe class Solver: @@ -9,8 +10,8 @@ class Solver: 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.progress_modifier = recipe.progress_extra_difficulty + self.quality_modifier = recipe.quality_extra_difficulty self.craftsmanship = user.craftsmanship self.control = user.control @@ -22,5 +23,24 @@ class Solver: self.threads = 8 self.verbose = 0 + self.solutions = [] + self.best_quality = None + + self.solve() + self.return_best_quality() + rich.inspect(self.best_quality) + def solve(self) -> str: + self.solutions = xiv_craft_solver.solve_from_python(self) return xiv_craft_solver.solve_from_python(self) + + def return_best_quality(self) -> str: + best_quality = 0 + output = 0 + for e in self.solutions: + if e.quality > best_quality: + best_quality = e.quality + output = e + self.best_quality = output + return self.best_quality + From b47d51c7accd802d1659a112bed641637f62edd8 Mon Sep 17 00:00:00 2001 From: vicky Date: Thu, 23 Feb 2023 15:51:10 +0100 Subject: [PATCH 4/9] Very first, barebones, version. But it is kinda usable. No async, no saving yet though. --- python/src/ffcraft_solver/__main__.py | 12 +++- python/src/ffcraft_solver/modules/loader.py | 2 +- python/src/ffcraft_solver/modules/log.py | 3 +- python/src/ffcraft_solver/modules/solver.py | 65 ++++++++++++++++++--- 4 files changed, 69 insertions(+), 13 deletions(-) diff --git a/python/src/ffcraft_solver/__main__.py b/python/src/ffcraft_solver/__main__.py index eae79d3..752030c 100644 --- a/python/src/ffcraft_solver/__main__.py +++ b/python/src/ffcraft_solver/__main__.py @@ -170,7 +170,12 @@ class Recipe: def request_solve() -> True: - solver.Solver(user, recipe) + dpg.set_value(results, str(solver.Solver(user, recipe).best_quality)) + return True + + +def refresh_log() -> True: + dpg.set_value(log_window, loggers.log) return True @@ -242,11 +247,12 @@ if __name__ == '__main__': dpg.add_separator() dpg.add_button(label="Solve!", callback=request_solve) dpg.add_text() - dpg.add_collapsing_header(label="Result") + dpg.add_collapsing_header(label="Result", leaf=True) + results = dpg.add_input_text(multiline=True, height=220, width=485, readonly=True) # 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) + tab_input=True, pos=[0, 642], tracked=True, readonly=True) dpg.setup_dearpygui() dpg.show_viewport() diff --git a/python/src/ffcraft_solver/modules/loader.py b/python/src/ffcraft_solver/modules/loader.py index 04a7764..3b06296 100644 --- a/python/src/ffcraft_solver/modules/loader.py +++ b/python/src/ffcraft_solver/modules/loader.py @@ -48,7 +48,7 @@ class Loader: return os.path.normpath(os.path.join(__file__, "../..", path)) def get_users_dict(self) -> dict: - loggers + 'Loaded user dictionary from users.yaml' + loggers.add_log('Loaded user dictionary from users.yaml') return self.user_list def get_users_names(self) -> list: diff --git a/python/src/ffcraft_solver/modules/log.py b/python/src/ffcraft_solver/modules/log.py index ccb2d7b..87040a4 100644 --- a/python/src/ffcraft_solver/modules/log.py +++ b/python/src/ffcraft_solver/modules/log.py @@ -6,9 +6,10 @@ class Loggers: timestamp = self.get_timestamp() self.log = f"{timestamp} Log initialised." - def __add__(self, other: str) -> str: + def add_log(self, other: str) -> str: timestamp = self.get_timestamp() self.log += '\n' + timestamp + ' ' + other + print(self.log) return self.log # noinspection PyMethodMayBeStatic diff --git a/python/src/ffcraft_solver/modules/solver.py b/python/src/ffcraft_solver/modules/solver.py index 56d835f..30d80b1 100644 --- a/python/src/ffcraft_solver/modules/solver.py +++ b/python/src/ffcraft_solver/modules/solver.py @@ -1,6 +1,48 @@ import rich import xiv_craft_solver from ffcraft_solver.__main__ import User, Recipe +from ffcraft_solver.modules import log + +loggers = log.Loggers() + + +class Result: + def __init__(self, result, title: str): + self.title = title + self.original = result + self.quality = result.quality + self.actions = result.actions + self.steps = result.steps + self.remaining_cp = result.cp + self.readable_actions = self.text_wrap(self.actions) + self.readable = f"""/// {self.title} +Rotation: +{self.readable_actions} +Quality: {self.quality} +Steps: {self.steps} +Remaining CP: {self.remaining_cp}""" + + def __str__(self) -> str: + return self.readable + + @staticmethod # il est con ou quoi? + def text_wrap(text: list[str]) -> str: + """Transforms a list of words into a string and wraps them at 60 characters with an indent.""" + + line = ' ' + saved_lines = [] + justified_text = '' + for w in text: + if len(line) < 56: + line += w + ' ' + else: + saved_lines.append(line) + line = ' ' + w + ' ' + + for line in saved_lines: + justified_text += line + '\n' + + return justified_text[:-1] class Solver: @@ -27,20 +69,27 @@ class Solver: self.best_quality = None self.solve() - self.return_best_quality() - rich.inspect(self.best_quality) + self.compute_all() def solve(self) -> str: self.solutions = xiv_craft_solver.solve_from_python(self) return xiv_craft_solver.solve_from_python(self) - def return_best_quality(self) -> str: + def compute_all(self) -> True: + self.compute_best_quality() + + def compute_best_quality(self) -> Result: best_quality = 0 output = 0 - for e in self.solutions: - if e.quality > best_quality: - best_quality = e.quality - output = e - self.best_quality = output + if self.solutions: + for e in self.solutions: + if e.quality > best_quality: + best_quality = e.quality + output = e + self.best_quality = Result(output, 'Best quality') + + else: + loggers.add_log('Could not complete craft with current effective stats.') return self.best_quality + From 9678a3bd9880489369b258ad6b7c55cf2c6d2952 Mon Sep 17 00:00:00 2001 From: vicky Date: Thu, 23 Feb 2023 19:26:44 +0100 Subject: [PATCH 5/9] Completed solution display and macro integration. Added translation module for future translations. --- python/src/ffcraft_solver/__main__.py | 51 +++++++++++++++++-- python/src/ffcraft_solver/modules/solver.py | 47 +++++++++++++++-- .../src/ffcraft_solver/modules/translator.py | 47 +++++++++++++++++ 3 files changed, 137 insertions(+), 8 deletions(-) create mode 100644 python/src/ffcraft_solver/modules/translator.py diff --git a/python/src/ffcraft_solver/__main__.py b/python/src/ffcraft_solver/__main__.py index 752030c..63df2e4 100644 --- a/python/src/ffcraft_solver/__main__.py +++ b/python/src/ffcraft_solver/__main__.py @@ -169,8 +169,39 @@ class Recipe: return self.name +class Solution: + def __init__(self, title): + self.result = None + self.title = title + + def print_result(self): + if self.result: + dpg.set_value(results, self.result) + else: + loggers.add_log('No solution to display.') + + def print_macro_1(self): + if self.result and self.result.macro1: + dpg.set_value(results, self.result.macro1) + else: + loggers.add_log('No macro to display.') + + def print_macro_2(self): + if self.result and self.result.macro2: + dpg.set_value(results, self.result.macro2) + else: + loggers.add_log('No macro to display.') + + def print_macro_3(self): + if self.result and self.result.macro3: + dpg.set_value(results, self.result.macro3) + else: + loggers.add_log('No macro to display.') + + def request_solve() -> True: - dpg.set_value(results, str(solver.Solver(user, recipe).best_quality)) + best_quality.result = solver.Solver(user, recipe).best_quality + dpg.set_value(results, best_quality.result) return True @@ -188,6 +219,7 @@ if __name__ == '__main__': # Initialization of all our classes user = User() recipe = Recipe() + best_quality = Solution("Best Quality") full_config = loader.Loader() characters_names = full_config.get_users_names() @@ -201,7 +233,7 @@ if __name__ == '__main__': # CHARACTER dpg.add_text("Character") user_combo = dpg.add_combo(items=characters_names, label="Your character", callback=user.set_name_combo) - dpg.set_value(user_combo, " ") + dpg.set_value(user_combo, ' ') # TODO: Load 1rst user in users.yaml by default user_stats = dpg.add_input_intx(size=3, label="Stats", tag="stats_tooltip", callback=user.set_initial_stats) with dpg.tooltip("stats_tooltip"): @@ -247,8 +279,19 @@ if __name__ == '__main__': dpg.add_separator() dpg.add_button(label="Solve!", callback=request_solve) dpg.add_text() - dpg.add_collapsing_header(label="Result", leaf=True) - results = dpg.add_input_text(multiline=True, height=220, width=485, readonly=True) + dpg.add_collapsing_header(label="Results", leaf=True) + with dpg.group(horizontal=True): + results = dpg.add_input_text(multiline=True, height=220, readonly=True) + with dpg.child_window(autosize_x=True, height=220): + dpg.add_button(label="BEST QUALITY", width=136, callback=best_quality.print_result) + dpg.add_button(label="Macro 1", width=136, callback=best_quality.print_macro_1) + dpg.add_button(label="Macro 2", width=136, callback=best_quality.print_macro_2) + dpg.add_button(label="SAFE MARGIN", width=136, callback=best_quality.print_result) + dpg.add_button(label="Macro 1", width=136, callback=best_quality.print_macro_1) + dpg.add_button(label="Macro 2", width=136, callback=best_quality.print_macro_2) + dpg.add_button(label="QUICKEST", width=136, callback=best_quality.print_result) + dpg.add_button(label="Macro 1", width=136, callback=best_quality.print_macro_1) + dpg.add_button(label="Macro 2", width=136, callback=best_quality.print_macro_2) # LOG log_window = dpg.add_input_text(multiline=True, default_value=loggers.log, height=50, width=500, diff --git a/python/src/ffcraft_solver/modules/solver.py b/python/src/ffcraft_solver/modules/solver.py index 30d80b1..730182d 100644 --- a/python/src/ffcraft_solver/modules/solver.py +++ b/python/src/ffcraft_solver/modules/solver.py @@ -1,7 +1,7 @@ import rich import xiv_craft_solver from ffcraft_solver.__main__ import User, Recipe -from ffcraft_solver.modules import log +from ffcraft_solver.modules import log, translator loggers = log.Loggers() @@ -14,7 +14,17 @@ class Result: self.actions = result.actions self.steps = result.steps self.remaining_cp = result.cp + + self.all_buffs_list = ['manipulation', 'veneration', 'mastersMend', 'wasteNot', 'wasteNot2', 'greatStrides', + 'innovation', 'finalAppraisal', 'carefulObservation', 'heartAndSoul'] + self.readable_actions = self.text_wrap(self.actions) + + self.macro1 = '' + self.macro2 = '' + self.macro3 = '' + self.make_macro() + self.readable = f"""/// {self.title} Rotation: {self.readable_actions} @@ -27,23 +37,52 @@ Remaining CP: {self.remaining_cp}""" @staticmethod # il est con ou quoi? def text_wrap(text: list[str]) -> str: - """Transforms a list of words into a string and wraps them at 60 characters with an indent.""" - + """Transforms a list of words into a string and wraps them at 34 characters with an indent.""" line = ' ' saved_lines = [] justified_text = '' for w in text: - if len(line) < 56: + if len(line) < 31: line += w + ' ' else: saved_lines.append(line) line = ' ' + w + ' ' + if line != saved_lines[-1]: + saved_lines.append(line) + for line in saved_lines: justified_text += line + '\n' return justified_text[:-1] + def make_macro(self) -> str: + saved_lines = [''] + translated_actions = translator.translate(self.actions, "en") + count = 0 + + for action in translated_actions: + line = f'/ac "{action}" ' + saved_lines.append(line) + count += 1 + + count = 0 + for line in saved_lines: + count += 1 + if count < 16: + self.macro1 += line + '\n' + elif 15 < count < 31: + self.macro2 += line + '\n' + elif 30 < count < 46: + self.macro3 += line + '\n' + else: + print("Log: Macro too long!") + + self.macro1 = self.macro1[1:] + self.macro2 = self.macro2[1:] + self.macro3 = self.macro3[1:] + return self.macro1 + class Solver: def __init__(self, user: User, recipe: Recipe): diff --git a/python/src/ffcraft_solver/modules/translator.py b/python/src/ffcraft_solver/modules/translator.py new file mode 100644 index 0000000..9219c8a --- /dev/null +++ b/python/src/ffcraft_solver/modules/translator.py @@ -0,0 +1,47 @@ +supported_languages = { + "en": { + 'basicSynth2': 'Basic Synthesis', + 'basicTouch': 'Basic Touch', + 'mastersMend': "Master's mend", + 'hastyTouch': 'Hasty Touch', + 'rapidSynthesis': 'Rapid Synthesis', + 'wasteNot': 'Waste Not', + 'veneration': 'Veneration', + 'standardTouch': 'Standard Touch', + 'greatStrides': 'Great Strides', + 'innovation': 'Innovation', + 'finalAppraisal': 'Final Appraisal', + 'wasteNot2': 'Waste Not II', + 'byregotsBlessing': "Byregot's Blessing", + 'preciseTouch': 'Precise Touch', + 'muscleMemory': 'Muscle Memory', + 'carefulSynthesis': 'Careful Synthesis', + 'manipulation': 'Manipulation', + 'prudentTouch': 'Prudent Touch', + 'focusedSynthesis': 'Focused Synthesis', + 'focusedTouch': 'Focused Touch', + 'reflect': 'Reflect', + 'preparatoryTouch': 'Preparatory Touch', + 'groundwork': 'Groundwork', + 'delicateSynthesis': 'Delicate Synthesis', + 'intensiveSynthesis': 'Intensive Synthesis', + 'trainedEye': 'Trained Eye', + 'advancedTouch': 'Advanced Touch', + 'prudentSynthesis': 'Prudent Synthesis', + 'trainedFinesse': 'Trained Finesse' + } +} + + +def translate(actions, lang: str): + output = [] + print(actions) + if lang in supported_languages: + dictionary = supported_languages[lang] + for action in actions: + output.append(dictionary[action]) + else: + print(f'Log: Language code "{lang}" not recognised.') + + return output + From 6f1e721c5dd39e4adf408fd5d93849eeac99ae36 Mon Sep 17 00:00:00 2001 From: vicky Date: Thu, 23 Feb 2023 20:32:50 +0100 Subject: [PATCH 6/9] now with 300% more solutions! --- python/src/ffcraft_solver/__main__.py | 20 ++++--- python/src/ffcraft_solver/modules/solver.py | 56 ++++++++++++++----- .../src/ffcraft_solver/modules/translator.py | 16 +++++- 3 files changed, 70 insertions(+), 22 deletions(-) diff --git a/python/src/ffcraft_solver/__main__.py b/python/src/ffcraft_solver/__main__.py index 63df2e4..1100353 100644 --- a/python/src/ffcraft_solver/__main__.py +++ b/python/src/ffcraft_solver/__main__.py @@ -200,7 +200,10 @@ class Solution: def request_solve() -> True: - best_quality.result = solver.Solver(user, recipe).best_quality + all_results = solver.Solver(user, recipe) + best_quality.result = all_results.best_quality + least_steps.result = all_results.least_steps + safe_50.result = all_results.safe_50 dpg.set_value(results, best_quality.result) return True @@ -220,6 +223,8 @@ if __name__ == '__main__': user = User() recipe = Recipe() best_quality = Solution("Best Quality") + least_steps = Solution("Least Steps") + safe_50 = Solution("Safe Margin") full_config = loader.Loader() characters_names = full_config.get_users_names() @@ -280,18 +285,19 @@ if __name__ == '__main__': dpg.add_button(label="Solve!", callback=request_solve) dpg.add_text() dpg.add_collapsing_header(label="Results", leaf=True) + # TODO: Add feedback when pressed with dpg.group(horizontal=True): results = dpg.add_input_text(multiline=True, height=220, readonly=True) with dpg.child_window(autosize_x=True, height=220): dpg.add_button(label="BEST QUALITY", width=136, callback=best_quality.print_result) dpg.add_button(label="Macro 1", width=136, callback=best_quality.print_macro_1) dpg.add_button(label="Macro 2", width=136, callback=best_quality.print_macro_2) - dpg.add_button(label="SAFE MARGIN", width=136, callback=best_quality.print_result) - dpg.add_button(label="Macro 1", width=136, callback=best_quality.print_macro_1) - dpg.add_button(label="Macro 2", width=136, callback=best_quality.print_macro_2) - dpg.add_button(label="QUICKEST", width=136, callback=best_quality.print_result) - dpg.add_button(label="Macro 1", width=136, callback=best_quality.print_macro_1) - dpg.add_button(label="Macro 2", width=136, callback=best_quality.print_macro_2) + dpg.add_button(label="SAFE MARGIN", width=136, callback=safe_50.print_result) + dpg.add_button(label="Macro 1", width=136, callback=safe_50.print_macro_1) + dpg.add_button(label="Macro 2", width=136, callback=safe_50.print_macro_2) + dpg.add_button(label="QUICKEST", width=136, callback=least_steps.print_result) + dpg.add_button(label="Macro 1", width=136, callback=least_steps.print_macro_1) + dpg.add_button(label="Macro 2", width=136, callback=least_steps.print_macro_2) # LOG log_window = dpg.add_input_text(multiline=True, default_value=loggers.log, height=50, width=500, diff --git a/python/src/ffcraft_solver/modules/solver.py b/python/src/ffcraft_solver/modules/solver.py index 730182d..5362647 100644 --- a/python/src/ffcraft_solver/modules/solver.py +++ b/python/src/ffcraft_solver/modules/solver.py @@ -58,7 +58,7 @@ Remaining CP: {self.remaining_cp}""" def make_macro(self) -> str: saved_lines = [''] - translated_actions = translator.translate(self.actions, "en") + translated_actions = translator.translate_list(self.actions, "en") count = 0 for action in translated_actions: @@ -106,6 +106,8 @@ class Solver: self.solutions = [] self.best_quality = None + self.least_steps = None + self.safe_50 = None self.solve() self.compute_all() @@ -115,20 +117,48 @@ class Solver: return xiv_craft_solver.solve_from_python(self) def compute_all(self) -> True: - self.compute_best_quality() + if self.solutions: + self.sort_quality() + self.compute_best_quality() + self.compute_least_steps() + self.compute_50percent_quality() + + def sort_quality(self) -> True: + self.solutions.sort(key=lambda x: x.quality) + return True def compute_best_quality(self) -> Result: - best_quality = 0 - output = 0 - if self.solutions: - for e in self.solutions: - if e.quality > best_quality: - best_quality = e.quality - output = e - self.best_quality = Result(output, 'Best quality') - - else: - loggers.add_log('Could not complete craft with current effective stats.') + self.best_quality = Result(self.solutions[-1], 'Best quality') return self.best_quality + def compute_50percent_quality(self) -> Result: + self.safe_50 = Result(self.solutions[round(len(self.solutions)/2)+1], 'Safe 50') + return self.safe_50 + + # def compute_best_quality(self) -> Result: + # best_quality = 0 + # output = 0 + # if self.solutions: + # for e in self.solutions: + # if e.quality > best_quality: + # best_quality = e.quality + # output = e + # self.best_quality = Result(output, 'Best quality') + # + # else: + # loggers.add_log('Could not complete craft with current effective stats.') + # return self.best_quality + + def compute_least_steps(self) -> Result: + least_steps = 100 + output = None + if self.solutions: + for e in self.solutions: + if e.steps < least_steps: + least_steps = e.steps + output = e + self.least_steps = Result(output, 'Least steps') + + return self.least_steps + diff --git a/python/src/ffcraft_solver/modules/translator.py b/python/src/ffcraft_solver/modules/translator.py index 9219c8a..28c8d02 100644 --- a/python/src/ffcraft_solver/modules/translator.py +++ b/python/src/ffcraft_solver/modules/translator.py @@ -1,5 +1,10 @@ +from ffcraft_solver.modules import log + +loggers = log.Loggers + supported_languages = { "en": { + 'basicSynth': 'Basic Synthesis', 'basicSynth2': 'Basic Synthesis', 'basicTouch': 'Basic Touch', 'mastersMend': "Master's mend", @@ -33,13 +38,20 @@ supported_languages = { } -def translate(actions, lang: str): +def translate_list(actions: list, lang: str): output = [] print(actions) if lang in supported_languages: dictionary = supported_languages[lang] for action in actions: - output.append(dictionary[action]) + try: + output.append(dictionary[action]) + except KeyError: + output.append(supported_languages["en"][action]) + loggers.log('Translation not found. Defaulting to English.\n' + ' Macros will probably be broken because of this.') + + else: print(f'Log: Language code "{lang}" not recognised.') From ed904f5eca06342bca7b2f4eeca0a8eaed3a2684 Mon Sep 17 00:00:00 2001 From: vicky Date: Thu, 23 Feb 2023 23:38:35 +0100 Subject: [PATCH 7/9] added macro completion message, needs next macro message --- python/src/ffcraft_solver/modules/solver.py | 34 ++++++++++----------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/python/src/ffcraft_solver/modules/solver.py b/python/src/ffcraft_solver/modules/solver.py index 5362647..670e239 100644 --- a/python/src/ffcraft_solver/modules/solver.py +++ b/python/src/ffcraft_solver/modules/solver.py @@ -66,18 +66,32 @@ Remaining CP: {self.remaining_cp}""" saved_lines.append(line) count += 1 + if self.steps != 29 or self.steps != 44: + saved_lines.append('/echo Craft complete ! ') + else: + loggers.log(f'No completion message in macro because rotation is exactly {self.steps} steps.') + count = 0 for line in saved_lines: count += 1 - if count < 16: + if count < 15: self.macro1 += line + '\n' - elif 15 < count < 31: + elif 14 < count < 30: self.macro2 += line + '\n' - elif 30 < count < 46: + elif 29 < count < 45: self.macro3 += line + '\n' else: print("Log: Macro too long!") + nb_macros = 0 + if self.macro1: + nb_macros = 1 + if self.macro2: + nb_macros += 1 + if self.macro3: + nb_macros += 1 + # TODO: add next macro line + self.macro1 = self.macro1[1:] self.macro2 = self.macro2[1:] self.macro3 = self.macro3[1:] @@ -135,20 +149,6 @@ class Solver: self.safe_50 = Result(self.solutions[round(len(self.solutions)/2)+1], 'Safe 50') return self.safe_50 - # def compute_best_quality(self) -> Result: - # best_quality = 0 - # output = 0 - # if self.solutions: - # for e in self.solutions: - # if e.quality > best_quality: - # best_quality = e.quality - # output = e - # self.best_quality = Result(output, 'Best quality') - # - # else: - # loggers.add_log('Could not complete craft with current effective stats.') - # return self.best_quality - def compute_least_steps(self) -> Result: least_steps = 100 output = None From e17e101c3991fa0fb58b782d4db4e65fa5867314 Mon Sep 17 00:00:00 2001 From: vicky Date: Fri, 24 Feb 2023 12:10:04 +0100 Subject: [PATCH 8/9] Made macros work --- python/src/ffcraft_solver/__main__.py | 2 +- python/src/ffcraft_solver/modules/loader.py | 6 +-- python/src/ffcraft_solver/modules/solver.py | 51 +++++++++++-------- .../src/ffcraft_solver/modules/translator.py | 4 +- 4 files changed, 35 insertions(+), 28 deletions(-) diff --git a/python/src/ffcraft_solver/__main__.py b/python/src/ffcraft_solver/__main__.py index 1100353..252ebd2 100644 --- a/python/src/ffcraft_solver/__main__.py +++ b/python/src/ffcraft_solver/__main__.py @@ -142,7 +142,7 @@ class Recipe: 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.') + loggers.add_log('Something went very wrong in recipe stat assignment.') self.progress = stats[0] self.quality = stats[1] diff --git a/python/src/ffcraft_solver/modules/loader.py b/python/src/ffcraft_solver/modules/loader.py index 3b06296..4af8c12 100644 --- a/python/src/ffcraft_solver/modules/loader.py +++ b/python/src/ffcraft_solver/modules/loader.py @@ -27,7 +27,7 @@ class Loader: 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) + loggers.add_log(e) try: with open(self.relative_import(self.config.yaml_consumable), 'r') as file: @@ -35,13 +35,13 @@ class Loader: self.foods_list.update(loaded_file['Foods']) self.pots_list.update(loaded_file['Pots']) except FileNotFoundError as e: - print(e) + loggers.add_log(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: - print(e) + loggers.add_log(e) @staticmethod def relative_import(path): diff --git a/python/src/ffcraft_solver/modules/solver.py b/python/src/ffcraft_solver/modules/solver.py index 670e239..3a2f39a 100644 --- a/python/src/ffcraft_solver/modules/solver.py +++ b/python/src/ffcraft_solver/modules/solver.py @@ -56,7 +56,7 @@ Remaining CP: {self.remaining_cp}""" return justified_text[:-1] - def make_macro(self) -> str: + def make_macro(self) -> True: saved_lines = [''] translated_actions = translator.translate_list(self.actions, "en") count = 0 @@ -65,37 +65,34 @@ Remaining CP: {self.remaining_cp}""" line = f'/ac "{action}" ' saved_lines.append(line) count += 1 + saved_lines = saved_lines[1:] - if self.steps != 29 or self.steps != 44: + if self.steps != 15 and self.steps != 29 and self.steps != 44: saved_lines.append('/echo Craft complete ! ') else: loggers.log(f'No completion message in macro because rotation is exactly {self.steps} steps.') + if self.steps > 15: + saved_lines.insert(14, '/echo Macro 1 complete ') + + if self.steps > 30: + saved_lines.insert(30, '/echo Macro 2 complete ') + # TODO : test index + count = 0 for line in saved_lines: count += 1 - if count < 15: + if count < 16: self.macro1 += line + '\n' - elif 14 < count < 30: + elif 15 < count < 31: self.macro2 += line + '\n' - elif 29 < count < 45: + elif 30 < count < 46: self.macro3 += line + '\n' - else: - print("Log: Macro too long!") - nb_macros = 0 - if self.macro1: - nb_macros = 1 - if self.macro2: - nb_macros += 1 - if self.macro3: - nb_macros += 1 - # TODO: add next macro line - - self.macro1 = self.macro1[1:] - self.macro2 = self.macro2[1:] - self.macro3 = self.macro3[1:] - return self.macro1 + self.macro1 = self.macro1[:-1] + self.macro2 = self.macro2[:-1] + self.macro3 = self.macro3[:-1] + return True class Solver: @@ -146,7 +143,19 @@ class Solver: return self.best_quality def compute_50percent_quality(self) -> Result: - self.safe_50 = Result(self.solutions[round(len(self.solutions)/2)+1], 'Safe 50') + done = False + threshold = self.quality * 1.5 + for s in reversed(self.solutions): + if s.quality > threshold: + self.safe_50 = Result(s, 'Safe 50') + done = True + + if not done: + loggers.add_log('Could not find a rotation for 150% quality.\n' + ' Defaulting to Best Quality.') + self.safe_50 = self.best_quality + + # self.safe_50 = Result(self.solutions[round(len(self.solutions)/2)+1], 'Safe 50') # old version return self.safe_50 def compute_least_steps(self) -> Result: diff --git a/python/src/ffcraft_solver/modules/translator.py b/python/src/ffcraft_solver/modules/translator.py index 28c8d02..1ed2d14 100644 --- a/python/src/ffcraft_solver/modules/translator.py +++ b/python/src/ffcraft_solver/modules/translator.py @@ -40,7 +40,6 @@ supported_languages = { def translate_list(actions: list, lang: str): output = [] - print(actions) if lang in supported_languages: dictionary = supported_languages[lang] for action in actions: @@ -51,9 +50,8 @@ def translate_list(actions: list, lang: str): loggers.log('Translation not found. Defaulting to English.\n' ' Macros will probably be broken because of this.') - else: - print(f'Log: Language code "{lang}" not recognised.') + loggers.add_log(f'Language code "{lang}" not recognised.') return output From bf8da553793e0a104a5e5972511075edc21508ec Mon Sep 17 00:00:00 2001 From: vicky Date: Fri, 24 Feb 2023 14:01:58 +0100 Subject: [PATCH 9/9] Fixed log to work as intended. Message order is reversed for now. --- python/src/ffcraft_solver/__main__.py | 31 ++++++++++++--------- python/src/ffcraft_solver/modules/loader.py | 19 ++++--------- python/src/ffcraft_solver/modules/log.py | 12 +++++--- python/src/ffcraft_solver/modules/solver.py | 8 ++---- 4 files changed, 35 insertions(+), 35 deletions(-) diff --git a/python/src/ffcraft_solver/__main__.py b/python/src/ffcraft_solver/__main__.py index 252ebd2..effa028 100644 --- a/python/src/ffcraft_solver/__main__.py +++ b/python/src/ffcraft_solver/__main__.py @@ -1,5 +1,6 @@ +import time + import dearpygui.dearpygui as dpg -import xiv_craft_solver as xcs from ffcraft_solver.modules import loader, log, solver import rich @@ -170,7 +171,8 @@ class Recipe: class Solution: - def __init__(self, title): + def __init__(self, title, logger): + self.loggers = logger self.result = None self.title = title @@ -178,33 +180,35 @@ class Solution: if self.result: dpg.set_value(results, self.result) else: - loggers.add_log('No solution to display.') + self.loggers.add_log('No solution to display.') def print_macro_1(self): if self.result and self.result.macro1: dpg.set_value(results, self.result.macro1) else: - loggers.add_log('No macro to display.') + self.loggers.add_log('No macro to display.') def print_macro_2(self): if self.result and self.result.macro2: dpg.set_value(results, self.result.macro2) else: - loggers.add_log('No macro to display.') + self.loggers.add_log('No macro to display.') def print_macro_3(self): if self.result and self.result.macro3: dpg.set_value(results, self.result.macro3) else: - loggers.add_log('No macro to display.') + self.loggers.add_log('No macro to display.') def request_solve() -> True: + loggers.add_log('Solver initialised. Please stand by.') all_results = solver.Solver(user, recipe) best_quality.result = all_results.best_quality least_steps.result = all_results.least_steps safe_50.result = all_results.safe_50 dpg.set_value(results, best_quality.result) + loggers.add_log('Solved!') return True @@ -220,20 +224,20 @@ if __name__ == '__main__': with dpg.window(label="Settings", width=500, height=700, no_resize=True, no_title_bar=True, no_move=True): # Initialization of all our classes + loggers = log.Loggers() + user = User() recipe = Recipe() - best_quality = Solution("Best Quality") - least_steps = Solution("Least Steps") - safe_50 = Solution("Safe Margin") + best_quality = Solution("Best Quality", loggers) + least_steps = Solution("Least Steps", loggers) + safe_50 = Solution("Safe Margin", loggers) - full_config = loader.Loader() + full_config = loader.Loader(loggers) 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() - loggers = log.Loggers() - # Start of GUI drawing # CHARACTER dpg.add_text("Character") @@ -286,6 +290,7 @@ if __name__ == '__main__': dpg.add_text() dpg.add_collapsing_header(label="Results", leaf=True) # TODO: Add feedback when pressed + with dpg.group(horizontal=True): results = dpg.add_input_text(multiline=True, height=220, readonly=True) with dpg.child_window(autosize_x=True, height=220): @@ -301,7 +306,7 @@ if __name__ == '__main__': # 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, readonly=True) + tab_input=True, pos=[0, 642], tracked=False, readonly=True, tag="log_window") dpg.setup_dearpygui() dpg.show_viewport() diff --git a/python/src/ffcraft_solver/modules/loader.py b/python/src/ffcraft_solver/modules/loader.py index 4af8c12..061a98b 100644 --- a/python/src/ffcraft_solver/modules/loader.py +++ b/python/src/ffcraft_solver/modules/loader.py @@ -1,12 +1,8 @@ -import rich import yaml import os from ffcraft_solver.modules import log -loggers = log.Loggers() - - class DefaultConfig: yaml_user = 'configs/users.yaml' yaml_consumable = 'configs/consumables.yaml' @@ -16,7 +12,8 @@ class DefaultConfig: class Loader: # TODO: create folder/file if missing when clicking "save" # TODO: log any missing file(s) or the whole folder - def __init__(self): + def __init__(self, loggers: log.Loggers): + self.loggers = loggers self.user_list = {' ': [0, 0, 0]} self.foods_list = {' ': [[0, 0], [0, 0], [0, 0]]} self.pots_list = {' ': [[0, 0], [0, 0], [0, 0]]} @@ -27,7 +24,7 @@ class Loader: with open(self.relative_import(self.config.yaml_user), 'r') as file: self.user_list.update(yaml.safe_load(file)) except FileNotFoundError as e: - loggers.add_log(e) + self.loggers.add_log(e) try: with open(self.relative_import(self.config.yaml_consumable), 'r') as file: @@ -35,20 +32,20 @@ class Loader: self.foods_list.update(loaded_file['Foods']) self.pots_list.update(loaded_file['Pots']) except FileNotFoundError as e: - loggers.add_log(e) + self.loggers.add_log(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: - loggers.add_log(e) + self.loggers.add_log(e) @staticmethod def relative_import(path): return os.path.normpath(os.path.join(__file__, "../..", path)) def get_users_dict(self) -> dict: - loggers.add_log('Loaded user dictionary from users.yaml') + self.loggers.add_log('Loaded user dictionary from users.yaml') return self.user_list def get_users_names(self) -> list: @@ -83,7 +80,3 @@ class Loader: for r in self.recipes_list: recipes_names.append(r) return recipes_names - - -if __name__ == "__main__": - loader = Loader() diff --git a/python/src/ffcraft_solver/modules/log.py b/python/src/ffcraft_solver/modules/log.py index 87040a4..d28c427 100644 --- a/python/src/ffcraft_solver/modules/log.py +++ b/python/src/ffcraft_solver/modules/log.py @@ -1,15 +1,19 @@ from datetime import datetime +import dearpygui.dearpygui as dpg class Loggers: - def __init__(self): + def __init__(self, log=None): timestamp = self.get_timestamp() - self.log = f"{timestamp} Log initialised." + if not log: + self.log = f"{timestamp} Log initialised." + else: + self.log = log def add_log(self, other: str) -> str: timestamp = self.get_timestamp() - self.log += '\n' + timestamp + ' ' + other - print(self.log) + self.log = timestamp + ' ' + other + '\n' + self.log + dpg.set_value('log_window', self.log) return self.log # noinspection PyMethodMayBeStatic diff --git a/python/src/ffcraft_solver/modules/solver.py b/python/src/ffcraft_solver/modules/solver.py index 3a2f39a..015d501 100644 --- a/python/src/ffcraft_solver/modules/solver.py +++ b/python/src/ffcraft_solver/modules/solver.py @@ -1,10 +1,8 @@ import rich -import xiv_craft_solver +import xiv_craft_solver as xcs from ffcraft_solver.__main__ import User, Recipe from ffcraft_solver.modules import log, translator -loggers = log.Loggers() - class Result: def __init__(self, result, title: str): @@ -124,8 +122,8 @@ class Solver: self.compute_all() def solve(self) -> str: - self.solutions = xiv_craft_solver.solve_from_python(self) - return xiv_craft_solver.solve_from_python(self) + self.solutions = xcs.solve_from_python(self) + return xcs.solve_from_python(self) def compute_all(self) -> True: if self.solutions: