-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from artwhaley/AlarmClk
Alarm clock
- Loading branch information
Showing
4 changed files
with
369 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using KRPC.Service.Attributes; | ||
using KRPC.SpaceCenter.ExtensionMethods; | ||
using KRPC.Utils; | ||
|
||
namespace KRPC.SpaceCenter.Services | ||
{ | ||
/// <summary> | ||
/// An Alarm. Can be accessed using <see cref="SpaceCenter.AlarmClock"/>. | ||
/// </summary> | ||
[KRPCClass(Service = "SpaceCenter")] | ||
public class Alarm : Equatable<Alarm> | ||
{ | ||
/// <summary> | ||
/// Create a alarm object from a KSP alarmTypeBase | ||
/// </summary> | ||
public Alarm(AlarmTypeBase alarm) | ||
{ | ||
InternalAlarm = alarm; | ||
} | ||
|
||
/// <summary> | ||
/// The KSP Alarm | ||
/// </summary> | ||
public AlarmTypeBase InternalAlarm { get; private set; } | ||
|
||
/// <summary> | ||
/// Returns true if the objects are equal. | ||
/// </summary> | ||
public override bool Equals(Alarm other) | ||
{ | ||
return !ReferenceEquals(other, null) && InternalAlarm.Id == other.InternalAlarm.Id; //Interna.ContractID == other.InternalContract.ContractID; | ||
} | ||
|
||
/// <summary> | ||
/// Hash code for the object. | ||
/// </summary> | ||
public override int GetHashCode() | ||
{ | ||
return InternalAlarm.GetHashCode(); | ||
} | ||
|
||
/// <summary> | ||
/// Type of Alarm | ||
/// </summary> | ||
[KRPCProperty] | ||
public string Type | ||
{ | ||
get { UdateAlarm(); return InternalAlarm.TypeName; } | ||
} | ||
|
||
/// <summary> | ||
/// Title of the Alarm | ||
/// </summary> | ||
[KRPCProperty] | ||
public string Title | ||
{ | ||
get { UdateAlarm(); return InternalAlarm.title; } | ||
|
||
|
||
} | ||
|
||
/// <summary> | ||
/// Description of the contract. | ||
/// </summary> | ||
[KRPCProperty] | ||
public string Description | ||
{ | ||
get { UdateAlarm(); return InternalAlarm.description; } | ||
} | ||
|
||
/// <summary> | ||
/// Time the Alarm will trigger | ||
/// </summary> | ||
[KRPCProperty] | ||
public double UT | ||
{ | ||
get { UdateAlarm(); return InternalAlarm.ut; } | ||
} | ||
|
||
/// <summary> | ||
/// Time until the alarm triggers | ||
/// </summary> | ||
[KRPCProperty] | ||
public double TimeTill | ||
{ | ||
get { UdateAlarm(); return InternalAlarm.TimeToAlarm; } | ||
} | ||
|
||
/// <summary> | ||
/// Seconds betwen the alarm going off and the event it references | ||
/// </summary> | ||
[KRPCProperty] | ||
public double EventOffset | ||
{ | ||
get { UdateAlarm(); return InternalAlarm.eventOffset; } | ||
} | ||
|
||
/// <summary> | ||
/// Vessel the alarm references | ||
/// </summary> | ||
[KRPCProperty(Nullable = true)] | ||
public Vessel Vessel | ||
{ | ||
get | ||
{ | ||
UdateAlarm(); | ||
KRPC.SpaceCenter.Services.Vessel V = new Vessel(InternalAlarm.Vessel); | ||
|
||
|
||
return V; | ||
} | ||
} | ||
|
||
|
||
/// <summary> | ||
/// Unique ID of alarm | ||
/// KSP destroys an old alarm and creates a new one each time an alarm is edited. | ||
/// This ID will remain constant between the old and new alarms though, so this is the value | ||
/// you want to store and each time you want to access an alarm, get the current alarm with the | ||
/// correct ID value. | ||
/// </summary> | ||
[KRPCProperty(Nullable = true)] | ||
public int ID | ||
{ | ||
get | ||
{ | ||
UdateAlarm(); | ||
return (int)InternalAlarm.Id; | ||
} | ||
} | ||
|
||
|
||
public void UdateAlarm() | ||
{ | ||
AlarmTypeBase newalarm; | ||
AlarmClockScenario.TryGetAlarm(InternalAlarm.Id, out newalarm); | ||
InternalAlarm = newalarm; | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,215 @@ | ||
using System.Collections.Generic; | ||
using System.Diagnostics.CodeAnalysis; | ||
using System.Linq; | ||
using KRPC.Service.Attributes; | ||
using KRPC.Utils; | ||
|
||
namespace KRPC.SpaceCenter.Services | ||
{ | ||
/// <summary> | ||
/// Contracts manager. | ||
/// Obtained by calling <see cref="SpaceCenter.ContractManager"/>. | ||
/// </summary> | ||
[KRPCClass(Service = "SpaceCenter")] | ||
public class AlarmClock : Equatable<AlarmClock> | ||
{ | ||
internal AlarmClock() | ||
{ | ||
} | ||
|
||
/// <summary> | ||
/// Returns true if the objects are equal. | ||
/// </summary> | ||
public override bool Equals(AlarmClock other) | ||
{ | ||
return !ReferenceEquals(other, null); | ||
} | ||
|
||
/// <summary> | ||
/// Hash code for the object. | ||
/// </summary> | ||
public override int GetHashCode() | ||
{ | ||
return 0; | ||
} | ||
|
||
/// <summary> | ||
/// Make a Simple Alarm | ||
/// Parameter 'time' is the number of seconds from now that the alarm should trigger. | ||
/// </summary> | ||
[KRPCMethod] | ||
public Alarm MakeRawAlarm(double time, string title="Raw Alarm", string description = "") | ||
{ | ||
AlarmTypeRaw alarm = new AlarmTypeRaw | ||
{ | ||
title = title, | ||
description = description, | ||
actions = | ||
{ | ||
warp = AlarmActions.WarpEnum.KillWarp, | ||
message = AlarmActions.MessageEnum.Yes | ||
}, | ||
ut = Planetarium.GetUniversalTime() + time | ||
}; | ||
AlarmClockScenario.AddAlarm(alarm); | ||
return new Alarm(alarm); | ||
} | ||
|
||
/// <summary> | ||
/// Make a Simple Alarm linked to a Vessel | ||
/// Parameter 'time' is the number of seconds from now that the alarm should trigger. | ||
/// </summary> | ||
[KRPCMethod] | ||
public Alarm MakeRawAlarmVessel(double time, Vessel V, string title="Raw Alarm", string description="") | ||
{ | ||
AlarmTypeRaw alarm = new AlarmTypeRaw | ||
{ | ||
title = title, | ||
description = description, | ||
ut = Planetarium.GetUniversalTime() + time, | ||
actions = | ||
{ | ||
warp = AlarmActions.WarpEnum.KillWarp, | ||
message = AlarmActions.MessageEnum.Yes | ||
}, | ||
vesselId = V.InternalVessel.persistentId | ||
}; | ||
AlarmClockScenario.AddAlarm(alarm); | ||
return new Alarm(alarm); | ||
} | ||
|
||
|
||
/// <summary> | ||
/// Create an alarm for the given vessel's next Apoapsis | ||
/// </summary> | ||
[KRPCMethod] | ||
public Alarm MakeApaAlarm(Vessel V, double offset = 60, string title="APA Alarm", string description="") | ||
{ | ||
AlarmTypeApoapsis alarm = new AlarmTypeApoapsis | ||
{ | ||
title = title, | ||
description = description, | ||
eventOffset = offset, | ||
actions = | ||
{ | ||
warp = AlarmActions.WarpEnum.KillWarp, | ||
message = AlarmActions.MessageEnum.Yes | ||
}, | ||
vesselId = V.InternalVessel.persistentId | ||
}; | ||
AlarmClockScenario.AddAlarm(alarm); | ||
return new Alarm(alarm); | ||
} | ||
|
||
/// <summary> | ||
/// Create an alarm for the given vessel's next Periapsis | ||
/// </summary> | ||
[KRPCMethod] | ||
public Alarm MakePeaAlarm(Vessel V, double offset = 60, string title="PEA Alarm", string description = "") | ||
{ | ||
AlarmTypePeriapsis alarm = new AlarmTypePeriapsis | ||
{ | ||
title = title, | ||
description = description, | ||
actions = | ||
{ | ||
warp = AlarmActions.WarpEnum.KillWarp, | ||
message = AlarmActions.MessageEnum.Yes | ||
}, | ||
vesselId = V.InternalVessel.persistentId | ||
}; | ||
alarm.eventOffset = offset; | ||
AlarmClockScenario.AddAlarm(alarm); | ||
return new Alarm(alarm); | ||
} | ||
|
||
/// <summary> | ||
/// Create an alarm for the given vessel and maneuver node | ||
/// </summary> | ||
[KRPCMethod] | ||
public Alarm MakeManeuverAlarm(Vessel V, Node Man, double offset = 60, bool AddBurnTime = true, string title="Maneuver Alarm", string description="" ) | ||
{ | ||
AlarmTypeManeuver alarm = new AlarmTypeManeuver | ||
{ | ||
title = title, | ||
description = description, | ||
eventOffset = offset, | ||
useBurnTimeMargin = AddBurnTime, | ||
actions = | ||
{ | ||
warp = AlarmActions.WarpEnum.KillWarp, | ||
message = AlarmActions.MessageEnum.Yes | ||
}, | ||
vesselId = V.InternalVessel.persistentId, | ||
Maneuver = Man.InternalNode | ||
}; | ||
|
||
AlarmClockScenario.AddAlarm(alarm); | ||
return new Alarm(alarm); | ||
} | ||
|
||
/// <summary> | ||
/// Create an alarm for the given vessel's next SOI change | ||
/// </summary> | ||
[KRPCMethod] | ||
public Alarm MakeSOIAlarm(Vessel V, double offset = 60, string title="SOI Change", string description="" ) | ||
{ | ||
AlarmTypeSOI alarm = new AlarmTypeSOI | ||
{ | ||
title = title, | ||
description = description, | ||
eventOffset = offset, | ||
actions = | ||
{ | ||
warp = AlarmActions.WarpEnum.KillWarp, | ||
message = AlarmActions.MessageEnum.Yes | ||
}, | ||
vesselId = V.InternalVessel.persistentId | ||
}; | ||
AlarmClockScenario.AddAlarm(alarm); | ||
return new Alarm(alarm); | ||
} | ||
|
||
//Not working - to be dealt with later | ||
///// <summary> | ||
///// Create an alarm for the given vessel's next transfer window | ||
///// </summary> | ||
//[KRPCMethod] | ||
//public Alarm MakeWindowAlarm(Vessel V, CelestialBody Target, string title="Transfer Window", string description="") | ||
//{ | ||
// AlarmTypeTransferWindow alarm = new AlarmTypeTransferWindow | ||
// { | ||
// title = title, | ||
// description = description, | ||
// actions = | ||
// { | ||
// warp = AlarmActions.WarpEnum.KillWarp, | ||
// message = AlarmActions.MessageEnum.Yes | ||
// }, | ||
// vesselId = V.InternalVessel.persistentId, | ||
// dest = Target.InternalBody, | ||
// source = V.InternalVessel.orbit.referenceBody | ||
//}; | ||
|
||
// AlarmClockScenario.AddAlarm(alarm); | ||
// return new Alarm(alarm); | ||
//} | ||
|
||
/// <summary> | ||
/// Returns a list of all alarms | ||
/// </summary> | ||
[KRPCMethod] | ||
public IList<Alarm> GetAlarms() | ||
{ | ||
IList<Alarm> Alarms = new List<Alarm>(); | ||
for (int i = 0; i < AlarmClockScenario.Instance.alarms.Count; i++) | ||
{ | ||
AlarmTypeBase a = AlarmClockScenario.Instance.alarms.At(i); | ||
Alarm A = new Alarm(a); | ||
Alarms.Add(A); | ||
|
||
} | ||
return Alarms; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters