summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/game_over_stats.dart63
-rw-r--r--lib/level.dart28
-rw-r--r--lib/level_selection.dart7
-rw-r--r--lib/simfile.dart20
4 files changed, 95 insertions, 23 deletions
diff --git a/lib/game_over_stats.dart b/lib/game_over_stats.dart
new file mode 100644
index 0000000..a80617c
--- /dev/null
+++ b/lib/game_over_stats.dart
@@ -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'))
+ ],
+ ),
+ ),
+ );
+ }
+}
diff --git a/lib/level.dart b/lib/level.dart
index aa042f4..cc17efb 100644
--- a/lib/level.dart
+++ b/lib/level.dart
@@ -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
diff --git a/lib/level_selection.dart b/lib/level_selection.dart
index e902304..5359d66 100644
--- a/lib/level_selection.dart
+++ b/lib/level_selection.dart
@@ -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;
});
}
diff --git a/lib/simfile.dart b/lib/simfile.dart
index 102c989..764e3aa 100644
--- a/lib/simfile.dart
+++ b/lib/simfile.dart
@@ -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, '');