# Path: sc2/paths.py
# class Paths(metaclass=_MetaPaths):
#     """Paths for SC2 folders, lazily loaded using the above metaclass."""
# 
# Path: sc2/controller.py
# class Controller(Protocol):
#     def __init__(self, ws, process):
#         super().__init__(ws)
#         self.__process = process
# 
#     @property
#     def running(self):
#         return self.__process._process is not None
# 
#     async def create_game(self, game_map, players, realtime, random_seed=None):
#         assert isinstance(realtime, bool)
#         req = sc_pb.RequestCreateGame(
#             local_map=sc_pb.LocalMap(
#                 map_path=str(game_map.relative_path)
#             ),
#             realtime=realtime
#         )
#         if random_seed is not None:
#             req.random_seed = random_seed
# 
#         for player in players:
#             p = req.player_setup.add()
#             p.type = player.type.value
#             if isinstance(player, Computer):
#                 p.race = player.race.value
#                 p.difficulty = player.difficulty.value
# 
#         logger.info("Creating new game")
#         logger.info(f"Map:     {game_map.name}")
#         logger.info(f"Players: {', '.join(str(p) for p in players)}")
#         result = await self._execute(create_game=req)
#         return result


from typing import Any, Optional, List
from .paths import Paths
from .controller import Controller
import sys
import signal
import time
import asyncio
import os.path
import shutil
import tempfile
import subprocess
import portpicker
import aiohttp
import logging

        def signal_handler(*args):
            kill_switch.kill_all()

        signal.signal(signal.SIGINT, signal_handler)

        try:
            self._process = self._launch()
            self._ws = await self._connect()
        except:
            await self._close_connection()
            self._clean()
            raise

        return Controller(self._ws, self)

    async def __aexit__(self, *args):
        kill_switch.kill_all()
        signal.signal(signal.SIGINT, signal.SIG_DFL)

    @property
    def ws_url(self):
        return f"ws://{self._host}:{self._port}/sc2api"

    def _launch(self):
        args = [
            str(Paths.EXECUTABLE),
            "-listen", self._host,
            "-port", str(self._port),
            "-displayMode", "1" if self._fullscreen else "0",

# Path: sc2/paths.py
# class Paths(metaclass=_MetaPaths):
#     """Paths for SC2 folders, lazily loaded using the above metaclass."""
# 
# Path: sc2/controller.py
# class Controller(Protocol):
#     def __init__(self, ws, process):
#         super().__init__(ws)
#         self.__process = process
# 
#     @property
#     def running(self):
#         return self.__process._process is not None
# 
#     async def create_game(self, game_map, players, realtime, random_seed=None):
#         assert isinstance(realtime, bool)
#         req = sc_pb.RequestCreateGame(
#             local_map=sc_pb.LocalMap(
#                 map_path=str(game_map.relative_path)
#             ),
#             realtime=realtime
#         )
#         if random_seed is not None:
#             req.random_seed = random_seed
# 
#         for player in players:
#             p = req.player_setup.add()
#             p.type = player.type.value
#             if isinstance(player, Computer):
#                 p.race = player.race.value
#                 p.difficulty = player.difficulty.value
# 
#         logger.info("Creating new game")
#         logger.info(f"Map:     {game_map.name}")
#         logger.info(f"Players: {', '.join(str(p) for p in players)}")
#         result = await self._execute(create_game=req)
#         return result


# Path: sc2/sc2process.py
from typing import Any, Optional, List
from .paths import Paths
from .controller import Controller
import sys
import signal
import time
import asyncio
import os.path
import shutil
import tempfile
import subprocess
import portpicker
import aiohttp
import logging


        def signal_handler(*args):
            kill_switch.kill_all()

        signal.signal(signal.SIGINT, signal_handler)

        try:
            self._process = self._launch()
            self._ws = await self._connect()
        except:
            await self._close_connection()
            self._clean()
            raise

        return Controller(self._ws, self)

    async def __aexit__(self, *args):
        kill_switch.kill_all()
        signal.signal(signal.SIGINT, signal.SIG_DFL)

    @property
    def ws_url(self):
        return f"ws://{self._host}:{self._port}/sc2api"

    def _launch(self):
        args = [
            str(Paths.EXECUTABLE),
            "-listen", self._host,
            "-port", str(self._port),
            "-displayMode", "1" if self._fullscreen else "0",

            "-dataDir", str(Paths.BASE),