/// <summary> /// For IEnumerables (arrays, lists, etc), we want to update the items, not the list. /// </summary> /// <param name="obj">The list whose items we want to update.</param> /// <param name="prefabObj">The corresponding list in the prefab.</param> /// <param name="factor">The scaling factor.</param> /// <param name="part">The part the object is on.</param> private void UpdateEnumerable(IEnumerable obj, IEnumerable prefabObj, ScalingFactor factor, Part part = null) { object[] prefabObjects = prefabObj as object[] ?? prefabObj.Cast <object>().ToArray(); object[] urrentObjects = obj as object[] ?? obj.Cast <object>().ToArray(); if (prefabObj == null || urrentObjects.Length != prefabObjects.Length) { prefabObjects = ((object)null).Repeat().Take(urrentObjects.Length).ToArray(); } foreach (ModuleAndPrefab item in urrentObjects.Zip(prefabObjects, ModuleAndPrefab.Create)) { if (!string.IsNullOrEmpty(_name) && _name != "*") // Operate on specific elements, not all. { System.Reflection.FieldInfo childName = item.Current.GetType().GetField("name"); if (childName != null) { if (childName.FieldType != typeof(string) || (string)childName.GetValue(item.Current) != _name) { continue; } } } UpdateFields(item.Current, item.Prefab, factor, part); } }
/// <summary> /// For IEnumerables (arrays, lists, etc), we want to update the items, not the list. /// </summary> /// <param name="obj">The list whose items we want to update.</param> /// <param name="baseObj">The corresponding list in the prefab.</param> /// <param name="factor">The scaling factor.</param> /// <param name="part">The part the object is on.</param> private void UpdateEnumerable(IEnumerable obj, IEnumerable baseObj, ScalingFactor factor, Part part = null) { IEnumerable other = baseObj; if (baseObj == null || obj.StupidCount() != baseObj.StupidCount()) { other = ((object)null).Repeat().Take(obj.StupidCount()); } foreach (var item in obj.Zip(other)) { if (!string.IsNullOrEmpty(_name) && _name != "*") // Operate on specific elements, not all. { var childName = item.Item1.GetType().GetField("name"); if (childName != null) { if (childName.FieldType != typeof(string) || (string)childName.GetValue(item.Item1) != _name) { continue; } } } UpdateFields(item.Item1, item.Item2, factor, part); } }
public void OnRescale(ScalingFactor factor) { TweakScaleTools.RescaleFloatRange(_module, "acquireRange", factor.relative.linear); TweakScaleTools.RescaleFloatRange(_module, "acquireForce", factor.relative.quadratic); TweakScaleTools.RescaleFloatRange(_module, "acquireTorque", factor.relative.quadratic); TweakScaleTools.RescaleFloatRange(_module, "undockEjectionForce", factor.relative.quadratic); TweakScaleTools.RescaleFloatRange(_module, "minDistanceToReEngage", factor.relative.linear); }
public void OnRescale(TweakScale.ScalingFactor factor) { // update variables radius *= factor.relative.linear; exitArea *= factor.relative.quadratic; // update simulation UpdateRadiusModifier(); }
/// <summary> /// Rescale the field of <paramref name="obj"/> according to the exponents of the ScaleExponents and <paramref name="factor"/>. /// </summary> /// <param name="obj">The object to rescale.</param> /// <param name="baseObj">The corresponding object in the prefab.</param> /// <param name="factor">The new scale.</param> public void UpdateFields(object obj, object baseObj, ScalingFactor factor) { if (obj is PartModule && obj.GetType().Name != _id) { Tools.LogWf("This ScaleExponent is intended for {0}, not {1}", _id, obj.GetType().Name); return; } if (obj is IEnumerable) { UpdateEnumerable((IEnumerable)obj, (IEnumerable)baseObj, factor); return; } foreach (var fieldName in Exponents) { var baseObjTmp = baseObj; if (_exponents[fieldName].Item2) { baseObjTmp = null; } var value = FieldChanger <double> .CreateFromName(obj, fieldName); if (value == null) { continue; } if (baseObjTmp == null) { // No prefab from which to grab values. Use relative scaling. value.Value = Rescale(value.Value, value.Value, fieldName, factor, relative: true); } else { var baseValue = FieldChanger <double> .CreateFromName(baseObj, fieldName); value.Value = Rescale(value.Value, baseValue.Value, fieldName, factor); } } foreach (var _child in _children) { string childName = _child.Key; var childObjField = FieldChanger <object> .CreateFromName(obj, childName); if (childObjField != null) { var baseChildObjField = FieldChanger <object> .CreateFromName(baseObj, childName); _child.Value.UpdateFields(childObjField.Value, baseChildObjField.Value, factor); } } }
public virtual void OnRescale(TweakScale.ScalingFactor factor) { try { Debug.Log("FNGenerator.OnRescale called with " + factor.absolute.linear); storedMassMultiplier = Mathf.Pow(factor.absolute.linear, 3); initialMass = part.prefabMass * storedMassMultiplier; } catch (Exception e) { Debug.LogError("[KSPI] - FNGenerator.OnRescale " + e.Message); } }
public virtual void OnRescale(TweakScale.ScalingFactor factor) { if (PowerOutputBase > 0 && PowerOutputExponent > 0 && factor.absolute.linear > 0) { //PowerOutput *= (float)Math.Pow(factor.relative.linear, PowerOutputExponent); PowerOutput = PowerOutputBase * (float)Math.Pow(factor.absolute.linear, PowerOutputExponent); //upgradedPowerOutput *= (float)Math.Pow(factor.relative.linear, upgradedPowerOutputExponent); upgradedPowerOutput = upgradedPowerOutputBase * (float)Math.Pow(factor.absolute.linear, upgradedPowerOutputExponent); } maximumThermalPowerFloat = MaximumThermalPower; }
public virtual void OnRescale(TweakScale.ScalingFactor factor) { try { storedScalingfactor = factor.absolute.linear; storedMassMultiplier = Math.Pow(storedScalingfactor, massExponent); initialMass = part.prefabMass * storedMassMultiplier; chargestatus = maxCharge; } catch (Exception e) { Debug.LogError("[KSPI] - AntimatterStorageTank.OnRescale " + e.Message); } }
/// <summary> /// Rescale the field of <paramref name="obj"/> according to the exponents of the ScaleExponents and <paramref name="factor"/>. /// </summary> /// <param name="obj">The object to rescale.</param> /// <param name="baseObj">The corresponding object in the prefab.</param> /// <param name="factor">The new scale.</param> /// <param name="part">The part the object is on.</param> 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); * return; * }*/ if (ShouldIgnore(part)) { return; } IEnumerable enumerable = obj as IEnumerable; if (enumerable != null) { UpdateEnumerable(enumerable, (IEnumerable)baseObj, factor, part); return; } foreach (KeyValuePair <string, ScalingMode> nameExponentKV in _exponents) { MemberUpdater value = MemberUpdater.Create(obj, nameExponentKV.Key); if (value == null) { continue; } MemberUpdater baseValue = nameExponentKV.Value.UseRelativeScaling ? null : MemberUpdater.Create(baseObj, nameExponentKV.Key); Rescale(value, baseValue ?? value, nameExponentKV.Key, nameExponentKV.Value, factor); } foreach (KeyValuePair <string, ScaleExponents> child in _children) { string childName = child.Key; MemberUpdater childObjField = MemberUpdater.Create(obj, childName); if (childObjField == null || child.Value == null) { continue; } MemberUpdater baseChildObjField = MemberUpdater.Create(baseObj, childName); child.Value.UpdateFields(childObjField.Value, (baseChildObjField ?? childObjField).Value, factor, part); } }
public override void OnRescale(ScalingFactor factor) { var baseModule = GetBaseModule<ModularFuelTanks.ModuleFuelTanks>(); module.basemass = baseModule.basemass * factor.absolute.cubic; module.basemassPV = baseModule.basemassPV * factor.absolute.cubic; module.volume = baseModule.volume * factor.absolute.cubic; try { module.UpdateMass(); } catch (Exception) { // Just silently ignore this one... // I have a reason: this is the only module that seems to misbehave when scaled too early. } }
public virtual void OnRescale(TweakScale.ScalingFactor factor) { try { currentVolumeMultiplier = (float)Math.Pow(factor.absolute.linear, volumeExponent); currentMassMultiplier = (float)Math.Pow(factor.absolute.linear, massExponent); //part.heatConvectiveConstant = this.heatConvectiveConstant * (float)Math.Pow(factor.absolute.linear, 1); //part.heatConductivity = this.heatConductivity * (float)Math.Pow(factor.absolute.linear, 1); UpdateMass(part, selectedTankSetup, false); } catch (Exception e) { Debug.LogError("OnRescale"); Debug.LogException(e); throw; } }
/// <summary> /// Rescales destination exponentValue according to its associated exponent. /// </summary> /// <param name="currentValue">The current exponentValue.</param> /// <param name="baseValue">The unscaled exponentValue, gotten from the prefab.</param> /// <param name="name">The name of the field.</param> /// <param name="factor">The rescaling factor.</param> /// <param name="relative">Whether to use relative or absolute scaling.</param> /// <returns>The rescaled exponentValue.</returns> public double Rescale(double currentValue, double baseValue, string name, ScalingFactor factor, bool relative = false) { if (!_exponents.ContainsKey(name)) { Tools.LogWf("No exponent found for {0}.{1}", this._id, name); return(currentValue); } var exponentValue = _exponents[name].Item1; if (exponentValue.Contains(',')) { if (factor.index == -1) { Tools.LogWf("Value list used for freescale part exponent field {0}: {1}", name, exponentValue); return(currentValue); } var values = Tools.ConvertString(exponentValue, new double[] { }); if (values.Length == 0) { Tools.LogWf("No valid values found for {0}: {1}", name, exponentValue); } if (values.Length <= factor.index) { Tools.LogWf("Too few values given for {0}. Expected at least {1}, got {2}: {3}", name, factor.index + 1, values.Length, exponentValue); } return(values[factor.index]); } else { double exponent; if (double.TryParse(exponentValue, out exponent)) { if (relative) { return(currentValue * Math.Pow(factor.relative.linear, exponent)); } return(baseValue * Math.Pow(factor.absolute.linear, exponent)); } return(currentValue); } }
public virtual void OnRescale(TweakScale.ScalingFactor factor) { try { Debug.Log("BeamGenerator.OnRescale called with " + factor.absolute.linear); storedMassMultiplier = Mathf.Pow(factor.absolute.linear, 3); initialMass = part.prefabMass * storedMassMultiplier; if (maximumPower > 0) { targetMass = maximumPower * powerMassFraction * 0.001; } else { targetMass = initialMass; } } catch (Exception e) { Debug.LogError("[KSPI] - BeamGenerator.OnRescale" + e.Message); } }
private void UpdateParticleEmitter(KSPParticleEmitter pe) { if (pe == null) { return; } ScalingFactor factor = _ts.ScalingFactor; if (!_scales.ContainsKey(pe)) { _scales[pe] = new EmitterData(pe); } EmitterData ed = _scales[pe]; pe.minSize = ed.MinSize * factor.absolute.linear; pe.maxSize = ed.MaxSize * factor.absolute.linear; pe.shape1D = ed.Shape1D * factor.absolute.linear; pe.shape2D = ed.Shape2D * factor.absolute.linear; pe.shape3D = ed.Shape3D * factor.absolute.linear; pe.force = ed.Force * factor.absolute.linear; pe.localVelocity = ed.LocalVelocity * factor.absolute.linear; }
public virtual void OnRescale(TweakScale.ScalingFactor akFactor) { scale = (double)(decimal)akFactor.absolute.linear; }
private void moveNode(AttachNode node, AttachNode baseNode, ScalingFactor factor, bool movePart) { Vector3 oldPosition = node.position; node.position = baseNode.position * factor.absolute.linear; if (movePart && node.attachedPart != null) { if (node.attachedPart == part.parent) part.transform.Translate(oldPosition - node.position); else node.attachedPart.transform.Translate(node.position - oldPosition, part.transform); } if (isFreeScale) { node.size = (int)(baseNode.size + (tweakScale - defaultScale) / (maxSize - minSize) * 5); } else { var options = (UI_ChooseOption)this.Fields["tweakName"].uiControlEditor; node.size = (int)(baseNode.size + (tweakName - defaultName) / (float)options.options.Length * 5); } if (node.size < 0) node.size = 0; node.breakingForce = part.breakingForce; node.breakingTorque = part.breakingTorque; }
/// <summary> /// Rescales destination exponentValue according to its associated exponent. /// </summary> /// <param name="current">The current exponentValue.</param> /// <param name="baseValue">The unscaled exponentValue, gotten from the prefab.</param> /// <param name="name">The name of the field.</param> /// <param name="scalingMode">Information on exactly how to scale this.</param> /// <param name="factor">The rescaling factor.</param> /// <returns>The rescaled exponentValue.</returns> static private void Rescale(MemberUpdater current, MemberUpdater baseValue, string name, ScalingMode scalingMode, ScalingFactor factor) { string 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}", name, exponentValue); return; } 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}", name, factor.index + 1, values.Length, exponentValue); return; } } else if (!double.TryParse(exponentValue, out exponent)) { Tools.LogWf("Invalid exponent {0} for field {1}", exponentValue, name); } double multiplyBy = 1; if (!double.IsNaN(exponent)) { multiplyBy = Math.Pow(scalingMode.UseRelativeScaling ? factor.relative.linear : factor.absolute.linear, exponent); } if (current.MemberType.GetInterface("IList") != null) { IList v = (IList)current.Value; IList v2 = (IList)baseValue.Value; if (v == null) { Tools.LogWf("current.Value == null!"); return; } for (int i = 0; i < v.Count && i < v2.Count; ++i) { if (values != null) { v[i] = values[factor.index]; } else if (!double.IsNaN(exponent) && (exponent != 0)) { if (v[i] is float) { v[i] = (float)v2[i] * multiplyBy; } else if (v[i] is double) { v[i] = (double)v2[i] * multiplyBy; } else if (v[i] is Vector3) { v[i] = (Vector3)v2[i] * (float)multiplyBy; } } } } if (values != null) { if (current.MemberType == typeof(float)) { current.Set((float)values[factor.index]); } else if (current.MemberType == typeof(float)) { current.Set(values[factor.index]); } } else if (!double.IsNaN(exponent) && (exponent != 0)) { current.Scale(multiplyBy, baseValue); } }
// values that change relative to the volume (i.e. scale cubed) private void updateByRelativeVolume(ScalingFactor factor) { part.mass = part.mass * massFactors.Select((a, i) => (float)Math.Pow(a * factor.relative.linear, i + 1)).Sum(); var newResourceValues = part.Resources.OfType<PartResource>().Select(a => new[] { a.amount * factor.relative.cubic, a.maxAmount * factor.relative.cubic }).ToArray(); int idx = 0; foreach (PartResource resource in part.Resources) { var newValues = newResourceValues[idx]; resource.amount = newValues[0]; resource.maxAmount = newValues[1]; idx++; } }
public void OnRescale(ScalingFactor factor) { TweakScaleTools.RescaleFloatRange(_module, "RollTorque", factor.relative.cubic); TweakScaleTools.RescaleFloatRange(_module, "PitchTorque", factor.relative.cubic); TweakScaleTools.RescaleFloatRange(_module, "YawTorque", factor.relative.cubic); }
public void OnRescale(ScalingFactor factor) { _rescale = true; }
/// <summary> /// Rescale the field of <paramref name="obj"/> according to the exponents of the ScaleExponents and <paramref name="factor"/>. /// </summary> /// <param name="obj">The object to rescale.</param> /// <param name="baseObj">The corresponding object in the prefab.</param> /// <param name="factor">The new scale.</param> /// <param name="part">The part the object is on.</param> 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); return; } if (ShouldIgnore(part)) return; var enumerable = obj as IEnumerable; if (enumerable != null) { UpdateEnumerable(enumerable, (IEnumerable)baseObj, factor, part); return; } foreach (var nameExponentKV in _exponents) { var value = MemberUpdater.Create(obj, nameExponentKV.Key); if (value == null) { continue; } var baseValue = nameExponentKV.Value.UseRelativeScaling ? null : MemberUpdater.Create(baseObj, nameExponentKV.Key); Rescale(value, baseValue ?? value, nameExponentKV.Key, nameExponentKV.Value, factor); } foreach (var child in _children) { var childName = child.Key; var childObjField = MemberUpdater.Create(obj, childName); if (childObjField == null || child.Value == null) continue; var baseChildObjField = MemberUpdater.Create(baseObj, childName); child.Value.UpdateFields(childObjField.Value, (baseChildObjField ?? childObjField).Value, factor, part); } }
public void OnRescale(ScalingFactor factor) { if (rotateJoint) return; // TODO translate limits should be treated here if we ever want to unify // translation and rotation in the part configs // => enable here when we remove them from the tweakScale configs //translateMin *= factor; //translateMax *= factor; minTweak *= factor.relative.linear; maxTweak *= factor.relative.linear; // The part center is the origin of the moving mesh // so if translation!=0, the fixed mesh moves on rescale. // We need to move the part back so the fixed mesh stays at the same place. transform.Translate(-translateAxis * translation * (factor.relative.linear-1f) ); if (HighLogic.LoadedSceneIsEditor) translation *= factor.relative.linear; // update the window so the new limits are applied UpdateMinMaxTweaks(); TweakWindow = part.FindActionWindow (); TweakIsDirty = true; Logger.Log ("OnRescale called, TweakWindow is null? = " + (TweakWindow == null), Logger.Level.Debug); }
/// <summary> /// Rescales destination exponentValue according to its associated exponent. /// </summary> /// <param name="current">The current exponentValue.</param> /// <param name="baseValue">The unscaled exponentValue, gotten from the prefab.</param> /// <param name="name">The name of the field.</param> /// <param name="scalingMode">Information on exactly how to scale this.</param> /// <param name="factor">The rescaling factor.</param> /// <returns>The rescaled exponentValue.</returns> private static void Rescale(MemberUpdater current, MemberUpdater baseValue, string name, ScalingMode scalingMode, ScalingFactor factor) { var exponentValue = scalingMode.Exponent; var 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}", name, exponentValue); return; } 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}", name, factor.index + 1, values.Length, exponentValue); return; } } else if (!double.TryParse(exponentValue, out exponent)) { Tools.LogWf("Invalid exponent {0} for field {1}", exponentValue, name); } double multiplyBy = 1; if (!double.IsNaN(exponent)) multiplyBy = Math.Pow(scalingMode.UseRelativeScaling ? factor.relative.linear : factor.absolute.linear, exponent); if (current.MemberType.GetInterface("IList") != null) { var v = (IList)current.Value; var v2 = (IList)baseValue.Value; if(v == null) { Tools.LogWf("current.Value == null!"); return; } for (var i = 0; i < v.Count && i < v2.Count; ++i) { if (values != null) { v[i] = values[factor.index]; } else if (!double.IsNaN(exponent)) { if (v[i] is float) { v[i] = (float)v2[i] * multiplyBy; } else if (v[i] is double) { v[i] = (double)v2[i] * multiplyBy; } else if (v[i] is Vector3) { v[i] = (Vector3)v2[i] * (float)multiplyBy; } } } } if (values != null) { if (current.MemberType == typeof (float)) { current.Set((float)values[factor.index]); } else if (current.MemberType == typeof(float)) { current.Set(values[factor.index]); } } else if (!double.IsNaN(exponent)) { current.Scale(multiplyBy, baseValue); } }
private void updateByWidth(ScalingFactor factor, bool moveParts) { if (defaultTransformScale.x == 0.0f) { defaultTransformScale = part.transform.GetChild(0).localScale; } savedScale = part.transform.GetChild(0).localScale = factor.absolute.linear * defaultTransformScale; part.transform.GetChild(0).hasChanged = true; part.transform.hasChanged = true; foreach (AttachNode node in part.attachNodes) { var nodesWithSameId = part.attachNodes .Where(a => a.id == node.id) .ToArray(); var idIdx = Array.FindIndex(nodesWithSameId, a => a == node); var baseNodesWithSameId = basePart.attachNodes .Where(a => a.id == node.id) .ToArray(); if (idIdx < baseNodesWithSameId.Length) { var baseNode = baseNodesWithSameId[idIdx]; moveNode(node, baseNode, factor, moveParts); } else { Tools.Logf("Error scaling part. Node {0} does not have counterpart in base part.", node.id); } } if (part.srfAttachNode != null) { moveNode(part.srfAttachNode, basePart.srfAttachNode, factor, moveParts); } if (moveParts) { Vector3 relativeVector = Vector3.one * factor.absolute.linear; foreach (Part child in part.children) { if (child.srfAttachNode != null && child.srfAttachNode.attachedPart == part) // part is attached to us, but not on a node { Vector3 attachedPosition = child.transform.localPosition + child.transform.localRotation * child.srfAttachNode.position; Vector3 targetPosition = Vector3.Scale(attachedPosition, relativeVector); child.transform.Translate(targetPosition - attachedPosition, part.transform); } } }; }
public static void UpdateObject(Part part, Part basePart, Dictionary<string, ScaleExponents> exps, ScalingFactor factor) { if (exps.ContainsKey("Part")) { exps["Part"].UpdateFields(part, basePart, factor); } var modulesAndExponents = part.Modules.Cast<PartModule>().Zip(basePart.Modules.Cast<PartModule>()).Join(exps, modules => modules.Item1.moduleName, exponents => exponents.Key, (modules, exponent) => Tuple.Create(modules, exponent.Value)).ToArray(); foreach (var modExp in modulesAndExponents) { modExp.Item2.UpdateFields(modExp.Item1.Item1, modExp.Item1.Item2, factor); } }
public static void UpdateObject(Part part, Part prefabObj, Dictionary <string, ScaleExponents> exponents, ScalingFactor factor) { if (exponents.ContainsKey("Part")) { exponents["Part"].UpdateFields(part, prefabObj, factor, part); } IEnumerable <ModuleAndPrefab> modulePairs = part.Modules.Zip(prefabObj.Modules, ModuleAndPrefab.Create); //foreach (var m in modulePairs) //{ // Debug.Log("moduleAndPrefab: " + (m.Prefab as PartModule).moduleName + " " + m.Prefab.GetType().ToString()); //} ModulesAndExponents[] modulesAndExponents = modulePairs.Join(exponents, modules => ((PartModule)modules.Current).moduleName, exps => exps.Key, ModulesAndExponents.Create).ToArray(); // include derived classes foreach (KeyValuePair <string, ScaleExponents> e in exponents) { //Debug.Log("check type: " + e.Key +", "+e.Value._name +", "+e.Value._id); Type type = GetType(e.Key); if (type == null) { continue; } foreach (ModuleAndPrefab m in modulePairs) { if (m.Current.GetType().IsSubclassOf(type)) { //Debug.Log("+modAndPrefab: " +((PartModule)m.Current).moduleName + " " + m.Prefab.GetType().ToString() +" "+e.Value._name +", "+e.Key); if (e.Key != ((PartModule)m.Current).moduleName) { e.Value.UpdateFields(m.Current, m.Prefab, factor, part); } } } } foreach (ModulesAndExponents modExp in modulesAndExponents) { //Debug.Log("modExP: " +(modExp.Prefab as PartModule).moduleName +" "+ modExp.Prefab.GetType().ToString()); modExp.Exponents.UpdateFields(modExp.Current, modExp.Prefab, factor, part); } }
// values that change relative to the surface area (i.e. scale squared) private void updateBySurfaceArea(ScalingFactor factor) { if (basePart.breakingForce == 22f) // not defined in the config, set to a reasonable default part.breakingForce = 32.0f * factor.absolute.quadratic; // scale 1 = 50, scale 2 = 200, etc. else // is defined, scale it relative to new surface area part.breakingForce = basePart.breakingForce * factor.absolute.quadratic; if (part.breakingForce < 22f) part.breakingForce = 22f; if (basePart.breakingTorque == 22f) part.breakingTorque = 32.0f * factor.absolute.quadratic; else part.breakingTorque = basePart.breakingTorque * factor.absolute.quadratic; if (part.breakingTorque < 22f) part.breakingTorque = 22f; }
public void OnRescale(ScalingFactor factor) { ScaleExponents.UpdateObject(_part, _basePart, _ts.config.exponents, factor); }
public void OnRescale(ScalingFactor factor) { TweakScaleTools.RescaleFloatRange(_module, "thrusterPowerThrottle", factor.relative.linear); }
/// <summary> /// Rescales destination exponentValue according to its associated exponent. /// </summary> /// <param name="currentValue">The current exponentValue.</param> /// <param name="baseValue">The unscaled exponentValue, gotten from the prefab.</param> /// <param name="name">The name of the field.</param> /// <param name="factor">The rescaling factor.</param> /// <param name="relative">Whether to use relative or absolute scaling.</param> /// <returns>The rescaled exponentValue.</returns> public double Rescale(double currentValue, double baseValue, string name, ScalingFactor factor, bool relative = false) { if (!_exponents.ContainsKey(name)) { Tools.LogWf("No exponent found for {0}.{1}", this._id, name); return currentValue; } var exponentValue = _exponents[name].Item1; if (exponentValue.Contains(',')) { if (factor.index == -1) { Tools.LogWf("Value list used for freescale part exponent field {0}: {1}", name, exponentValue); return currentValue; } var values = Tools.ConvertString(exponentValue, new double[] { }); if (values.Length == 0) { Tools.LogWf("No valid values found for {0}: {1}", name, exponentValue); } if (values.Length <= factor.index) { Tools.LogWf("Too few values given for {0}. Expected at least {1}, got {2}: {3}", name, factor.index + 1, values.Length, exponentValue); } return values[factor.index]; } else { double exponent; if (double.TryParse(exponentValue, out exponent)) { if (relative) { return currentValue * Math.Pow(factor.relative.linear, exponent); } return baseValue * Math.Pow(factor.absolute.linear, exponent); } return currentValue; } }
public static void UpdateObject(Part part, Part basePart, Dictionary <string, ScaleExponents> exps, ScalingFactor factor) { if (exps.ContainsKey("Part")) { exps["Part"].UpdateFields(part, basePart, factor, part); } var modulesAndExponents = part.Modules.Cast <PartModule>().Zip(basePart.Modules.Cast <PartModule>()).Join(exps, modules => modules.Item1.moduleName, exponents => exponents.Key, (modules, exponent) => Tuple.Create(modules, exponent.Value)).ToArray(); foreach (var modExp in modulesAndExponents) { modExp.Item2.UpdateFields(modExp.Item1.Item1, modExp.Item1.Item2, factor, part); } }
public static void UpdateObject(Part part, Part prefabObj, Dictionary<string, ScaleExponents> exponents, ScalingFactor factor) { if (exponents.ContainsKey("Part")) { exponents["Part"].UpdateFields(part, prefabObj, factor, part); } var modulePairs = part.Modules.Zip(prefabObj.Modules, ModuleAndPrefab.Create); var modulesAndExponents = modulePairs.Join(exponents, modules => ((PartModule)modules.Current).moduleName, exps => exps.Key, ModulesAndExponents.Create).ToArray(); foreach (var modExp in modulesAndExponents) { modExp.Exponents.UpdateFields(modExp.Current, modExp.Prefab, factor, part); } }
/// <summary> /// Rescale the field of <paramref name="obj"/> according to the exponents of the ScaleExponents and <paramref name="factor"/>. /// </summary> /// <param name="obj">The object to rescale.</param> /// <param name="baseObj">The corresponding object in the prefab.</param> /// <param name="factor">The new scale.</param> public void UpdateFields(object obj, object baseObj, ScalingFactor factor) { if (obj is PartModule && obj.GetType().Name != _id) { Tools.LogWf("This ScaleExponent is intended for {0}, not {1}", _id, obj.GetType().Name); return; } if (obj is IEnumerable) { UpdateEnumerable((IEnumerable)obj, (IEnumerable)baseObj, factor); return; } foreach (var fieldName in Exponents) { var baseObjTmp = baseObj; if (_exponents[fieldName].Item2) { baseObjTmp = null; } var value = FieldChanger<double>.CreateFromName(obj, fieldName); if (value == null) { continue; } if (baseObjTmp == null) { // No prefab from which to grab values. Use relative scaling. value.Value = Rescale(value.Value, value.Value, fieldName, factor, relative: true); } else { var baseValue = FieldChanger<double>.CreateFromName(baseObj, fieldName); value.Value = Rescale(value.Value, baseValue.Value, fieldName, factor); } } foreach (var _child in _children) { string childName = _child.Key; var childObjField = FieldChanger<object>.CreateFromName(obj, childName); if (childObjField != null) { var baseChildObjField = FieldChanger<object>.CreateFromName(baseObj, childName); _child.Value.UpdateFields(childObjField.Value, baseChildObjField.Value, factor); } } }
/// <summary> /// For IEnumerables (arrays, lists, etc), we want to update the items, not the list. /// </summary> /// <param name="obj">The list whose items we want to update.</param> /// <param name="prefabObj">The corresponding list in the prefab.</param> /// <param name="factor">The scaling factor.</param> /// <param name="part">The part the object is on.</param> private void UpdateEnumerable(IEnumerable obj, IEnumerable prefabObj, ScalingFactor factor, Part part = null) { var prefabObjects = prefabObj as object[] ?? prefabObj.Cast<object>().ToArray(); var urrentObjects = obj as object[] ?? obj.Cast<object>().ToArray(); if (prefabObj == null || urrentObjects.Length != prefabObjects.Length) { prefabObjects = ((object)null).Repeat().Take(urrentObjects.Length).ToArray(); } foreach (var item in urrentObjects.Zip(prefabObjects, ModuleAndPrefab.Create)) { if (!string.IsNullOrEmpty(_name) && _name != "*") // Operate on specific elements, not all. { var childName = item.Current.GetType().GetField("name"); if (childName != null) { if (childName.FieldType != typeof(string) || (string)childName.GetValue(item.Current) != _name) { continue; } } } UpdateFields(item.Current, item.Prefab, factor, part); } }
/// <summary> /// For IEnumerables (arrays, lists, etc), we want to update the items, not the list. /// </summary> /// <param name="obj">The list whose items we want to update.</param> /// <param name="baseObj">The corresponding list in the prefab.</param> /// <param name="factor">The scaling factor.</param> private void UpdateEnumerable(IEnumerable obj, IEnumerable baseObj, ScalingFactor factor) { IEnumerable other = baseObj; if (baseObj == null || obj.StupidCount() != baseObj.StupidCount()) { other = ((object)null).Repeat().Take(obj.StupidCount()); } foreach (var item in obj.Zip(other)) { if (!string.IsNullOrEmpty(_name) && _name != "*") // Operate on specific elements, not all. { var childName = item.Item1.GetType().GetField("name"); if (childName != null) { if (childName.FieldType != typeof(string) || (string)childName.GetValue(item.Item1) != _name) { continue; } } } UpdateFields(item.Item1, item.Item2, factor); } }
public void OnRescale(ScalingFactor factor) { TweakScaleTools.RescaleFloatRange(_module, "ejectionForce", factor.relative.quadratic); }
public static void UpdateObject(Part part, Part prefabObj, Dictionary <string, ScaleExponents> exponents, ScalingFactor factor) { if (exponents.ContainsKey("Part")) { exponents["Part"].UpdateFields(part, prefabObj, factor, part); } var modulePairs = part.Modules.Zip(prefabObj.Modules, ModuleAndPrefab.Create); var modulesAndExponents = modulePairs.Join(exponents, modules => ((PartModule)modules.Current).moduleName, exps => exps.Key, ModulesAndExponents.Create).ToArray(); foreach (var modExp in modulesAndExponents) { modExp.Exponents.UpdateFields(modExp.Current, modExp.Prefab, factor, part); } }
public virtual void OnRescale(TweakScale.ScalingFactor akFactor) { scale = akFactor.absolute.linear; }