Completed solution display and macro integration.
Added translation module for future translations.
This commit is contained in:
parent
b47d51c7ac
commit
9678a3bd98
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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}" <wait.{"2" if self.actions[count] in self.all_buffs_list else "3"}>'
|
||||
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):
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
Reference in New Issue