< Summary

Class:GDX.Developer.ConsoleVariables.FloatConsoleVariable
Assembly:GDX
File(s):./Packages/com.dotbunny.gdx/GDX/Developer/ConsoleVariables/FloatConsoleVariable.cs
Covered lines:0
Uncovered lines:42
Coverable lines:42
Total lines:84
Line coverage:0% (0 of 42)
Covered branches:0
Total branches:0
Covered methods:0
Total methods:8
Method coverage:0% (0 of 8)

Coverage History

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
FloatConsoleVariable(...)0%30500%
GetConsoleVariableType()0%2100%
GetBoxedValue()0%2100%
SetValueFromString(...)0%12300%
GetCurrentValueAsString()0%2100%
GetDefaultValueAsString()0%2100%
GetValue()0%2100%
SetValue(...)0%6200%

File(s)

./Packages/com.dotbunny.gdx/GDX/Developer/ConsoleVariables/FloatConsoleVariable.cs

#LineLine coverage
 1// Copyright (c) 2020-2024 dotBunny Inc.
 2// dotBunny licenses this file to you under the BSL-1.0 license.
 3// See the LICENSE file in the project root for more information.
 4
 5using System;
 6using System.Globalization;
 7
 8namespace GDX.Developer.ConsoleVariables
 9{
 10#if UNITY_2022_2_OR_NEWER
 11    public class FloatConsoleVariable : ConsoleVariableBase
 12    {
 13        public Action<float> OnValueChanged;
 14        readonly float m_DefaultValue;
 15        float m_CurrentValue;
 16
 17        public FloatConsoleVariable(string name, string description, float defaultValue,
 018            ConsoleVariableFlags flags = ConsoleVariableFlags.None) : base(name, description, flags)
 019        {
 020            if (ConsoleVariableSettings.TryGetValue(name, out string settingsValue) && float.TryParse(settingsValue, out
 021            {
 022                m_DefaultValue = newDefaultValue;
 023            }
 24            else
 025            {
 026                m_DefaultValue = defaultValue;
 027            }
 28
 029            if (CommandLineParser.Arguments.ContainsKey(name) && float.TryParse(CommandLineParser.Arguments[name], out f
 030            {
 031                m_CurrentValue = newCurrentValue;
 032            }
 33            else
 034            {
 035                m_CurrentValue = defaultValue;
 036            }
 037        }
 38
 39        /// <inheritdoc />
 40        public override ConsoleVariableType GetConsoleVariableType()
 041        {
 042            return ConsoleVariableType.Float;
 043        }
 44
 45        /// <inheritdoc />
 46        public override object GetBoxedValue()
 047        {
 048            return m_CurrentValue;
 049        }
 50
 51        /// <inheritdoc />
 52        public sealed override void SetValueFromString(string newValue)
 053        {
 054            if(float.TryParse(newValue, out m_CurrentValue))
 055            {
 056                OnValueChanged?.Invoke(m_CurrentValue);
 057            }
 058        }
 59
 60        /// <inheritdoc />
 61        public override string GetCurrentValueAsString()
 062        {
 063            return m_CurrentValue.ToString(CultureInfo.InvariantCulture);
 064        }
 65
 66        /// <inheritdoc />
 67        public override string GetDefaultValueAsString()
 068        {
 069            return m_DefaultValue.ToString(CultureInfo.InvariantCulture);
 070        }
 71
 72        public float GetValue()
 073        {
 074            return m_CurrentValue;
 075        }
 76
 77        public void SetValue(float newValue)
 078        {
 079            m_CurrentValue = newValue;
 080            OnValueChanged?.Invoke(m_CurrentValue);
 081        }
 82    }
 83#endif // UNITY_2022_2_OR_NEWER
 84}