-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into fix-errors-map
- Loading branch information
Showing
43 changed files
with
716 additions
and
217 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,44 @@ | ||
import "package:flutter/foundation.dart"; | ||
import "package:proxima/models/database/user/user_data.dart"; | ||
import "package:proxima/models/database/user/user_firestore.dart"; | ||
|
||
/// A class that stores data for a user avatar UI. | ||
@immutable | ||
class UserAvatarDetails { | ||
final String displayName; | ||
final int? userCentauriPoints; | ||
final int? centauriPoints; | ||
|
||
/// Creates a [UserAvatarDetails] object. | ||
/// [displayName] is the user's display name, of which | ||
/// the first letter is displayed on the avatar. | ||
/// [userCentauriPoints] is the user's centauri points, | ||
/// which is used to color the avatar background. | ||
/// [centauriPoints] is the user's centauri points. | ||
/// The [centauriPoints] parameter can be null, which is useful for loading states. | ||
const UserAvatarDetails({ | ||
required this.displayName, | ||
required this.userCentauriPoints, | ||
required this.centauriPoints, | ||
}); | ||
|
||
/// Converts a [UserData] object, [userData], to a [UserAvatarDetails] object. | ||
factory UserAvatarDetails.fromUserData(UserData userData) { | ||
/// Converts a [UserFirestore] object, [user], to a [UserAvatarDetails] object. | ||
factory UserAvatarDetails.fromUser( | ||
UserFirestore user, | ||
) { | ||
return UserAvatarDetails( | ||
displayName: userData.displayName, | ||
userCentauriPoints: userData.centauriPoints, | ||
displayName: user.data.displayName, | ||
centauriPoints: user.data.centauriPoints, | ||
); | ||
} | ||
|
||
@override | ||
bool operator ==(Object other) { | ||
return other is UserAvatarDetails && | ||
other.displayName == displayName && | ||
other.userCentauriPoints == userCentauriPoints; | ||
other.centauriPoints == centauriPoints; | ||
} | ||
|
||
@override | ||
int get hashCode { | ||
return Object.hash( | ||
displayName, | ||
userCentauriPoints, | ||
centauriPoints, | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import "package:flutter/material.dart"; | ||
import "package:proxima/models/ui/linear_segmented_hsv_colormap.dart"; | ||
import "package:proxima/services/database/challenge_repository_service.dart"; | ||
|
||
/// Stops for the colormap used to color the user's avatar based on their centauri points. | ||
/// The stops are defined as the number of challenges completed. | ||
const _challengesStops = [ | ||
// sqrt(10) ~= 3, which is the approximate step between each stop | ||
0, | ||
10, // ~ 3 days of daily challenge | ||
30, | ||
100, | ||
300, // ~ 3 months of daily challenge | ||
1000, | ||
3000, // ~ 3 years of daily challenge | ||
10000, | ||
]; | ||
|
||
/// Color used when the user's centauri points are null. | ||
const loadingUserAvatarColor = Colors.transparent; | ||
|
||
/// Converts some amount of [centauriPoints] to a color, based on a uniform | ||
/// [LinearSegmentedHSVColormap] (defined by _challengesStop). [brightness] | ||
/// defines the value and saturation of the colormap. | ||
/// If [centauriPoints] is null, the color is transparent. | ||
Color centauriToUserAvatarColor(int? centauriPoints, Brightness brightness) { | ||
if (centauriPoints == null) return loadingUserAvatarColor; | ||
|
||
final hsvValue = switch (brightness) { | ||
Brightness.light => 0.9, | ||
Brightness.dark => 0.5, | ||
}; | ||
final hsvSaturation = switch (brightness) { | ||
Brightness.light => 0.4, | ||
Brightness.dark => 0.8, | ||
}; | ||
|
||
const chalReward = ChallengeRepositoryService.soloChallengeReward; | ||
final colorMap = LinearSegmentedHSVColormap.uniform( | ||
_challengesStops.map((nChallenges) => nChallenges * chalReward).toList(), | ||
value: hsvValue, | ||
saturation: hsvSaturation, | ||
); | ||
|
||
return colorMap(centauriPoints).toColor(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.