< Summary

Class:GDX.Developer.ConsoleVariables.IntegerConsoleVariable
Assembly:GDX
File(s):./Packages/com.dotbunny.gdx/GDX/Developer/ConsoleVariables/IntegerConsoleVariable.cs
Covered lines:0
Uncovered lines:42
Coverable lines:42
Total lines:83
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
IntegerConsoleVariable(...)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/IntegerConsoleVariable.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;
 6
 7namespace GDX.Developer.ConsoleVariables
 8{
 9#if UNITY_2022_2_OR_NEWER
 10    public class IntegerConsoleVariable : ConsoleVariableBase
 11    {
 12        public Action<int> OnValueChanged;
 13        readonly int m_DefaultValue;
 14        int m_CurrentValue;
 15
 16        public IntegerConsoleVariable(string name, string description, int defaultValue,
 017            ConsoleVariableFlags flags = ConsoleVariableFlags.None) : base(name, description, flags)
 018        {
 019            if (ConsoleVariableSettings.TryGetValue(name, out string settingsValue) && int.TryParse(settingsValue, out i
 020            {
 021                m_DefaultValue = newDefaultValue;
 022            }
 23            else
 024            {
 025                m_DefaultValue = defaultValue;
 026            }
 27
 028            if (CommandLineParser.Arguments.ContainsKey(name) && int.TryParse(CommandLineParser.Arguments[name], out int
 029            {
 030                m_CurrentValue = newCurrentValue;
 031            }
 32            else
 033            {
 034                m_CurrentValue = defaultValue;
 035            }
 036        }
 37
 38        /// <inheritdoc />
 39        public override ConsoleVariableType GetConsoleVariableType()
 040        {
 041            return ConsoleVariableType.Integer;
 042        }
 43
 44        /// <inheritdoc />
 45        public override object GetBoxedValue()
 046        {
 047            return m_CurrentValue;
 048        }
 49
 50        /// <inheritdoc />
 51        public sealed override void SetValueFromString(string newValue)
 052        {
 053            if (int.TryParse(newValue, out m_CurrentValue))
 054            {
 055                OnValueChanged?.Invoke(m_CurrentValue);
 056            }
 057        }
 58
 59        /// <inheritdoc />
 60        public override string GetCurrentValueAsString()
 061        {
 062            return m_CurrentValue.ToString();
 063        }
 64
 65        /// <inheritdoc />
 66        public override string GetDefaultValueAsString()
 067        {
 068            return m_DefaultValue.ToString();
 069        }
 70
 71        public int GetValue()
 072        {
 073            return m_CurrentValue;
 074        }
 75
 76        public void SetValue(int newValue)
 077        {
 078            m_CurrentValue = newValue;
 079            OnValueChanged?.Invoke(m_CurrentValue);
 080        }
 81    }
 82#endif // UNITY_2022_2_OR_NEWER
 83}