-
Notifications
You must be signed in to change notification settings - Fork 67
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 #448 from MOARdV/master
Another 0.24.1 pull
- Loading branch information
Showing
12 changed files
with
547 additions
and
100 deletions.
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 |
---|---|---|
|
@@ -5,7 +5,7 @@ | |
"VERSION": { | ||
"MAJOR": 0, | ||
"MINOR": 24, | ||
"PATCH": 0 | ||
"PATCH": 1 | ||
}, | ||
"KSP_VERSION": { | ||
"MAJOR": 1, | ||
|
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
166 changes: 166 additions & 0 deletions
166
RasterPropMonitor/Auxiliary modules/JSIEngineMonitor.cs
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,166 @@ | ||
/***************************************************************************** | ||
* RasterPropMonitor | ||
* ================= | ||
* Plugin for Kerbal Space Program | ||
* | ||
* by Mihara (Eugene Medvedev), MOARdV, and other contributors | ||
* | ||
* RasterPropMonitor 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, revision | ||
* date 29 June 2007, or (at your option) any later version. | ||
* | ||
* RasterPropMonitor 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. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with RasterPropMonitor. If not, see <http://www.gnu.org/licenses/>. | ||
****************************************************************************/ | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace JSI | ||
{ | ||
/// <summary> | ||
/// Provides a module for RasterPropMonitor to use for providing granular | ||
/// control of an engine as well as detailed information. | ||
/// </summary> | ||
class JSIEngineMonitor : PartModule | ||
{ | ||
// Internal data storage. | ||
[KSPField(isPersistant = true)] | ||
public int enginedID = 0; | ||
|
||
// Fields to handle right-click GUI. | ||
[KSPField(guiActive = true, guiActiveEditor = true, guiName = "Engine ID: ")] | ||
public string engineDisplayName; | ||
|
||
[KSPEvent(guiActive = true, guiActiveEditor = true, guiName = "ID +")] | ||
public void IdPlus() | ||
{ | ||
enginedID++; | ||
UpdateName(); | ||
} | ||
|
||
[KSPEvent(guiActive = true, guiActiveEditor = true, guiName = "ID -")] | ||
public void IdMinus() | ||
{ | ||
enginedID--; | ||
if (enginedID <= 0) | ||
enginedID = 0; | ||
UpdateName(); | ||
} | ||
|
||
private void UpdateName() | ||
{ | ||
engineDisplayName = (enginedID > 0) ? enginedID.ToString() : "Untracked"; | ||
} | ||
|
||
private int mmeIndex = -1; | ||
private int engineMode1Index = -1; | ||
private int engineMode2Index = -1; | ||
|
||
public void Start() | ||
{ | ||
if (!HighLogic.LoadedSceneIsFlight) | ||
{ | ||
return; | ||
} | ||
|
||
for(int i=0; i<part.Modules.Count; ++i) | ||
{ | ||
if(part.Modules[i] is MultiModeEngine) | ||
{ | ||
if (mmeIndex == -1) | ||
{ | ||
mmeIndex = i; | ||
JUtil.LogMessage(this, "Start(): mmeIndex = {0}", i); | ||
} | ||
else | ||
{ | ||
JUtil.LogErrorMessage(this, "Found more than one MultiModeEngine on {0} - I don't know what to do with it.", part.name); | ||
} | ||
} | ||
else if(part.Modules[i] is ModuleEngines) | ||
{ | ||
if(engineMode1Index == -1) | ||
{ | ||
engineMode1Index = i; | ||
JUtil.LogMessage(this, "Start(): engineMode1Index = {0}", i); | ||
} | ||
else if(engineMode2Index == -1) | ||
{ | ||
engineMode2Index = i; | ||
JUtil.LogMessage(this, "Start(): engineMode2Index = {0}", i); | ||
} | ||
else | ||
{ | ||
JUtil.LogErrorMessage(this, "Found more than 2 ModuleEngines on {0} - I don't know what to do with them.", part.name); | ||
} | ||
} | ||
} | ||
|
||
if(engineMode1Index == -1) | ||
{ | ||
Destroy(this); | ||
// No engines! | ||
} | ||
UpdateName(); | ||
} | ||
|
||
public void FixedUpdate() | ||
{ | ||
if (HighLogic.LoadedSceneIsEditor) | ||
{ | ||
return; | ||
} | ||
|
||
if (!JUtil.IsActiveVessel(vessel)) | ||
{ | ||
return; | ||
} | ||
} | ||
|
||
public bool GetRunningPrimary() | ||
{ | ||
if(mmeIndex == -1) | ||
{ | ||
return true; | ||
} | ||
else | ||
{ | ||
MultiModeEngine mme = part.Modules[mmeIndex] as MultiModeEngine; | ||
return mme.runningPrimary; | ||
} | ||
} | ||
|
||
public void SetRunningPrimary(bool state) | ||
{ | ||
try | ||
{ | ||
if (mmeIndex > -1) | ||
{ | ||
MultiModeEngine mme = part.Modules[mmeIndex] as MultiModeEngine; | ||
|
||
// There doesn't appear to be a simpler way to switch modes. | ||
// One this I could do is store the even index instead of looping | ||
// over it every time we change modes. | ||
if (mme.runningPrimary != state) | ||
{ | ||
var ev = mme.Events["ModeEvent"]; | ||
if (ev != null) | ||
{ | ||
ev.Invoke(); | ||
} | ||
} | ||
} | ||
} | ||
catch | ||
{ | ||
// no-op | ||
} | ||
} | ||
} | ||
} |
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,100 @@ | ||
/***************************************************************************** | ||
* RasterPropMonitor | ||
* ================= | ||
* Plugin for Kerbal Space Program | ||
* | ||
* by Mihara (Eugene Medvedev), MOARdV, and other contributors | ||
* | ||
* RasterPropMonitor 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, revision | ||
* date 29 June 2007, or (at your option) any later version. | ||
* | ||
* RasterPropMonitor 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. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with RasterPropMonitor. If not, see <http://www.gnu.org/licenses/>. | ||
****************************************************************************/ | ||
using System; | ||
using UnityEngine; | ||
|
||
namespace JSI | ||
{ | ||
class JSINavBall : InternalNavBall | ||
{ | ||
/// <summary> | ||
/// Name of the enabling variable. Required. | ||
/// </summary> | ||
[KSPField] | ||
public string variableName = string.Empty; | ||
|
||
/// <summary> | ||
/// vec2 containing the 'enabled' range. May be numeric or varibles. Required. | ||
/// </summary> | ||
[KSPField] | ||
public string range = string.Empty; | ||
|
||
/// <summary> | ||
/// Maximum angle that the navball can change per second, in degrees. Defaults to 180. | ||
/// </summary> | ||
[KSPField] | ||
public float maxAngleChange = 180.0f; | ||
|
||
private VariableOrNumberRange enablingVariable; | ||
|
||
private Quaternion lastOrientation; | ||
|
||
public override void OnAwake() | ||
{ | ||
base.OnAwake(); | ||
|
||
lastOrientation = navBall.rotation; | ||
|
||
if (string.IsNullOrEmpty(variableName) || string.IsNullOrEmpty(range)) | ||
{ | ||
JUtil.LogErrorMessage(this, "variableName or range was null!"); | ||
return; | ||
} | ||
string[] tokens = range.Split(','); | ||
if (tokens.Length != 2) | ||
{ | ||
JUtil.LogErrorMessage(this, "range '{0}' did not have exactly two values!", range); | ||
return; | ||
} | ||
|
||
enablingVariable = new VariableOrNumberRange(variableName, tokens[0], tokens[1]); | ||
} | ||
|
||
public override void OnUpdate() | ||
{ | ||
if (enablingVariable == null) | ||
{ | ||
return; | ||
} | ||
|
||
RPMVesselComputer comp = RPMVesselComputer.Instance(vessel); | ||
if (enablingVariable.IsInRange(comp)) | ||
{ | ||
base.OnUpdate(); | ||
Quaternion post = navBall.rotation; | ||
float deltaAngle = Quaternion.Angle(lastOrientation, post); | ||
float maxAngle = maxAngleChange * Time.deltaTime; | ||
|
||
// If the rotation angle exceeds what we can do, slow it down | ||
if (deltaAngle > maxAngle) | ||
{ | ||
Quaternion newRotation = Quaternion.Slerp(lastOrientation, post, maxAngle / deltaAngle); | ||
lastOrientation = newRotation; | ||
navBall.rotation = newRotation; | ||
} | ||
else | ||
{ | ||
lastOrientation = post; | ||
} | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.