Very first, barebones, version. But it is kinda usable. No async, no saving yet though.
This commit is contained in:
parent
67b67712cf
commit
b47d51c7ac
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
||||
|
|
|
|||
Reference in New Issue