aboutsummaryrefslogtreecommitdiff
path: root/TimeHACK.Engine/SaveSystem.cs
diff options
context:
space:
mode:
Diffstat (limited to 'TimeHACK.Engine/SaveSystem.cs')
-rw-r--r--TimeHACK.Engine/SaveSystem.cs61
1 files changed, 40 insertions, 21 deletions
diff --git a/TimeHACK.Engine/SaveSystem.cs b/TimeHACK.Engine/SaveSystem.cs
index 2016110..89c9cb0 100644
--- a/TimeHACK.Engine/SaveSystem.cs
+++ b/TimeHACK.Engine/SaveSystem.cs
@@ -11,6 +11,7 @@ namespace TimeHACK.Engine
public static class SaveSystem
{
public static Save CurrentSave { get; private set; }
+ public static Boolean DevMode = false;
public static string GameDirectory
{
@@ -20,7 +21,7 @@ namespace TimeHACK.Engine
}
}
- public static string ProfileDirectory
+ public static string AllProfilesDirectory
{
get
{
@@ -28,33 +29,47 @@ namespace TimeHACK.Engine
}
}
- public static bool LoadSave()
+ public static string ProfileName = "";
+ public static string ProfileFile = "main.save";
+
+ public static string ProfileDirectory
{
- if(File.Exists(Path.Combine(ProfileDirectory, "user.save")))
- {
- //Read base64 string from file
- string b64 = File.ReadAllText(Path.Combine(ProfileDirectory, "user.save"));
- //Get Unicode byte array
- byte[] bytes = Convert.FromBase64String(b64);
- //Decode the Unicode
- string json = Encoding.UTF8.GetString(bytes);
- //Deserialize save object.
- CurrentSave = JsonConvert.DeserializeObject<Save>(json);
- return true;
- }
- else
+ get
{
- NewGame();
- return false;
+ return Path.Combine(GameDirectory, Path.Combine("Profiles", ProfileName));
}
}
+ public static bool LoadSave()
+ {
+ // ON A FINAL RELEASE USE THE "FINAL RELEASE THINGS"
+ #region Final Release Things
+ //Read base64 string from file
+ //string b64 = File.ReadAllText(Path.Combine(ProfileDirectory, ProfileFile));
+ //Get Unicode byte array
+ //byte[] bytes = Convert.FromBase64String(b64);
+ //Decode the Unicode
+ //string json = Encoding.UTF8.GetString(bytes);
+ //Deserialize save object.
+ #endregion
+ // USE THE THINGS IN THE "DEVELOPER THINGS" FOR A DEVELOPMENT RELEASE
+ #region Developer Things
+ string json = File.ReadAllText(Path.Combine(ProfileDirectory, ProfileFile));
+ #endregion
+ CurrentSave = JsonConvert.DeserializeObject<Save>(json);
+ return true;
+ }
+
public static void NewGame()
{
+
//TODO: User must set a username....somehow
if (!Directory.Exists(GameDirectory))
Directory.CreateDirectory(GameDirectory);
+ if (!Directory.Exists(AllProfilesDirectory))
+ Directory.CreateDirectory(AllProfilesDirectory);
+
if (!Directory.Exists(ProfileDirectory))
Directory.CreateDirectory(ProfileDirectory);
@@ -68,13 +83,17 @@ namespace TimeHACK.Engine
public static void SaveGame()
{
//Serialize the save to JSON.
- string json = JsonConvert.SerializeObject(CurrentSave);
+ string json = JsonConvert.SerializeObject(CurrentSave, Formatting.Indented);
+
+ // ADD THE TWO LINES OF CODE BELOW ON A FINAL RELEASE
//Get JSON bytes (Unicode format).
- var bytes = Encoding.UTF8.GetBytes(json);
+ //var bytes = Encoding.UTF8.GetBytes(json);
//Encode the array into Base64.
- string b64 = Convert.ToBase64String(bytes);
+ //string b64 = Convert.ToBase64String(bytes);
//Write to disk.
- File.WriteAllText(Path.Combine(ProfileDirectory, "user.save"), b64);
+
+ // CHANGE THE "JSON" TO "B64" ON A FINAL RELEASE!
+ File.WriteAllText(Path.Combine(ProfileDirectory, ProfileFile), json);
}
}