mirror of
https://github.com/RYDE-WORK/ballistica.git
synced 2026-02-06 15:47:06 +08:00
got coop in headless builds working
This commit is contained in:
parent
9e2fa821f3
commit
fa0036f14c
@ -156,8 +156,29 @@ class CoopSession(Session):
|
|||||||
from ba._general import WeakCall
|
from ba._general import WeakCall
|
||||||
super().on_player_leave(sessionplayer)
|
super().on_player_leave(sessionplayer)
|
||||||
|
|
||||||
# If all our players leave we wanna quit out of the session.
|
if _ba.app.server is not None:
|
||||||
_ba.timer(2.0, WeakCall(self._end_session_if_empty))
|
# If we're in server mode, end game and show results.
|
||||||
|
activity = self.getactivity()
|
||||||
|
_ba.timer(2.0, WeakCall(self._end_activity_if_empty))
|
||||||
|
else:
|
||||||
|
# Otherwise, if all our players leave
|
||||||
|
# we wanna quit out of the session.
|
||||||
|
_ba.timer(2.0, WeakCall(self._end_session_if_empty))
|
||||||
|
|
||||||
|
def _end_activity_if_empty(self) -> None:
|
||||||
|
activity = self.getactivity()
|
||||||
|
if activity is None:
|
||||||
|
return # Probably everything is already broken, why do something?
|
||||||
|
|
||||||
|
if activity.players:
|
||||||
|
return
|
||||||
|
|
||||||
|
with _ba.Context(activity):
|
||||||
|
from ba._gameactivity import GameActivity
|
||||||
|
|
||||||
|
# FIXME: rewrite this, doesn't cover all cases
|
||||||
|
assert isinstance(activity, GameActivity)
|
||||||
|
activity.end_game()
|
||||||
|
|
||||||
def _end_session_if_empty(self) -> None:
|
def _end_session_if_empty(self) -> None:
|
||||||
activity = self.getactivity()
|
activity = self.getactivity()
|
||||||
@ -250,10 +271,11 @@ class CoopSession(Session):
|
|||||||
|
|
||||||
# If at any point we have no in-game players, quit out of the session
|
# If at any point we have no in-game players, quit out of the session
|
||||||
# (this can happen if someone leaves in the tutorial for instance).
|
# (this can happen if someone leaves in the tutorial for instance).
|
||||||
active_players = [p for p in self.sessionplayers if p.in_game]
|
if isinstance(activity, TutorialActivity):
|
||||||
if not active_players:
|
active_players = [p for p in self.sessionplayers if p.in_game]
|
||||||
self.end()
|
if not active_players:
|
||||||
return
|
self.end()
|
||||||
|
return
|
||||||
|
|
||||||
# If we're in a between-round activity or a restart-activity,
|
# If we're in a between-round activity or a restart-activity,
|
||||||
# hop into a round.
|
# hop into a round.
|
||||||
|
|||||||
@ -122,7 +122,7 @@ class CoopScoreScreen(ba.Activity[ba.Player, ba.Team]):
|
|||||||
self._birth_time = ba.time()
|
self._birth_time = ba.time()
|
||||||
self._min_view_time = 5.0
|
self._min_view_time = 5.0
|
||||||
self._allow_server_transition = False
|
self._allow_server_transition = False
|
||||||
self._server_transitioning: Optional[bool] = True
|
self._server_transitioning: Optional[bool] = None
|
||||||
|
|
||||||
self._playerinfos: List[ba.PlayerInfo] = settings['playerinfos']
|
self._playerinfos: List[ba.PlayerInfo] = settings['playerinfos']
|
||||||
assert isinstance(self._playerinfos, list)
|
assert isinstance(self._playerinfos, list)
|
||||||
@ -494,8 +494,6 @@ class CoopScoreScreen(ba.Activity[ba.Player, ba.Team]):
|
|||||||
def _player_press(self) -> None:
|
def _player_press(self) -> None:
|
||||||
# (Only for headless builds).
|
# (Only for headless builds).
|
||||||
|
|
||||||
print('HERE PLAYER PRESS')
|
|
||||||
|
|
||||||
# If this activity is a good 'end point', ask server-mode just once if
|
# If this activity is a good 'end point', ask server-mode just once if
|
||||||
# it wants to do anything special like switch sessions or kill the app.
|
# it wants to do anything special like switch sessions or kill the app.
|
||||||
if (self._allow_server_transition and _ba.app.server is not None
|
if (self._allow_server_transition and _ba.app.server is not None
|
||||||
@ -503,16 +501,14 @@ class CoopScoreScreen(ba.Activity[ba.Player, ba.Team]):
|
|||||||
self._server_transitioning = _ba.app.server.handle_transition()
|
self._server_transitioning = _ba.app.server.handle_transition()
|
||||||
assert isinstance(self._server_transitioning, bool)
|
assert isinstance(self._server_transitioning, bool)
|
||||||
|
|
||||||
print('HERE IF PASSED')
|
|
||||||
|
|
||||||
# If server-mode is handling this, don't do anything ourself.
|
# If server-mode is handling this, don't do anything ourself.
|
||||||
if self._server_transitioning is True:
|
if self._server_transitioning is True:
|
||||||
return
|
return
|
||||||
|
|
||||||
print('HERE RESTARTING COOP')
|
|
||||||
# Otherwise restart current level.
|
# Otherwise restart current level.
|
||||||
print('HERE ui_restart() only for testing; replace after that')
|
self._campaign.set_selected_level(self._level_name)
|
||||||
self._ui_restart()
|
with ba.Context(self):
|
||||||
|
self.end({'outcome': 'restart'})
|
||||||
|
|
||||||
def _safe_assign(self, player: EmptyPlayer) -> None:
|
def _safe_assign(self, player: EmptyPlayer) -> None:
|
||||||
# (Only for headless builds).
|
# (Only for headless builds).
|
||||||
@ -520,16 +516,15 @@ class CoopScoreScreen(ba.Activity[ba.Player, ba.Team]):
|
|||||||
# Just to be extra careful, don't assign if we're transitioning out.
|
# Just to be extra careful, don't assign if we're transitioning out.
|
||||||
# (though theoretically that should be ok).
|
# (though theoretically that should be ok).
|
||||||
if not self.is_transitioning_out() and player:
|
if not self.is_transitioning_out() and player:
|
||||||
player.assigninput((ba.InputType.JUMP_PRESS, ba.InputType.PUNCH_PRESS,
|
player.assigninput(
|
||||||
ba.InputType.BOMB_PRESS, ba.InputType.PICK_UP_PRESS),
|
(ba.InputType.JUMP_PRESS, ba.InputType.PUNCH_PRESS,
|
||||||
self._player_press)
|
ba.InputType.BOMB_PRESS, ba.InputType.PICK_UP_PRESS),
|
||||||
|
self._player_press)
|
||||||
|
|
||||||
def on_player_join(self, player: PlayerType) -> None:
|
def on_player_join(self, player: PlayerType) -> None:
|
||||||
print('HERE ON PLAYER JOIN')
|
|
||||||
super().on_player_join(player)
|
super().on_player_join(player)
|
||||||
|
|
||||||
if ba.app.server is not None:
|
if ba.app.server is not None:
|
||||||
print('HERE INPUT ASSIGNED')
|
|
||||||
# Host can't press retry button, so anyone can do it instead.
|
# Host can't press retry button, so anyone can do it instead.
|
||||||
time_till_assign = max(
|
time_till_assign = max(
|
||||||
0, self._birth_time + self._min_view_time - _ba.time())
|
0, self._birth_time + self._min_view_time - _ba.time())
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user