Skip to content

Commit

Permalink
Successful version 1
Browse files Browse the repository at this point in the history
  • Loading branch information
ProgrammerFailure committed Aug 2, 2024
1 parent 20ac1a9 commit 29c9420
Show file tree
Hide file tree
Showing 11 changed files with 32 additions and 36 deletions.
10 changes: 7 additions & 3 deletions BeamedPowerReceiver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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";
Expand Down
12 changes: 8 additions & 4 deletions BeamedPowerReflector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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");

Expand All @@ -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";
Expand Down
10 changes: 8 additions & 2 deletions BeamedPowerSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<ConfigNode>();
Fields["CoreTemp"].guiUnits = "K/" + maxCoreTemp.ToString() + "K";
Expand Down Expand Up @@ -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")]
Expand Down
1 change: 1 addition & 0 deletions ReceivedPower.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ namespace BeamedPowerStandalone
{
public class ReceivedPower
{

PlanetOcclusion occlusion = new PlanetOcclusion();
VesselFinder vesselFinder = new VesselFinder();
RelativisticEffects relativistic = new RelativisticEffects();
Expand Down
24 changes: 1 addition & 23 deletions Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 7 additions & 4 deletions VesselModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Binary file modified bin/Debug/BeamedPowerStandalone.dll
Binary file not shown.
Binary file modified bin/Debug/BeamedPowerStandalone.pdb
Binary file not shown.
Binary file modified obj/Debug/BeamedPowerStandalone.csproj.AssemblyReference.cache
Binary file not shown.
Binary file modified obj/Debug/BeamedPowerStandalone.dll
Binary file not shown.
Binary file modified obj/Debug/BeamedPowerStandalone.pdb
Binary file not shown.

0 comments on commit 29c9420

Please sign in to comment.