-
Notifications
You must be signed in to change notification settings - Fork 131
/
Startup.cs
83 lines (71 loc) · 1.77 KB
/
Startup.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
using System.Text.Json;
namespace Celeste64;
/// <summary>
/// Creates a slight delay so the window looks OK before we load Assets
/// TODO: Would be nice if Foster could hide the Window till assets are ready.
/// </summary>
public class Startup : Scene
{
private int loadDelay = 5;
private void BeginGame()
{
// load assets
Assets.Load();
// load save file
{
var saveFile = Path.Join(App.UserPath, Save.FileName);
if (File.Exists(saveFile))
Save.Instance = Save.Deserialize(File.ReadAllText(saveFile)) ?? new();
else
Save.Instance = new();
Save.Instance.SyncSettings();
}
// try to load controls, or overwrite with defaults if they don't exist
{
var controlsFile = Path.Join(App.UserPath, ControlsConfig.FileName);
ControlsConfig? controls = null;
if (File.Exists(controlsFile))
{
try
{
controls = JsonSerializer.Deserialize(File.ReadAllText(controlsFile), ControlsConfigContext.Default.ControlsConfig);
}
catch
{
controls = null;
}
}
// create defaults if not found
if (controls == null)
{
controls = ControlsConfig.Defaults;
using var stream = File.Create(controlsFile);
JsonSerializer.Serialize(stream, ControlsConfig.Defaults, ControlsConfigContext.Default.ControlsConfig);
stream.Flush();
}
Controls.Load(controls);
}
// enter game
//Assets.Levels[0].Enter(new AngledWipe());
Game.Instance.Goto(new Transition()
{
Mode = Transition.Modes.Replace,
Scene = () => new Titlescreen(),
ToBlack = null,
FromBlack = new AngledWipe(),
});
}
public override void Update()
{
if (loadDelay > 0)
{
loadDelay--;
if (loadDelay <= 0)
BeginGame();
}
}
public override void Render(Target target)
{
target.Clear(Color.Black);
}
}