Skip to content

Commit

Permalink
fixed tasklistsaving if no file exists
Browse files Browse the repository at this point in the history
  • Loading branch information
KH241 committed Feb 11, 2022
1 parent e8bb629 commit 9814041
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 631 deletions.
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
[Ll]ibrary/
[Tt]emp/
[Oo]bj/
[Bb]uild/
[Bb]uilds/
[Ll]ogs/
Assets/AssetStoreTools*

Expand Down
Binary file removed Imagetargets/Oxygen.jpg
Binary file not shown.
42 changes: 0 additions & 42 deletions Krypton/Assets/Resources/taskLists.txt

This file was deleted.

7 changes: 0 additions & 7 deletions Krypton/Assets/Resources/taskLists.txt.meta

This file was deleted.

9 changes: 8 additions & 1 deletion Krypton/Assets/Scripts/Task/TaskListsSaver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace TaskMode
*/
public static class TaskListsSaver
{
private const string FILEPATH = "Assets/Resources/taskLists.txt";
private const string FILEPATH = "taskLists.json";

public static TaskList[] TaskLists => LoadTaskLists();

Expand All @@ -19,6 +19,9 @@ public static class TaskListsSaver
*/
public static TaskList[] LoadTaskLists()
{
//Create File if it doesnt exist
if (!File.Exists(FILEPATH)) { File.Create(FILEPATH).Close(); }

StreamReader reader = new StreamReader(FILEPATH);
string json = reader.ReadToEnd();
reader.Close();
Expand Down Expand Up @@ -56,6 +59,10 @@ public static int SaveTask(TaskList taskList)
ListWrapper wrapper = new ListWrapper();
wrapper.TaskLists = lists.ToArray();

//Create File if it doesnt exist
if (!File.Exists(FILEPATH)) { File.Create(FILEPATH).Close(); }


//Write to file
StreamWriter writer = new StreamWriter(FILEPATH, false);
writer.Write(JsonUtility.ToJson(wrapper, true));
Expand Down
Loading

0 comments on commit 9814041

Please sign in to comment.