forked from danielcollishaw/firefly
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request danielcollishaw#26 from danielcollishaw/save_system
Save System Implemented
- Loading branch information
Showing
261 changed files
with
269 additions
and
62,233 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#region Copyright | ||
/*---------------------------------------------------------------*/ | ||
/* File: GameSave.cs */ | ||
/* Firefly */ | ||
/* AI For Game Programming - CAP 4053 */ | ||
/* Copyright (c) 2023 Serenity Studios */ | ||
/* All rights reserved. */ | ||
/* Made with love, by Justin Sasso. */ | ||
/*---------------------------------------------------------------*/ | ||
#endregion | ||
|
||
using System; | ||
using UnityEngine; | ||
using Newtonsoft.Json; | ||
using System.IO; | ||
|
||
public class GameSave | ||
{ | ||
public bool[] LevelsUnlocked { get; set; } = new bool[] { }; | ||
|
||
private const string SAVE_PATH = "save.json"; | ||
public GameSave() { } | ||
|
||
public static GameSave LoadGameSave() | ||
{ | ||
string jsonData; | ||
|
||
try | ||
{ | ||
using (StreamReader streamRdr = new StreamReader(CreatePath())) | ||
{ | ||
jsonData = streamRdr.ReadToEnd(); | ||
} | ||
} | ||
catch (IOException ex) | ||
{ | ||
Debug.Log("Couldn't LoadGameSave. Could be first startup: " + ex); | ||
return new GameSave(); | ||
} | ||
|
||
return DeserializeGameSave(jsonData); | ||
} | ||
public static bool SaveGameSave(GameSave gameSave) | ||
{ | ||
string jsonData = SerializeGameSave(gameSave); | ||
|
||
using (StreamWriter outputFile = new StreamWriter(CreatePath())) | ||
{ | ||
outputFile.Write(jsonData); | ||
} | ||
|
||
return true; | ||
} | ||
private static string CreatePath() | ||
{ | ||
string path = string.Format("{0}{1}", Application.dataPath, SAVE_PATH); | ||
Debug.Log("Path created: " + path); // DEBUG | ||
return path; | ||
} | ||
|
||
private static string SerializeGameSave(GameSave gameSave) => JsonConvert.SerializeObject(gameSave); | ||
private static GameSave DeserializeGameSave(string jsonData) => JsonConvert.DeserializeObject<GameSave>(jsonData); | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"LevelsUnlocked":[false,false]} |
Binary file not shown.
Binary file not shown.
This file was deleted.
Oops, something went wrong.
Binary file removed
BIN
-93.6 KB
Packages/Microsoft.Bcl.AsyncInterfaces.7.0.0/Microsoft.Bcl.AsyncInterfaces.7.0.0.nupkg
Binary file not shown.
Oops, something went wrong.