summaryrefslogtreecommitdiff
path: root/DSACore/DSA_Game/Save
diff options
context:
space:
mode:
authorTrueDoctor <d-kobert@web.de>2018-09-26 23:49:26 +0200
committerTrueDoctor <d-kobert@web.de>2018-09-26 23:49:26 +0200
commit19bf37de7642ae8cdefd8fc6b4fadac3ac96ea9b (patch)
tree08e7a9b15d806777fa1b839e897a171823649ab1 /DSACore/DSA_Game/Save
parentb411aa2128c2724bec0ecedb8cb4e1ffa59f3b53 (diff)
ported most code to WebApiProject
everything except the user identification and file locations should be somewhat functional
Diffstat (limited to 'DSACore/DSA_Game/Save')
-rw-r--r--DSACore/DSA_Game/Save/Properties.cs65
-rw-r--r--DSACore/DSA_Game/Save/SaveCommand.cs4
-rw-r--r--DSACore/DSA_Game/Save/Session.cs4
3 files changed, 42 insertions, 31 deletions
diff --git a/DSACore/DSA_Game/Save/Properties.cs b/DSACore/DSA_Game/Save/Properties.cs
index a27c9d7..1c86ab9 100644
--- a/DSACore/DSA_Game/Save/Properties.cs
+++ b/DSACore/DSA_Game/Save/Properties.cs
@@ -1,10 +1,12 @@
using System;
using System.Collections.Generic;
+using System.IO;
using System.Linq;
using DSACore.Audio;
using DSACore.Auxiliary;
+using Newtonsoft.Json;
-namespace DiscoBot.DSA_Game.Save
+namespace DSACore.DSA_Game.Save
{
using System.Collections;
using System.IO;
@@ -21,38 +23,43 @@ namespace DiscoBot.DSA_Game.Save
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<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 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");
+ var files = Directory.GetFiles(path, "*.json");
- foreach (string file in files)
+ foreach (string file in files)
+ {
+ try
{
- 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)
+ string name = file.Split('\\').Last().Split('.')[0].Replace('-', '.');
+ string data = File.ReadAllText(file);
+ Type type = Type.GetType(name);
+ if (data.StartsWith("["))
{
- // ignored
- Console.WriteLine($"Laden von Save-File {file} fehlgeschlagen."+ e);
+ 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\")
@@ -61,17 +68,21 @@ namespace DiscoBot.DSA_Game.Save
{
foreach (var o in objects)
{
- string assembly = o.Value is IList list ? ((IList)list)[0]?.GetType().FullName : o.Value.GetType().FullName;
+ 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
+ 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);
+ Console.WriteLine($"Speichern von Save-File fehlgeschlagen." + e);
}
}
}
-}
+} \ No newline at end of file
diff --git a/DSACore/DSA_Game/Save/SaveCommand.cs b/DSACore/DSA_Game/Save/SaveCommand.cs
index 9a2ae8e..198d707 100644
--- a/DSACore/DSA_Game/Save/SaveCommand.cs
+++ b/DSACore/DSA_Game/Save/SaveCommand.cs
@@ -2,7 +2,7 @@
using System.Linq;
using System.Threading.Tasks;
-namespace DiscoBot.DSA_Game.Save
+namespace DSACore.DSA_Game.Save
{
using System.IO;
@@ -17,7 +17,7 @@ namespace DiscoBot.DSA_Game.Save
return;
}
- var path = DSA_Game.Save.Session.DirectoryPath + @"\" + name;
+ var path = Save.Session.DirectoryPath + @"\" + name;
var files = Directory.GetFiles(path);
var session = files.OrderByDescending(x => Convert.ToInt32(x.Split('-').Last().Split('.').First())).First();
diff --git a/DSACore/DSA_Game/Save/Session.cs b/DSACore/DSA_Game/Save/Session.cs
index d0cba21..60e900f 100644
--- a/DSACore/DSA_Game/Save/Session.cs
+++ b/DSACore/DSA_Game/Save/Session.cs
@@ -1,10 +1,10 @@
using System;
using System.Collections.Generic;
-namespace DiscoBot.DSA_Game.Save
+namespace DSACore.DSA_Game.Save
{
using System.IO;
- using DiscoBot.DSA_Game.Characters;
+ using Characters;
using Newtonsoft.Json;
public class Session