From 6e63f275f958a327f4d526707487036a0fd87a8f Mon Sep 17 00:00:00 2001 From: Marvin Winkens Date: Thu, 6 Jun 2024 17:47:08 +0200 Subject: [PATCH] implement ddnet check option fully --- src/backend/map_generator.py | 6 ++++-- src/widgets/widget_mapper_generator.py | 16 ++++++++++++---- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/backend/map_generator.py b/src/backend/map_generator.py index 8000707..e6fb30f 100644 --- a/src/backend/map_generator.py +++ b/src/backend/map_generator.py @@ -1,3 +1,5 @@ +import tempfile + import twmap import numpy as np from src.config.app_state import AppState @@ -6,7 +8,7 @@ class MapGenerator: - def __init__(self, map_name): + def __init__(self, file_path): self._map = twmap.Map.empty("DDNet06") solid_map = np.loadtxt("data/debroijn_torus.txt", dtype=np.uint8) @@ -44,7 +46,7 @@ def __init__(self, map_name): tile_layer.tiles = tile_layer_map # save map - self._map.save(map_name) + self._map.save(str(file_path)) def __del__(self): # TODO delete map diff --git a/src/widgets/widget_mapper_generator.py b/src/widgets/widget_mapper_generator.py index 9299b58..eff84d2 100644 --- a/src/widgets/widget_mapper_generator.py +++ b/src/widgets/widget_mapper_generator.py @@ -1,4 +1,6 @@ import subprocess +import tempfile +from datetime import datetime from pathlib import Path from PyQt6.QtWidgets import QWidget, QHBoxLayout, QVBoxLayout, QRadioButton, QLabel, QPushButton, QLineEdit, QComboBox @@ -138,15 +140,21 @@ def startDDNetCheck(self): # add tmp mapping rule # automap map with debroijn torus # open map with ddnet - map_name = "tmp_map.map" - MapGenerator(map_name) + date_str = datetime.now().strftime("%Y%m%d_%H%M%S") + map_name = f"map_{date_str}.map" + + temp_dir = Path(tempfile.gettempdir()) + temp_dir_simple_ddnet = temp_dir.joinpath(Path("simple_ddnet")) + temp_dir_simple_ddnet.mkdir(exist_ok=True) + file_path = str(temp_dir.joinpath(Path(map_name))) + MapGenerator(file_path) client_path = ConfigManager.instance().config()["client_path"] if not client_path: self.ddnet_push_button.setDisabled(True) return - # cmd = [client_path, map_name] - # subprocess.Popen(cmd, start_new_session=True) + cmd = [client_path, file_path] + subprocess.Popen(cmd, start_new_session=True) def rulesLoaded(self): rules = AppState.ruleManager().getRules()