diff --git a/assets/src/ba_data/python/ba/_app.py b/assets/src/ba_data/python/ba/_app.py index c4235d30..7cb8b361 100644 --- a/assets/src/ba_data/python/ba/_app.py +++ b/assets/src/ba_data/python/ba/_app.py @@ -201,6 +201,19 @@ class App: """ return self._subplatform + @property + def api_version(self) -> int: + """The game's api version. + + Only python modules and packages associated with the current api + version will be detected by the game (see the ba_meta tag). This + value will change whenever backward-incompatible changes are + introduced to game apis; when that happens, scripts should be updated + accordingly and set to target the new api. + """ + from ba._meta import CURRENT_API_VERSION + return CURRENT_API_VERSION + @property def interface_type(self) -> str: """Interface mode the game is in; can be 'large', 'medium', or 'small'. diff --git a/assets/src/ba_data/python/ba/_meta.py b/assets/src/ba_data/python/ba/_meta.py index cb34ed86..618e131e 100644 --- a/assets/src/ba_data/python/ba/_meta.py +++ b/assets/src/ba_data/python/ba/_meta.py @@ -37,10 +37,18 @@ if TYPE_CHECKING: # The meta api version of this build of the game. # Only packages and modules requiring this exact api version # will be considered when scanning directories. -# See: https://github.com/efroemling/ballistica/wiki/Using-ba_meta-Tags +# See: https://github.com/efroemling/ballistica/wiki/Meta-Tags CURRENT_API_VERSION = 6 +@dataclass +class ScanResults: + """Final results from a metadata scan.""" + games: List[str] = field(default_factory=list) + errors: str = '' + warnings: str = '' + + def start_scan() -> None: """Begin scanning script directories for scripts containing metadata. @@ -53,14 +61,6 @@ def start_scan() -> None: thread.start() -@dataclass -class ScanResults: - """Final results from a metadata scan.""" - games: List[str] = field(default_factory=list) - errors: str = '' - warnings: str = '' - - def handle_scan_results(results: ScanResults) -> None: """Called in the game thread with results of a completed scan.""" from ba import _lang @@ -94,7 +94,6 @@ class ScanThread(threading.Thread): scan.scan() results = scan.results except Exception as exc: - # results = {'errors': 'Scan exception: ' + str(exc)} results = ScanResults(errors=f'Scan exception: {exc}') # Push a call to the game thread to print warnings/errors @@ -192,11 +191,9 @@ class DirectoryScan: # If we find a module requiring a different api version, warn # and ignore. if required_api is not None and required_api != CURRENT_API_VERSION: - self.results.warnings += ('Warning: ' + str(subpath) + - ' requires api ' + str(required_api) + - ' but we are running ' + - str(CURRENT_API_VERSION) + - '; ignoring module.\n') + self.results.warnings += ( + f'Warning: {subpath} requires api {required_api} but' + f' we are running {CURRENT_API_VERSION}; ignoring module.\n') return # Ok; can proceed with a full scan of this module. @@ -211,18 +208,17 @@ class DirectoryScan: self.scan_module(submodule[0], submodule[1]) except Exception: from ba import _error - self.results.warnings += ("Error scanning '" + str(subpath) + - "': " + _error.exc_str() + '\n') + self.results.warnings += ( + f"Error scanning '{subpath}': {_error.exc_str()}\n") def _process_module_meta_tags(self, subpath: pathlib.Path, flines: List[str], meta_lines: Dict[int, List[str]]) -> None: """Pull data from a module based on its ba_meta tags.""" for lindex, mline in meta_lines.items(): - # meta_lines is just anything containing 'ba_meta'; make sure + # meta_lines is just anything containing '# ba_meta '; make sure # the ba_meta is in the right place. if mline[0] != 'ba_meta': - print(f'GOT "{mline[0]}"') self.results.warnings += ( 'Warning: ' + str(subpath) + ': malformed ba_meta statement on line ' + diff --git a/assets/src/ba_data/python/bastd/game/assault.py b/assets/src/ba_data/python/bastd/game/assault.py index a8116789..498a886f 100644 --- a/assets/src/ba_data/python/bastd/game/assault.py +++ b/assets/src/ba_data/python/bastd/game/assault.py @@ -21,7 +21,7 @@ """Defines assault minigame.""" # ba_meta require api 6 -# (see https://github.com/efroemling/ballistica/wiki/Using-ba_meta-Tags) +# (see https://github.com/efroemling/ballistica/wiki/Meta-Tags) from __future__ import annotations diff --git a/assets/src/ba_data/python/bastd/game/capturetheflag.py b/assets/src/ba_data/python/bastd/game/capturetheflag.py index 4d795727..e005308d 100644 --- a/assets/src/ba_data/python/bastd/game/capturetheflag.py +++ b/assets/src/ba_data/python/bastd/game/capturetheflag.py @@ -21,7 +21,7 @@ """Defines a capture-the-flag game.""" # ba_meta require api 6 -# (see https://github.com/efroemling/ballistica/wiki/Using-ba_meta-Tags) +# (see https://github.com/efroemling/ballistica/wiki/Meta-Tags) from __future__ import annotations diff --git a/assets/src/ba_data/python/bastd/game/chosenone.py b/assets/src/ba_data/python/bastd/game/chosenone.py index 65c6470b..e9c87bea 100644 --- a/assets/src/ba_data/python/bastd/game/chosenone.py +++ b/assets/src/ba_data/python/bastd/game/chosenone.py @@ -21,7 +21,7 @@ """Provides the chosen-one mini-game.""" # ba_meta require api 6 -# (see https://github.com/efroemling/ballistica/wiki/Using-ba_meta-Tags) +# (see https://github.com/efroemling/ballistica/wiki/Meta-Tags) from __future__ import annotations from typing import TYPE_CHECKING diff --git a/assets/src/ba_data/python/bastd/game/conquest.py b/assets/src/ba_data/python/bastd/game/conquest.py index e354e1f5..85dd792a 100644 --- a/assets/src/ba_data/python/bastd/game/conquest.py +++ b/assets/src/ba_data/python/bastd/game/conquest.py @@ -21,7 +21,7 @@ """Provides the Conquest game.""" # ba_meta require api 6 -# (see https://github.com/efroemling/ballistica/wiki/Using-ba_meta-Tags) +# (see https://github.com/efroemling/ballistica/wiki/Meta-Tags) from __future__ import annotations diff --git a/assets/src/ba_data/python/bastd/game/deathmatch.py b/assets/src/ba_data/python/bastd/game/deathmatch.py index 009b688d..d3d7e0a8 100644 --- a/assets/src/ba_data/python/bastd/game/deathmatch.py +++ b/assets/src/ba_data/python/bastd/game/deathmatch.py @@ -21,7 +21,7 @@ """DeathMatch game and support classes.""" # ba_meta require api 6 -# (see https://github.com/efroemling/ballistica/wiki/Using-ba_meta-Tags) +# (see https://github.com/efroemling/ballistica/wiki/Meta-Tags) from __future__ import annotations from typing import TYPE_CHECKING diff --git a/assets/src/ba_data/python/bastd/game/easteregghunt.py b/assets/src/ba_data/python/bastd/game/easteregghunt.py index 9c6a60e9..224974e5 100644 --- a/assets/src/ba_data/python/bastd/game/easteregghunt.py +++ b/assets/src/ba_data/python/bastd/game/easteregghunt.py @@ -21,7 +21,7 @@ """Provides an easter egg hunt game.""" # ba_meta require api 6 -# (see https://github.com/efroemling/ballistica/wiki/Using-ba_meta-Tags) +# (see https://github.com/efroemling/ballistica/wiki/Meta-Tags) from __future__ import annotations @@ -40,7 +40,7 @@ if TYPE_CHECKING: # ba_meta export game class EasterEggHuntGame(ba.TeamGameActivity): - """A game where score is based on collecting eggs""" + """A game where score is based on collecting eggs.""" @classmethod def get_name(cls) -> str: @@ -237,7 +237,6 @@ class EasterEggHuntGame(ba.TeamGameActivity): pos[1] + random.uniform(-spread, spread), pos[2] + random.uniform(-spread, spread)))) else: - # Default handler. super().handlemessage(msg) diff --git a/assets/src/ba_data/python/bastd/game/elimination.py b/assets/src/ba_data/python/bastd/game/elimination.py index 89a7af6a..834e1e22 100644 --- a/assets/src/ba_data/python/bastd/game/elimination.py +++ b/assets/src/ba_data/python/bastd/game/elimination.py @@ -21,7 +21,7 @@ """Elimination mini-game.""" # ba_meta require api 6 -# (see https://github.com/efroemling/ballistica/wiki/Using-ba_meta-Tags) +# (see https://github.com/efroemling/ballistica/wiki/Meta-Tags) from __future__ import annotations diff --git a/assets/src/ba_data/python/bastd/game/football.py b/assets/src/ba_data/python/bastd/game/football.py index ecf6e6d0..4d4a7654 100644 --- a/assets/src/ba_data/python/bastd/game/football.py +++ b/assets/src/ba_data/python/bastd/game/football.py @@ -21,7 +21,7 @@ """Implements football games (both co-op and teams varieties).""" # ba_meta require api 6 -# (see https://github.com/efroemling/ballistica/wiki/Using-ba_meta-Tags) +# (see https://github.com/efroemling/ballistica/wiki/Meta-Tags) from __future__ import annotations diff --git a/assets/src/ba_data/python/bastd/game/hockey.py b/assets/src/ba_data/python/bastd/game/hockey.py index 9c876cb8..0c8ad6d9 100644 --- a/assets/src/ba_data/python/bastd/game/hockey.py +++ b/assets/src/ba_data/python/bastd/game/hockey.py @@ -21,7 +21,7 @@ """Hockey game and support classes.""" # ba_meta require api 6 -# (see https://github.com/efroemling/ballistica/wiki/Using-ba_meta-Tags) +# (see https://github.com/efroemling/ballistica/wiki/Meta-Tags) from __future__ import annotations diff --git a/assets/src/ba_data/python/bastd/game/keepaway.py b/assets/src/ba_data/python/bastd/game/keepaway.py index c7fc5209..3deff35a 100644 --- a/assets/src/ba_data/python/bastd/game/keepaway.py +++ b/assets/src/ba_data/python/bastd/game/keepaway.py @@ -21,7 +21,7 @@ """Defines a keep-away game type.""" # ba_meta require api 6 -# (see https://github.com/efroemling/ballistica/wiki/Using-ba_meta-Tags) +# (see https://github.com/efroemling/ballistica/wiki/Meta-Tags) from __future__ import annotations diff --git a/assets/src/ba_data/python/bastd/game/kingofthehill.py b/assets/src/ba_data/python/bastd/game/kingofthehill.py index d0f514f7..ca3e0500 100644 --- a/assets/src/ba_data/python/bastd/game/kingofthehill.py +++ b/assets/src/ba_data/python/bastd/game/kingofthehill.py @@ -21,7 +21,7 @@ """Defines the King of the Hill game.""" # ba_meta require api 6 -# (see https://github.com/efroemling/ballistica/wiki/Using-ba_meta-Tags) +# (see https://github.com/efroemling/ballistica/wiki/Meta-Tags) from __future__ import annotations diff --git a/assets/src/ba_data/python/bastd/game/meteorshower.py b/assets/src/ba_data/python/bastd/game/meteorshower.py index 877fc42f..6d2fac2a 100644 --- a/assets/src/ba_data/python/bastd/game/meteorshower.py +++ b/assets/src/ba_data/python/bastd/game/meteorshower.py @@ -21,7 +21,7 @@ """Defines a bomb-dodging mini-game.""" # ba_meta require api 6 -# (see https://github.com/efroemling/ballistica/wiki/Using-ba_meta-Tags) +# (see https://github.com/efroemling/ballistica/wiki/Meta-Tags) from __future__ import annotations diff --git a/assets/src/ba_data/python/bastd/game/ninjafight.py b/assets/src/ba_data/python/bastd/game/ninjafight.py index 847132cb..28968e25 100644 --- a/assets/src/ba_data/python/bastd/game/ninjafight.py +++ b/assets/src/ba_data/python/bastd/game/ninjafight.py @@ -21,7 +21,7 @@ """Provides Ninja Fight mini-game.""" # ba_meta require api 6 -# (see https://github.com/efroemling/ballistica/wiki/Using-ba_meta-Tags) +# (see https://github.com/efroemling/ballistica/wiki/Meta-Tags) from __future__ import annotations diff --git a/assets/src/ba_data/python/bastd/game/race.py b/assets/src/ba_data/python/bastd/game/race.py index 63e717a5..b35cb0fa 100644 --- a/assets/src/ba_data/python/bastd/game/race.py +++ b/assets/src/ba_data/python/bastd/game/race.py @@ -21,7 +21,7 @@ """Defines Race mini-game.""" # ba_meta require api 6 -# (see https://github.com/efroemling/ballistica/wiki/Using-ba_meta-Tags) +# (see https://github.com/efroemling/ballistica/wiki/Meta-Tags) from __future__ import annotations diff --git a/assets/src/ba_data/python/bastd/game/targetpractice.py b/assets/src/ba_data/python/bastd/game/targetpractice.py index 3503f1d0..e0c0f86c 100644 --- a/assets/src/ba_data/python/bastd/game/targetpractice.py +++ b/assets/src/ba_data/python/bastd/game/targetpractice.py @@ -21,7 +21,7 @@ """Implements Target Practice game.""" # ba_meta require api 6 -# (see https://github.com/efroemling/ballistica/wiki/Using-ba_meta-Tags) +# (see https://github.com/efroemling/ballistica/wiki/Meta-Tags) from __future__ import annotations