diff --git a/src/games/hostgamewidget.py b/src/games/hostgamewidget.py index 99c1dabf0..3b36fa850 100644 --- a/src/games/hostgamewidget.py +++ b/src/games/hostgamewidget.py @@ -3,11 +3,11 @@ from PyQt6 import QtCore import fa.check -import games.mapgenoptionsdialog as MapGenDialog import util import vaults.modvault.utils from fa import maps from games.gamemodel import GameModel +from games.mapgenoptionsdialog import MapGenDialog from model.game import Game from model.game import GameState from model.game import GameVisibility @@ -252,9 +252,15 @@ def save_last_hosted_settings(self, password): util.settings.endGroup() @QtCore.pyqtSlot() - def generateMap(self): - dialog = MapGenDialog.MapGenDialog(self) + def generateMap(self) -> None: + dialog = MapGenDialog(self.client.map_generator) + dialog.map_generated.connect(self.on_map_generated) dialog.exec() + dialog.deleteLater() + + def on_map_generated(self, mapname: str) -> None: + self.setupMapList() + self.set_map(mapname) def build_launcher(playerset, me, client, view_builder, map_preview_dler): diff --git a/src/games/mapgenoptionsdialog.py b/src/games/mapgenoptionsdialog.py index c88249b51..1b1215743 100644 --- a/src/games/mapgenoptionsdialog.py +++ b/src/games/mapgenoptionsdialog.py @@ -16,12 +16,15 @@ from games.mapgenoptionsvalues import TerrainStyle from games.mapgenoptionsvalues import TerrainSymmetry from games.mapgenoptionsvalues import TextureStyle +from mapGenerator.mapgenManager import MapGeneratorManager FormClass, BaseClass = util.THEME.loadUiType("games/mapgen.ui") class MapGenDialog(FormClass, BaseClass): - def __init__(self, parent, *args, **kwargs): + map_generated = QtCore.pyqtSignal(str) + + def __init__(self, mapgen_manager: MapGeneratorManager, *args, **kwargs) -> None: BaseClass.__init__(self, *args, **kwargs) self.setupUi(self) @@ -30,7 +33,7 @@ def __init__(self, parent, *args, **kwargs): self.load_stylesheet() - self.parent = parent + self.mapgen_manager = mapgen_manager self.useCustomStyleCheckBox.checkStateChanged.connect(self.on_custom_style) self.generationType.currentTextChanged.connect(self.gen_type_changed) @@ -164,13 +167,11 @@ def reset_mapgen_prefs(self) -> None: @QtCore.pyqtSlot() def generate_map(self) -> None: - map_ = self.parent.client.map_generator.generateMap( - args=self.set_arguments(), - ) - if map_: - self.parent.setupMapList() - self.parent.set_map(map_) + if result := self.mapgen_manager.generateMap(args=self.set_arguments()): + self.map_generated.emit(result) self.save_preferences_and_quit() + else: + self.save_preferences() def set_arguments(self) -> list[str]: args = []