Skip to content

Commit c62787f

Browse files
committed
SC2: Python 3.11 compatibility
1 parent 18127a7 commit c62787f

34 files changed

+7671
-13
lines changed

Starcraft2Client.py

+8-11
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,10 @@
2525
sc2_logger = logging.getLogger("Starcraft2")
2626

2727
import nest_asyncio
28-
import sc2
29-
from sc2.bot_ai import BotAI
30-
from sc2.data import Race
31-
from sc2.main import run_game
32-
from sc2.player import Bot
28+
from worlds._sc2common import bot
29+
from worlds._sc2common.bot.data import Race
30+
from worlds._sc2common.bot.main import run_game
31+
from worlds._sc2common.bot.player import Bot
3332
from worlds.sc2wol import SC2WoLWorld
3433
from worlds.sc2wol.Items import lookup_id_to_name, item_table, ItemData, type_flaggroups
3534
from worlds.sc2wol.Locations import SC2WOL_LOC_ID_OFFSET
@@ -240,8 +239,6 @@ def run_gui(self):
240239
from kivy.uix.floatlayout import FloatLayout
241240
from kivy.properties import StringProperty
242241

243-
import Utils
244-
245242
class HoverableButton(HoverBehavior, Button):
246243
pass
247244

@@ -544,11 +541,11 @@ async def starcraft_launch(ctx: SC2Context, mission_id: int):
544541
sc2_logger.info(f"Launching {lookup_id_to_mission[mission_id]}. If game does not launch check log file for errors.")
545542

546543
with DllDirectory(None):
547-
run_game(sc2.maps.get(maps_table[mission_id - 1]), [Bot(Race.Terran, ArchipelagoBot(ctx, mission_id),
544+
run_game(bot.maps.get(maps_table[mission_id - 1]), [Bot(Race.Terran, ArchipelagoBot(ctx, mission_id),
548545
name="Archipelago", fullscreen=True)], realtime=True)
549546

550547

551-
class ArchipelagoBot(sc2.bot_ai.BotAI):
548+
class ArchipelagoBot(bot.bot_ai.BotAI):
552549
game_running: bool = False
553550
mission_completed: bool = False
554551
boni: typing.List[bool]
@@ -867,7 +864,7 @@ def check_game_install_path() -> bool:
867864
documentspath = buf.value
868865
einfo = str(documentspath / Path("StarCraft II\\ExecuteInfo.txt"))
869866
else:
870-
einfo = str(sc2.paths.get_home() / Path(sc2.paths.USERPATH[sc2.paths.PF]))
867+
einfo = str(bot.paths.get_home() / Path(bot.paths.USERPATH[bot.paths.PF]))
871868

872869
# Check if the file exists.
873870
if os.path.isfile(einfo):
@@ -883,7 +880,7 @@ def check_game_install_path() -> bool:
883880
f"try again.")
884881
return False
885882
if os.path.exists(base):
886-
executable = sc2.paths.latest_executeble(Path(base).expanduser() / "Versions")
883+
executable = bot.paths.latest_executeble(Path(base).expanduser() / "Versions")
887884

888885
# Finally, check the path for an actual executable.
889886
# If we find one, great. Set up the SC2PATH.

worlds/_sc2common/__init__.py

Whitespace-only changes.

worlds/_sc2common/bot/__init__.py

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from pathlib import Path
2+
from loguru import logger
3+
4+
5+
def is_submodule(path):
6+
if path.is_file():
7+
return path.suffix == ".py" and path.stem != "__init__"
8+
if path.is_dir():
9+
return (path / "__init__.py").exists()
10+
return False
11+
12+
13+
__all__ = [p.stem for p in Path(__file__).parent.iterdir() if is_submodule(p)]
14+
15+
16+
logger = logger

0 commit comments

Comments
 (0)