diff options
Diffstat (limited to 'lib/utils')
| -rw-r--r-- | lib/utils/simfile.dart | 61 | 
1 files changed, 36 insertions, 25 deletions
| diff --git a/lib/utils/simfile.dart b/lib/utils/simfile.dart index 0af734f..c528084 100644 --- a/lib/utils/simfile.dart +++ b/lib/utils/simfile.dart @@ -1,5 +1,7 @@  import 'dart:io'; +import 'package:audioplayers/audioplayers.dart'; +  enum Difficulty { Beginner, Easy, Medium, Hard, Challenge, Edit }  // These are the standard note values: @@ -36,12 +38,13 @@ class Chart {  }  class Simfile { -  String directoryPath; -  String? simfilePath; +  String? directoryPath; +  String simfilePath;    String? audioPath;    String? bannerPath;    String? lines; +  Duration? duration;    // tags of simfile    Map<String, String> tags = {}; @@ -50,7 +53,7 @@ class Simfile {    Map<double, double> bpms = {};    double offset = 0; -  Simfile(this.directoryPath); +  Simfile(this.simfilePath);    void _parseChart({required List<String> keys, required String value}) {      Chart chart = Chart(); @@ -119,33 +122,41 @@ class Simfile {      _parseChart(keys: keys, value: value);    } -  void load() { -    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; - -    bannerPath = Directory(directoryPath) -        .listSync() -        .firstWhere((file) => file.path.toLowerCase().endsWith('banner.png'), -            orElse: () => File('')) -        .path; - -    lines = File(simfilePath!).readAsStringSync(); - +  Future<bool> load() async { +    directoryPath = File(simfilePath).parent.path; +    lines = File(simfilePath).readAsStringSync(); +          RegExp commentsRegExp = RegExp(r'//.*$');      lines = lines?.replaceAll(commentsRegExp, '');      RegExp fieldDataRegExp = RegExp(r'#([^;]+):([^;]*);');      for (final fieldData in fieldDataRegExp.allMatches(lines!)) { -      _parseTag(fieldData); +      try { +        _parseTag(fieldData); +      } catch (err) { +        return false; +      }      } + +    String? musicFileName = tags["MUSIC"]; +    if (musicFileName == null) return false; +    String? bannerFileName = tags["BANNER"]; +    if (bannerFileName == null) return false; + +    for (FileSystemEntity entity in Directory(directoryPath!).listSync()) { +      if (entity.path.endsWith('.ogg')) { +        audioPath = entity.path; +      } +      if (entity.path.endsWith('anner.png')) { +        bannerPath = entity.path; +      } +    } + +    AudioPlayer audioplayer = AudioPlayer(); +    await audioplayer.setSource(DeviceFileSource(audioPath!)); +    duration = await audioplayer.getDuration(); +    audioplayer.dispose(); + +    return true;    }  } | 
