-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSaveFileManager.cs
More file actions
47 lines (41 loc) · 1.38 KB
/
SaveFileManager.cs
File metadata and controls
47 lines (41 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
using Godot;
using System;
public partial class SaveFileManager : Node
{
public static SaveFileManager Instance;
private string savePath = "user://save.dat";
public override void _Ready()
{
Instance = this;
}
public void SaveGame()
{
var file = FileAccess.Open(savePath, FileAccess.ModeFlags.Write);
file.StoreVar(Global.Instance.UnlockedLevels.Duplicate());
file.StoreVar(Global.Instance.CollectedFlowers.Duplicate());
file.StoreVar(Global.Instance.Flowers);
file.Close();
}
public void LoadGame()
{
if (FileAccess.FileExists(savePath))
{
var file = FileAccess.Open(savePath, FileAccess.ModeFlags.Read);
var unlockedLevelsData = file.GetVar();
var collectedFlowersData = file.GetVar();
var flowersData = file.GetVar();
file.Close();
Global.Instance.UnlockedLevels = unlockedLevelsData.AsGodotDictionary<string, bool>();
Global.Instance.CollectedFlowers = collectedFlowersData.AsGodotDictionary<string, bool>();
Global.Instance.Flowers = flowersData.AsInt16();
}
}
public void DeleteSave()
{
if (FileAccess.FileExists(savePath))
{
DirAccess.RemoveAbsolute(ProjectSettings.GlobalizePath(savePath));
Global.Instance.SetDefaults();
}
}
}