From e6181c24124d97f2fbc932b8a68311e625463156 Mon Sep 17 00:00:00 2001 From: uzvkl Date: Tue, 11 Jun 2019 23:05:52 +0200 Subject: Move dsa related stuff to subfolder --- DSALib/DSA_Game/Save/Properties.cs | 74 ------------------------------------- DSALib/DSA_Game/Save/SaveCommand.cs | 66 --------------------------------- DSALib/DSA_Game/Save/Session.cs | 51 ------------------------- 3 files changed, 191 deletions(-) delete mode 100644 DSALib/DSA_Game/Save/Properties.cs delete mode 100644 DSALib/DSA_Game/Save/SaveCommand.cs delete mode 100644 DSALib/DSA_Game/Save/Session.cs (limited to 'DSALib/DSA_Game/Save') diff --git a/DSALib/DSA_Game/Save/Properties.cs b/DSALib/DSA_Game/Save/Properties.cs deleted file mode 100644 index 2312af0..0000000 --- a/DSALib/DSA_Game/Save/Properties.cs +++ /dev/null @@ -1,74 +0,0 @@ -using System; -using System.Collections; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using DSALib.Auxiliary; -using Newtonsoft.Json; - -namespace DSALib.DSA_Game.Save -{ - public static class Properties - { - public static Dictionary objects; - - static Properties() - { - objects = new Dictionary(); - /*this.objects.Add("Sounds", new List()); - this.objects.Add("CommandInfos", new List());*/ - } - - public static List CommandInfos - { - get => objects["CommandInfo"] as List; - set => objects["CommandInfo"] = value; - } // use Properties.Commandinfos to access the abstract Object array - - - public static void Deserialize(string path = @"Properties") - { - var files = Directory.GetFiles(path, "*.json"); - - foreach (var file in files) - try - { - var name = file.Split('\\').Last().Split('.')[0].Replace('-', '.'); - var data = File.ReadAllText(file); - var 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 - Console.WriteLine($"Laden von Save-File {file} fehlgeschlagen." + e); - } - } - - public static void Serialize(string path = @"..\..\Properties\") - { - try - { - foreach (var o in objects) - { - var assembly = o.Value is IList list - ? 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 - Console.WriteLine("Speichern von Save-File fehlgeschlagen." + e); - } - } - } -} \ No newline at end of file diff --git a/DSALib/DSA_Game/Save/SaveCommand.cs b/DSALib/DSA_Game/Save/SaveCommand.cs deleted file mode 100644 index c5a1bb4..0000000 --- a/DSALib/DSA_Game/Save/SaveCommand.cs +++ /dev/null @@ -1,66 +0,0 @@ -using System; -using System.IO; -using System.Linq; - -namespace DSALib.DSA_Game.Save -{ - public class SaveCommand - { - public void LoadSession(string name = "") - { - if (name.Equals("?") || name.Equals(string.Empty)) - { - Console.WriteLine("Gespeicherte Sessions:"); - Console.WriteLine(ListSessions()); - return; - } - - var path = 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); - - Console.WriteLine($"{name} wurde geladen"); - } - - public void SessionSave(string name = "") - { - //var sendFile = this.Context.Channel.SendWebFile("https://cdn.discordapp.com/attachments/377123019673567232/465615882048110603/giphy.gif"); - - if (name.Equals("?") || name.Equals(string.Empty)) - { - Console.WriteLine("Gespeicherte Sessions:"); - Console.WriteLine(ListSessions()); - return; - } - - var path = Session.DirectoryPath + @"\" + name; - if (Directory.Exists(path)) - { - var files = Directory.GetFiles(path); - var 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"); - } - - Console.WriteLine($"{name} wurde gespeichert"); - //await sendFile; - } - - private string[] ListSessions() - { - var dirs = Directory.GetDirectories(Session.DirectoryPath) - .OrderByDescending(x => new DirectoryInfo(x).LastAccessTime.Ticks).ToArray(); - for (var i = 0; i < dirs.Length; i++) dirs[i] += "; " + new DirectoryInfo(dirs[i]).LastAccessTime; - - return dirs; - } - } -} \ No newline at end of file diff --git a/DSALib/DSA_Game/Save/Session.cs b/DSALib/DSA_Game/Save/Session.cs deleted file mode 100644 index 62aa8f6..0000000 --- a/DSALib/DSA_Game/Save/Session.cs +++ /dev/null @@ -1,51 +0,0 @@ -using System; -using System.Collections.Generic; -using System.IO; -using DSALib.DSA_Game.Characters; -using Newtonsoft.Json; - -namespace DSALib.DSA_Game.Save -{ - public class Session - { - public static string DirectoryPath { get; set; } = Dsa.rootPath + @"sessions"; - - public Dictionary Relation { get; set; } = - new Dictionary(); // dictionary to match the char - - public List Chars { get; set; } = new List(); // list of all characters - - public string SessionName { get; set; } - - public static Session Load(string path) - { - try - { - return - JsonConvert.DeserializeObject( - File.ReadAllText(path)); // Deserialize Data and create Session Object - } - catch (Exception e) - { - // ignored - Console.WriteLine($"Laden von Save-File {path} fehlgeschlagen." + e); - return null; - } - } - - public void Save(string path) - { - try - { - File.WriteAllText(path, - JsonConvert.SerializeObject(this, - Formatting.Indented)); // Deserialize Data and create CommandInfo Struct - } - catch (Exception e) - { - Console.WriteLine($"Speichern von Save-File {path} fehlgeschlagen.\n" + e); - // ignored - } - } - } -} \ No newline at end of file -- cgit v1.2.3-70-g09d2