Skip to content

Commit

Permalink
Support RemoteTech Antennas in Automation (#119)
Browse files Browse the repository at this point in the history
* Support RemoteTech antennas in Automation

* Added support for unloaded vessel

* Undo changes to Kerbalism.csproj
  • Loading branch information
MartinDomig authored and steamport committed Jul 9, 2018
1 parent b40acc3 commit 3363174
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 1 deletion.
3 changes: 2 additions & 1 deletion GameData/Kerbalism/Localization/de.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,8 @@ Localization
#KERBALISM_Generic_OFF = Aus
#KERBALISM_Generic_ENABLED = Aktiviert
#KERBALISM_Generic_DISABLED = Deaktiviert
#KERBALISM_Generic_ACTIVE = Aktiv
#KERBALISM_Generic_ACTIVE = Aktiv
#KERBALISM_Generic_INACTIVE = Inaktiv
#KERBALISM_Generic_ALWAYSON = immer An
#KERBALISM_Generic_RECORDING = nimmt auf
#KERBALISM_Generic_STOPPED = Angehalten
Expand Down
1 change: 1 addition & 0 deletions GameData/Kerbalism/Localization/en-us.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ Localization
#KERBALISM_Generic_ENABLED = enabled
#KERBALISM_Generic_DISABLED = disabled
#KERBALISM_Generic_ACTIVE = active
#KERBALISM_Generic_INACTIVE = inactive
#KERBALISM_Generic_ALWAYSON = always on
#KERBALISM_Generic_RECORDING = recording
#KERBALISM_Generic_STOPPED = stopped
Expand Down
4 changes: 4 additions & 0 deletions src/Automation/Computer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,8 @@ public void Automate(Vessel v, Vessel_info vi, Vessel_resources resources)
case "ModuleMultiPointSurfaceLight": dev = new LightDevice(m as ModuleLight); break;
case "SCANsat": dev = new ScannerDevice(m); break;
case "ModuleSCANresourceScanner": dev = new ScannerDevice(m); break;
case "ModuleRTAntenna": dev = new RemoteTechAntennaDevice(m); break;
case "ModuleRTAntennaPassive": dev = new RemoteTechAntennaDevice(m); break;
default: continue;
}

Expand Down Expand Up @@ -316,6 +318,8 @@ public void Automate(Vessel v, Vessel_info vi, Vessel_resources resources)
case "ModuleMultiPointSurfaceLight": dev = new ProtoLightDevice(m, p.flightID); break;
case "SCANsat": dev = new ProtoScannerDevice(m, part_prefab, v, p.flightID); break;
case "ModuleSCANresourceScanner": dev = new ProtoScannerDevice(m, part_prefab, v, p.flightID); break;
case "ModuleRTAntenna": dev = new ProtoRemoteTechAntennaDevice(m, module_prefab, v, p.flightID); break;
case "ModuleRTAntennaPassive": dev = new ProtoRemoteTechAntennaDevice(m, module_prefab, v, p.flightID); break;
default: continue;
}

Expand Down
91 changes: 91 additions & 0 deletions src/Automation/Devices/RemoteTechAntenna.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
using System;
using System.Collections.Generic;
using UnityEngine;
using KSP.Localization;


namespace KERBALISM
{

public sealed class RemoteTechAntennaDevice : Device
{
public RemoteTechAntennaDevice(PartModule antenna)
{
this.antenna = antenna;
}

public override string Name()
{
return "antenna";
}

public override uint Part()
{
return antenna.part.flightID;
}

public override string Info()
{
return Lib.ReflectionValue<bool>(antenna, "IsRTActive")
? "<color=cyan>" + Localizer.Format("#KERBALISM_Generic_ACTIVE") + "</color>"
: "<color=red>" + Localizer.Format("#KERBALISM_Generic_INACTIVE") + "</color>";
}

public override void Ctrl(bool value)
{
Lib.ReflectionValue(antenna, "IsRTActive", value);
}

public override void Toggle()
{
Ctrl(!Lib.ReflectionValue<bool>(antenna, "IsRTActive"));
}

PartModule antenna;
}

public sealed class ProtoRemoteTechAntennaDevice : Device
{
public ProtoRemoteTechAntennaDevice(ProtoPartModuleSnapshot antenna, PartModule module_prefab, Vessel v, uint part_id)
{
this.antenna = antenna;
this.module_prefab = module_prefab;
this.vessel = v;
this.part_id = part_id;
}

public override string Name()
{
return "antenna";
}

public override uint Part()
{
return part_id;
}

public override string Info()
{
return Lib.Proto.GetBool(antenna, "IsRTActive")
? "<color=cyan>" + Localizer.Format("#KERBALISM_Generic_ACTIVE") + "</color>"
: "<color=red>" + Localizer.Format("#KERBALISM_Generic_INACTIVE") + "</color>";
}

public override void Ctrl(bool value)
{
Lib.Proto.Set(antenna, "IsRTActive", value);
}

public override void Toggle()
{
Ctrl(!Lib.Proto.GetBool(antenna, "IsRTActive"));
}

private readonly ProtoPartModuleSnapshot antenna;
private readonly PartModule module_prefab;
private readonly Vessel vessel;
private readonly uint part_id;
}

} // KERBALISM

0 comments on commit 3363174

Please sign in to comment.