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 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 @property
def interface_type(self) -> str: def interface_type(self) -> str:
"""Interface mode the game is in; can be 'large', 'medium', or 'small'. """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. # The meta api version of this build of the game.
# Only packages and modules requiring this exact api version # Only packages and modules requiring this exact api version
# will be considered when scanning directories. # 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 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: def start_scan() -> None:
"""Begin scanning script directories for scripts containing metadata. """Begin scanning script directories for scripts containing metadata.
@ -53,14 +61,6 @@ def start_scan() -> None:
thread.start() 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: def handle_scan_results(results: ScanResults) -> None:
"""Called in the game thread with results of a completed scan.""" """Called in the game thread with results of a completed scan."""
from ba import _lang from ba import _lang
@ -94,7 +94,6 @@ class ScanThread(threading.Thread):
scan.scan() scan.scan()
results = scan.results results = scan.results
except Exception as exc: except Exception as exc:
# results = {'errors': 'Scan exception: ' + str(exc)}
results = ScanResults(errors=f'Scan exception: {exc}') results = ScanResults(errors=f'Scan exception: {exc}')
# Push a call to the game thread to print warnings/errors # 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 # If we find a module requiring a different api version, warn
# and ignore. # and ignore.
if required_api is not None and required_api != CURRENT_API_VERSION: if required_api is not None and required_api != CURRENT_API_VERSION:
self.results.warnings += ('Warning: ' + str(subpath) + self.results.warnings += (
' requires api ' + str(required_api) + f'Warning: {subpath} requires api {required_api} but'
' but we are running ' + f' we are running {CURRENT_API_VERSION}; ignoring module.\n')
str(CURRENT_API_VERSION) +
'; ignoring module.\n')
return return
# Ok; can proceed with a full scan of this module. # Ok; can proceed with a full scan of this module.
@ -211,18 +208,17 @@ class DirectoryScan:
self.scan_module(submodule[0], submodule[1]) self.scan_module(submodule[0], submodule[1])
except Exception: except Exception:
from ba import _error from ba import _error
self.results.warnings += ("Error scanning '" + str(subpath) + self.results.warnings += (
"': " + _error.exc_str() + '\n') f"Error scanning '{subpath}': {_error.exc_str()}\n")
def _process_module_meta_tags(self, subpath: pathlib.Path, def _process_module_meta_tags(self, subpath: pathlib.Path,
flines: List[str], flines: List[str],
meta_lines: Dict[int, List[str]]) -> None: meta_lines: Dict[int, List[str]]) -> None:
"""Pull data from a module based on its ba_meta tags.""" """Pull data from a module based on its ba_meta tags."""
for lindex, mline in meta_lines.items(): 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. # the ba_meta is in the right place.
if mline[0] != 'ba_meta': if mline[0] != 'ba_meta':
print(f'GOT "{mline[0]}"')
self.results.warnings += ( self.results.warnings += (
'Warning: ' + str(subpath) + 'Warning: ' + str(subpath) +
': malformed ba_meta statement on line ' + ': malformed ba_meta statement on line ' +

View File

@ -21,7 +21,7 @@
"""Defines assault minigame.""" """Defines assault minigame."""
# ba_meta require api 6 # 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 __future__ import annotations

View File

@ -21,7 +21,7 @@
"""Defines a capture-the-flag game.""" """Defines a capture-the-flag game."""
# ba_meta require api 6 # 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 __future__ import annotations

View File

@ -21,7 +21,7 @@
"""Provides the chosen-one mini-game.""" """Provides the chosen-one mini-game."""
# ba_meta require api 6 # 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 __future__ import annotations
from typing import TYPE_CHECKING from typing import TYPE_CHECKING

View File

@ -21,7 +21,7 @@
"""Provides the Conquest game.""" """Provides the Conquest game."""
# ba_meta require api 6 # 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 __future__ import annotations

View File

@ -21,7 +21,7 @@
"""DeathMatch game and support classes.""" """DeathMatch game and support classes."""
# ba_meta require api 6 # 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 __future__ import annotations
from typing import TYPE_CHECKING from typing import TYPE_CHECKING

View File

@ -21,7 +21,7 @@
"""Provides an easter egg hunt game.""" """Provides an easter egg hunt game."""
# ba_meta require api 6 # 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 __future__ import annotations
@ -40,7 +40,7 @@ if TYPE_CHECKING:
# ba_meta export game # ba_meta export game
class EasterEggHuntGame(ba.TeamGameActivity): class EasterEggHuntGame(ba.TeamGameActivity):
"""A game where score is based on collecting eggs""" """A game where score is based on collecting eggs."""
@classmethod @classmethod
def get_name(cls) -> str: def get_name(cls) -> str:
@ -237,7 +237,6 @@ class EasterEggHuntGame(ba.TeamGameActivity):
pos[1] + random.uniform(-spread, spread), pos[1] + random.uniform(-spread, spread),
pos[2] + random.uniform(-spread, spread)))) pos[2] + random.uniform(-spread, spread))))
else: else:
# Default handler. # Default handler.
super().handlemessage(msg) super().handlemessage(msg)

View File

@ -21,7 +21,7 @@
"""Elimination mini-game.""" """Elimination mini-game."""
# ba_meta require api 6 # 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 __future__ import annotations

View File

@ -21,7 +21,7 @@
"""Implements football games (both co-op and teams varieties).""" """Implements football games (both co-op and teams varieties)."""
# ba_meta require api 6 # 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 __future__ import annotations

View File

@ -21,7 +21,7 @@
"""Hockey game and support classes.""" """Hockey game and support classes."""
# ba_meta require api 6 # 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 __future__ import annotations

View File

@ -21,7 +21,7 @@
"""Defines a keep-away game type.""" """Defines a keep-away game type."""
# ba_meta require api 6 # 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 __future__ import annotations

View File

@ -21,7 +21,7 @@
"""Defines the King of the Hill game.""" """Defines the King of the Hill game."""
# ba_meta require api 6 # 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 __future__ import annotations

View File

@ -21,7 +21,7 @@
"""Defines a bomb-dodging mini-game.""" """Defines a bomb-dodging mini-game."""
# ba_meta require api 6 # 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 __future__ import annotations

View File

@ -21,7 +21,7 @@
"""Provides Ninja Fight mini-game.""" """Provides Ninja Fight mini-game."""
# ba_meta require api 6 # 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 __future__ import annotations

View File

@ -21,7 +21,7 @@
"""Defines Race mini-game.""" """Defines Race mini-game."""
# ba_meta require api 6 # 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 __future__ import annotations

View File

@ -21,7 +21,7 @@
"""Implements Target Practice game.""" """Implements Target Practice game."""
# ba_meta require api 6 # 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 __future__ import annotations