summaryrefslogtreecommitdiff
path: root/DSACore/DSA_Game/Save
diff options
context:
space:
mode:
Diffstat (limited to 'DSACore/DSA_Game/Save')
-rw-r--r--DSACore/DSA_Game/Save/Properties.cs26
-rw-r--r--DSACore/DSA_Game/Save/SaveCommand.cs32
-rw-r--r--DSACore/DSA_Game/Save/Session.cs28
3 files changed, 39 insertions, 47 deletions
diff --git a/DSACore/DSA_Game/Save/Properties.cs b/DSACore/DSA_Game/Save/Properties.cs
index 459a9c7..7eba911 100644
--- a/DSACore/DSA_Game/Save/Properties.cs
+++ b/DSACore/DSA_Game/Save/Properties.cs
@@ -1,4 +1,5 @@
using System;
+using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
@@ -8,10 +9,6 @@ using Newtonsoft.Json;
namespace DSACore.DSA_Game.Save
{
- using System.Collections;
- using System.IO;
- using Newtonsoft.Json;
-
public static class Properties
{
public static Dictionary<string, object> objects;
@@ -39,17 +36,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 +52,6 @@ namespace DSACore.DSA_Game.Save
// ignored
Console.WriteLine($"Laden von Save-File {file} fehlgeschlagen." + e);
}
- }
}
public static void Serialize(string path = @"..\..\Properties\")
@@ -68,8 +60,8 @@ namespace DSACore.DSA_Game.Save
{
foreach (var o in objects)
{
- string assembly = o.Value is IList list
- ? ((IList) list)[0]?.GetType().FullName
+ var assembly = o.Value is IList list
+ ? list[0]?.GetType().FullName
: o.Value.GetType().FullName;
var name = path + assembly.Replace('.', '-') + ".json";
@@ -81,7 +73,7 @@ namespace DSACore.DSA_Game.Save
catch (Exception e)
{
// ignored
- Console.WriteLine($"Speichern von Save-File fehlgeschlagen." + e);
+ Console.WriteLine("Speichern von Save-File fehlgeschlagen." + e);
}
}
}
diff --git a/DSACore/DSA_Game/Save/SaveCommand.cs b/DSACore/DSA_Game/Save/SaveCommand.cs
index 198d707..f358047 100644
--- a/DSACore/DSA_Game/Save/SaveCommand.cs
+++ b/DSACore/DSA_Game/Save/SaveCommand.cs
@@ -1,23 +1,21 @@
using System;
+using System.IO;
using System.Linq;
-using System.Threading.Tasks;
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("Gespeicherte Sessions:");
+ 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();
@@ -32,16 +30,16 @@ namespace DSACore.DSA_Game.Save
if (name.Equals("?") || name.Equals(string.Empty))
{
- Console.WriteLine($"Gespeicherte Sessions:");
- Console.WriteLine(this.ListSessions());
+ Console.WriteLine("Gespeicherte Sessions:");
+ 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");
}
@@ -49,7 +47,7 @@ namespace DSACore.DSA_Game.Save
{
Directory.CreateDirectory(path);
Dsa.Session.SessionName = name;
- Dsa.Session.Save(path + "\\" + name + $"-0.json");
+ Dsa.Session.Save(path + "\\" + name + "-0.json");
}
Console.WriteLine($"{name} wurde gespeichert");
@@ -58,13 +56,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..6944fb1 100644
--- a/DSACore/DSA_Game/Save/Session.cs
+++ b/DSACore/DSA_Game/Save/Session.cs
@@ -1,32 +1,34 @@
using System;
using System.Collections.Generic;
+using System.IO;
+using DSACore.DSA_Game.Characters;
+using Newtonsoft.Json;
namespace DSACore.DSA_Game.Save
{
- using System.IO;
- using Characters;
- using Newtonsoft.Json;
-
public class Session
{
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 +37,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