summaryrefslogtreecommitdiff
path: root/DiscoBot/DSA_Game/Save
diff options
context:
space:
mode:
Diffstat (limited to 'DiscoBot/DSA_Game/Save')
-rw-r--r--DiscoBot/DSA_Game/Save/Properties.cs88
-rw-r--r--DiscoBot/DSA_Game/Save/SaveCommand.cs82
-rw-r--r--DiscoBot/DSA_Game/Save/Session.cs60
3 files changed, 0 insertions, 230 deletions
diff --git a/DiscoBot/DSA_Game/Save/Properties.cs b/DiscoBot/DSA_Game/Save/Properties.cs
deleted file mode 100644
index 67d30b0..0000000
--- a/DiscoBot/DSA_Game/Save/Properties.cs
+++ /dev/null
@@ -1,88 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace DiscoBot.DSA_Game.Save
-{
- using System.Collections;
- using System.IO;
- using System.Reflection;
- using System.Runtime.CompilerServices;
-
- using DiscoBot.Audio;
- using DiscoBot.Auxiliary;
- using DiscoBot.Commands;
-
- using Discord;
-
- using Newtonsoft.Json;
-
- public static class Properties
- {
- private static Dictionary<string, object> objects;
-
- static Properties()
- {
- objects = new Dictionary<string, object>();
- /*this.objects.Add("Sounds", new List<Sound>());
- this.objects.Add("CommandInfos", new List<CommandInfo>());*/
- }
-
- public static List<CommandInfo> CommandInfos { get => objects["CommandInfo"] as List<CommandInfo>; set => objects["CommandInfo"] = value; } // use Properties.Commandinfos to access the abstract Object array
-
- public static List<Sound> Sounds { get => objects["Sound"] as List<Sound>; set => objects["Sound"] = value; }
-
- public static void Deserialize(string path = @"..\..\Properties")
- {
-
- var files = Directory.GetFiles(path, "*.json");
-
- foreach (string file in files)
- {
- try
- {
- string name = file.Split('\\').Last().Split('.')[0].Replace('-', '.');
- string data = File.ReadAllText(file);
- Type type = Type.GetType(name);
- if (data.StartsWith("["))
- {
- type = typeof(List<>).MakeGenericType(type);
- }
-
- var o = JsonConvert.DeserializeObject(data, type);
- objects.Add(name.Split('.').Last(), o);
- }
- catch (Exception e)
- {
- // ignored
- var log = new LogMessage(LogSeverity.Warning, "Properties", $"Laden von Save-File {file} fehlgeschlagen.", e);
- Console.WriteLine(log);
- }
-
- }
-
- }
-
- public static void Serialize(string path = @"..\..\Properties\")
- {
- try
- {
- foreach (var o in objects)
- {
- string assembly = o.Value is IList list ? ((IList)list)[0]?.GetType().FullName : o.Value.GetType().FullName;
-
- var name = path + assembly.Replace('.', '-') + ".json";
- File.WriteAllText(name, JsonConvert.SerializeObject(o.Value, Formatting.Indented)); // Deserialize Data and create CommandInfo Struct
- }
- }
- catch (Exception e)
- {
- // ignored
- var log = new LogMessage(LogSeverity.Warning, "Properties", $"Speichern von Save-File fehlgeschlagen.", e);
- Console.WriteLine(log);
- }
- }
- }
-}
diff --git a/DiscoBot/DSA_Game/Save/SaveCommand.cs b/DiscoBot/DSA_Game/Save/SaveCommand.cs
deleted file mode 100644
index 1f160ec..0000000
--- a/DiscoBot/DSA_Game/Save/SaveCommand.cs
+++ /dev/null
@@ -1,82 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace DiscoBot.DSA_Game.Save
-{
- using System.Diagnostics;
- using System.IO;
- using System.Net;
- using System.Net.Http;
-
- using DiscoBot.Auxiliary;
-
- using Discord.Commands;
-
- public class SaveCommand : ModuleBase
- {
- [Command("load"), Summary("Load Session")]
- [Alias("session")]
- public async Task LoadSessionAsync([Remainder, Summary("Session Name")] string name = "")
- {
- if (name.Equals("?") || name.Equals(string.Empty))
- {
- await this.ReplyAsync($"Gespeicherte Sessions:");
- await this.ReplyAsync(this.ListSessions());
- return;
- }
-
- var path = DSA_Game.Save.Session.DirectoryPath + @"\" + name;
-
- var files = Directory.GetFiles(path);
- var session = files.OrderByDescending(x => Convert.ToInt32(x.Split('-').Last().Split('.').First())).First();
- Dsa.Session = Session.Load(session);
-
- await this.ReplyAsync($"{name} wurde geladen");
- }
-
- [Command("save", RunMode = RunMode.Async), Summary("Save Session")]
- public async Task SessionSaveAsync([Remainder, Summary("Session Name")] string name = "")
- {
- //var sendFile = this.Context.Channel.SendWebFile("https://cdn.discordapp.com/attachments/377123019673567232/465615882048110603/giphy.gif");
-
- if (name.Equals("?") || name.Equals(string.Empty))
- {
- await this.ReplyAsync($"Gespeicherte Sessions:");
- await this.ReplyAsync(this.ListSessions());
- return;
- }
-
- var path = DSA_Game.Save.Session.DirectoryPath + @"\" + name;
- if (Directory.Exists(path))
- {
- var files = Directory.GetFiles(path);
- int current = files.Max(x => Convert.ToInt32(x.Split('-').Last().Split('.').First()));
- Dsa.Session.SessionName = name;
- Dsa.Session.Save(path + "\\" + name + $"-{++current}.json");
- }
- else
- {
- Directory.CreateDirectory(path);
- Dsa.Session.SessionName = name;
- Dsa.Session.Save(path + "\\" + name + $"-0.json");
- }
-
- await this.ReplyAsync($"{name} wurde gespeichert");
- //await sendFile;
- }
-
- private string[] ListSessions()
- {
- string[] dirs = Directory.GetDirectories(Session.DirectoryPath).OrderByDescending(x => new DirectoryInfo(x).LastAccessTime.Ticks).ToArray();
- for (int i = 0; i < dirs.Length; i++)
- {
- dirs[i] += "; " + new DirectoryInfo(dirs[i]).LastAccessTime;
- }
-
- return dirs;
- }
- }
-}
diff --git a/DiscoBot/DSA_Game/Save/Session.cs b/DiscoBot/DSA_Game/Save/Session.cs
deleted file mode 100644
index 578fa50..0000000
--- a/DiscoBot/DSA_Game/Save/Session.cs
+++ /dev/null
@@ -1,60 +0,0 @@
-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 System.Runtime.CompilerServices;
-
- using DiscoBot.DSA_Game.Characters;
-
- using Discord;
- using Discord.Commands;
-
- using Newtonsoft.Json;
-
- public class Session
- {
- public static string DirectoryPath { get; set; } = @"..\..\sessions";
-
- public ICommandContext GeneralContext { get; set; }
-
- public Dictionary<string, string> Relation { get; set; } = new Dictionary<string, string>(); // dictionary to match the char
-
- public List<SaveChar> Chars { get; set; } = new List<SaveChar>(); // list of all characters
-
- public string SessionName { get; set; }
-
- public static Session Load(string path = @"..\..\session.json")
- {
- try
- {
- return JsonConvert.DeserializeObject<Session>(File.ReadAllText(path)); // Deserialize Data and create Session Object
- }
- catch (Exception e)
- {
- // ignored
- var log = new LogMessage(LogSeverity.Warning, "Properties", $"Laden von Save-File {path} fehlgeschlagen.", e);
- Console.WriteLine(log);
- return null;
- }
- }
-
- public void Save(string path = @"..\..\session.json")
- {
- try
- {
- File.WriteAllText(path, JsonConvert.SerializeObject(this, Formatting.Indented)); // Deserialize Data and create CommandInfo Struct
- }
- catch (Exception e)
- {
- var log = new LogMessage(LogSeverity.Warning, "Properties", $"Speichern von Save-File {path} fehlgeschlagen.", e);
- Console.WriteLine(log);
- // ignored
- }
- }
- }
-}