Skip to content

Commit

Permalink
make sc2_version accepted by old join and host methods
Browse files Browse the repository at this point in the history
  • Loading branch information
dysonreturns committed Jan 17, 2025
1 parent 15fbac3 commit 8f60593
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
5 changes: 3 additions & 2 deletions sc2/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -415,8 +415,9 @@ async def _join_game(
portconfig,
save_replay_as=None,
game_time_limit=None,
sc2_version=None,
):
async with SC2Process(fullscreen=players[1].fullscreen) as server:
async with SC2Process(fullscreen=players[1].fullscreen, sc2_version=sc2_version) as server:
await server.ping()

client = Client(server._ws)
Expand Down Expand Up @@ -466,7 +467,7 @@ def run_game(map_settings, players, **kwargs) -> Result | list[Result | None]:
Returns a list of two Result enums if the game was "Human vs Bot" or "Bot vs Bot".
"""
if sum(isinstance(p, (Human, Bot)) for p in players) > 1:
host_only_args = ["save_replay_as", "rgb_render_config", "random_seed", "sc2_version", "disable_fog"]
host_only_args = ["save_replay_as", "rgb_render_config", "random_seed", "disable_fog"]
join_kwargs = {k: v for k, v in kwargs.items() if k not in host_only_args}

portconfig = Portconfig()
Expand Down
12 changes: 12 additions & 0 deletions sc2/sc2process.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,23 @@ def find_data_hash(self, target_sc2_version: str) -> str | None:
return version["data-hash"]
return None

def find_base_dir(self, target_sc2_version: str) -> str | None:
""" Returns the base directory from the matching version string. """
version: dict
for version in self.versions:
if version["label"] == target_sc2_version:
return "Base"+str(version["base-version"])
return None

def _launch(self):
if self._sc2_version and not self._base_build:
self._base_build = self.find_base_dir(self._sc2_version)

if self._base_build:
executable = str(paths.latest_executeble(Paths.BASE / "Versions", self._base_build))
else:
executable = str(Paths.EXECUTABLE)

if self._port is None:
self._port = portpicker.pick_unused_port()
self._used_portpicker = True
Expand Down

0 comments on commit 8f60593

Please sign in to comment.