cleaning up ba_meta

This commit is contained in:
Eric Froemling 2020-03-22 22:04:23 -07:00
parent cf1a6abc9d
commit 8ff3b2de75
17 changed files with 44 additions and 36 deletions

View File

@ -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'.

View File

@ -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 ' +

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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)

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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