-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6a503a7
commit 6af0734
Showing
3 changed files
with
83 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
using System; | ||
|
||
using UnityEngine; | ||
|
||
namespace RealScience.Conditions | ||
{ | ||
class RealScienceCondition_Part : RealScienceCondition | ||
{ | ||
// common properties | ||
public string conditionType = "Part"; | ||
public bool restriction = false; | ||
public string exclusion = ""; | ||
public float dataRateModifier = 1f; | ||
// specific properties | ||
public string requiredPartName; | ||
|
||
public override float DataRateModifier | ||
{ | ||
get { return dataRateModifier; } | ||
} | ||
public override bool IsRestriction | ||
{ | ||
get { return restriction; } | ||
} | ||
public override string Exclusion | ||
{ | ||
get { return exclusion; } | ||
} | ||
|
||
public override bool Evaluate(Part part, float deltaTime) | ||
{ | ||
foreach(Part vPart in part.vessel.Parts) | ||
{ | ||
if (vPart.partName.ToLower() == requiredPartName) | ||
return true; | ||
} | ||
return false; | ||
} | ||
public override void Load(ConfigNode node) | ||
{ | ||
// Load common properties | ||
if (node.HasValue("conditionType")) | ||
conditionType = node.GetValue("conditionType"); | ||
if (node.HasValue("exclusion")) | ||
exclusion = node.GetValue("exclusion"); | ||
if (node.HasValue("restriction")) | ||
{ | ||
try | ||
{ | ||
restriction = bool.Parse(node.GetValue("restriction")); | ||
} | ||
catch (FormatException) | ||
{ | ||
restriction = false; | ||
} | ||
} | ||
if (node.HasValue("dataRateModifier")) | ||
{ | ||
try | ||
{ | ||
dataRateModifier = float.Parse(node.GetValue("dataRateModifier")); | ||
} | ||
catch (FormatException) | ||
{ | ||
dataRateModifier = 1f; | ||
} | ||
} | ||
// Load specific properties | ||
if (node.HasValue("requiredPartName")) | ||
requiredPartName = node.GetValue("requiredPartName"); | ||
} | ||
public override void Save(ConfigNode node) | ||
{ | ||
// Save common properties | ||
node.AddValue("conditionType", conditionType); | ||
node.AddValue("restriction", restriction); | ||
node.AddValue("exclusion", exclusion); | ||
node.AddValue("dataRateModifier", dataRateModifier); | ||
node.AddValue("requiredPartName", requiredPartName); | ||
} | ||
} | ||
} |
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