This repository has been archived by the owner on Feb 10, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
QS_SpaceCenter.cs
125 lines (112 loc) · 4.27 KB
/
QS_SpaceCenter.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/*
QuickStart
Copyright 2016 Malah
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
using System.Collections;
using System.IO;
using UnityEngine;
namespace QuickStart {
public partial class QSpaceCenter {
public bool Ready = false;
public static QSpaceCenter Instance {
get;
private set;
}
private void Awake() {
if (QLoading.Ended) {
QuickStart.Warning ("Reload? Destroy.", "QSpaceCenter");
Destroy (this);
return;
}
if (Instance != null) {
QuickStart.Warning ("There's already an Instance", "QSpaceCenter");
Destroy (this);
return;
}
Instance = this;
QuickStart.Log ("Awake", "QSpaceCenter");
}
private void Start() {
InputLockManager.RemoveControlLock("applicationFocus");
if (!QSettings.Instance.Enabled || QSettings.Instance.gameScene == (int)GameScenes.SPACECENTER) {
QuickStart.Log ("Not need to keep it loaded.", "QSpaceCenter");
QLoading.Ended = true;
Destroy (this);
return;
}
StartCoroutine (QStart ());
QuickStart.Log ("Start", "QSpaceCenter");
}
private IEnumerator QStart() {
while (!Ready || !QuickStart_Persistent.Ready) {
yield return 0;
}
yield return new WaitForEndOfFrame ();
yield return new WaitForSecondsRealtime (QSettings.Instance.WaitLoading);
yield return new WaitForEndOfFrame ();
QuickStart.Log ("SpaceCenter Loaded", "QSpaceCenter");
if (QSettings.Instance.gameScene == (int)GameScenes.FLIGHT) {
string _saveGame = GamePersistence.SaveGame (HighLogic.CurrentGame, QSaveGame.File, HighLogic.SaveFolder, SaveMode.OVERWRITE);
if (!string.IsNullOrEmpty (QuickStart_Persistent.vesselID)) {
int _idx = HighLogic.CurrentGame.flightState.protoVessels.FindLastIndex (pv => pv.vesselID == QuickStart_Persistent.VesselID);
if (_idx != -1) {
QuickStart.Log (string.Format("StartAndFocusVessel: {0}({1})[{2}] idx: {3}", QSaveGame.vesselName, QSaveGame.vesselType, QuickStart_Persistent.vesselID, _idx), "QSpaceCenter");
FlightDriver.StartAndFocusVessel (_saveGame, _idx);
} else {
QuickStart.Warning ("QStart: invalid idx", "QSpaceCenter");
DestroyThis ();
}
} else {
QuickStart.Warning ("QStart: No vessel found", "QSpaceCenter");
DestroyThis ();
}
}
if (QSettings.Instance.gameScene == (int)GameScenes.TRACKSTATION) {
HighLogic.LoadScene (GameScenes.LOADINGBUFFER);
HighLogic.LoadScene (GameScenes.TRACKSTATION);
InputLockManager.ClearControlLocks ();
QuickStart.Log ("Goto Tracking Station", "QSpaceCenter");
DestroyThis ();
}
if (QSettings.Instance.gameScene == (int)GameScenes.EDITOR) {
if (QSettings.Instance.enableEditorLoadAutoSave && File.Exists (QuickStart_Persistent.shipPath)) {
EditorDriver.StartAndLoadVessel(QuickStart_Persistent.shipPath, (EditorFacility)QSettings.Instance.editorFacility);
QuickStart.Log ("StartAndLoadVessel: " + QuickStart_Persistent.shipPath, "QSpaceCenter");
} else {
EditorDriver.StartupBehaviour = EditorDriver.StartupBehaviours.START_CLEAN;
EditorDriver.StartEditor((EditorFacility)QSettings.Instance.editorFacility);
QuickStart.Log ("StartEditor", "QSpaceCenter");
}
InputLockManager.ClearControlLocks ();
QuickStart.Log ("Goto " + (QSettings.Instance.editorFacility == (int)EditorFacility.VAB ? "Vehicle Assembly Building" : "Space Plane Hangar"), "QSpaceCenter");
DestroyThis ();
}
Destroy (this);
yield break;
}
private void LateUpdate() {
if (!Ready) {
QuickStart.Log ("Ready", "QSpaceCenter");
Ready = true;
}
}
private void OnDestroy() {
QuickStart.Log ("OnDestroy", "QSpaceCenter");
}
private void DestroyThis() {
QuickStart.Log ("DestroyThis", "QSpaceCenter");
QLoading.Ended = true;
Destroy (this);
}
}
}