public override void OnLoad(ConfigNode node) { base.OnLoad(node); try { coneTopMode = (ConeEndMode)Enum.Parse(typeof(ConeEndMode), node.GetValue("coneTopMode"), true); } catch { } try { coneBottomMode = (ConeEndMode)Enum.Parse(typeof(ConeEndMode), node.GetValue("coneBottomMode"), true); } catch { } }
public override void OnLoad(ConfigNode node) { base.OnLoad(node); try { coneTopMode = (ConeEndMode)Enum.Parse(typeof(ConeEndMode), node.GetValue("coneTopMode"), true); } // ReSharper disable once EmptyGeneralCatchClause catch { } try { coneBottomMode = (ConeEndMode)Enum.Parse(typeof(ConeEndMode), node.GetValue("coneBottomMode"), true); } // ReSharper disable once EmptyGeneralCatchClause catch { } }
public override void OnLoad(ConfigNode node) { base.OnLoad(node); if (!HighLogic.LoadedSceneIsFlight) { try { coneTopMode = (node.HasValue("coneTopMode")) ? (ConeEndMode)Enum.Parse(typeof(ConeEndMode), node.GetValue("coneTopMode"), true) : ConeEndMode.CanZero; coneBottomMode = (node.HasValue("coneBottomMode")) ? (ConeEndMode)Enum.Parse(typeof(ConeEndMode), node.GetValue("coneBottomMode"), true) : ConeEndMode.CanZero; } catch { Debug.Log($"{ModTag} Invalid coneTopMode or coneBottomMode set for {this} in {node}"); coneTopMode = coneBottomMode = ConeEndMode.CanZero; } } }
private void MaintainParameterRelations(ref float bigEnd, ref float oldBigEnd, ref float smallEnd, ref float oldSmallEnd, ConeEndMode smallEndMode) { // ReSharper disable CompareOfFloatsByEqualityOperator // Ensure the bigger end is not smaller than the min diameter if (bigEnd < PPart.diameterMin) { bigEnd = PPart.diameterMin; } // Aspect ratio stuff if (PPart.aspectMin == 0 && float.IsPositiveInfinity(PPart.aspectMax)) { return; } float aspect = bigEnd / length; if (!MathUtils.TestClamp(ref aspect, PPart.aspectMin, PPart.aspectMax)) { return; } if (bigEnd != oldBigEnd) { // Big end can push the length try { length = MathUtils.RoundTo(bigEnd / aspect, 0.001f); // The aspect is within range if false, we can safely return if (!MathUtils.TestClamp(ref length, PPart.lengthMin, PPart.lengthMax)) { return; } // If the aspect is fixed, then the length is dependent on the diameter anyhow // so just return (we can still limit the total length if we want) if (PPart.aspectMin == PPart.aspectMax) { return; } // Bottom has gone out of range, push back. bigEnd = MathUtils.RoundTo(aspect * length, 0.001f); } finally { oldLength = length; } } else if (length != oldLength) { try { // Length can push the big end bigEnd = MathUtils.RoundTo(aspect * length, 0.001f); // The aspect is within range if true if (!MathUtils.TestClamp(ref bigEnd, PPart.diameterMin, PPart.diameterMax)) { // need to push back on the length length = MathUtils.RoundTo(bigEnd / aspect, 0.001f); } // Delta the small end by the same amount. if (smallEndMode != ConeEndMode.Constant) { smallEnd += bigEnd - oldBigEnd; if (smallEndMode == ConeEndMode.LimitMin && smallEnd < PPart.diameterMin) { smallEnd = PPart.diameterMin; } } } finally { oldBigEnd = bigEnd; oldSmallEnd = smallEnd; } } // The small end is ignored for aspects. // ReSharper restore CompareOfFloatsByEqualityOperator }
private void MaintainParameterRelations(ref float bigEnd, ref float oldBigEnd, ref float smallEnd, ref float oldSmallEnd, ConeEndMode smallEndMode) { // ReSharper disable CompareOfFloatsByEqualityOperator // Ensure the bigger end is not smaller than the min diameter if (bigEnd < PPart.diameterMin) bigEnd = PPart.diameterMin; // Aspect ratio stuff if (PPart.aspectMin == 0 && float.IsPositiveInfinity(PPart.aspectMax)) return; float aspect = bigEnd / length; if (!MathUtils.TestClamp(ref aspect, PPart.aspectMin, PPart.aspectMax)) return; if (bigEnd != oldBigEnd) { // Big end can push the length try { length = MathUtils.RoundTo(bigEnd / aspect, 0.001f); // The aspect is within range if false, we can safely return if (!MathUtils.TestClamp(ref length, PPart.lengthMin, PPart.lengthMax)) return; // If the aspect is fixed, then the length is dependent on the diameter anyhow // so just return (we can still limit the total length if we want) if (PPart.aspectMin == PPart.aspectMax) return; // Bottom has gone out of range, push back. bigEnd = MathUtils.RoundTo(aspect * length, 0.001f); } finally { oldLength = length; } } else if (length != oldLength) { try { // Length can push the big end bigEnd = MathUtils.RoundTo(aspect * length, 0.001f); // The aspect is within range if true if (!MathUtils.TestClamp(ref bigEnd, PPart.diameterMin, PPart.diameterMax)) { // need to push back on the length length = MathUtils.RoundTo(bigEnd / aspect, 0.001f); } // Delta the small end by the same amount. if(smallEndMode != ConeEndMode.Constant) { smallEnd += bigEnd - oldBigEnd; if (smallEndMode == ConeEndMode.LimitMin && smallEnd < PPart.diameterMin) smallEnd = PPart.diameterMin; } } finally { oldBigEnd = bigEnd; oldSmallEnd = smallEnd; } } // The small end is ignored for aspects. // ReSharper restore CompareOfFloatsByEqualityOperator }