Skip to content

Allow passing in sc2_version to all legacy host and launch methods #213

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading