Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added assets/images/Frigate_icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
44 changes: 44 additions & 0 deletions lib/services/games_page_S/games_page_service.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:firebase_auth/firebase_auth.dart';

class GamesPageService {
Future<int> getUnlockedBadgesCount() async {

Check warning on line 5 in lib/services/games_page_S/games_page_service.dart

View check run for this annotation

Codecov / codecov/patch

lib/services/games_page_S/games_page_service.dart#L5

Added line #L5 was not covered by tests
try {
FirebaseFirestore db = FirebaseFirestore.instance;
final FirebaseAuth auth = FirebaseAuth.instance;
User? currentUser = auth.currentUser;

Check warning on line 9 in lib/services/games_page_S/games_page_service.dart

View check run for this annotation

Codecov / codecov/patch

lib/services/games_page_S/games_page_service.dart#L7-L9

Added lines #L7 - L9 were not covered by tests

if (currentUser == null) {
return 0;
}

QuerySnapshot<Map<String, dynamic>> querySnapshot = await db.collection('badges')
.where('userID', isEqualTo: currentUser.uid)
.get();

Check warning on line 17 in lib/services/games_page_S/games_page_service.dart

View check run for this annotation

Codecov / codecov/patch

lib/services/games_page_S/games_page_service.dart#L15-L17

Added lines #L15 - L17 were not covered by tests

if (querySnapshot.docs.isNotEmpty) {
DocumentSnapshot<Map<String, dynamic>> badgesData = querySnapshot.docs.first;
Map<String, dynamic>? data = badgesData.data();

Check warning on line 21 in lib/services/games_page_S/games_page_service.dart

View check run for this annotation

Codecov / codecov/patch

lib/services/games_page_S/games_page_service.dart#L19-L21

Added lines #L19 - L21 were not covered by tests

if (data == null) {
return 0;
}

int unlockedCount = 0;

data.forEach((key, value) {
if (value is Map<String, dynamic> && value['unlocked'] == true) {
unlockedCount++;

Check warning on line 31 in lib/services/games_page_S/games_page_service.dart

View check run for this annotation

Codecov / codecov/patch

lib/services/games_page_S/games_page_service.dart#L29-L31

Added lines #L29 - L31 were not covered by tests
}
});

return unlockedCount;
} else {
return 0;
}
} catch (e) {
// print("Error fetching badges: $e");
return 0;
}
}
}
236 changes: 236 additions & 0 deletions lib/view/pages/games_page/games_page.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,236 @@
import 'package:flame/flame.dart';
import 'package:gameonconnect/view/pages/GameyCon/loadingpage.dart';
import 'package:gameonconnect/view/pages/flappy_bird/game_screen_page.dart';
import 'package:gameonconnect/view/pages/space_shooter_game/game_page.dart';
import 'package:flutter/material.dart';
import 'package:gameonconnect/services/games_page_S/games_page_service.dart';

class GamesPageWidget extends StatefulWidget {
const GamesPageWidget({super.key});

@override
State<GamesPageWidget> createState() => _GamesPageWidgetState();

Check warning on line 12 in lib/view/pages/games_page/games_page.dart

View check run for this annotation

Codecov / codecov/patch

lib/view/pages/games_page/games_page.dart#L11-L12

Added lines #L11 - L12 were not covered by tests
}

class _GamesPageWidgetState extends State<GamesPageWidget> {
final scaffoldKey = GlobalKey<ScaffoldState>();
int unlockedBadges = 0;

@override

Check warning on line 19 in lib/view/pages/games_page/games_page.dart

View check run for this annotation

Codecov / codecov/patch

lib/view/pages/games_page/games_page.dart#L19

Added line #L19 was not covered by tests
void initState() {
super.initState();
_loadUnlockedBadges();

Check warning on line 22 in lib/view/pages/games_page/games_page.dart

View check run for this annotation

Codecov / codecov/patch

lib/view/pages/games_page/games_page.dart#L21-L22

Added lines #L21 - L22 were not covered by tests
}

Future<void> _loadUnlockedBadges() async {
int count = await GamesPageService().getUnlockedBadgesCount();
if (mounted) {
setState(() {
unlockedBadges = count;

Check warning on line 29 in lib/view/pages/games_page/games_page.dart

View check run for this annotation

Codecov / codecov/patch

lib/view/pages/games_page/games_page.dart#L25-L29

Added lines #L25 - L29 were not covered by tests
});
}
}

void _showInfoMessage(String message) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text(message)),

Check warning on line 36 in lib/view/pages/games_page/games_page.dart

