-
Notifications
You must be signed in to change notification settings - Fork 0
/
SaveSystem.cs
57 lines (45 loc) · 1.46 KB
/
SaveSystem.cs
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
48
49
50
51
52
53
54
55
56
57
using System;
using System.Diagnostics;
using System.Linq;
using Godot;
namespace TonstudioDiscoball;
public partial class SaveSystem : Node {
private const string SaveFile = "user://disco_config.tres";
public override void _Ready() {
Load();
}
public void SaveWindowPosition() {
var window = GetWindow();
var config = DiscoConfig.CurrentConfig;
config.WindowPosition = window.Position;
config.WindowSize = window.Size;
config.Screen = window.CurrentScreen;
Save();
}
public void ResetWindowPosition() {
DiscoConfig.CurrentConfig.ResetWindowPosition();
ApplyCurrentConfig();
Save();
}
public static void Save() {
Trace.TraceInformation($"Saving config: {DiscoConfig.CurrentConfig}");
ResourceSaver.Save(DiscoConfig.CurrentConfig, SaveFile);
}
private void Load() {
var config = ResourceLoader.Load<DiscoConfig>(SaveFile);
if (config != null) {
DiscoConfig.CurrentConfig = config;
ApplyCurrentConfig();
} else {
DiscoConfig.CurrentConfig = new DiscoConfig();
ApplyCurrentConfig();
}
}
private void ApplyCurrentConfig() {
var config = DiscoConfig.CurrentConfig;
var window = GetWindow();
window.CurrentScreen = config.Screen;
window.Size = config.WindowSize;
window.Position = config.WindowPosition;
}
}