From e030b60c2567af239b81c9a36c502fa22defdc97 Mon Sep 17 00:00:00 2001 From: Orangerot Date: Tue, 14 Jan 2025 17:35:24 +0100 Subject: feat: add comments --- lib/screens/level.dart | 10 ++++++++++ lib/screens/level_selection.dart | 4 ++++ 2 files changed, 14 insertions(+) (limited to 'lib/screens') diff --git a/lib/screens/level.dart b/lib/screens/level.dart index 9c5823b..a22c237 100644 --- a/lib/screens/level.dart +++ b/lib/screens/level.dart @@ -87,6 +87,7 @@ class _LevelState extends State with SingleTickerProviderStateMixin { } }); + // go to GameOverStats when level finishes player.onPlayerComplete.listen((void _) { Route route = MaterialPageRoute( builder: (context) => GameOverStats( @@ -105,6 +106,7 @@ class _LevelState extends State with SingleTickerProviderStateMixin { }); } + // convert beats to notes widget.simfile.chartSimplest?.beats.forEach((time, noteData) { int arrowIndex = noteData.indexOf('1'); if (arrowIndex < 0 || arrowIndex > 3) { @@ -126,6 +128,7 @@ class _LevelState extends State with SingleTickerProviderStateMixin { super.dispose(); } + /// toggle between pause and resume void _pauseResume() { if (_isPlaying) { player.pause(); @@ -140,18 +143,24 @@ class _LevelState extends State with SingleTickerProviderStateMixin { } } + /// checks if the [note] is hit on [time] with the correct InputDirection void _noteHitCheck(Note note, Duration time) { note.position = note.time - time.inMilliseconds / 60000.0; if (note.wasHit != null) { return; } + + // you have +- half a second to hit if (note.position.abs() < 0.5 * 1.0 / 60.0) { + // combine keyboard and esense input InputDirection esenseDirection = ESenseInput.instance.getInputDirection(note.direction); inputDirection.up |= esenseDirection.up; inputDirection.down |= esenseDirection.down; inputDirection.left |= esenseDirection.left; inputDirection.right |= esenseDirection.right; + + // check if input matches arrow direction bool keypressCorrect = false; switch (note.direction) { case ArrowDirection.up: @@ -189,6 +198,7 @@ class _LevelState extends State with SingleTickerProviderStateMixin { } } + /// sets the InputDirection based on the arrow keys void _keyboardHandler(event) { bool isDown = false; if (event is KeyDownEvent) { diff --git a/lib/screens/level_selection.dart b/lib/screens/level_selection.dart index 7241ad7..5984e65 100644 --- a/lib/screens/level_selection.dart +++ b/lib/screens/level_selection.dart @@ -28,6 +28,7 @@ class _LevelSelectionState extends State { loadFolderPath(); } + /// gets folder path from persistent storage and updates state with loaded simfiles Future loadFolderPath() async { SharedPreferences prefs = await SharedPreferences.getInstance(); final String? stepmaniaCoursesPathSetting = @@ -44,6 +45,7 @@ class _LevelSelectionState extends State { }); } + /// open folder selection dialog and save selected folder in persistent storage Future selectFolder() async { await Permission.manageExternalStorage.request(); String? selectedFolder = await FilePicker.platform.getDirectoryPath(); @@ -57,6 +59,7 @@ class _LevelSelectionState extends State { } } + /// load all simfiles from a [directoryPath] Future> listFilesAndFolders(String directoryPath) async { final directory = Directory(directoryPath); try { @@ -86,6 +89,7 @@ class _LevelSelectionState extends State { } } + /// filter stepmaniaCoursesFolders based on [input] void filterLevels(String input) { setState(() { stepmaniaCoursesFoldersFiltered = stepmaniaCoursesFolders -- cgit v1.2.3