Skip to content

Commit 6e63f27

Browse files
committed
implement ddnet check option fully
1 parent ab415f2 commit 6e63f27

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

src/backend/map_generator.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import tempfile
2+
13
import twmap
24
import numpy as np
35
from src.config.app_state import AppState
@@ -6,7 +8,7 @@
68

79

810
class MapGenerator:
9-
def __init__(self, map_name):
11+
def __init__(self, file_path):
1012
self._map = twmap.Map.empty("DDNet06")
1113

1214
solid_map = np.loadtxt("data/debroijn_torus.txt", dtype=np.uint8)
@@ -44,7 +46,7 @@ def __init__(self, map_name):
4446
tile_layer.tiles = tile_layer_map
4547

4648
# save map
47-
self._map.save(map_name)
49+
self._map.save(str(file_path))
4850

4951
def __del__(self):
5052
# TODO delete map

src/widgets/widget_mapper_generator.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import subprocess
2+
import tempfile
3+
from datetime import datetime
24
from pathlib import Path
35

46
from PyQt6.QtWidgets import QWidget, QHBoxLayout, QVBoxLayout, QRadioButton, QLabel, QPushButton, QLineEdit, QComboBox
@@ -138,15 +140,21 @@ def startDDNetCheck(self):
138140
# add tmp mapping rule
139141
# automap map with debroijn torus
140142
# open map with ddnet
141-
map_name = "tmp_map.map"
142-
MapGenerator(map_name)
143+
date_str = datetime.now().strftime("%Y%m%d_%H%M%S")
144+
map_name = f"map_{date_str}.map"
145+
146+
temp_dir = Path(tempfile.gettempdir())
147+
temp_dir_simple_ddnet = temp_dir.joinpath(Path("simple_ddnet"))
148+
temp_dir_simple_ddnet.mkdir(exist_ok=True)
149+
file_path = str(temp_dir.joinpath(Path(map_name)))
150+
MapGenerator(file_path)
143151

144152
client_path = ConfigManager.instance().config()["client_path"]
145153
if not client_path:
146154
self.ddnet_push_button.setDisabled(True)
147155
return
148-
# cmd = [client_path, map_name]
149-
# subprocess.Popen(cmd, start_new_session=True)
156+
cmd = [client_path, file_path]
157+
subprocess.Popen(cmd, start_new_session=True)
150158

151159
def rulesLoaded(self):
152160
rules = AppState.ruleManager().getRules()

0 commit comments

Comments
 (0)