features/save #20
|
|
@ -1,8 +1,6 @@
|
|||
import time
|
||||
|
||||
import re
|
||||
import dearpygui.dearpygui as dpg
|
||||
from xiv_csolver.modules import loader, log, solver
|
||||
import rich
|
||||
from xiv_csolver.modules import loader, log, solver, printer
|
||||
|
||||
|
||||
class User:
|
||||
|
|
@ -110,6 +108,22 @@ class User:
|
|||
dpg.set_value(user_stats, [self.initial_craftsmanship, self.initial_control, self.initial_cp])
|
||||
return self.name
|
||||
|
||||
@staticmethod
|
||||
def save_users() -> True:
|
||||
if dpg.get_value(save_user_as) == '':
|
||||
loggers.add_log('Cannot save user without a name.')
|
||||
elif re.search(r'^\s+$', dpg.get_value(save_user_as)):
|
||||
loggers.add_log('Name cannot be only whitespaces.')
|
||||
elif re.search(r'^\s.+', dpg.get_value(save_user_as)):
|
||||
loggers.add_log('Name cannot start with a whitespace.')
|
||||
elif re.search(r'\s$', dpg.get_value(save_user_as)):
|
||||
loggers.add_log('Name cannot end with a whitespace.')
|
||||
else:
|
||||
saver.save_users(dpg.get_value(save_user_as), dpg.get_value(user_stats))
|
||||
loggers.add_log('User saved!')
|
||||
dpg.configure_item('user_combo', items=full_config.get_users_names())
|
||||
return True
|
||||
|
||||
|
||||
class Recipe:
|
||||
name = ' '
|
||||
|
|
@ -122,7 +136,7 @@ class Recipe:
|
|||
progress_extra_difficulty = 0
|
||||
|
||||
def refresh_gui(self):
|
||||
dpg.set_value(recipe_stats, self.get_recipe_stats()[0:3])
|
||||
dpg.set_value(basic_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)
|
||||
|
|
@ -133,11 +147,11 @@ class Recipe:
|
|||
stats = [0, 0, 0]
|
||||
advanced_stats = [0, 0, 0, 0]
|
||||
|
||||
if tag == 'recipe_tooltip':
|
||||
if tag == 'basic_recipe_stats':
|
||||
stats = app_data
|
||||
advanced_stats = dpg.get_value(advanced_recipe_stats)
|
||||
elif tag == 'advanced_recipe_tooltip':
|
||||
stats = dpg.get_value(recipe_stats)
|
||||
elif tag == 'advanced_recipe_stats':
|
||||
stats = dpg.get_value(basic_recipe_stats)
|
||||
advanced_stats = app_data
|
||||
elif tag == 0:
|
||||
stats = [app_data[0], app_data[1], app_data[2]]
|
||||
|
|
@ -169,6 +183,22 @@ class Recipe:
|
|||
def get_recipe_name(self) -> str:
|
||||
return self.name
|
||||
|
||||
@staticmethod
|
||||
def save_recipe() -> True:
|
||||
if dpg.get_value(save_recipe_as) == '':
|
||||
loggers.add_log('Cannot save recipe without a name.')
|
||||
elif re.search(r'^\s+$', dpg.get_value(save_recipe_as)):
|
||||
loggers.add_log('Name cannot be only whitespaces.')
|
||||
elif re.search(r'^\s.+', dpg.get_value(save_recipe_as)):
|
||||
loggers.add_log('Name cannot start with a whitespace.')
|
||||
elif re.search(r'\s$', dpg.get_value(save_recipe_as)):
|
||||
loggers.add_log('Name cannot end with a whitespace.')
|
||||
else:
|
||||
saver.save_recipe(dpg.get_value(save_recipe_as), dpg.get_value(basic_recipe_stats), dpg.get_value(advanced_recipe_stats))
|
||||
loggers.add_log('Recipe saved!')
|
||||
dpg.configure_item('recipe_combo', items=full_config.get_recipes_names())
|
||||
return True
|
||||
|
||||
|
||||
class Solution:
|
||||
def __init__(self, title, logger):
|
||||
|
|
@ -238,10 +268,12 @@ if __name__ == '__main__':
|
|||
pots_names = full_config.get_pots_names()
|
||||
recipe_names = full_config.get_recipes_names()
|
||||
|
||||
saver = printer.Printer(full_config)
|
||||
|
||||
# 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)
|
||||
user_combo = dpg.add_combo(tag='user_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)
|
||||
|
|
@ -249,8 +281,8 @@ if __name__ == '__main__':
|
|||
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 == ' '
|
||||
# TODO: make it so field is not cleared at every input in stats
|
||||
dpg.add_button(label="Save!", callback=user.save_users)
|
||||
|
||||
# EFFECTIVE STATS
|
||||
dpg.add_separator()
|
||||
|
|
@ -264,24 +296,25 @@ if __name__ == '__main__':
|
|||
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)
|
||||
# TODO : possibility to add new food/pots without manually adding them to the config files
|
||||
|
||||
# RECIPE
|
||||
dpg.add_separator()
|
||||
dpg.add_text("Recipe")
|
||||
recipe_combo = dpg.add_combo(items=recipe_names, label="Recipe", callback=recipe.set_recipe_name)
|
||||
recipe_combo = dpg.add_combo(items=recipe_names, tag='recipe_combo', 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"):
|
||||
basic_recipe_stats = dpg.add_input_intx(size=3, label="Stats", tag="basic_recipe_stats", callback=recipe.set_recipe_stats)
|
||||
with dpg.tooltip("basic_recipe_stats"):
|
||||
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
|
||||
size=4, label="Advanced stats", tag="advanced_recipe_stats", callback=recipe.set_recipe_stats
|
||||
)
|
||||
with dpg.tooltip("advanced_recipe_tooltip"):
|
||||
with dpg.tooltip("advanced_recipe_stats"):
|
||||
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)
|
||||
dpg.add_button(label="Save!", callback=recipe.save_recipe)
|
||||
# TODO: Can't save if value == ' '
|
||||
|
||||
# SOLVE
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
# 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.
|
||||
# Unfortunately that is how the craft system works 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]
|
||||
Grade 5 Strength Alkahest: [1300, 6200, 40, 123, 107, 100, 100]
|
||||
|
|
|
|||
|
|
@ -1,8 +1,9 @@
|
|||
# Name: [Craftsmanship, control, cp]
|
||||
# You are encouraged to use this either for multiple characters if you have them, or different jobs having
|
||||
# different gear or melds.
|
||||
# The top line will always be selected by default
|
||||
# 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 the craft system works in FFXIV.
|
||||
|
||||
Vicky Crosia: [4021, 3933, 587]
|
||||
Dandaedre Zadiel: [0, 0, 0]
|
||||
Sekundes Dullahan: [2566, 2443, 522]
|
||||
Grade 7 Tincture of Strength: [5060, 12628, 70, 130, 115, 80, 70]
|
||||
Grade 5 Strength Alkahest: [1300, 6200, 40, 123, 107, 100, 100]
|
||||
ewq: [0, 1, 2, 3, 4, 5, 6]
|
||||
|
|
|
|||
|
|
@ -1,17 +1,21 @@
|
|||
import rich
|
||||
import yaml
|
||||
import os
|
||||
from xiv_csolver.modules import log
|
||||
|
||||
|
||||
class DefaultConfig:
|
||||
yaml_user = 'configs/users.yaml'
|
||||
yaml_consumable = 'configs/consumables.yaml'
|
||||
yaml_recipes = 'configs/recipes.yaml'
|
||||
yaml_dir = 'configs/'
|
||||
yaml_user = yaml_dir + 'users.yaml'
|
||||
yaml_consumable = yaml_dir + 'consumables.yaml'
|
||||
yaml_recipes = yaml_dir + 'recipes.yaml'
|
||||
|
||||
|
||||
class Loader:
|
||||
# TODO: create folder/file if missing when clicking "save"
|
||||
# TODO: log any missing file(s) or the whole folder
|
||||
# TODO: find a way to log at initialization
|
||||
# TODO: except ParserError and handle it
|
||||
def __init__(self, loggers: log.Loggers):
|
||||
self.loggers = loggers
|
||||
self.user_list = {' ': [0, 0, 0]}
|
||||
|
|
@ -20,32 +24,53 @@ class Loader:
|
|||
self.recipes_list = {' ': [0, 0, 0, 0, 0, 0, 0]}
|
||||
self.config = DefaultConfig()
|
||||
|
||||
if not os.path.exists(self.relative_import(self.config.yaml_dir)):
|
||||
os.mkdir(self.relative_import(self.config.yaml_dir))
|
||||
try:
|
||||
with open(self.relative_import(self.config.yaml_user), 'r') as file:
|
||||
self.user_list.update(yaml.safe_load(file))
|
||||
loaded_file = yaml.safe_load(file)
|
||||
if loaded_file:
|
||||
self.user_list.update(loaded_file)
|
||||
except FileNotFoundError as e:
|
||||
self.loggers.add_log(e)
|
||||
print(e)
|
||||
# self.loggers.add_log(f'File {self.config.yaml_user} not found.')
|
||||
print(f'File {self.config.yaml_user} not found.')
|
||||
print(f'Creating {self.config.yaml_user}.')
|
||||
with open(self.relative_import(self.config.yaml_user), 'w+') as _:
|
||||
pass
|
||||
|
||||
try:
|
||||
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'])
|
||||
if loaded_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:
|
||||
self.loggers.add_log(e)
|
||||
print(e)
|
||||
# self.loggers.add_log(f'File {self.config.yaml_consumable} not found.')
|
||||
print(f'File {self.config.yaml_consumable} not found.')
|
||||
print(f'Creating {self.config.yaml_consumable}.')
|
||||
with open(self.relative_import(self.config.yaml_consumable), 'w+') as _:
|
||||
pass
|
||||
|
||||
try:
|
||||
with open(self.relative_import(self.config.yaml_recipes), 'r') as file:
|
||||
self.recipes_list.update(yaml.safe_load(file))
|
||||
loaded_file = yaml.safe_load(file)
|
||||
if loaded_file:
|
||||
self.recipes_list.update(loaded_file)
|
||||
except (FileNotFoundError, IsADirectoryError) as e:
|
||||
self.loggers.add_log(e)
|
||||
print(e)
|
||||
# self.loggers.add_log(f'File {self.config.yaml_recipes} not found.')
|
||||
print(f'File {self.config.yaml_recipes} not found.')
|
||||
print(f'Creating {self.config.yaml_recipes}.')
|
||||
with open(self.relative_import(self.config.yaml_recipes), 'w+') as _:
|
||||
pass
|
||||
|
||||
@staticmethod
|
||||
def relative_import(path):
|
||||
return os.path.normpath(os.path.join(__file__, "../..", path))
|
||||
|
||||
def get_users_dict(self) -> dict:
|
||||
self.loggers.add_log('Loaded user dictionary from users.yaml')
|
||||
return self.user_list
|
||||
|
||||
def get_users_names(self) -> list:
|
||||
|
|
|
|||
|
|
@ -3,12 +3,9 @@ import dearpygui.dearpygui as dpg
|
|||
|
||||
|
||||
class Loggers:
|
||||
def __init__(self, log=None):
|
||||
def __init__(self):
|
||||
timestamp = self.get_timestamp()
|
||||
if not log:
|
||||
self.log = f"{timestamp} Log initialised."
|
||||
else:
|
||||
self.log = log
|
||||
self.log = f"{timestamp} Log initialised."
|
||||
|
||||
def add_log(self, other: str) -> str:
|
||||
timestamp = self.get_timestamp()
|
||||
|
|
|
|||
|
|
@ -0,0 +1,77 @@
|
|||
from xiv_csolver.modules import loader
|
||||
|
||||
|
||||
class Printer:
|
||||
def __init__(self, full_config: loader.Loader):
|
||||
self.full_config = full_config
|
||||
self.help_text_dict = {
|
||||
'users': '''# Name: [Craftsmanship, control, cp]
|
||||
# You are encouraged to use this either for multiple characters if you have them, or different jobs having
|
||||
# different gear or melds.
|
||||
# The top line will always be selected by default
|
||||
''',
|
||||
'foods': '''Foods:
|
||||
# Name: [[Bonus craftsmanship%, max value], [bonus control%, max value], [bonus cp%, max value]]
|
||||
# For example, Calamari Ripieni HQ gives 5% craftsmanship up to a maximum of 120, and 26% CP up to a
|
||||
# maximum of 82, and is hence noted as:
|
||||
# Calamari Ripieni HQ: [[5, 120], [0, 0], [26, 82]]
|
||||
#
|
||||
# Here is your template to copy/paste and fill in:
|
||||
# Name: [[0, 0], [0, 0], [0, 0]]''',
|
||||
'pots': ''' # Same as above:
|
||||
# Name: [[Bonus craftsmanship%, max value], [bonus control%, max value], [bonus cp%, max value]]
|
||||
# For example, Cunning Craftsman's Draught HQ gives 6% CP up to a maximum of 21, and is hence noted as:
|
||||
# Cunning Craftsman's Draught HQ: [[0, 0], [0, 0], [6, 21]]
|
||||
#
|
||||
# Here is your template to copy/paste and fill in:
|
||||
# Name: [[0, 0], [0, 0], [0, 0]]''',
|
||||
'recipe': '''# 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 the craft system works in FFXIV.'''
|
||||
}
|
||||
|
||||
def save_users(self, user_name: str = None, user_stats: list = None) -> dict:
|
||||
output = self.help_text_dict['users'] + '\n\n'
|
||||
|
||||
if user_name.title() == '':
|
||||
for user, stats in self.full_config.get_users_dict().items():
|
||||
if user != ' ':
|
||||
output += f'{user}: [{stats[0]}, {stats[1]}, {stats[2]}]\n'
|
||||
|
||||
else:
|
||||
self.full_config.get_users_dict()[user_name] = user_stats
|
||||
for user, stats in self.full_config.get_users_dict().items():
|
||||
if user != ' ':
|
||||
output += f'{user}: [{stats[0]}, {stats[1]}, {stats[2]}]\n'
|
||||
|
||||
self.print_users(output)
|
||||
return self.full_config.get_users_dict()
|
||||
|
||||
def print_users(self, output: str) -> True:
|
||||
with open(self.full_config.relative_import(self.full_config.config.yaml_user), 'w') as file:
|
||||
file.write(output)
|
||||
return True
|
||||
|
||||
def save_recipe(self, recipe_name: str = None, recipe_basic_stats: list = None, recipe_advanced_stats: list = None) -> dict:
|
||||
output = self.help_text_dict['recipe'] + '\n\n'
|
||||
|
||||
if recipe_name.title() == '':
|
||||
for recipe, stats in self.full_config.get_recipes_dict().items():
|
||||
if recipe != ' ':
|
||||
output += f'{recipe}: [{stats[0]}, {stats[1]}, {stats[2]}, {stats[3]}, {stats[4]}, {stats[5]}, {stats[6]}]\n'
|
||||
|
||||
else:
|
||||
self.full_config.get_recipes_dict()[recipe_name] = recipe_basic_stats[:-1] + recipe_advanced_stats
|
||||
for recipe, stats in self.full_config.get_recipes_dict().items():
|
||||
if recipe != ' ':
|
||||
output += f'{recipe}: [{stats[0]}, {stats[1]}, {stats[2]}, {stats[3]}, {stats[4]}, {stats[5]}, {stats[6]}]\n'
|
||||
|
||||
self.print_recipe(output)
|
||||
return self.full_config.get_recipes_dict()
|
||||
|
||||
def print_recipe(self, output) -> True:
|
||||
with open(self.full_config.relative_import(self.full_config.config.yaml_recipes), 'w') as file:
|
||||
file.write(output)
|
||||
return True
|
||||
|
|
@ -125,7 +125,7 @@ class Solver:
|
|||
|
||||
def solve(self) -> str:
|
||||
self.solutions = xcs.solve_from_python(self)
|
||||
return xcs.solve_from_python(self)
|
||||
return self.solutions
|
||||
|
||||
def compute_all(self) -> True:
|
||||
if self.solutions:
|
||||
|
|
@ -149,24 +149,24 @@ class Solver:
|
|||
if s.quality > threshold:
|
||||
self.safe_50 = Result(s, 'Safe 50')
|
||||
done = True
|
||||
else:
|
||||
break
|
||||
|
||||
if not done:
|
||||
self.loggers.add_log('Could not find a rotation for a 50% Safe Margin.\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:
|
||||
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')
|
||||
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
|
||||
|
||||
|
|
|
|||
Reference in New Issue