From eb7d1dda65fb31b58615d53b4784c79cc3b60423 Mon Sep 17 00:00:00 2001 From: Me on Windows Date: Sat, 19 Jun 2021 16:03:37 +0000 Subject: [PATCH] Implement PlayerConfig building --- QuickPlay/Configuration.cs | 31 ++++++++++++++++++++++++++----- QuickPlay/Interfaces.cs | 10 +++++++--- 2 files changed, 33 insertions(+), 8 deletions(-) diff --git a/QuickPlay/Configuration.cs b/QuickPlay/Configuration.cs index 0e3c913..3ab5a5d 100644 --- a/QuickPlay/Configuration.cs +++ b/QuickPlay/Configuration.cs @@ -100,23 +100,27 @@ namespace QuickPlay /// public class PlayerConfiguration { - List songs; + Dictionary songs; + string playerName; public static PlayerConfiguration FromFile(StreamReader reader) { var parser = new IniParser(reader); var ini = parser.Parse(); - foreach (string key in ini.Keys) + var result = new PlayerConfiguration(); + foreach (var elem in ini) { // Two options: either general options, or song descriptions - if (key == "general") + if (elem.Key == "general") { - + result.playerName = elem.Value["name"]; } else { - // Song + var song = new Song(elem.Key, elem.Value); + result.songs[elem.Key] = song; } } + return result; } public IPlayer GetPlayer() @@ -168,4 +172,21 @@ namespace QuickPlay { public PlayerConfiguration GetConfiguration() => null; } + + class Song: IPlayable + { + public string Identifier { get; private set; } + public PlayableMetadata Metadata { get; private set; } + public Song(string id, Dictionary data) { + Identifier = id; + Metadata = new PlayableMetadata + { + usualPlayingTime = TimeSpan.Parse(data["time"]) + }; + } + public void Play() + { + throw new NotImplementedException(); + } + } } \ No newline at end of file diff --git a/QuickPlay/Interfaces.cs b/QuickPlay/Interfaces.cs index aa5194a..8f0b6f5 100644 --- a/QuickPlay/Interfaces.cs +++ b/QuickPlay/Interfaces.cs @@ -11,6 +11,7 @@ namespace QuickPlay /// public interface IPlayer { + Dictionary Songs { get; } void Play(string identifier); float CurrentProgress { get; } bool IsReady { get; } @@ -21,12 +22,15 @@ namespace QuickPlay /// // This is not really an interface, but since it is a dataclass, I treat it // more as a part of interface, so it belongs to this file. - class PlayableMetadata + + // Also, in order not to need boilerplate code, this should be semantically + // treated as immutable even though it's not. + public class PlayableMetadata { - public readonly TimeSpan usualPlayingTime; + public TimeSpan usualPlayingTime; } - interface IPlayable + public interface IPlayable { void Play(); string Identifier { get; }