< Summary

Class:GDX.Developer.ConsoleVariables.BooleanConsoleVariable
Assembly:GDX
File(s):./Packages/com.dotbunny.gdx/GDX/Developer/ConsoleVariables/BooleanConsoleVariable.cs
Covered lines:0
Uncovered lines:40
Coverable lines:40
Total lines:82
Line coverage:0% (0 of 40)
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
BooleanConsoleVariable(...)0%30500%
GetConsoleVariableType()0%2100%
GetBoxedValue()0%2100%
SetValueFromString(...)0%6200%
GetCurrentValueAsString()0%2100%
GetDefaultValueAsString()0%2100%
GetValue()0%2100%
SetValue(...)0%6200%

File(s)

./Packages/com.dotbunny.gdx/GDX/Developer/ConsoleVariables/BooleanConsoleVariable.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 BooleanConsoleVariable : ConsoleVariableBase
 11    {
 12
 13        public Action<bool> OnValueChanged;
 14        readonly bool m_DefaultValue;
 15        bool m_CurrentValue;
 16
 17        public BooleanConsoleVariable(string name, string description, bool defaultValue,
 018            ConsoleVariableFlags flags = ConsoleVariableFlags.None) : base(name, description, flags)
 019        {
 020            if (ConsoleVariableSettings.TryGetValue(name, out string settingsValue) && bool.TryParse(settingsValue, out 
 021            {
 022                m_DefaultValue = newDefaultValue;
 023            }
 24            else
 025            {
 026                m_DefaultValue = defaultValue;
 027            }
 28
 029            if (CommandLineParser.Arguments.ContainsKey(name) && bool.TryParse(CommandLineParser.Arguments[name], out bo
 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.Boolean;
 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            m_CurrentValue = newValue.IsBooleanPositiveValue();
 055            OnValueChanged?.Invoke(m_CurrentValue);
 056        }
 57
 58        /// <inheritdoc />
 59        public override string GetCurrentValueAsString()
 060        {
 061            return m_CurrentValue.ToString();
 062        }
 63
 64        /// <inheritdoc />
 65        public override string GetDefaultValueAsString()
 066        {
 067            return m_DefaultValue.ToString();
 068        }
 69
 70        public bool GetValue()
 071        {
 072            return m_CurrentValue;
 073        }
 74
 75        public void SetValue(bool newValue)
 076        {
 077            m_CurrentValue = newValue;
 078            OnValueChanged?.Invoke(m_CurrentValue);
 079        }
 80    }
 81#endif // UNITY_2022_2_OR_NEWER
 82}