diff options
author | TrueDoctor <d-kobert@web.de> | 2018-06-15 09:58:24 +0200 |
---|---|---|
committer | TrueDoctor <d-kobert@web.de> | 2018-06-15 09:58:24 +0200 |
commit | 380d9ec6048663b0e497e2437222d783236b864f (patch) | |
tree | 635fd93e6902c696abe31526da1fc15db7f2d516 /DiscoBot/DSA_Game | |
parent | c00b3bbf39ae2756aecceaa54b3a87a0e3955a9e (diff) |
Added Properties Class
auto load last settings
removed sound enumerable
moved Sonds to properties
moved Commands to properties
Diffstat (limited to 'DiscoBot/DSA_Game')
-rw-r--r-- | DiscoBot/DSA_Game/Characters/Character.cs | 6 | ||||
-rw-r--r-- | DiscoBot/DSA_Game/Dsa.cs | 7 | ||||
-rw-r--r-- | DiscoBot/DSA_Game/Save/Properties.cs | 51 |
3 files changed, 61 insertions, 3 deletions
diff --git a/DiscoBot/DSA_Game/Characters/Character.cs b/DiscoBot/DSA_Game/Characters/Character.cs index 5c39fc5..c1acd39 100644 --- a/DiscoBot/DSA_Game/Characters/Character.cs +++ b/DiscoBot/DSA_Game/Characters/Character.cs @@ -120,7 +120,7 @@ { try { - SoundEffects.Play(Sound.Wrong); + SoundEffects.Play("Wrong"); } catch { } @@ -149,7 +149,7 @@ { try { - SoundEffects.Play(Sound.Wrong); + SoundEffects.Play("Wrong"); } catch { } return $"{this.Name} kann nicht mit der Waffenart {talent} umgehen..."; @@ -177,7 +177,7 @@ { try { - SoundEffects.Play(Sound.Wrong); + SoundEffects.Play("Wrong"); } catch { } return $"{this.Name} kann nicht mit der Waffenart {talent} umgehen..."; diff --git a/DiscoBot/DSA_Game/Dsa.cs b/DiscoBot/DSA_Game/Dsa.cs index e514691..c6ea1c3 100644 --- a/DiscoBot/DSA_Game/Dsa.cs +++ b/DiscoBot/DSA_Game/Dsa.cs @@ -6,7 +6,9 @@ using DiscoBot.Audio; using DiscoBot.Auxiliary; + using DiscoBot.Commands; using DiscoBot.DSA_Game.Characters; + using DiscoBot.DSA_Game.Save; using Discord.Commands; @@ -21,6 +23,8 @@ public static List<ICharacter> Chars { get; set; } = new List<ICharacter>(); // list of all characters public static List<Talent> Talente { get; set; } = new List<Talent>(); + + public static Properties Properties { get; set; } public static void Startup() { @@ -53,6 +57,9 @@ .Where(c => !Talente.Exists(v => v.Name.Equals(c.Name))).ToList().ForEach(v => Talente.Add(v)); } + Properties = Save.Properties.Deserialize(); + Properties.Serialize(); + Talente = Talente.OrderBy(x => x.Name).ToList(); } } diff --git a/DiscoBot/DSA_Game/Save/Properties.cs b/DiscoBot/DSA_Game/Save/Properties.cs new file mode 100644 index 0000000..5d99a56 --- /dev/null +++ b/DiscoBot/DSA_Game/Save/Properties.cs @@ -0,0 +1,51 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DiscoBot.DSA_Game.Save +{ + using System.IO; + + using DiscoBot.Audio; + using DiscoBot.Auxiliary; + using DiscoBot.Commands; + + using Newtonsoft.Json; + + public class Properties + { + public List<CommandInfo> CommandInfos { get; set; } + + public List<Sound> Sounds { get; set; } + + public static Properties Deserialize(string path = @"..\..\Properties.json") + { + try + { + return JsonConvert.DeserializeObject<Properties>(File.ReadAllText(path)); // Deserialize Data and create CommandInfo Struct + } + catch (Exception e) + { + // ignored + return null; + } + } + + public void Serialize(string path = @"..\..\Properties.json") + {/* + var stream = new StreamWriter(path); // Load properties file + var reader = new JsonTextWriter(stream); // create stream reader*/ + + try + { + File.WriteAllText(path, JsonConvert.SerializeObject(this, Formatting.Indented)); // Deserialize Data and create CommandInfo Struct + } + catch (Exception e) + { + // ignored + } + } + } +} |