Version 0.9.22 0.9.22
[VOID.git] / VOID_Core.cs
blob:a/VOID_Core.cs -> blob:b/VOID_Core.cs
--- a/VOID_Core.cs
+++ b/VOID_Core.cs
@@ -1,34 +1,44 @@
+// VOID
 //
-//  VOID_Core.cs
+// VOID_Core.cs
 //
-//  Author:
-//       toadicus <>
+// Copyright © 2014, toadicus
+// All rights reserved.
 //
-//  Copyright (c) 2013 toadicus
+// Redistribution and use in source and binary forms, with or without modification,
+// are permitted provided that the following conditions are met:
 //
-//  This program is free software: you can redistribute it and/or modify
-//  it under the terms of the GNU General Public License as published by
-//  the Free Software Foundation, either version 3 of the License, or
-//  (at your option) any later version.
+// 1. Redistributions of source code must retain the above copyright notice,
+//    this list of conditions and the following disclaimer.
 //
-//  This program is distributed in the hope that it will be useful,
-//  but WITHOUT ANY WARRANTY; without even the implied warranty of
-//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-//  GNU General Public License for more details.
+// 2. Redistributions in binary form must reproduce the above copyright notice,
+//    this list of conditions and the following disclaimer in the documentation and/or other
+//    materials provided with the distribution.
 //
-//  You should have received a copy of the GNU General Public License
-//  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+// 3. Neither the name of the copyright holder nor the names of its contributors may be used
+//    to endorse or promote products derived from this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+using Engineer.VesselSimulator;
+using KSP;
 using System;
 using System.Collections.Generic;
 using System.Linq;
-using KSP;
+using ToadicusTools;
 using UnityEngine;
-using Engineer.VesselSimulator;
 
 namespace VOID
 {
 	public class VOID_Core : VOID_Module, IVOID_Module
 	{
+		#region Singleton Members
 		/*
 		 * Static Members
 		 * */
@@ -63,13 +73,15 @@
 			_instance = null;
 			_initialized = false;
 		}
+		#endregion
 
 		public static double Constant_G = 6.674e-11;
+
 		/*
 		 * Fields
 		 * */
 		protected string VoidName = "VOID";
-		protected string VoidVersion = "0.9.22";
+		protected string VoidVersion = "0.11.0";
 
 		protected bool _factoryReset = false;
 
@@ -127,6 +139,9 @@
 		protected VOID_SaveValue<double> _updatePeriod = 1001f / 15000f;
 		protected float _updateTimer = 0f;
 		protected string stringFrequency;
+
+		[AVOID_SaveValue("vesselSimActive")]
+		protected VOID_SaveValue<bool> vesselSimActive;
 
 		// Vessel Type Housekeeping
 		protected List<VesselType> _allVesselTypes = new List<VesselType>();
@@ -302,7 +317,7 @@
 		{
 			get
 			{
-				return _UseToolbarManager;
+				return _UseToolbarManager & ToolbarManager.ToolbarAvailable;
 			}
 			set
 			{
@@ -463,11 +478,15 @@
 		{
 			this.LoadBeforeUpdate();
 
-			if (this.vessel != null)
-			{
-				SimManager.Instance.Gravity = VOID_Core.Instance.vessel.mainBody.gravParameter /
+			if (this.vessel != null && this.vesselSimActive)
+			{
+				SimManager.Gravity = VOID_Core.Instance.vessel.mainBody.gravParameter /
 					Math.Pow(VOID_Core.Instance.vessel.Radius(), 2);
-				SimManager.Instance.TryStartSimulation();
+				SimManager.TryStartSimulation();
+			}
+			else if (!this.vesselSimActive)
+			{
+				SimManager.ClearResults();
 			}
 
 			if (!this.guiRunning)
@@ -613,6 +632,9 @@
 
 			this.UseToolbarManager = GUILayout.Toggle(this.UseToolbarManager, "Use Blizzy's Toolbar If Available");
 
+			this.vesselSimActive.value = GUILayout.Toggle(this.vesselSimActive.value,
+				"Enable Engineering Calculations");
+
 			GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true));
 
 			GUILayout.Label("Skin:", GUILayout.ExpandWidth(false));
@@ -858,6 +880,12 @@
 
 		protected void InitializeToolbarButton()
 		{
+			// Do nothing if the Toolbar is not available.
+			if (!ToolbarManager.ToolbarAvailable)
+			{
+				return;
+			}
+
 			this.ToolbarButton = ToolbarManager.Instance.add(this.VoidName, "coreToggle");
 			this.ToolbarButton.Text = this.VoidName;
 			this.SetIconTexture(this.powerState | this.activeState);
@@ -973,6 +1001,8 @@
 			this.VOIDIconOffInactivePath = "VOID/Textures/void_icon_light";
 			this.VOIDIconOffActivePath = "VOID/Textures/void_icon_dark";
 
+			this.vesselSimActive = true;
+
 			this.UseToolbarManager = false;
 
 			this.LoadConfig();
@@ -999,19 +1029,11 @@
 			}
 		}
 
-		public static Engineer.VesselSimulator.SimManager simManager
-		{
-			get
-			{
-				return Engineer.VesselSimulator.SimManager.Instance;
-			}
-		}
-
 		public static double KerbinGee
 		{
 			get
 			{
-				return core.Kerbin.gravParameter / Math.Pow(core.Kerbin.Radius, 2);
+				return core.Kerbin.gravParameter / (core.Kerbin.Radius * core.Kerbin.Radius);
 			}
 		}
 	}