Skip to content

Commit

Permalink
SC2: Python 3.11 compatibility (#1821)
Browse files Browse the repository at this point in the history
Co-authored-by: Salzkorn
  • Loading branch information
Ziktofel authored Jun 12, 2023
1 parent f6cb90d commit ce2433b
Show file tree
Hide file tree
Showing 36 changed files with 7,699 additions and 13 deletions.
19 changes: 8 additions & 11 deletions Starcraft2Client.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,10 @@
sc2_logger = logging.getLogger("Starcraft2")

import nest_asyncio
import sc2
from sc2.bot_ai import BotAI
from sc2.data import Race
from sc2.main import run_game
from sc2.player import Bot
from worlds._sc2common import bot
from worlds._sc2common.bot.data import Race
from worlds._sc2common.bot.main import run_game
from worlds._sc2common.bot.player import Bot
from worlds.sc2wol import SC2WoLWorld
from worlds.sc2wol.Items import lookup_id_to_name, item_table, ItemData, type_flaggroups
from worlds.sc2wol.Locations import SC2WOL_LOC_ID_OFFSET
Expand Down Expand Up @@ -240,8 +239,6 @@ def run_gui(self):
from kivy.uix.floatlayout import FloatLayout
from kivy.properties import StringProperty

import Utils

class HoverableButton(HoverBehavior, Button):
pass

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

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


class ArchipelagoBot(sc2.bot_ai.BotAI):
class ArchipelagoBot(bot.bot_ai.BotAI):
game_running: bool = False
mission_completed: bool = False
boni: typing.List[bool]
Expand Down Expand Up @@ -867,7 +864,7 @@ def check_game_install_path() -> bool:
documentspath = buf.value
einfo = str(documentspath / Path("StarCraft II\\ExecuteInfo.txt"))
else:
einfo = str(sc2.paths.get_home() / Path(sc2.paths.USERPATH[sc2.paths.PF]))
einfo = str(bot.paths.get_home() / Path(bot.paths.USERPATH[bot.paths.PF]))

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

# Finally, check the path for an actual executable.
# If we find one, great. Set up the SC2PATH.
Expand Down
Empty file added worlds/_sc2common/__init__.py
Empty file.
21 changes: 21 additions & 0 deletions worlds/_sc2common/bot/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2017 Hannes Karppila

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
6 changes: 6 additions & 0 deletions worlds/_sc2common/bot/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# SC2 Bot
This is client library to communicate with Starcraft 2 game
It's based on `burnysc2` python package, see https://github.com/BurnySc2/python-sc2

The base package is stripped down to clean up unneeded features and those not working outside a
melee game.
16 changes: 16 additions & 0 deletions worlds/_sc2common/bot/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from pathlib import Path
from loguru import logger


def is_submodule(path):
if path.is_file():
return path.suffix == ".py" and path.stem != "__init__"
if path.is_dir():
return (path / "__init__.py").exists()
return False


__all__ = [p.stem for p in Path(__file__).parent.iterdir() if is_submodule(p)]


logger = logger
Loading

0 comments on commit ce2433b

Please sign in to comment.