def get_team_score_str(self, team: ba.Team) -> ba.Lstr: """Return the score for the given ba.Team as an Lstr. (properly formatted for the score type.) """ from ba._gameutils import timestring from ba._lang import Lstr from ba._enums import TimeFormat from ba._score import ScoreType if not self._game_set: raise RuntimeError("Can't get team-score-str until game is set.") for score in list(self._scores.values()): if score[0]() is team.sessionteam: if score[1] is None: return Lstr(value='-') if self._score_type is ScoreType.SECONDS: return timestring(score[1] * 1000, centi=False, timeformat=TimeFormat.MILLISECONDS) if self._score_type is ScoreType.MILLISECONDS: return timestring(score[1], centi=True, timeformat=TimeFormat.MILLISECONDS) return Lstr(value=str(score[1])) return Lstr(value='-')
def _show_standard_scores_to_beat_ui(self, scores: List[Dict[str, Any]]) -> None: from efro.util import asserttype from ba._gameutils import timestring, animate from ba._nodeactor import NodeActor from ba._enums import TimeFormat display_type = self.get_score_type() if scores is not None: # Sort by originating date so that the most recent is first. scores.sort(reverse=True, key=lambda s: asserttype(s['time'], int)) # Now make a display for the most recent challenge. for score in scores: if score['type'] == 'score_challenge': tval = (score['player'] + ': ' + timestring( int(score['value']) * 10, timeformat=TimeFormat.MILLISECONDS).evaluate() if display_type == 'time' else str(score['value'])) hattach = 'center' if display_type == 'time' else 'left' halign = 'center' if display_type == 'time' else 'left' pos = (20, -70) if display_type == 'time' else (20, -130) txt = NodeActor( _ba.newnode('text', attrs={ 'v_attach': 'top', 'h_attach': hattach, 'h_align': halign, 'color': (0.7, 0.4, 1, 1), 'shadow': 0.5, 'flatness': 1.0, 'position': pos, 'scale': 0.6, 'text': tval })).autoretain() assert txt.node is not None animate(txt.node, 'scale', {1.0: 0.0, 1.1: 0.7, 1.2: 0.6}) break