summaryrefslogtreecommitdiff
path: root/DiscoBot/DSA_Game
diff options
context:
space:
mode:
Diffstat (limited to 'DiscoBot/DSA_Game')
-rw-r--r--DiscoBot/DSA_Game/Characters/Character.cs6
-rw-r--r--DiscoBot/DSA_Game/Dsa.cs7
-rw-r--r--DiscoBot/DSA_Game/Save/Properties.cs51
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
+ }
+ }
+ }
+}