# 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
    @classmethod
    def add(cls, value):
        logger.debug("kill_switch: Add switch")
        cls._to_kill.append(value)

    @classmethod
    def kill_all(cls):
        logger.info("kill_switch: Process cleanup")
        for p in cls._to_kill:
            p._clean()

class SC2Process:
    def __init__(self, host: str = "127.0.0.1", port: Optional[int] = None, fullscreen: bool = False,
                 render: bool = False) -> None:
        assert isinstance(host, str)
        assert isinstance(port, int) or port is None

        self._render = render
        self._fullscreen = fullscreen
        self._host = host
        if port is None:
            self._port = portpicker.pick_unused_port()
        else:
            self._port = port
        self._tmp_dir = tempfile.mkdtemp(prefix="SC2_")
        self._process = None
        self._session = None
        self._ws = None

    async def __aenter__(self):

# 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

    @classmethod
    def add(cls, value):
        logger.debug("kill_switch: Add switch")
        cls._to_kill.append(value)

    @classmethod
    def kill_all(cls):
        logger.info("kill_switch: Process cleanup")
        for p in cls._to_kill:
            p._clean()

class SC2Process:
    def __init__(self, host: str = "127.0.0.1", port: Optional[int] = None, fullscreen: bool = False,
                 render: bool = False) -> None:
        assert isinstance(host, str)
        assert isinstance(port, int) or port is None

        self._render = render
        self._fullscreen = fullscreen
        self._host = host
        if port is None:
            self._port = portpicker.pick_unused_port()
        else:
            self._port = port
        self._tmp_dir = tempfile.mkdtemp(prefix="SC2_")
        self._process = None
        self._session = None
        self._ws = None

    async def __aenter__(self):

        kill_switch.add(self)