View check run for this annotation

Codecov / codecov/patch

lib/view/pages/games_page/games_page.dart#L34-L36

Added lines #L34 - L36 were not covered by tests
);
}

@override

Check warning on line 40 in lib/view/pages/games_page/games_page.dart

View check run for this annotation

Codecov / codecov/patch

lib/view/pages/games_page/games_page.dart#L40

Added line #L40 was not covered by tests
Widget build(BuildContext context) {
return GestureDetector(
onTap: () => FocusScope.of(context).unfocus(),
child: Scaffold(
key: scaffoldKey,
backgroundColor: Theme.of(context).colorScheme.surface,
appBar: AppBar(
backgroundColor: Theme.of(context).colorScheme.surface,

Check warning on line 48 in lib/view/pages/games_page/games_page.dart

View check run for this annotation

Codecov / codecov/patch

lib/view/pages/games_page/games_page.dart#L42-L48

Added lines #L42 - L48 were not covered by tests
automaticallyImplyLeading: false,
title: Padding(

Check warning on line 50 in lib/view/pages/games_page/games_page.dart

View check run for this annotation

Codecov / codecov/patch

lib/view/pages/games_page/games_page.dart#L50

Added line #L50 was not covered by tests
padding: const EdgeInsets.only(top: 16.0),
child: Text(

Check warning on line 52 in lib/view/pages/games_page/games_page.dart

View check run for this annotation

Codecov / codecov/patch

lib/view/pages/games_page/games_page.dart#L52

Added line #L52 was not covered by tests
'Mini Games',
style: TextStyle(

Check warning on line 54 in lib/view/pages/games_page/games_page.dart

View check run for this annotation

Codecov / codecov/patch

lib/view/pages/games_page/games_page.dart#L54

Added line #L54 was not covered by tests
fontSize: 32,
fontWeight: FontWeight.bold,
color: Theme.of(context).colorScheme.onSurface,

Check warning on line 57 in lib/view/pages/games_page/games_page.dart

View check run for this annotation

Codecov / codecov/patch

lib/view/pages/games_page/games_page.dart#L57

Added line #L57 was not covered by tests
),
),
),
centerTitle: false,
elevation: 0,
),
body: SafeArea(
child: Column(

Check warning on line 65 in lib/view/pages/games_page/games_page.dart

View check run for this annotation

Codecov / codecov/patch

lib/view/pages/games_page/games_page.dart#L64-L65

Added lines #L64 - L65 were not covered by tests
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.start,
children: [

Check warning on line 68 in lib/view/pages/games_page/games_page.dart

View check run for this annotation

Codecov / codecov/patch

lib/view/pages/games_page/games_page.dart#L68

Added line #L68 was not covered by tests
// Space Shooter Game container (requires 1 badge)
Padding(

Check warning on line 70 in lib/view/pages/games_page/games_page.dart

View check run for this annotation

Codecov / codecov/patch

lib/view/pages/games_page/games_page.dart#L70

Added line #L70 was not covered by tests
padding: const EdgeInsets.fromLTRB(12, 30, 12, 12),
child: GestureDetector(
onTap: () {
if (unlockedBadges >= 1) {
Navigator.push(

Check warning on line 75 in lib/view/pages/games_page/games_page.dart

View check run for this annotation

Codecov / codecov/patch

lib/view/pages/games_page/games_page.dart#L72-L75

Added lines #L72 - L75 were not covered by tests
context,
MaterialPageRoute(
builder: (context) => const GamePage(),

Check warning on line 78 in lib/view/pages/games_page/games_page.dart

View check run for this annotation

Codecov / codecov/patch

lib/view/pages/games_page/games_page.dart#L77-L78

Added lines #L77 - L78 were not covered by tests
),
);
} else {
_showInfoMessage("You need at least 1 badge unlocked to play this game.");

Check warning on line 82 in lib/view/pages/games_page/games_page.dart

View check run for this annotation

Codecov / codecov/patch

lib/view/pages/games_page/games_page.dart#L82

Added line #L82 was not covered by tests
}
},
child: Container(

Check warning on line 85 in lib/view/pages/games_page/games_page.dart

View check run for this annotation

Codecov / codecov/patch

lib/view/pages/games_page/games_page.dart#L85

Added line #L85 was not covered by tests
width: double.infinity,
height: 130,
decoration: BoxDecoration(
color: Theme.of(context).colorScheme.primaryContainer,
borderRadius: BorderRadius.circular(10),

Check warning on line 90 in lib/view/pages/games_page/games_page.dart

View check run for this annotation

Codecov / codecov/patch

lib/view/pages/games_page/games_page.dart#L88-L90

Added lines #L88 - L90 were not covered by tests
),
child: Column(

Check warning on line 92 in lib/view/pages/games_page/games_page.dart

View check run for this annotation

Codecov / codecov/patch

lib/view/pages/games_page/games_page.dart#L92

Added line #L92 was not covered by tests
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [

Check warning on line 94 in lib/view/pages/games_page/games_page.dart

View check run for this annotation

Codecov / codecov/patch

lib/view/pages/games_page/games_page.dart#L94

Added line #L94 was not covered by tests
const Text(
'Space Shooter Game',
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.bold,
),
),
ClipRRect(
borderRadius: BorderRadius.circular(8),
child: unlockedBadges >= 1
? Image.asset(

Check warning on line 105 in lib/view/pages/games_page/games_page.dart

View check run for this annotation

Codecov / codecov/patch

lib/view/pages/games_page/games_page.dart#L102-L105

Added lines #L102 - L105 were not covered by tests
'assets/images/Frigate_icon.png',
width: 60,
height: 60,
fit: BoxFit.cover,
)
: Icon(

Check warning on line 111 in lib/view/pages/games_page/games_page.dart

View check run for this annotation

Codecov / codecov/patch

lib/view/pages/games_page/games_page.dart#L111

Added line #L111 was not covered by tests
Icons.lock_outlined,
color: Theme.of(context).colorScheme.primary,

Check warning on line 113 in lib/view/pages/games_page/games_page.dart

View check run for this annotation

Codecov / codecov/patch

lib/view/pages/games_page/games_page.dart#L113

Added line #L113 was not covered by tests
size: 60,
),
),
],
),
),
),
),
// Flappy Bird container (requires 4 badges)
Padding(

Check warning on line 123 in lib/view/pages/games_page/games_page.dart

View check run for this annotation

Codecov / codecov/patch

lib/view/pages/games_page/games_page.dart#L123

Added line #L123 was not covered by tests
padding: const EdgeInsets.all(12),
child: GestureDetector(
onTap: () {
if (unlockedBadges >= 4) {
Navigator.push(

Check warning on line 128 in lib/view/pages/games_page/games_page.dart

View check run for this annotation

Codecov / codecov/patch

lib/view/pages/games_page/games_page.dart#L125-L128

Added lines #L125 - L128 were not covered by tests
context,
MaterialPageRoute(
builder: (context) => const GameScreen(),

Check warning on line 131 in lib/view/pages/games_page/games_page.dart

View check run for this annotation

Codecov / codecov/patch

lib/view/pages/games_page/games_page.dart#L130-L131

Added lines #L130 - L131 were not covered by tests
),
);
} else {
_showInfoMessage("You need at least 4 badges unlocked to play this game.");

Check warning on line 135 in lib/view/pages/games_page/games_page.dart

View check run for this annotation

Codecov / codecov/patch

lib/view/pages/games_page/games_page.dart#L135

Added line #L135 was not covered by tests
}
},
child: Container(

Check warning on line 138 in lib/view/pages/games_page/games_page.dart

View check run for this annotation

Codecov / codecov/patch

lib/view/pages/games_page/games_page.dart#L138

Added line #L138 was not covered by tests
width: double.infinity,
height: 130,
decoration: BoxDecoration(
color: Theme.of(context).colorScheme.primaryContainer,
borderRadius: BorderRadius.circular(10),

Check warning on line 143 in lib/view/pages/games_page/games_page.dart

View check run for this annotation

Codecov / codecov/patch

lib/view/pages/games_page/games_page.dart#L141-L143

Added lines #L141 - L143 were not covered by tests
),
child: Column(

Check warning on line 145 in lib/view/pages/games_page/games_page.dart

View check run for this annotation

Codecov / codecov/patch

lib/view/pages/games_page/games_page.dart#L145

Added line #L145 was not covered by tests
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [

Check warning on line 147 in lib/view/pages/games_page/games_page.dart

View check run for this annotation

Codecov / codecov/patch

lib/view/pages/games_page/games_page.dart#L147

Added line #L147 was not covered by tests
const Text(
'Flappy Bird',
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.bold,
),
),
ClipRRect(
borderRadius: BorderRadius.circular(8),
child: unlockedBadges >= 4
? Image.asset(

Check warning on line 158 in lib/view/pages/games_page/games_page.dart

View check run for this annotation

Codecov / codecov/patch

lib/view/pages/games_page/games_page.dart#L155-L158

Added lines #L155 - L158 were not covered by tests
'assets/images/bird_downflap.png',
width: 60,
height: 60,
fit: BoxFit.cover,
)
: Icon(

Check warning on line 164 in lib/view/pages/games_page/games_page.dart

View check run for this annotation

Codecov / codecov/patch

lib/view/pages/games_page/games_page.dart#L164

Added line #L164 was not covered by tests
Icons.lock_outlined,
color: Theme.of(context).colorScheme.primary,

Check warning on line 166 in lib/view/pages/games_page/games_page.dart

View check run for this annotation

Codecov / codecov/patch

lib/view/pages/games_page/games_page.dart#L166

Added line #L166 was not covered by tests
size: 60,
),
),
],
),
),
),
),
// GameyCon container (requires 9 badges)
Padding(

Check warning on line 176 in lib/view/pages/games_page/games_page.dart

View check run for this annotation

Codecov / codecov/patch

lib/view/pages/games_page/games_page.dart#L176

Added line #L176 was not covered by tests
padding: const EdgeInsets.all(12),
child: GestureDetector(
onTap: () async {
if (unlockedBadges >= 9) {
await Flame.device.fullScreen();
if (!context.mounted) return;
Navigator.push(

Check warning on line 183 in lib/view/pages/games_page/games_page.dart

View check run for this annotation

Codecov / codecov/patch

lib/view/pages/games_page/games_page.dart#L178-L183

Added lines #L178 - L183 were not covered by tests
context,
MaterialPageRoute(
builder: (context) => const LoadingGameyConPage(),

Check warning on line 186 in lib/view/pages/games_page/games_page.dart

View check run for this annotation

Codecov / codecov/patch

lib/view/pages/games_page/games_page.dart#L185-L186

Added lines #L185 - L186 were not covered by tests
),
);
} else {
_showInfoMessage("You need at least 9 badges unlocked to play this game.");

Check warning on line 190 in lib/view/pages/games_page/games_page.dart

View check run for this annotation

Codecov / codecov/patch

lib/view/pages/games_page/games_page.dart#L190

Added line #L190 was not covered by tests
}
},
child: Container(

Check warning on line 193 in lib/view/pages/games_page/games_page.dart

View check run for this annotation

Codecov / codecov/patch

lib/view/pages/games_page/games_page.dart#L193

Added line #L193 was not covered by tests
width: double.infinity,
height: 130,
decoration: BoxDecoration(
color: Theme.of(context).colorScheme.primaryContainer,
borderRadius: BorderRadius.circular(10),

Check warning on line 198 in lib/view/pages/games_page/games_page.dart

View check run for this annotation

Codecov / codecov/patch

lib/view/pages/games_page/games_page.dart#L196-L198

Added lines #L196 - L198 were not covered by tests
),
child: Column(

Check warning on line 200 in lib/view/pages/games_page/games_page.dart

View check run for this annotation

Codecov / codecov/patch

lib/view/pages/games_page/games_page.dart#L200

Added line #L200 was not covered by tests
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [

Check warning on line 202 in lib/view/pages/games_page/games_page.dart

View check run for this annotation

Codecov / codecov/patch

lib/view/pages/games_page/games_page.dart#L202

Added line #L202 was not covered by tests
const Text(
'GameyCon',
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.bold,
),
),
ClipRRect(
borderRadius: BorderRadius.circular(8),
child: unlockedBadges >= 9
? Image.asset(

Check warning on line 213 in lib/view/pages/games_page/games_page.dart

View check run for this annotation

Codecov / codecov/patch

lib/view/pages/games_page/games_page.dart#L210-L213

Added lines #L210 - L213 were not covered by tests
'assets/images/Main Characters/Mask Dude/Fall (32x32).png',
width: 60,
height: 60,
fit: BoxFit.cover,
)
: Icon(

Check warning on line 219 in lib/view/pages/games_page/games_page.dart

View check run for this annotation

Codecov / codecov/patch

lib/view/pages/games_page/games_page.dart#L219

Added line #L219 was not covered by tests
Icons.lock_outlined,
color: Theme.of(context).colorScheme.primary,

Check warning on line 221 in lib/view/pages/games_page/games_page.dart

View check run for this annotation

Codecov / codecov/patch

lib/view/pages/games_page/games_page.dart#L221

Added line #L221 was not covered by tests
size: 60,
),
),
],
),
),
),
),
],
),
),
),
);
}
}
Loading
Loading