mirror of
https://github.com/RYDE-WORK/ballistica.git
synced 2026-01-28 10:03:15 +08:00
Merge branch 'master' of https://github.com/efroemling/ballistica
This commit is contained in:
commit
75746ea19b
@ -22,6 +22,7 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from dataclasses import dataclass
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
import ba
|
||||
@ -119,48 +120,45 @@ def get_factory() -> FlagFactory:
|
||||
return factory
|
||||
|
||||
|
||||
@dataclass
|
||||
class FlagPickedUpMessage:
|
||||
"""A message saying a ba.Flag has been picked up.
|
||||
|
||||
category: Message Classes
|
||||
category: Message Classes
|
||||
|
||||
Attributes:
|
||||
Attrs:
|
||||
|
||||
flag
|
||||
The ba.Flag that has been picked up.
|
||||
flag
|
||||
The ba.Flag that has been picked up.
|
||||
|
||||
node
|
||||
The ba.Node doing the picking up.
|
||||
"""
|
||||
|
||||
def __init__(self, flag: Flag, node: ba.Node):
|
||||
"""Instantiate with given values."""
|
||||
self.flag = flag
|
||||
self.node = node
|
||||
node
|
||||
The ba.Node doing the picking up.
|
||||
"""
|
||||
flag: Flag
|
||||
node: ba.Node
|
||||
|
||||
|
||||
@dataclass
|
||||
class FlagDeathMessage:
|
||||
"""A message saying a ba.Flag has died.
|
||||
|
||||
category: Message Classes
|
||||
|
||||
Attributes:
|
||||
Attrs:
|
||||
|
||||
flag
|
||||
The ba.Flag that died.
|
||||
"""
|
||||
|
||||
def __init__(self, flag: Flag):
|
||||
"""Instantiate with given values."""
|
||||
self.flag = flag
|
||||
flag: Flag
|
||||
|
||||
|
||||
@dataclass
|
||||
class FlagDroppedMessage:
|
||||
"""A message saying a ba.Flag has been dropped.
|
||||
|
||||
category: Message Classes
|
||||
|
||||
Attributes:
|
||||
Attrs:
|
||||
|
||||
flag
|
||||
The ba.Flag that was dropped.
|
||||
@ -168,11 +166,8 @@ class FlagDroppedMessage:
|
||||
node
|
||||
The ba.Node that was holding it.
|
||||
"""
|
||||
|
||||
def __init__(self, flag: Flag, node: ba.Node):
|
||||
"""Instantiate with given values."""
|
||||
self.flag = flag
|
||||
self.node = node
|
||||
flag: Flag
|
||||
node: ba.Node
|
||||
|
||||
|
||||
class Flag(ba.Actor):
|
||||
|
||||
@ -29,7 +29,7 @@ from typing import TYPE_CHECKING
|
||||
|
||||
import ba
|
||||
from bastd.actor import flag as stdflag
|
||||
from bastd.actor import playerspaz
|
||||
from bastd.actor.playerspaz import PlayerSpaz, PlayerSpazDeathMessage
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from typing import Any, Type, List, Dict, Tuple, Sequence, Union, Optional
|
||||
@ -68,6 +68,14 @@ class CTFFlag(stdflag.Flag):
|
||||
"""return the flag's team."""
|
||||
return self._team
|
||||
|
||||
@classmethod
|
||||
def from_node(cls, node: Optional[ba.Node]) -> Optional[CTFFlag]:
|
||||
"""Attempt to get a CTFFlag from a flag node."""
|
||||
if not node:
|
||||
return None
|
||||
delegate = node.getdelegate()
|
||||
return delegate if isinstance(delegate, CTFFlag) else None
|
||||
|
||||
|
||||
# ba_meta export game
|
||||
class CaptureTheFlagGame(ba.TeamGameActivity):
|
||||
@ -222,8 +230,12 @@ class CaptureTheFlagGame(ba.TeamGameActivity):
|
||||
ba.playsound(self._swipsound, position=flag.node.position)
|
||||
|
||||
def _handle_flag_entered_base(self, team: ba.Team) -> None:
|
||||
flag = ba.get_collision_info("opposing_node").getdelegate()
|
||||
assert isinstance(flag, CTFFlag)
|
||||
node = ba.get_collision_info("opposing_node")
|
||||
assert isinstance(node, (ba.Node, type(None)))
|
||||
flag = CTFFlag.from_node(node)
|
||||
if not flag:
|
||||
print('Unable to get flag in _handle_flag_entered_base')
|
||||
return
|
||||
|
||||
if flag.team is team:
|
||||
team.gamedata['home_flag_at_base'] = True
|
||||
@ -327,10 +339,10 @@ class CaptureTheFlagGame(ba.TeamGameActivity):
|
||||
def _handle_flag_left_base(self, team: ba.Team) -> None:
|
||||
cur_time = ba.time()
|
||||
op_node = ba.get_collision_info("opposing_node")
|
||||
try:
|
||||
flag = op_node.getdelegate()
|
||||
except Exception:
|
||||
return # Can happen when we kill a flag.
|
||||
assert isinstance(op_node, (ba.Node, type(None)))
|
||||
flag = CTFFlag.from_node(op_node)
|
||||
if not flag:
|
||||
return
|
||||
|
||||
if flag.team is team:
|
||||
|
||||
@ -380,23 +392,26 @@ class CaptureTheFlagGame(ba.TeamGameActivity):
|
||||
return_score,
|
||||
screenmessage=False)
|
||||
|
||||
@staticmethod
|
||||
def _player_from_node(node: Optional[ba.Node]) -> Optional[ba.Player]:
|
||||
"""Return a player if given a node that is part of one's actor."""
|
||||
if not node:
|
||||
return None
|
||||
delegate = node.getdelegate()
|
||||
if not isinstance(delegate, PlayerSpaz):
|
||||
return None
|
||||
return delegate.getplayer()
|
||||
|
||||
def _handle_hit_own_flag(self, team: ba.Team, val: int) -> None:
|
||||
"""
|
||||
keep track of when each player is touching their
|
||||
own flag so we can award points when returned
|
||||
"""
|
||||
# I wear the cone of shame.
|
||||
# pylint: disable=too-many-branches
|
||||
srcnode = ba.get_collision_info('source_node')
|
||||
try:
|
||||
player = srcnode.getdelegate().getplayer()
|
||||
except Exception:
|
||||
player = None
|
||||
assert isinstance(srcnode, (ba.Node, type(None)))
|
||||
player = self._player_from_node(srcnode)
|
||||
if player:
|
||||
if val:
|
||||
player.gamedata['touching_own_flag'] += 1
|
||||
else:
|
||||
player.gamedata['touching_own_flag'] -= 1
|
||||
player.gamedata['touching_own_flag'] += (1 if val else -1)
|
||||
|
||||
# If return-time is zero, just kill it immediately.. otherwise keep
|
||||
# track of touches and count down.
|
||||
@ -481,7 +496,7 @@ class CaptureTheFlagGame(ba.TeamGameActivity):
|
||||
self.settings['Score to Win'])
|
||||
|
||||
def handlemessage(self, msg: Any) -> Any:
|
||||
if isinstance(msg, playerspaz.PlayerSpazDeathMessage):
|
||||
if isinstance(msg, PlayerSpazDeathMessage):
|
||||
# Augment standard behavior.
|
||||
super().handlemessage(msg)
|
||||
self.respawn_player(msg.spaz.player)
|
||||
|
||||
@ -35,19 +35,22 @@ def gamepad_configure_callback(event: Dict[str, Any]) -> None:
|
||||
"""Respond to a gamepad button press during config selection."""
|
||||
from ba.internal import get_remote_app_name
|
||||
from bastd.ui.settings import gamepad
|
||||
# ignore all but button-presses
|
||||
|
||||
# Ignore all but button-presses.
|
||||
if event['type'] not in ['BUTTONDOWN', 'HATMOTION']:
|
||||
return
|
||||
_ba.release_gamepad_input()
|
||||
try:
|
||||
ba.containerwidget(edit=ba.app.main_menu_window, transition='out_left')
|
||||
except Exception:
|
||||
ba.print_exception("error transitioning out main_menu_window")
|
||||
ba.print_exception("Error transitioning out main_menu_window.")
|
||||
ba.playsound(ba.getsound('activateBeep'))
|
||||
ba.playsound(ba.getsound('swish'))
|
||||
if event['input_device'].get_allows_configuring():
|
||||
ba.app.main_menu_window = (gamepad.GamepadSettingsWindow(
|
||||
event["input_device"]).get_root_widget())
|
||||
inputdevice = event['input_device']
|
||||
assert isinstance(inputdevice, ba.InputDevice)
|
||||
if inputdevice.allows_configuring:
|
||||
ba.app.main_menu_window = (
|
||||
gamepad.GamepadSettingsWindow(inputdevice).get_root_widget())
|
||||
else:
|
||||
width = 700
|
||||
height = 200
|
||||
@ -56,7 +59,7 @@ def gamepad_configure_callback(event: Dict[str, Any]) -> None:
|
||||
scale=1.7 if ba.app.small_ui else 1.4 if ba.app.med_ui else 1.0,
|
||||
size=(width, height),
|
||||
transition='in_right'))
|
||||
device_name = event['input_device'].get_name()
|
||||
device_name = inputdevice.name
|
||||
if device_name == 'iDevice':
|
||||
msg = ba.Lstr(resource='bsRemoteConfigureInAppText',
|
||||
subs=[('${REMOTE_APP_NAME}', get_remote_app_name())])
|
||||
|
||||
@ -65,12 +65,11 @@ class StateData:
|
||||
login_token: Optional[str] = None
|
||||
|
||||
|
||||
# noinspection PyUnresolvedReferences
|
||||
@dataclass
|
||||
class Response:
|
||||
"""Response sent from the bacloud server to the client.
|
||||
|
||||
Attributes:
|
||||
Attrs:
|
||||
message: If present, client should print this message before any other
|
||||
response processing (including error handling) occurs.
|
||||
message_end: end arg for message print() call.
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user