diff --git a/.gitignore b/.gitignore
index 518d9e39..377a59a1 100644
--- a/.gitignore
+++ b/.gitignore
@@ -14,4 +14,5 @@
/Scale_Editor/bin
/Scale_Editor/obj
/lib
-/Releases
\ No newline at end of file
+/Releases
+/Gamedata/TweakScale/plugins/Scale_Editor.dll
diff --git a/Gamedata/TweakScale/ScaleExponents.cfg b/Gamedata/TweakScale/ScaleExponents.cfg
index 43938cc2..63b17419 100644
--- a/Gamedata/TweakScale/ScaleExponents.cfg
+++ b/Gamedata/TweakScale/ScaleExponents.cfg
@@ -265,12 +265,6 @@ TWEAKSCALEEXPONENTS
effectSize2 = 1
}
-TWEAKSCALEEXPONENTS
-{
- name = FNNozzleController
- radius = 1
-}
-
TWEAKSCALEEXPONENTS
{
name = AntimatterStorageTank
@@ -345,14 +339,12 @@ TWEAKSCALEEXPONENTS
{
name = FNNozzleController
radius = 1
- engineMaxThrust = 2
}
TWEAKSCALEEXPONENTS
{
name = FNNozzleControllerFX
radius = 1
- engineMaxThrust = 2
}
TWEAKSCALEEXPONENTS
@@ -439,4 +431,50 @@ TWEAKSCALEEXPONENTS
lockMinDist = 1
maxLenght = 1
powerDrain = 2
-}
\ No newline at end of file
+}
+
+TWEAKSCALEEXPONENTS
+{
+ name = ModuleTweakableDecouple
+ ejectionForce = 2
+}
+
+TWEAKSCALEEXPONENTS
+{
+ name = ModuleTweakableDockingNode
+ acquireRange = 1
+ acquireForce = 2
+ acquireTorque = 2
+ undockEjectionForce = 2
+ minDistanceToReEngage = 1
+}
+
+TWEAKSCALEEXPONENTS
+{
+ name = ModuleTweakableEVA
+ thrusterPowerThrottle = 1
+}
+
+TWEAKSCALEEXPONENTS
+{
+ name = ModuleTweakableReactionWheel
+ RollTorque = 3
+ PitchTorque = 3
+ YawTorque = 3
+}
+
+TWEAKSCALEEXPONENTS
+{
+ name = FSfuelSwitch
+ tankList
+ {
+ resources
+ {
+ !amount = 3
+ !maxAmount = 3
+ }
+ }
+ weightList = 3
+ tankCostList = 3
+}
+
diff --git a/Gamedata/TweakScale/plugins/Scale.dll b/Gamedata/TweakScale/plugins/Scale.dll
index d89b3369..81c20e36 100644
Binary files a/Gamedata/TweakScale/plugins/Scale.dll and b/Gamedata/TweakScale/plugins/Scale.dll differ
diff --git a/Gamedata/TweakScale/plugins/Scale_FAR.dll b/Gamedata/TweakScale/plugins/Scale_FAR.dll
deleted file mode 100644
index f96c9d38..00000000
Binary files a/Gamedata/TweakScale/plugins/Scale_FAR.dll and /dev/null differ
diff --git a/Gamedata/TweakScale/plugins/Scale_KAS.dll b/Gamedata/TweakScale/plugins/Scale_KAS.dll
deleted file mode 100644
index 3b346f2f..00000000
Binary files a/Gamedata/TweakScale/plugins/Scale_KAS.dll and /dev/null differ
diff --git a/Gamedata/TweakScale/plugins/Scale_TweakableEverything.dll b/Gamedata/TweakScale/plugins/Scale_TweakableEverything.dll
deleted file mode 100644
index 3847ba26..00000000
Binary files a/Gamedata/TweakScale/plugins/Scale_TweakableEverything.dll and /dev/null differ
diff --git a/Gamedata/TweakScale/plugins/TweakScale_FAR.dll b/Gamedata/TweakScale/plugins/TweakScale_FAR.dll
deleted file mode 100644
index 2ccf640e..00000000
Binary files a/Gamedata/TweakScale/plugins/TweakScale_FAR.dll and /dev/null differ
diff --git a/Gamedata/TweakScale/plugins/TweakScale_TweakableEverything.dll b/Gamedata/TweakScale/plugins/TweakScale_TweakableEverything.dll
deleted file mode 100644
index afe1e67e..00000000
Binary files a/Gamedata/TweakScale/plugins/TweakScale_TweakableEverything.dll and /dev/null differ
diff --git a/MemberUpdater.cs b/MemberUpdater.cs
index 9632bfb9..0b8892e9 100644
--- a/MemberUpdater.cs
+++ b/MemberUpdater.cs
@@ -12,28 +12,51 @@ public class MemberUpdater
object _object = null;
FieldInfo _field = null;
PropertyInfo _property = null;
+ UI_FloatRange _floatRange = null;
- public MemberUpdater(object obj, string name)
+ public static MemberUpdater Create(object obj, string name)
{
if (obj == null)
{
- return;
+ return null;
}
-
var objectType = obj.GetType();
- _object = obj;
- _field = objectType.GetField(name, BindingFlags.Instance | BindingFlags.Public);
- _property = objectType.GetProperty(name, BindingFlags.Instance | BindingFlags.Public);
+ var field = objectType.GetField(name, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
+ var property = objectType.GetProperty(name, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
+ UI_FloatRange floatRange = null;
+ if (obj is PartModule)
+ {
+ var fieldData = (obj as PartModule).Fields[name];
+ if ((object)fieldData != null)
+ {
+ var ctrl = fieldData.uiControlEditor;
+ if (ctrl is UI_FloatRange)
+ {
+ floatRange = ctrl as UI_FloatRange;
+ }
+ }
+ }
- if (_property != null && _property.GetIndexParameters().Length > 0)
+ if (property != null && property.GetIndexParameters().Length > 0)
{
Tools.LogWf("Property {0} on {1} requires indices, which TweakScale currently does not support.", name, objectType.Name);
- _property = null;
+ return null;
}
- if (_field == null && _property == null)
+ if (field == null && property == null)
{
Tools.LogWf("No valid member found for {0} in {1}", name, objectType.Name);
+ return null;
}
+
+ return new MemberUpdater(obj, field, property, floatRange);
+ }
+
+ private MemberUpdater(object obj, FieldInfo field, PropertyInfo property, UI_FloatRange floatRange)
+ {
+ _object = obj;
+ _field = field;
+ _property = property;
+ _floatRange = floatRange;
}
public object Value
@@ -55,6 +78,22 @@ public object Value
}
}
+ public Type MemberType
+ {
+ get
+ {
+ if (_field != null)
+ {
+ return _field.FieldType;
+ }
+ else if (_property != null)
+ {
+ return _property.PropertyType;
+ }
+ return null;
+ }
+ }
+
public void Set(object value)
{
if (_field != null)
@@ -67,14 +106,6 @@ public void Set(object value)
}
}
- public Type MemberType
- {
- get
- {
- return _field == null ? _field.FieldType : _property.PropertyType;
- }
- }
-
public void Scale(double scale, MemberUpdater source)
{
if (_field == null && _property == null)
@@ -85,17 +116,29 @@ public void Scale(double scale, MemberUpdater source)
object newValue = Value;
if (MemberType == typeof(float))
{
- newValue = (float)newValue * (float)scale;
+ Set((float)newValue * (float)scale);
+ RescaleFloatRange((float)scale);
}
else if (MemberType == typeof(double))
{
- newValue = (double)newValue * scale;
+ Set((double)newValue * scale);
+ RescaleFloatRange((float)scale);
}
else if (MemberType == typeof(Vector3))
{
- newValue = (Vector3)newValue * (float)scale;
+ Set((Vector3)newValue * (float)scale);
+ }
+ }
+
+ private void RescaleFloatRange(float factor)
+ {
+ if ((object)_floatRange == null)
+ {
+ return;
}
- Set(newValue);
+ _floatRange.maxValue *= factor;
+ _floatRange.minValue *= factor;
+ _floatRange.stepIncrement *= factor;
}
}
}
diff --git a/Scale.sln b/Scale.sln
index 377ea5e3..9b691a1f 100644
--- a/Scale.sln
+++ b/Scale.sln
@@ -11,6 +11,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Scale_Editor", "Scale_Edito
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Scale_TweakableEverything", "Scale_TweakableEverything\Scale_TweakableEverything.csproj", "{5CFCCBB6-528C-4E96-93BB-829AC621DC2A}"
EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Scale_FS", "Scale_FS\Scale_FS.csproj", "{FC9D7E8E-9C06-4F09-8647-967C7355AA9A}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Scale_FAR", "Scale_FAR\Scale_FAR.csproj", "{AC68606D-F655-4524-8A1B-EFFDFC87F2C6}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -33,6 +37,14 @@ Global
{5CFCCBB6-528C-4E96-93BB-829AC621DC2A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5CFCCBB6-528C-4E96-93BB-829AC621DC2A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5CFCCBB6-528C-4E96-93BB-829AC621DC2A}.Release|Any CPU.Build.0 = Release|Any CPU
+ {FC9D7E8E-9C06-4F09-8647-967C7355AA9A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {FC9D7E8E-9C06-4F09-8647-967C7355AA9A}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {FC9D7E8E-9C06-4F09-8647-967C7355AA9A}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {FC9D7E8E-9C06-4F09-8647-967C7355AA9A}.Release|Any CPU.Build.0 = Release|Any CPU
+ {AC68606D-F655-4524-8A1B-EFFDFC87F2C6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {AC68606D-F655-4524-8A1B-EFFDFC87F2C6}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {AC68606D-F655-4524-8A1B-EFFDFC87F2C6}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {AC68606D-F655-4524-8A1B-EFFDFC87F2C6}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
diff --git a/ScaleExponents.cs b/ScaleExponents.cs
index 15bf4163..44ac38b8 100644
--- a/ScaleExponents.cs
+++ b/ScaleExponents.cs
@@ -3,6 +3,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
+using UnityEngine;
namespace TweakScale
{
@@ -191,34 +192,68 @@ public static ScaleExponents Merge(ScaleExponents destination, ScaleExponents so
/// The rescaling factor.
/// Whether to use relative or absolute scaling.
/// The rescaled exponentValue.
- private void Rescale(MemberUpdater current, MemberUpdater baseValue, KeyValuePair scalingMode, ScalingFactor factor)
+ private void Rescale(MemberUpdater current, MemberUpdater baseValue, string name, ScalingMode scalingMode, ScalingFactor factor)
{
- var exponentValue = scalingMode.Value.Exponent;
+ var exponentValue = scalingMode.Exponent;
+ double exponent = double.NaN;
+ double[] values = null;
if (exponentValue.Contains(','))
{
if (factor.index == -1)
{
- Tools.LogWf("Value list used for freescale part exponent field {0}: {1}", scalingMode.Key, exponentValue);
+ Tools.LogWf("Value list used for freescale part exponent field {0}: {1}", name, exponentValue);
+ return;
}
- var values = Tools.ConvertString(exponentValue, new double[] { });
+ values = Tools.ConvertString(exponentValue, new double[] { });
if (values.Length <= factor.index)
{
- Tools.LogWf("Too few values given for {0}. Expected at least {1}, got {2}: {3}", scalingMode.Key, factor.index + 1, values.Length, exponentValue);
+ Tools.LogWf("Too few values given for {0}. Expected at least {1}, got {2}: {3}", name, factor.index + 1, values.Length, exponentValue);
+ return;
}
- current.Set(values[factor.index]);
}
- else
+ else if (!double.TryParse(exponentValue, out exponent))
{
- double exponent;
- if (double.TryParse(exponentValue, out exponent))
- {
- current.Scale(Math.Pow(factor.relative.linear, exponent), baseValue);
- }
- else
+ Tools.LogWf("Invalid exponent {0} for field {1}", exponentValue, name);
+ }
+
+
+ if (current.MemberType.GetInterface("IList") != null)
+ {
+ var v = (IList)current.Value;
+ var v2 = (IList)baseValue.Value;
+
+ for (int i = 0; i < v.Count && i < v2.Count; ++i)
{
- Tools.LogWf("Invalid exponent {0} for field {1}", exponentValue, scalingMode.Key);
+ if (values != null)
+ {
+ v[i] = values[factor.index];
+ }
+ else if (!double.IsNaN(exponent))
+ {
+ if (v[i] is float)
+ {
+ v[i] = (float)v2[i] * Math.Pow(factor.relative.linear, exponent);
+ }
+ else if (v[i] is double)
+ {
+ v[i] = (double)v2[i] * Math.Pow(factor.relative.linear, exponent);
+ }
+ else if (v[i] is Vector3)
+ {
+ v[i] = (Vector3)v2[i] * (float)Math.Pow(factor.relative.linear, exponent);
+ }
+ }
}
}
+
+ if (values != null)
+ {
+ current.Set(values[factor.index]);
+ }
+ else if (!double.IsNaN(exponent))
+ {
+ current.Scale(Math.Pow(factor.relative.linear, exponent), baseValue);
+ }
}
///
@@ -230,6 +265,11 @@ private void Rescale(MemberUpdater current, MemberUpdater baseValue, KeyValuePai
/// The part the object is on.
private void UpdateFields(object obj, object baseObj, ScalingFactor factor, Part part)
{
+ if ((object)obj == null)
+ {
+ return;
+ }
+
if (obj is PartModule && obj.GetType().Name != _id)
{
Tools.LogWf("This ScaleExponent is intended for {0}, not {1}", _id, obj.GetType().Name);
@@ -254,40 +294,32 @@ private void UpdateFields(object obj, object baseObj, ScalingFactor factor, Part
return;
}
- foreach (var exponent in _exponents)
+ foreach (var nameExponentKV in _exponents)
{
- var value = new MemberUpdater(obj, exponent.Key);
+ var value = MemberUpdater.Create(obj, nameExponentKV.Key);
if (value == null)
{
continue;
}
var baseObjTmp = baseObj;
- if (exponent.Value.UseRelativeScaling)
+ if (nameExponentKV.Value.UseRelativeScaling)
{
// Forced relative scaling. Don't even dare look at the prefab!
baseObjTmp = null;
}
- if (baseObjTmp == null)
- {
- // No prefab from which to grab values. Use relative scaling.
- Rescale(value, value, exponent, factor);
- }
- else
- {
- var baseValue = new MemberUpdater(baseObj, exponent.Key);
- Rescale(value, baseValue, exponent, factor);
- }
+ var baseValue = MemberUpdater.Create(baseObj, nameExponentKV.Key);
+ Rescale(value, baseValue ?? value, nameExponentKV.Key, nameExponentKV.Value, factor);
}
foreach (var _child in _children)
{
string childName = _child.Key;
- var childObjField = new MemberUpdater(obj, childName);
- if (childObjField != null)
+ var childObjField = MemberUpdater.Create(obj, childName);
+ if (childObjField != null && _child.Value != null)
{
- var baseChildObjField = new MemberUpdater(baseObj, childName);
- _child.Value.UpdateFields(childObjField.Value, baseChildObjField.Value, factor, part);
+ var baseChildObjField = MemberUpdater.Create(baseObj, childName);
+ _child.Value.UpdateFields(childObjField.Value, (baseChildObjField ?? childObjField).Value, factor, part);
}
}
}