-
Notifications
You must be signed in to change notification settings - Fork 19
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 #34 from KSP-RO/MultiThrustTransform
Allow thrust transforms with different names on the same module
- Loading branch information
Showing
4 changed files
with
149 additions
and
2 deletions.
There are no files selected for viewing
Binary file not shown.
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
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,56 @@ | ||
using System; | ||
|
||
namespace SolverEngines | ||
{ | ||
public class ThrustTransformInfo | ||
{ | ||
public readonly string transformName; | ||
public readonly float overallMultiplier = 1; | ||
public readonly float[] multipliers = null; | ||
|
||
public ThrustTransformInfo(ConfigNode node) | ||
{ | ||
if (node == null) throw new ArgumentNullException(nameof(node)); | ||
|
||
transformName = node.GetValue("name"); | ||
if (string.IsNullOrEmpty(transformName)) throw new ArgumentException("Missing or blank name"); | ||
|
||
string overallMultiplierStr = node.GetValue("overallMultiplier"); | ||
if (!string.IsNullOrEmpty(overallMultiplierStr)) | ||
{ | ||
if (!float.TryParse(overallMultiplierStr, out overallMultiplier)) | ||
{ | ||
throw new ArgumentException("Could not parse overallMultiplier as float: " + overallMultiplierStr); | ||
} | ||
else if (overallMultiplier <= 0) | ||
{ | ||
throw new ArgumentException("overallMultiplier must be positive: " + overallMultiplierStr); | ||
} | ||
} | ||
|
||
if (node.HasValue("multiplier")) | ||
{ | ||
string[] strMultipliers = node.GetValues("multiplier"); | ||
|
||
multipliers = new float[strMultipliers.Length]; | ||
for (int i = 0; i < strMultipliers.Length; i++) | ||
{ | ||
if (!float.TryParse(strMultipliers[i], out multipliers[i])) | ||
{ | ||
throw new ArgumentException("Could not parse multiplier as flooat: " + strMultipliers[i]); | ||
} | ||
else if (multipliers[i] <= 0) | ||
{ | ||
throw new ArgumentException("multiplier must be positive: " + strMultipliers[i]); | ||
} | ||
} | ||
|
||
if (multipliers.Length == 1) | ||
{ | ||
overallMultiplier *= multipliers[0]; | ||
multipliers = null; | ||
} | ||
} | ||
} | ||
} | ||
} |