Added option to save users and make them appear and update user list, no print yet

This commit is contained in:
vicky 2023-03-03 17:30:36 +01:00
parent d8819feb41
commit 383912d8f4
6 changed files with 123 additions and 29 deletions

View File

@ -1,7 +1,7 @@
import time
import dearpygui.dearpygui as dpg
from xiv_csolver.modules import loader, log, solver
from xiv_csolver.modules import loader, log, solver, printer
import rich
@ -110,6 +110,16 @@ 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.')
else:
saver.save_users(dpg.get_value(save_user_as), dpg.get_value(user_stats))
dpg.configure_item('user_combo', items=full_config.get_users_names())
return True
class Recipe:
name = ' '
@ -238,10 +248,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,7 +261,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: make it so field is not cleared at every input in stats
dpg.add_button(label="Save!", callback=user.save_users)
# TODO: Can't save if value == ' '
# EFFECTIVE STATS
@ -264,6 +277,7 @@ 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()

View File

@ -5,4 +5,4 @@
Vicky Crosia: [4021, 3933, 587]
Dandaedre Zadiel: [0, 0, 0]
Sekundes Dullahan: [2566, 2443, 522]
Sekundes Dullahan: [2566, 2443, 522]

View File

@ -1,17 +1,20 @@
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
def __init__(self, loggers: log.Loggers):
self.loggers = loggers
self.user_list = {' ': [0, 0, 0]}
@ -20,32 +23,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:

View File

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

View File

@ -0,0 +1,59 @@
import rich
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):
output = self.help_text_dict['users'] + '\n\n'
if user_name.title() == '':
for user, stats in self.full_config.get_users_dict().items():
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():
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):
pass
def save_recipe(self):
pass
def save_consumables(self):
pass

View File

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