summaryrefslogtreecommitdiff
path: root/DSACore/DSA_Game/Save
diff options
context:
space:
mode:
authorDennis Kobert <d-kobert@web.de>2019-05-19 16:03:38 +0200
committerDennis Kobert <d-kobert@web.de>2019-05-19 16:03:38 +0200
commitf89f308c525e9deebc6d2cf6416e27dfe1a299dc (patch)
tree7097ef871ead0245efda696198443eab8e443d3a /DSACore/DSA_Game/Save
parentf3983341be939235c1a6cd522b3bb5cc318a6d1a (diff)
Cleanup DiscoBot Project
Diffstat (limited to 'DSACore/DSA_Game/Save')
-rw-r--r--DSACore/DSA_Game/Save/Properties.cs17
-rw-r--r--DSACore/DSA_Game/Save/SaveCommand.cs22
-rw-r--r--DSACore/DSA_Game/Save/Session.cs21
3 files changed, 29 insertions, 31 deletions
diff --git a/DSACore/DSA_Game/Save/Properties.cs b/DSACore/DSA_Game/Save/Properties.cs
index 459a9c7..50bd8fa 100644
--- a/DSACore/DSA_Game/Save/Properties.cs
+++ b/DSACore/DSA_Game/Save/Properties.cs
@@ -39,17 +39,13 @@ namespace DSACore.DSA_Game.Save
{
var files = Directory.GetFiles(path, "*.json");
- foreach (string file in files)
- {
+ foreach (var 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 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);
@@ -59,7 +55,6 @@ namespace DSACore.DSA_Game.Save
// ignored
Console.WriteLine($"Laden von Save-File {file} fehlgeschlagen." + e);
}
- }
}
public static void Serialize(string path = @"..\..\Properties\")
@@ -68,7 +63,7 @@ namespace DSACore.DSA_Game.Save
{
foreach (var o in objects)
{
- string assembly = o.Value is IList list
+ var assembly = o.Value is IList list
? ((IList) list)[0]?.GetType().FullName
: o.Value.GetType().FullName;
diff --git a/DSACore/DSA_Game/Save/SaveCommand.cs b/DSACore/DSA_Game/Save/SaveCommand.cs
index 198d707..80d4426 100644
--- a/DSACore/DSA_Game/Save/SaveCommand.cs
+++ b/DSACore/DSA_Game/Save/SaveCommand.cs
@@ -6,18 +6,18 @@ namespace DSACore.DSA_Game.Save
{
using System.IO;
- public class SaveCommand
+ public class SaveCommand
{
public void LoadSession(string name = "")
{
if (name.Equals("?") || name.Equals(string.Empty))
{
Console.WriteLine($"Gespeicherte Sessions:");
- Console.WriteLine(this.ListSessions());
+ Console.WriteLine(ListSessions());
return;
}
- var path = Save.Session.DirectoryPath + @"\" + name;
+ var path = Session.DirectoryPath + @"\" + name;
var files = Directory.GetFiles(path);
var session = files.OrderByDescending(x => Convert.ToInt32(x.Split('-').Last().Split('.').First())).First();
@@ -33,15 +33,15 @@ namespace DSACore.DSA_Game.Save
if (name.Equals("?") || name.Equals(string.Empty))
{
Console.WriteLine($"Gespeicherte Sessions:");
- Console.WriteLine(this.ListSessions());
+ Console.WriteLine(ListSessions());
return;
}
- var path = DSA_Game.Save.Session.DirectoryPath + @"\" + name;
+ var path = Session.DirectoryPath + @"\" + name;
if (Directory.Exists(path))
{
var files = Directory.GetFiles(path);
- int current = files.Max(x => Convert.ToInt32(x.Split('-').Last().Split('.').First()));
+ var current = files.Max(x => Convert.ToInt32(x.Split('-').Last().Split('.').First()));
Dsa.Session.SessionName = name;
Dsa.Session.Save(path + "\\" + name + $"-{++current}.json");
}
@@ -58,13 +58,11 @@ namespace DSACore.DSA_Game.Save
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;
- }
+ 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/DSACore/DSA_Game/Save/Session.cs b/DSACore/DSA_Game/Save/Session.cs
index b402656..595f0e8 100644
--- a/DSACore/DSA_Game/Save/Session.cs
+++ b/DSACore/DSA_Game/Save/Session.cs
@@ -11,22 +11,25 @@ namespace DSACore.DSA_Game.Save
{
public static string DirectoryPath { get; set; } = Dsa.rootPath + @"sessions";
- public Dictionary<string, string> Relation { get; set; } = new Dictionary<string, string>(); // dictionary to match the char
+ 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 List<SaveChar> Chars { get; set; } = new List<SaveChar>(); // list of all characters
public string SessionName { get; set; }
-
+
public static Session Load(string path)
{
try
{
- return JsonConvert.DeserializeObject<Session>(File.ReadAllText(path)); // Deserialize Data and create Session Object
+ return
+ JsonConvert.DeserializeObject<Session>(
+ File.ReadAllText(path)); // Deserialize Data and create Session Object
}
catch (Exception e)
{
// ignored
- Console.WriteLine($"Laden von Save-File {path} fehlgeschlagen."+ e);
+ Console.WriteLine($"Laden von Save-File {path} fehlgeschlagen." + e);
return null;
}
}
@@ -35,13 +38,15 @@ namespace DSACore.DSA_Game.Save
{
try
{
- File.WriteAllText(path, JsonConvert.SerializeObject(this, Formatting.Indented)); // Deserialize Data and create CommandInfo Struct
+ 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);
+ Console.WriteLine($"Speichern von Save-File {path} fehlgeschlagen.\n" + e);
// ignored
}
}
}
-}
+} \ No newline at end of file