diff options
author | Dennis Kobert <d-kobert@web.de> | 2019-05-19 17:58:42 +0200 |
---|---|---|
committer | Dennis Kobert <d-kobert@web.de> | 2019-05-19 17:58:42 +0200 |
commit | 2ab4051c6fe720dc47e99b0c305a0d779ee02d51 (patch) | |
tree | 9510ddbb174a54474934adf7991a5ba2aa39f818 /DSACore/DSA_Game/Save/Properties.cs | |
parent | c4d046858e0822b7c2c540ac2368b2c0e88e7a26 (diff) |
Moved Gamelogic to DSALib
Diffstat (limited to 'DSACore/DSA_Game/Save/Properties.cs')
-rw-r--r-- | DSACore/DSA_Game/Save/Properties.cs | 80 |
1 files changed, 0 insertions, 80 deletions
diff --git a/DSACore/DSA_Game/Save/Properties.cs b/DSACore/DSA_Game/Save/Properties.cs deleted file mode 100644 index 7eba911..0000000 --- a/DSACore/DSA_Game/Save/Properties.cs +++ /dev/null @@ -1,80 +0,0 @@ -using System; -using System.Collections; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using DSACore.Audio; -using DSACore.Auxiliary; -using Newtonsoft.Json; - -namespace DSACore.DSA_Game.Save -{ - public static class Properties - { - public 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 (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 |