mirror of https://github.com/flutter/pinball.git
parent
5dfcb9e913
commit
00d629f551
@ -1 +1,2 @@
|
||||
export 'bloc/leaderboard_bloc.dart';
|
||||
export 'models/leader_board_entry.dart';
|
||||
|
@ -0,0 +1,79 @@
|
||||
import 'package:leaderboard_repository/leaderboard_repository.dart';
|
||||
import 'package:pinball_theme/pinball_theme.dart';
|
||||
|
||||
/// {@template leaderboard_entry}
|
||||
/// A model representing a leaderboard entry containing the ranking position,
|
||||
/// player's initials, score, and chosen character.
|
||||
///
|
||||
/// {@endtemplate}
|
||||
class LeaderboardEntry {
|
||||
/// {@macro leaderboard_entry}
|
||||
LeaderboardEntry({
|
||||
required this.rank,
|
||||
required this.playerInitials,
|
||||
required this.score,
|
||||
required this.character,
|
||||
});
|
||||
|
||||
/// Ranking position for [LeaderboardEntry].
|
||||
final String rank;
|
||||
|
||||
/// Player's chosen initials for [LeaderboardEntry].
|
||||
final String playerInitials;
|
||||
|
||||
/// Score for [LeaderboardEntry].
|
||||
final int score;
|
||||
|
||||
/// [CharacterTheme] for [LeaderboardEntry].
|
||||
final CharacterTheme character;
|
||||
}
|
||||
|
||||
/// Converts [LeaderboardEntryData] to [LeaderboardEntry].
|
||||
extension LeaderboardEntryDataX on LeaderboardEntryData {
|
||||
LeaderboardEntry toEntry(int position) {
|
||||
return LeaderboardEntry(
|
||||
rank: position.toString(),
|
||||
playerInitials: playerInitials,
|
||||
score: score,
|
||||
character: character.toTheme,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// Converts [CharacterType] to [CharacterTheme] to show on UI character theme
|
||||
/// from repository.
|
||||
extension CharacterTypeX on CharacterType {
|
||||
/// Conversion method to [CharacterTheme]
|
||||
CharacterTheme get toTheme {
|
||||
switch (this) {
|
||||
case CharacterType.dash:
|
||||
return const DashTheme();
|
||||
case CharacterType.sparky:
|
||||
return const SparkyTheme();
|
||||
case CharacterType.android:
|
||||
return const AndroidTheme();
|
||||
case CharacterType.dino:
|
||||
return const DinoTheme();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Converts [CharacterTheme] to [CharacterType] to persist at repository the
|
||||
/// character theme from UI.
|
||||
extension CharacterThemeX on CharacterTheme {
|
||||
/// Conversion method to [CharacterType]
|
||||
CharacterType get toType {
|
||||
switch (runtimeType) {
|
||||
case DashTheme:
|
||||
return CharacterType.dash;
|
||||
case SparkyTheme:
|
||||
return CharacterType.sparky;
|
||||
case AndroidTheme:
|
||||
return CharacterType.android;
|
||||
case DinoTheme:
|
||||
return CharacterType.dino;
|
||||
default:
|
||||
return CharacterType.dash;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in new issue