feat: GameOverStats Widgets shows stats after a course
This commit is contained in:
parent
0178eb5ffc
commit
685323adea
63
lib/game_over_stats.dart
Normal file
63
lib/game_over_stats.dart
Normal file
|
@ -0,0 +1,63 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:sense_the_rhythm/arrows.dart';
|
||||
import 'package:sense_the_rhythm/level.dart';
|
||||
import 'package:sense_the_rhythm/simfile.dart';
|
||||
|
||||
class GameOverStats extends StatelessWidget {
|
||||
const GameOverStats({super.key, required this.simfile, required this.notes});
|
||||
|
||||
final Simfile simfile;
|
||||
final List<Note> notes;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
int hits = notes.where((note) => note.wasHit == true).length;
|
||||
int misses = notes.where((note) => note.wasHit == false).length;
|
||||
int total = notes.length;
|
||||
int percent = (hits.toDouble() / total.toDouble() * 100).toInt();
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
leading: IconButton(
|
||||
onPressed: () => Navigator.pop(context),
|
||||
icon: Icon(Icons.arrow_back)),
|
||||
title: Text('Game Stats'),
|
||||
),
|
||||
body: Center(
|
||||
child: Column(
|
||||
children: [
|
||||
Text(' $percent%',
|
||||
style: TextStyle(
|
||||
fontSize: 60,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: Colors.orange)),
|
||||
DataTable(columns: [
|
||||
DataColumn(label: Container()),
|
||||
DataColumn(label: Container()),
|
||||
], rows: [
|
||||
DataRow(cells: [
|
||||
DataCell(Text('Hits')),
|
||||
DataCell(Text(hits.toString())),
|
||||
]),
|
||||
DataRow(cells: [
|
||||
DataCell(Text('Misses')),
|
||||
DataCell(Text(misses.toString())),
|
||||
]),
|
||||
DataRow(cells: [
|
||||
DataCell(Text('Total')),
|
||||
DataCell(Text(total.toString())),
|
||||
]),
|
||||
]),
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
Route route = MaterialPageRoute(
|
||||
builder: (context) => Level(stepmaniaFolderPath: simfile.directoryPath));
|
||||
Navigator.pushReplacement(context, route);
|
||||
},
|
||||
child: Text('Retry'))
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
|
@ -5,6 +5,7 @@ import 'package:flutter/material.dart';
|
|||
import 'package:audioplayers/audioplayers.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:sense_the_rhythm/arrows.dart';
|
||||
import 'package:sense_the_rhythm/game_over_stats.dart';
|
||||
import 'package:sense_the_rhythm/simfile.dart';
|
||||
|
||||
class Level extends StatefulWidget {
|
||||
|
@ -73,6 +74,15 @@ class _LevelState extends State<Level> {
|
|||
setState(() => _duration = d);
|
||||
});
|
||||
|
||||
player.onPlayerComplete.listen((void _) {
|
||||
Route route = MaterialPageRoute(
|
||||
builder: (context) => GameOverStats(
|
||||
simfile: simfile!,
|
||||
notes: notes,
|
||||
));
|
||||
Navigator.pushReplacement(context, route);
|
||||
});
|
||||
|
||||
player.onPositionChanged.listen((Duration p) {
|
||||
// print('Current position: $p');
|
||||
setState(() => _position = p);
|
||||
|
@ -121,19 +131,7 @@ class _LevelState extends State<Level> {
|
|||
}
|
||||
});
|
||||
|
||||
String simfilePath = Directory(widget.stepmaniaFolderPath)
|
||||
.listSync()
|
||||
.firstWhere((entity) => entity.path.endsWith('.sm'),
|
||||
orElse: () => File(''))
|
||||
.path;
|
||||
|
||||
String audioPath = Directory(widget.stepmaniaFolderPath)
|
||||
.listSync()
|
||||
.firstWhere((entity) => entity.path.endsWith('.ogg'),
|
||||
orElse: () => File(''))
|
||||
.path;
|
||||
|
||||
simfile = Simfile(simfilePath);
|
||||
simfile = Simfile(widget.stepmaniaFolderPath);
|
||||
simfile!.load();
|
||||
|
||||
simfile!.chartSimplest!.beats.forEach((time, noteData) {
|
||||
|
@ -144,9 +142,7 @@ class _LevelState extends State<Level> {
|
|||
notes.add(Note(time: time, direction: ArrowDirection.values[arrowIndex]));
|
||||
});
|
||||
|
||||
print(audioPath);
|
||||
|
||||
player.play(DeviceFileSource(audioPath));
|
||||
player.play(DeviceFileSource(simfile!.audioPath!));
|
||||
}
|
||||
|
||||
@override
|
||||
|
|
|
@ -109,12 +109,11 @@ class _LevelSelectionState extends State<LevelSelection> {
|
|||
prefs.getString('stepmania_courses');
|
||||
|
||||
if (stepmaniaCoursesPathSetting == null) return;
|
||||
List<FileSystemEntity> stepmaniaCoursesFoldersFuture = await listFilesAndFolders(stepmaniaCoursesPathSetting);
|
||||
|
||||
setState(() {
|
||||
stepmaniaCoursesPath = stepmaniaCoursesPathSetting;
|
||||
});
|
||||
setState(() async {
|
||||
stepmaniaCoursesFolders =
|
||||
await listFilesAndFolders(stepmaniaCoursesPathSetting);
|
||||
stepmaniaCoursesFolders = stepmaniaCoursesFoldersFuture;
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -37,7 +37,10 @@ class Chart {
|
|||
}
|
||||
|
||||
class Simfile {
|
||||
String path;
|
||||
String directoryPath;
|
||||
String? simfilePath;
|
||||
String? audioPath;
|
||||
String? bannerPath;
|
||||
String? lines;
|
||||
|
||||
// tags of simfile
|
||||
|
@ -48,7 +51,7 @@ class Simfile {
|
|||
Map<double, double> bpms = {};
|
||||
double offset = 0;
|
||||
|
||||
Simfile(this.path);
|
||||
Simfile(this.directoryPath);
|
||||
|
||||
void _parseChart({required List<String> keys, required String value}) {
|
||||
Chart chart = Chart();
|
||||
|
@ -118,7 +121,18 @@ class Simfile {
|
|||
}
|
||||
|
||||
void load() {
|
||||
lines = File(path).readAsStringSync();
|
||||
simfilePath = Directory(directoryPath)
|
||||
.listSync()
|
||||
.firstWhere((entity) => entity.path.endsWith('.sm'),
|
||||
orElse: () => File('')).path;
|
||||
|
||||
audioPath = Directory(directoryPath)
|
||||
.listSync()
|
||||
.firstWhere((entity) => entity.path.endsWith('.ogg'),
|
||||
orElse: () => File(''))
|
||||
.path;
|
||||
|
||||
lines = File(simfilePath!).readAsStringSync();
|
||||
|
||||
RegExp commentsRegExp = RegExp(r'//.*$');
|
||||
lines = lines?.replaceAll(commentsRegExp, '');
|
||||
|
|
Loading…
Reference in a new issue