forked from jbengtson/KSCSwitcher
-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathKSCLoader.cs
82 lines (76 loc) · 2.66 KB
/
KSCLoader.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
namespace regexKSP
{
[KSPAddon(KSPAddon.Startup.MainMenu, false)]
public class ScenarioSpawn : MonoBehaviour
{
void Start()
{
KSCLoader.instance ??= new KSCLoader();
enabled = false;
}
}
public class KSCLoader
{
public static KSCLoader instance = null;
public KSCSiteManager Sites = new KSCSiteManager();
private void OnGameStateCreated(Game game)
{
LastKSC.CreateSettings(game);
if (HighLogic.LoadedScene == GameScenes.SPACECENTER)
{
ProtoScenarioModule m = HighLogic.CurrentGame.scenarios.FirstOrDefault(m => m.moduleName == "LastKSC");
if (m == null) return;
LastKSC l = (LastKSC)m.Load(ScenarioRunner.Instance);
bool noSite;
if (!string.IsNullOrEmpty(l.lastSite))
{
// found a site, load it
ConfigNode site = Sites.GetSiteByName(l.lastSite);
if (site == null)
{
l.lastSite = Sites.defaultSite;
noSite = true;
}
else
{
KSCSwitcher.SetSiteAndResetCamera(site);
Debug.Log("[KSCSwitcher] set the launch site to the last site, " + l.lastSite);
return;
}
}
else
{
l.lastSite = Sites.defaultSite;
noSite = true;
}
if (noSite)
{
if (!string.IsNullOrEmpty(Sites.defaultSite))
{
ConfigNode site = Sites.GetSiteByName(Sites.defaultSite);
if (site == null)
{
Debug.LogError("[KSCSwitcher] found a default site name but could not retrieve the site config: " + Sites.defaultSite);
return;
}
else
{
KSCSwitcher.SetSiteAndResetCamera(site);
Debug.Log("[KSCSwitcher] set the initial launch site to the default" + Sites.defaultSite);
}
}
}
}
}
public KSCLoader()
{
GameEvents.onGameStateCreated.Add(OnGameStateCreated);
}
}
}