Skip to content

Commit

Permalink
Merge pull request #9 from frencrs/master
Browse files Browse the repository at this point in the history
Adding in scaleNodes option for config SCALETYPE
  • Loading branch information
Biotronic committed Sep 20, 2014
2 parents 9154ffc + b52abd6 commit 72ec6c3
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
17 changes: 15 additions & 2 deletions Scale.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ public class TweakScale : PartModule, IPartCostModifier
/// The scale exponentValue array. If isFreeScale is false, the part may only be one of these scales.
/// </summary>
protected float[] scaleFactors = { 0.625f, 1.25f, 2.5f, 3.75f, 5f };

/// <summary>
/// The node scale array. If node scales are defined the nodes will be resized to these values.
///</summary>
protected int[] scaleNodes = { };

/// <summary>
/// The unmodified prefab part. From this, default values are found.
Expand Down Expand Up @@ -215,6 +220,7 @@ private void SetupFromConfig(ScaleConfig config)
if (scaleFactors.Length > 0)
{
scaleFactors = config.scaleFactors;
scaleNodes = config.scaleNodes;
options.options = config.scaleNames;
}
}
Expand Down Expand Up @@ -316,8 +322,15 @@ private void rescaleNode(AttachNode node, AttachNode baseNode)
}
else
{
var options = (UI_ChooseOption)this.Fields["tweakName"].uiControlEditor;
node.size = (int)(baseNode.size + (tweakName - Tools.ClosestIndex(defaultScale, config.allScaleFactors)) / (float)config.allScaleFactors.Length * 5);
var options = (UI_ChooseOption)this.Fields["tweakName"].uiControlEditor;
if (scaleNodes.Length > 0)
{
node.size = (int)(baseNode.size + (1 * scaleNodes[tweakName]));
}
else
{
node.size = (int)(baseNode.size + (tweakName - Tools.ClosestIndex(defaultScale, config.allScaleFactors)) / (float)config.allScaleFactors.Length * 5);
}
}
if (node.size < 0)
{
Expand Down
11 changes: 11 additions & 0 deletions ScaleConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ public static ScaleConfig[] AllConfigs
private static ScaleConfig defaultConfig = new ScaleConfig();

private float[] _scaleFactors = { 0.625f, 1.25f, 2.5f, 3.75f, 5f };
private int[] _scaleNodes = { };
private string[] _scaleNames = { "62.5cm", "1.25m", "2.5m", "3.75m", "5m" };
public Dictionary<string, ScaleExponents> exponents = new Dictionary<string, ScaleExponents>();

Expand Down Expand Up @@ -119,6 +120,14 @@ public string[] scaleNames
return result;
}
}

public int[] scaleNodes
{
get
{
return _scaleNodes;
}
}

private ScaleConfig()
{
Expand All @@ -139,6 +148,7 @@ public ScaleConfig(ConfigNode config)
maxValue = Tools.ConfigValue(config, "maxScale", defaultValue: source.maxValue);
suffix = Tools.ConfigValue(config, "suffix", defaultValue: source.suffix);
_scaleFactors = Tools.ConfigValue(config, "scaleFactors", defaultValue: source._scaleFactors);
_scaleNodes = Tools.ConfigValue(config, "scaleNodes", defaultValue: source._scaleNodes);
_scaleNames = Tools.ConfigValue(config, "scaleNames", defaultValue: source._scaleNames).Select(a => a.Trim()).ToArray();
techRequired = Tools.ConfigValue(config, "techRequired", defaultValue: source.techRequired).Select(a=>a.Trim()).ToArray();
name = Tools.ConfigValue(config, "name", defaultValue: "unnamed scaletype");
Expand Down Expand Up @@ -168,6 +178,7 @@ public override string ToString()
string result = "ScaleConfig {\n";
result += " isFreeScale = " + isFreeScale.ToString() + "\n";
result += " scaleFactors = " + scaleFactors.ToString() + "\n";
result += " scaleNodes = " + scaleNodes.ToString() + "\n";
result += " minValue = " + minValue.ToString() + "\n";
result += " maxValue = " + maxValue.ToString() + "\n";
return result + "}";
Expand Down

0 comments on commit 72ec6c3

Please sign in to comment.