mirror of
https://github.com/MarioSpore/Grinch-AP.git
synced 2025-10-21 12:11:33 -06:00

* First Pass removal of game-specific code * SMW, DKC3, and SM hooked into AutoClient * All SNES autoclients functional * Fix ALttP Deathlink * Don't default to being ALttP, and properly error check ctx.game * Adjust variable naming * In response to: > we should probably document usage somewhere. I'm open to suggestions of where this should be documented. I think the most valuable documentation for APIs is docstrings and full typing. about websockets change in imports - from websockets documentation: > For convenience, many public APIs can be imported from the websockets package. However, this feature is incompatible with static code analysis. It breaks autocompletion in an IDE or type checking with mypy. If you’re using such tools, use the real import paths. * todo note for python 3.11 typing.NotRequired * missed staging in previous commit * added missing death Game States for DeathLink Co-authored-by: beauxq <beauxq@users.noreply.github.com> Co-authored-by: lordlou <87331798+lordlou@users.noreply.github.com>
43 lines
1.3 KiB
Python
43 lines
1.3 KiB
Python
|
|
from __future__ import annotations
|
|
import abc
|
|
from typing import TYPE_CHECKING, ClassVar, Dict, Tuple, Any, Optional
|
|
|
|
if TYPE_CHECKING:
|
|
from SNIClient import SNIContext
|
|
|
|
|
|
class AutoSNIClientRegister(abc.ABCMeta):
|
|
game_handlers: ClassVar[Dict[str, SNIClient]] = {}
|
|
|
|
def __new__(cls, name: str, bases: Tuple[type, ...], dct: Dict[str, Any]) -> AutoSNIClientRegister:
|
|
# construct class
|
|
new_class = super().__new__(cls, name, bases, dct)
|
|
if "game" in dct:
|
|
AutoSNIClientRegister.game_handlers[dct["game"]] = new_class()
|
|
return new_class
|
|
|
|
@staticmethod
|
|
async def get_handler(ctx: SNIContext) -> Optional[SNIClient]:
|
|
for _game, handler in AutoSNIClientRegister.game_handlers.items():
|
|
if await handler.validate_rom(ctx):
|
|
return handler
|
|
return None
|
|
|
|
|
|
class SNIClient(abc.ABC, metaclass=AutoSNIClientRegister):
|
|
|
|
@abc.abstractmethod
|
|
async def validate_rom(self, ctx: SNIContext) -> bool:
|
|
""" TODO: interface documentation here """
|
|
...
|
|
|
|
@abc.abstractmethod
|
|
async def game_watcher(self, ctx: SNIContext) -> None:
|
|
""" TODO: interface documentation here """
|
|
...
|
|
|
|
async def deathlink_kill_player(self, ctx: SNIContext) -> None:
|
|
""" override this with implementation to kill player """
|
|
pass
|