Skip to content

Commit

Permalink
implement ddnet check option fully
Browse files Browse the repository at this point in the history
  • Loading branch information
mwinkens committed Jun 6, 2024
1 parent ab415f2 commit 6e63f27
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
6 changes: 4 additions & 2 deletions src/backend/map_generator.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import tempfile

import twmap
import numpy as np
from src.config.app_state import AppState
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand Down
16 changes: 12 additions & 4 deletions src/widgets/widget_mapper_generator.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 6e63f27

Please sign in to comment.