-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQuickloadReverter.cs
More file actions
47 lines (41 loc) · 1.67 KB
/
QuickloadReverter.cs
File metadata and controls
47 lines (41 loc) · 1.67 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 UnityEngine;
namespace QuickloadReverter
{
[KSPAddonFixed(KSPAddon.Startup.MainMenu, true, typeof(QuickloadReverter))]
public class QuickloadReverter : MonoBehaviour
{
bool keyWasReleased = true;
float lastBackupTime = 0;
public void Start()
{
DontDestroyOnLoad(this);
}
public void Update()
{
if (!HighLogic.LoadedSceneIsFlight) return;
// Detecting the keypress is pretty hacky :(
if (Input.GetKeyDown(GameSettings.QUICKLOAD.primary) || Input.GetKeyDown(GameSettings.QUICKLOAD.secondary))
{
if (!Input.GetKey(KeyCode.LeftAlt) && !Input.GetKey(KeyCode.RightAlt))
{
if (keyWasReleased)
{
if (Time.time - lastBackupTime > 10)
{
ScreenMessages.PostScreenMessage("Saving pre_quickload.sfs.", 1.5f, ScreenMessageStyle.UPPER_RIGHT);
GamePersistence.SaveGame("pre_quickload", HighLogic.SaveFolder, SaveMode.OVERWRITE);
keyWasReleased = false;
lastBackupTime = Time.time;
}
}
}
}
// Unfortunately, GetKeyDown resets when the quicksave is loaded, so we have to detect
// the key release ourselves.
if (!Input.GetKey(GameSettings.QUICKLOAD.primary) && !Input.GetKey(GameSettings.QUICKLOAD.secondary))
{
keyWasReleased = true;
}
}
}
}