diff --git a/ph_rando/shuffler/_util.py b/ph_rando/shuffler/_util.py new file mode 100644 index 00000000..33d65274 --- /dev/null +++ b/ph_rando/shuffler/_util.py @@ -0,0 +1,7 @@ +import random +import string + + +def generate_random_seed() -> str: + # TODO: make this more robust + return ''.join(random.choices(string.ascii_letters, k=20)) diff --git a/ph_rando/ui/cli.py b/ph_rando/ui/cli.py index 0f72afff..d0cd762b 100644 --- a/ph_rando/ui/cli.py +++ b/ph_rando/ui/cli.py @@ -1,8 +1,6 @@ import json import logging from pathlib import Path -import random -import string import click @@ -10,6 +8,7 @@ from ph_rando.patcher._patcher import Patcher from ph_rando.shuffler._shuffler import Shuffler from ph_rando.shuffler._spoiler_log import generate_spoiler_log +from ph_rando.shuffler._util import generate_random_seed @click.command() @@ -56,7 +55,7 @@ def randomizer_cli( # Generate random seed if one isn't provided if seed is None: - seed = ''.join(random.choices(string.ascii_letters, k=20)) + seed = generate_random_seed() # Run the shuffler shuffled_aux_data = Shuffler(seed, settings).generate() diff --git a/ph_rando/ui/gui.py b/ph_rando/ui/gui.py index 39d027b1..42dbcdc1 100644 --- a/ph_rando/ui/gui.py +++ b/ph_rando/ui/gui.py @@ -19,14 +19,19 @@ import inflection from ph_rando.common import RANDOMIZER_SETTINGS +from ph_rando.shuffler._util import generate_random_seed class RandomizerUi(QWidget): - rom_path: Path + rom_path: Path | None + seed: str | None def __init__(self) -> None: super().__init__() + self.rom_path = None + self.seed = None + self.setWindowTitle('Phantom Hourglass Randomizer') layout = QFormLayout() self.setLayout(layout) @@ -35,7 +40,7 @@ def __init__(self) -> None: self.render_settings() self.render_bottom_panel() - def _get_rom_file_select_widget(self) -> None: + def _get_rom_file_select_widget(self) -> QWidget: rom_input_widget = QWidget() hbox = QHBoxLayout() rom_input_widget.setLayout(hbox) @@ -62,24 +67,40 @@ def on_rom_path_change(path: str) -> None: return rom_input_widget + def _get_seed_widget(self) -> QWidget: + seed_widget = QWidget() + hbox = QHBoxLayout() + seed_widget.setLayout(hbox) + seed = QLineEdit() + hbox.addWidget(QLabel('Seed')) + hbox.addWidget(seed) + + gen_seed_button = QPushButton(text='Random Seed') + hbox.addWidget(gen_seed_button) + + def on_random_seed_click() -> None: + self.seed = generate_random_seed() + seed.setText(self.seed) + + def on_seed_change(value: str) -> None: + self.seed = value + seed.setText(value) + + gen_seed_button.clicked.connect(on_random_seed_click) + seed.textChanged.connect(on_seed_change) + + return seed_widget + def render_file_open_ui(self) -> None: layout = self.layout() + groupbox = QGroupBox('ROM Selection') layout.addWidget(groupbox) vbox = QVBoxLayout() groupbox.setLayout(vbox) vbox.addWidget(self._get_rom_file_select_widget()) - - seed_input_widget = QWidget() - vbox.addWidget(seed_input_widget) - hbox = QHBoxLayout() - seed_input_widget.setLayout(hbox) - seed = QLineEdit() - gen_seed_button = QPushButton(text='Random Seed') - hbox.addWidget(QLabel('Seed')) - hbox.addWidget(seed) - hbox.addWidget(gen_seed_button) + vbox.addWidget(self._get_seed_widget()) def render_settings(self) -> None: groupbox = QGroupBox('Randomizer Settings')