mirror of
https://github.com/RYDE-WORK/ballistica.git
synced 2026-02-05 06:53:18 +08:00
Tidied up RespawnIcon
This commit is contained in:
parent
c2d017510c
commit
053247f004
@ -28,7 +28,7 @@ from typing import TYPE_CHECKING
|
|||||||
import ba
|
import ba
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from typing import Optional
|
from typing import Optional, Dict, Tuple
|
||||||
|
|
||||||
|
|
||||||
class RespawnIcon:
|
class RespawnIcon:
|
||||||
@ -43,34 +43,9 @@ class RespawnIcon:
|
|||||||
"""
|
"""
|
||||||
Instantiate with a given ba.Player and respawn_time (in seconds)
|
Instantiate with a given ba.Player and respawn_time (in seconds)
|
||||||
"""
|
"""
|
||||||
# FIXME; tidy up
|
|
||||||
# pylint: disable=too-many-locals
|
|
||||||
|
|
||||||
activity = ba.getactivity()
|
|
||||||
self._visible = True
|
self._visible = True
|
||||||
if isinstance(ba.getsession(), ba.TeamsSession):
|
|
||||||
on_right = player.team.get_id() % 2 == 1
|
on_right, offs_extra, respawn_icons = self._get_context(player)
|
||||||
# store a list of icons in the team
|
|
||||||
try:
|
|
||||||
respawn_icons = (
|
|
||||||
player.team.gamedata['_spaz_respawn_icons_right'])
|
|
||||||
except Exception:
|
|
||||||
respawn_icons = (
|
|
||||||
player.team.gamedata['_spaz_respawn_icons_right']) = {}
|
|
||||||
offs_extra = -20
|
|
||||||
else:
|
|
||||||
on_right = False
|
|
||||||
# Store a list of icons in the activity.
|
|
||||||
# FIXME: Need an elegant way to store our
|
|
||||||
# shared stuff with the activity.
|
|
||||||
try:
|
|
||||||
respawn_icons = activity.spaz_respawn_icons_right
|
|
||||||
except Exception:
|
|
||||||
respawn_icons = activity.spaz_respawn_icons_right = {}
|
|
||||||
if isinstance(activity.session, ba.FreeForAllSession):
|
|
||||||
offs_extra = -150
|
|
||||||
else:
|
|
||||||
offs_extra = -20
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
mask_tex = (player.team.gamedata['_spaz_respawn_icons_mask_tex'])
|
mask_tex = (player.team.gamedata['_spaz_respawn_icons_mask_tex'])
|
||||||
@ -78,7 +53,7 @@ class RespawnIcon:
|
|||||||
mask_tex = player.team.gamedata['_spaz_respawn_icons_mask_tex'] = (
|
mask_tex = player.team.gamedata['_spaz_respawn_icons_mask_tex'] = (
|
||||||
ba.gettexture('characterIconMask'))
|
ba.gettexture('characterIconMask'))
|
||||||
|
|
||||||
# now find the first unused slot and use that
|
# Now find the first unused slot and use that.
|
||||||
index = 0
|
index = 0
|
||||||
while (index in respawn_icons and respawn_icons[index]() is not None
|
while (index in respawn_icons and respawn_icons[index]() is not None
|
||||||
and respawn_icons[index]().visible):
|
and respawn_icons[index]().visible):
|
||||||
@ -157,17 +132,42 @@ class RespawnIcon:
|
|||||||
"""Is this icon still visible?"""
|
"""Is this icon still visible?"""
|
||||||
return self._visible
|
return self._visible
|
||||||
|
|
||||||
|
def _get_context(self, player: ba.Player) -> Tuple[bool, float, Dict]:
|
||||||
|
"""Return info on where we should be shown and stored."""
|
||||||
|
activity = ba.getactivity()
|
||||||
|
if isinstance(ba.getsession(), ba.TeamsSession):
|
||||||
|
on_right = player.team.get_id() % 2 == 1
|
||||||
|
|
||||||
|
# Store a list of icons in the team.
|
||||||
|
try:
|
||||||
|
respawn_icons = (
|
||||||
|
player.team.gamedata['_spaz_respawn_icons_right'])
|
||||||
|
except Exception:
|
||||||
|
respawn_icons = (
|
||||||
|
player.team.gamedata['_spaz_respawn_icons_right']) = {}
|
||||||
|
offs_extra = -20
|
||||||
|
else:
|
||||||
|
on_right = False
|
||||||
|
|
||||||
|
# Store a list of icons in the activity.
|
||||||
|
# FIXME: Need an elegant way to store our shared stuff with
|
||||||
|
# the activity.
|
||||||
|
try:
|
||||||
|
respawn_icons = activity.spaz_respawn_icons_right
|
||||||
|
except Exception:
|
||||||
|
respawn_icons = activity.spaz_respawn_icons_right = {}
|
||||||
|
if isinstance(activity.session, ba.FreeForAllSession):
|
||||||
|
offs_extra = -150
|
||||||
|
else:
|
||||||
|
offs_extra = -20
|
||||||
|
return on_right, offs_extra, respawn_icons
|
||||||
|
|
||||||
def _update(self) -> None:
|
def _update(self) -> None:
|
||||||
remaining = int(
|
remaining = int(round(self._respawn_time - ba.time()))
|
||||||
round(int(1000.0 * self._respawn_time) -
|
|
||||||
ba.time(timeformat=ba.TimeFormat.MILLISECONDS)) / 1000.0)
|
|
||||||
if remaining > 0:
|
if remaining > 0:
|
||||||
assert self._text is not None
|
assert self._text is not None
|
||||||
if self._text.node:
|
if self._text.node:
|
||||||
self._text.node.text = str(remaining)
|
self._text.node.text = str(remaining)
|
||||||
else:
|
else:
|
||||||
self._clear()
|
self._visible = False
|
||||||
|
self._image = self._text = self._timer = self._name = None
|
||||||
def _clear(self) -> None:
|
|
||||||
self._visible = False
|
|
||||||
self._image = self._text = self._timer = self._name = None
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user