From 685323adeab3d27bff4df16a201f9f14688475d5 Mon Sep 17 00:00:00 2001 From: Orangerot Date: Tue, 7 Jan 2025 06:05:28 +0100 Subject: feat: GameOverStats Widgets shows stats after a course --- lib/level.dart | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) (limited to 'lib/level.dart') 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 { 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 { } }); - 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 { notes.add(Note(time: time, direction: ArrowDirection.values[arrowIndex])); }); - print(audioPath); - - player.play(DeviceFileSource(audioPath)); + player.play(DeviceFileSource(simfile!.audioPath!)); } @override -- cgit v1.2.3