public override void OnDecodeFromConfigNode() { Notes = KACUtils.DecodeVarStrings(NotesStorage); AlarmTime = new KSPDateTime(AlarmTimeStorage); if (RepeatAlarmPeriodStorage != 0) { RepeatAlarmPeriod = new KSPTimeSpan(RepeatAlarmPeriodStorage); } //dont try and create a GUID from null or empty :) if (ContractGUIDStorage != null && ContractGUIDStorage != "") { ContractGUID = new Guid(ContractGUIDStorage); } _TargetObject = TargetDeserialize(TargetObjectStorage); ManNodes = ManNodeDeserializeList(ManNodesStorage); }
internal static KACAlarm LoadFromString3(String AlarmDetails, Double CurrentUT) { //String is "VesselID|Name|Notes|AlarmTime.UT|AlarmMarginSecs|Type|Enabled|HaltWarp|PauseGame|ActionedAt|Maneuver|Xfer|Target|Options|<ENDLINE>"); String[] vars = AlarmDetails.Split("|".ToCharArray(), StringSplitOptions.None); MonoBehaviourExtended.LogFormatted("AlarmExtract"); for (int i = 0; i < vars.Length; i++) { MonoBehaviourExtended.LogFormatted("{0}:{1}", i, vars[i]); } String SaveName = HighLogic.CurrentGame.Title; String VesselID = vars[0]; String Name = KACUtils.DecodeVarStrings(vars[1]); String Notes = KACUtils.DecodeVarStrings(vars[2]); Double UT = Convert.ToDouble(vars[3]); Double AlarmMarginSecs = Convert.ToDouble(vars[4]); KACAlarm.AlarmTypeEnum TypeOfAlarm = (KACAlarm.AlarmTypeEnum)Enum.Parse(typeof(KACAlarm.AlarmTypeEnum), vars[5]); Boolean Enabled = Convert.ToBoolean(vars[6]); Boolean HaltWarp = Convert.ToBoolean(vars[7]); Boolean PauseGame = Convert.ToBoolean(vars[8]); Double ActionedAt = Convert.ToDouble(vars[9]); List <ManeuverNode> ManNodes = null; String XferOriginBodyName = "", XferTargetBodyName = ""; ITargetable TargetObject = null; String TargetLoader = ""; Boolean Triggered = false, Actioned = false, AlarmWindowClosed = false; if (vars[10] != "") { ManNodes = ManNodeDeserializeList(vars[10]); } if (vars[11] != "") { try { MonoBehaviourExtended.LogFormatted("{0}", vars[11]); String[] XferParts = vars[11].Split(",".ToCharArray()); XferOriginBodyName = XferParts[0]; XferTargetBodyName = XferParts[1]; } catch (Exception ex) { MonoBehaviourExtended.LogFormatted("Unable to load transfer details for {0}", Name); MonoBehaviourExtended.LogFormatted(ex.Message); } } if (vars[12] != "") { //find the targetable object and set it TargetObject = TargetDeserialize(vars[12]); if (TargetObject == null && vars[12].StartsWith("Vessel,")) { TargetLoader = vars[12]; } } //Now do the work to set Actioned/triggered/etc if needed //LogFormatted("A:{0},T:{1:0},Act:{2:0}", this.Name, CurrentUT, this.ActionedAt); if (ActionedAt > 0 && CurrentUT > ActionedAt) { MonoBehaviourExtended.LogFormatted("Suppressing Alarm on Load:{0}", Name); Triggered = true; Actioned = true; AlarmWindowClosed = true; } else if (ActionedAt > CurrentUT) { MonoBehaviourExtended.LogFormatted("Reenabling Alarm on Load:{0}", Name); Triggered = false; Actioned = false; ActionedAt = 0; AlarmWindowClosed = false; } KACAlarm resultAlarm = new KACAlarm(UT); resultAlarm.Name = Name; resultAlarm.VesselID = VesselID; resultAlarm.Enabled = Enabled; resultAlarm.Notes = Notes; resultAlarm.AlarmMarginSecs = AlarmMarginSecs; resultAlarm.TypeOfAlarm = TypeOfAlarm; if (HaltWarp) { resultAlarm.AlarmAction = KACAlarm.AlarmActionEnum.KillWarp; } else if (PauseGame) { resultAlarm.AlarmAction = KACAlarm.AlarmActionEnum.PauseGame; } if (ManNodes != null) { resultAlarm.ManNodes = ManNodes; } if (TargetObject != null) { resultAlarm.TargetObject = TargetObject; } resultAlarm.TargetLoader = TargetLoader; resultAlarm.XferOriginBodyName = XferOriginBodyName; resultAlarm.XferTargetBodyName = XferTargetBodyName; resultAlarm.Triggered = Triggered; resultAlarm.Actioned = Actioned; resultAlarm.AlarmWindowClosed = AlarmWindowClosed; return(resultAlarm); }
public void LoadFromString3(String AlarmDetails, Double CurrentUT) { //String is "VesselID|Name|Notes|AlarmTime.UT|AlarmMarginSecs|Type|Enabled|HaltWarp|PauseGame|ActionedAt|Manuever|Xfer|Target|Options|<ENDLINE>"); String[] vars = AlarmDetails.Split("|".ToCharArray(), StringSplitOptions.None); this.SaveName = HighLogic.CurrentGame.Title; this.VesselID = vars[0]; this.Name = KACUtils.DecodeVarStrings(vars[1]); this.Notes = KACUtils.DecodeVarStrings(vars[2]); this.AlarmTime.UT = Convert.ToDouble(vars[3]); this.AlarmMarginSecs = Convert.ToDouble(vars[4]); this.TypeOfAlarm = (KACAlarm.AlarmType)Enum.Parse(typeof(KACAlarm.AlarmType), vars[5]); this.Enabled = Convert.ToBoolean(vars[6]); this.HaltWarp = Convert.ToBoolean(vars[7]); this.PauseGame = Convert.ToBoolean(vars[8]); this.ActionedAt = Convert.ToDouble(vars[9]); if (vars[10] != "") { this.ManNodes = ManNodeDeserializeList(vars[10]); } if (vars[11] != "") { try { String[] XferParts = vars[11].Split(",".ToCharArray()); this.XferOriginBodyName = XferParts[0]; this.XferTargetBodyName = XferParts[1]; } catch (Exception ex) { KACWorker.DebugLogFormatted("Unable to load transfer details for {0}", Name); KACWorker.DebugLogFormatted(ex.Message); } } if (vars[12] != "") { //find the targetable object and set it this.TargetObject = TargetDeserialize(vars[12]); if (this.TargetObject == null && vars[12].StartsWith("Vessel,")) { this.TargetLoader = vars[12]; } } //Now do the work to set Actioned/triggered/etc if needed //KACWorker.DebugLogFormatted("A:{0},T:{1:0},Act:{2:0}", this.Name, CurrentUT, this.ActionedAt); if (ActionedAt > 0 && CurrentUT > ActionedAt) { KACWorker.DebugLogFormatted("Suppressing Alarm on Load:{0}", this.Name); this.Triggered = true; this.Actioned = true; this.AlarmWindowClosed = true; } else if (ActionedAt > CurrentUT) { KACWorker.DebugLogFormatted("Reenabling Alarm on Load:{0}", this.Name); this.Triggered = false; this.Actioned = false; this.ActionedAt = 0; this.AlarmWindowClosed = false; } }