diff --git a/BeamedPowerReceiver.cs b/BeamedPowerReceiver.cs index 527af2d..e98ea68 100644 --- a/BeamedPowerReceiver.cs +++ b/BeamedPowerReceiver.cs @@ -7,7 +7,8 @@ namespace BeamedPowerStandalone public class WirelessReceiver : PartModule { // UI-right click menu in flight - static string ManagedResource = ConfigFileReader.DetectedResource; + static string ManagedResource; + static int ResourceHash; [KSPField(guiName = "Power Receiver", isPersistant = true, guiActive = true, guiActiveEditor = false), UI_Toggle(scene = UI_Scene.Flight)] public bool Listening; @@ -49,15 +50,18 @@ public class WirelessReceiver : PartModule public float maxSkinTemp = 1200f; int initFrames; ModuleCoreHeat coreHeat; ReceivedPower receiver; - readonly int ResourceHash = PartResourceLibrary.Instance.GetDefinition(ManagedResource).id; string ExceedTempLimit = Localizer.Format("#LOC_BeamedPower_status_ExceededTempLimit"); string operational = Localizer.Format("#LOC_BeamedPower_status_Operational"); [KSPField(isPersistant = true)] public int counter; - public void Start() { + string ConfigFilePath = KSPUtil.ApplicationRootPath + "GameData/BeamedPowerStandalone/Settings.cfg"; + ConfigNode MainNode; + MainNode = ConfigNode.Load(ConfigFilePath); + ManagedResource = MainNode.GetNode("BPSettings").GetValue("ManagedResource"); + ResourceHash = PartResourceLibrary.Instance.GetDefinition(ManagedResource).id; initFrames = 0; receiver = new ReceivedPower(); Fields["CoreTemp"].guiUnits = "K/" + maxCoreTemp.ToString() + "K"; diff --git a/BeamedPowerReflector.cs b/BeamedPowerReflector.cs index b274963..7050fac 100644 --- a/BeamedPowerReflector.cs +++ b/BeamedPowerReflector.cs @@ -8,7 +8,9 @@ namespace BeamedPowerStandalone public class WirelessReflector : PartModule { // parameters set in part.cfg file - static string ManagedResource = ConfigFileReader.DetectedResource; + + static string ManagedResource; + static int ResourceHash; [KSPField(isPersistant = false)] public float Reflectivity; @@ -82,9 +84,8 @@ public class WirelessReflector : PartModule // declaring frequently used variables VesselFinder vesselFinder = new VesselFinder(); int frames; - readonly int ResourceHash = PartResourceLibrary.Instance.GetDefinition(ManagedResource).id; int initFrames; ModuleCoreHeat coreHeat; ReceivedPower receiver = new ReceivedPower(); double heatModifier; - + int initFrames; string operational = Localizer.Format("#LOC_BeamedPower_status_Operational"); string ExceedTempLimit = Localizer.Format("#LOC_BeamedPower_status_ExceededTempLimit"); @@ -101,9 +102,12 @@ public void ReceiverCounter() receiverCounter += 1; } - // initialise variables public void Start() { + string ConfigFilePath = KSPUtil.ApplicationRootPath + "GameData/BeamedPowerStandalone/Settings.cfg"; + ConfigNode MainNode = ConfigNode.Load(ConfigFilePath); + ManagedResource = MainNode.GetNode("BPSettings").GetValue("ManagedResource"); + ResourceHash = PartResourceLibrary.Instance.GetDefinition(ManagedResource).id; initFrames = 0; frames = 0; Fields["CoreTemp"].guiUnits = "K/" + maxCoreTemp.ToString() + "K"; Fields["SkinTemp"].guiUnits = "K/" + maxSkinTemp.ToString() + "K"; diff --git a/BeamedPowerSource.cs b/BeamedPowerSource.cs index 25ec0c8..bc10c85 100644 --- a/BeamedPowerSource.cs +++ b/BeamedPowerSource.cs @@ -7,7 +7,8 @@ namespace BeamedPowerStandalone { public class WirelessSource : PartModule { - static string ManagedResource = ConfigFileReader.DetectedResource; + static string ManagedResource; + public int ResourceHash; // creating things on part right click menu (flight) [KSPField(guiName = "Power Transmitter", isPersistant = true, guiActive = true, guiActiveEditor = false), UI_Toggle(scene = UI_Scene.Flight)] public bool Transmitting; @@ -60,6 +61,11 @@ public class WirelessSource : PartModule public void Start() { + string ConfigFilePath = KSPUtil.ApplicationRootPath + "GameData/BeamedPowerStandalone/Settings.cfg"; + ConfigNode MainNode = ConfigNode.Load(ConfigFilePath); + ManagedResource = MainNode.GetNode("BPSettings").GetValue("ManagedResource"); + ResourceHash = PartResourceLibrary.Instance.GetDefinition(ManagedResource).id; + Debug.Log(Time.realtimeSinceStartup + ManagedResource); frames = 20; initFrames = 0; receiversList = new List(); Fields["CoreTemp"].guiUnits = "K/" + maxCoreTemp.ToString() + "K"; @@ -112,7 +118,7 @@ public void VesselCounter() } // getting resource id of 'Electric Charge' - public int ResourceHash = PartResourceLibrary.Instance.GetDefinition(ManagedResource).id; + // setting action group capability [KSPAction(guiName = "Toggle Power Transmitter")] diff --git a/ReceivedPower.cs b/ReceivedPower.cs index 24cd63c..6694b35 100644 --- a/ReceivedPower.cs +++ b/ReceivedPower.cs @@ -7,6 +7,7 @@ namespace BeamedPowerStandalone { public class ReceivedPower { + PlanetOcclusion occlusion = new PlanetOcclusion(); VesselFinder vesselFinder = new VesselFinder(); RelativisticEffects relativistic = new RelativisticEffects(); diff --git a/Settings.cs b/Settings.cs index 5e9de73..68e8361 100644 --- a/Settings.cs +++ b/Settings.cs @@ -4,29 +4,7 @@ namespace BeamedPowerStandalone { // instructions for implementing custom difficulty settings were found on '1.2 modders notes' on the forums - [KSPAddon(KSPAddon.Startup.Instantly, false)] - public class ConfigFileReader : MonoBehaviour - { - static readonly string ConfigFilePath = KSPUtil.ApplicationRootPath + "GameData/MyMod/Settings.cfg"; - static ConfigNode Node1; - public static string DetectedResource; - public void Start() - { - Node1 = ConfigNode.Load(ConfigFilePath); - DetectedResource = Node1.GetNode("TestNode").GetValue("DetectedResource"); - } - public void Update() - { - //if (String.IsNullOrEmpty(DetectedResource)) - //{ - // Debug.Log(Time.realtimeSinceStartup + "DetectedResource is empty"); - //} - //else - //{ - // Debug.Log(Time.realtimeSinceStartup + "DetectedResource is: " + DetectedResource); - //} - } - } + public class BPSettings : GameParameters.CustomParameterNode diff --git a/VesselModule.cs b/VesselModule.cs index 2debb5a..48a9d57 100644 --- a/VesselModule.cs +++ b/VesselModule.cs @@ -6,13 +6,16 @@ namespace BeamedPowerStandalone // as vessel modules are processed in the background, this adds background vessel resource management public class BackgroundProcessing : VesselModule { - static string ManagedResource = ConfigFileReader.DetectedResource; + static string ManagedResource; int ResourceHash; int frames; double requestAmount; - + public override void OnLoadVessel() { - base.OnLoadVessel(); - ResourceHash = PartResourceLibrary.Instance.GetDefinition(ManagedResource).id; frames = 0; requestAmount = 0; + string ConfigFilePath = KSPUtil.ApplicationRootPath + "GameData/BeamedPowerStandalone/Settings.cfg"; + ConfigNode MainNode; + MainNode = ConfigNode.Load(ConfigFilePath); + ManagedResource = MainNode.GetNode("BPSettings").GetValue("ManagedResource"); + ResourceHash = PartResourceLibrary.Instance.GetDefinition(ManagedResource).id; } private double LoadVesselPowerData() diff --git a/bin/Debug/BeamedPowerStandalone.dll b/bin/Debug/BeamedPowerStandalone.dll index 0e7df17..050ef8e 100644 Binary files a/bin/Debug/BeamedPowerStandalone.dll and b/bin/Debug/BeamedPowerStandalone.dll differ diff --git a/bin/Debug/BeamedPowerStandalone.pdb b/bin/Debug/BeamedPowerStandalone.pdb index 106da4c..633e7d2 100644 Binary files a/bin/Debug/BeamedPowerStandalone.pdb and b/bin/Debug/BeamedPowerStandalone.pdb differ diff --git a/obj/Debug/BeamedPowerStandalone.csproj.AssemblyReference.cache b/obj/Debug/BeamedPowerStandalone.csproj.AssemblyReference.cache index a22af3f..35933e3 100644 Binary files a/obj/Debug/BeamedPowerStandalone.csproj.AssemblyReference.cache and b/obj/Debug/BeamedPowerStandalone.csproj.AssemblyReference.cache differ diff --git a/obj/Debug/BeamedPowerStandalone.dll b/obj/Debug/BeamedPowerStandalone.dll index 0e7df17..050ef8e 100644 Binary files a/obj/Debug/BeamedPowerStandalone.dll and b/obj/Debug/BeamedPowerStandalone.dll differ diff --git a/obj/Debug/BeamedPowerStandalone.pdb b/obj/Debug/BeamedPowerStandalone.pdb index 106da4c..633e7d2 100644 Binary files a/obj/Debug/BeamedPowerStandalone.pdb and b/obj/Debug/BeamedPowerStandalone.pdb differ