From 380d9ec6048663b0e497e2437222d783236b864f Mon Sep 17 00:00:00 2001 From: TrueDoctor Date: Fri, 15 Jun 2018 09:58:24 +0200 Subject: Added Properties Class auto load last settings removed sound enumerable moved Sonds to properties moved Commands to properties --- DiscoBot/DSA_Game/Characters/Character.cs | 6 ++-- DiscoBot/DSA_Game/Dsa.cs | 7 +++++ DiscoBot/DSA_Game/Save/Properties.cs | 51 +++++++++++++++++++++++++++++++ 3 files changed, 61 insertions(+), 3 deletions(-) create mode 100644 DiscoBot/DSA_Game/Save/Properties.cs (limited to 'DiscoBot/DSA_Game') 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 Chars { get; set; } = new List(); // list of all characters public static List Talente { get; set; } = new List(); + + 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 CommandInfos { get; set; } + + public List Sounds { get; set; } + + public static Properties Deserialize(string path = @"..\..\Properties.json") + { + try + { + return JsonConvert.DeserializeObject(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 + } + } + } +} -- cgit v1.2.3-70-g09d2