Skip to content

Commit

Permalink
Achievement model blocked by achievementTracker\
Browse files Browse the repository at this point in the history
  • Loading branch information
cgu2020 committed Apr 24, 2024
1 parent 48e891f commit ee4ef8d
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 17 deletions.
14 changes: 13 additions & 1 deletion game/lib/achievements/achievements_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import 'package:game/model/challenge_model.dart';
import 'package:game/model/event_model.dart';
import 'package:game/model/group_model.dart';
import 'package:game/model/tracker_model.dart';
import 'package:game/model/achievement_model.dart';
import 'package:game/model/user_model.dart';
import 'package:provider/provider.dart';
import 'package:game/journeys/filter_form.dart';
Expand Down Expand Up @@ -125,7 +126,18 @@ class _AchievementsPageState extends State<AchievementsPage> {
padding: const EdgeInsets.symmetric(horizontal: 3),
itemCount: eventCells.length,
itemBuilder: (context, index) {
return eventCells[index];
return ChallengeCell(
key: UniqueKey(),
eventData[index].location,
eventData[index].name,
eventData[index].lat,
eventData[index].long,
eventData[index].thumbnail,
eventData[index].complete,
eventData[index].description,
eventData[index].difficulty,
eventData[index].points,
eventData[index].eventId);
},
physics: BouncingScrollPhysics(),
separatorBuilder: (context, index) {
Expand Down
29 changes: 13 additions & 16 deletions game/lib/gameplay/gameplay_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import 'package:game/model/tracker_model.dart';
import 'package:game/model/group_model.dart';
import 'package:game/api/geopoint.dart';
import 'package:game/navigation_page/home_navbar.dart';
import 'package:game/utils/utility_functions.dart';
import 'package:geolocator/geolocator.dart';
import 'package:game/model/challenge_model.dart';
import 'gameplay_map.dart';
Expand Down Expand Up @@ -42,6 +41,17 @@ class _GameplayPageState extends State<GameplayPage> {

late StreamSubscription<Position> positionStream;

final Map<String, String> friendlyLocation = {
"ENG_QUAD": "Eng Quad",
"ARTS_QUAD": "Arts Quad",
"AG_QUAD": "Ag Quad",
"NORTH_CAMPUS": "North Campus",
"WEST_CAMPUS": "West Campus",
"COLLEGETOWN": "Collegetown",
"ITHACA_COMMONS": "Ithaca Commons",
"ANY": "Cornell",
};

@override
void initState() {
startPositionStream();
Expand Down Expand Up @@ -156,13 +166,7 @@ class _GameplayPageState extends State<GameplayPage> {
vertical: 4.0, horizontal: 8.0),
child: Text(
(event.challenges!.length > 1
? "Journey " +
(tracker.prevChallenges.length +
1)
.toString() +
"/" +
event.challenges!.length
.toString()
? "Journey"
: "Challenge"),
style: TextStyle(
fontSize: 14,
Expand Down Expand Up @@ -191,7 +195,7 @@ class _GameplayPageState extends State<GameplayPage> {
Text(
' ' +
(friendlyLocation[
challenge.location?.name] ??
challenge.location] ??
""),
style: TextStyle(
fontSize: 12,
Expand All @@ -217,13 +221,6 @@ class _GameplayPageState extends State<GameplayPage> {
"assets/icons/bearcoins.svg"),
Text(
' ' +
((tracker.hintsUsed > 0)
? ((challenge.points ?? 0) -
tracker.hintsUsed *
25)
.toString() +
'/'
: '') +
(challenge.points ?? 0).toString() +
" PTS",
style: TextStyle(
Expand Down
30 changes: 30 additions & 0 deletions game/lib/model/achievement_model.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import 'package:flutter/foundation.dart';
import 'package:game/api/game_api.dart';
import 'package:game/api/game_client_dto.dart';

/**
* This file represents the model for the achievements. Whenever a achievement is updated, added or deleted from the backend, the model is updated and notifies the Consumer so that the front end can be modified.
*/
class AchievementModel extends ChangeNotifier {
Map<String, AchievementDto> _achievementsById = {};
ApiClient _client;

AchievementModel(ApiClient client) : _client = client {
/**
* Stream that listens to updates on the achievements.
*/
client.clientApi.updateAchievementDataStream.listen((event) {
if (event.deleted) {
_achievementsById.remove(event.achievement.id);
} else {
_achievementsById[event.achievement.id] = event.achievement;
}
notifyListeners();
});

client.clientApi.connectedStream.listen((event) {
_achievementsById.clear();
notifyListeners();
});
}
}

0 comments on commit ee4ef8d

Please sign in to comment.