-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathCore.cs
112 lines (88 loc) · 3.63 KB
/
Core.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
namespace kOS
{
[KSPAddon(KSPAddon.Startup.Instantly, true)]
public class Core : MonoBehaviour
{
public static VersionInfo VersionInfo = new VersionInfo(1, 0);
public static Core Fetch;
public TermWindow Window;
public void Awake()
{
if (Fetch == null) // Instantiation now happens every time the menu comes up
{
print ("****************** init confirmed");
Fetch = this;
var gObj = new GameObject("kOSTermWindow", typeof(TermWindow));
UnityEngine.Object.DontDestroyOnLoad(gObj);
Window = (TermWindow)gObj.GetComponent(typeof(TermWindow));
Window.Core = this;
}
}
public void SaveSettings()
{
var writer = KSP.IO.BinaryReader.CreateForType<File>(HighLogic.fetch.GameSaveFolder + "/");
}
public static void Debug(String line)
{
}
public static void OpenWindow(CPU cpu)
{
Fetch.Window.AttachTo(cpu);
Fetch.Window.Open();
}
internal static void ToggleWindow(CPU cpu)
{
Fetch.Window.AttachTo(cpu);
Fetch.Window.Toggle();
}
void InjectModules()
{
// This is an extermely hacky solution to getting the mk2 cockpits to have built-in kOS units.
// Basically we wait until the game has started processing parts, but before it's started processing
// the cockpits, and we slip in an extra configNode into them
//GameDatabase.Instance.Recompile = true; // Not needed because we're injecting during original compile
//GameDatabase.Instance.StartLoad();
UnityEngine.Debug.Log("Editing mk2 to include kOS");
var moduleNode = new ConfigNode("MODULE");
moduleNode.AddValue("name", "kOSProcessor");
ConfigNode propNode = new ConfigNode("PROP");
propNode.AddValue("name", "kOSInternalDisplay");
propNode.AddValue("position", "-0.1055,0.202,-0.4557");
propNode.AddValue("rotation", "0.5372996,0,0,0.8433914");
propNode.AddValue("scale", "0.79,1,0.82");
foreach (var d in GameDatabase.Instance.root.AllConfigs)
{
if (d.url == "Squad/SPP/Mk2CockpitStandard/part/mk2Cockpit_Standard" ||
d.url == "Squad/SPP/mk2Cockpit_Inline/part/mk2Cockpit_Inline" ||
d.url == "Squad/Parts/Command/mk2CockpitStandard/mk2CockpitStandard/mk2Cockpit_Standard" ||
d.url == "Squad/Parts/Command/mk2CockpitInline/mk2CockpitInline/mk2Cockpit_Inline")
{
d.config.AddNode(moduleNode);
}
else if (d.url == "Squad/SPP/Mk2CockpitStandardInternal/internal/mk2CockpitStandardInternals" ||
d.url == "Squad/Spaces/mk2CockpitStandardInternal/internal/mk2CockpitStandardInternals")
{
d.config.AddNode(propNode);
}
}
}
private bool hasTriggeredInjectScript = false;
void Update()
{
if (this == Fetch && !hasTriggeredInjectScript && GameDatabase.Instance.root.AllConfigs.Count() > 0)
{
hasTriggeredInjectScript = true;
InjectModules();
}
}
public static Guid lastVessel;
void OnGUI()
{
}
}
}