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