From a2b618f56645eefd85133482b307565e4c6e00d9 Mon Sep 17 00:00:00 2001 From: vicky Date: Fri, 3 Mar 2023 18:18:43 +0100 Subject: [PATCH] added verification logic to save as input, added printing to yaml for users --- python/src/xiv_csolver/__main__.py | 14 +++++++++----- python/src/xiv_csolver/configs/users.yaml | 7 +++++-- python/src/xiv_csolver/modules/printer.py | 11 ++++++----- 3 files changed, 20 insertions(+), 12 deletions(-) diff --git a/python/src/xiv_csolver/__main__.py b/python/src/xiv_csolver/__main__.py index 17ea9ac..00b7784 100644 --- a/python/src/xiv_csolver/__main__.py +++ b/python/src/xiv_csolver/__main__.py @@ -1,8 +1,6 @@ -import time - +import re import dearpygui.dearpygui as dpg from xiv_csolver.modules import loader, log, solver, printer -import rich class User: @@ -114,10 +112,16 @@ class User: 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)) - - dpg.configure_item('user_combo', items=full_config.get_users_names()) + loggers.add_log('User saved!') + dpg.configure_item('user_combo', items=full_config.get_users_names()) return True diff --git a/python/src/xiv_csolver/configs/users.yaml b/python/src/xiv_csolver/configs/users.yaml index 6ab4b59..ed0ef89 100644 --- a/python/src/xiv_csolver/configs/users.yaml +++ b/python/src/xiv_csolver/configs/users.yaml @@ -1,8 +1,11 @@ # 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 +# The top line will always be selected by default + Vicky Crosia: [4021, 3933, 587] -Dandaedre Zadiel: [0, 0, 0] +Dandaedre Zadiel: [0, 0, 2] Sekundes Dullahan: [2566, 2443, 522] +ewww: [213, 3124, 0] +bernard: [0, 0, 0] diff --git a/python/src/xiv_csolver/modules/printer.py b/python/src/xiv_csolver/modules/printer.py index 74686ba..8ebb840 100644 --- a/python/src/xiv_csolver/modules/printer.py +++ b/python/src/xiv_csolver/modules/printer.py @@ -1,5 +1,3 @@ -import rich - from xiv_csolver.modules import loader @@ -39,18 +37,21 @@ class Printer: 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' + 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(): - output += f'{user}: [{stats[0]}, {stats[1]}, {stats[2]}]\n' + 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): - pass + with open(self.full_config.relative_import(self.full_config.config.yaml_user), 'w') as file: + file.write(output) def save_recipe(self): pass