< Summary

Class:GDX.Developer.WatchSettings
Assembly:GDX
File(s):./Packages/com.dotbunny.gdx/GDX/Developer/WatchSettings.cs
Covered lines:20
Uncovered lines:44
Coverable lines:64
Total lines:107
Line coverage:31.2% (20 of 64)
Covered branches:0
Total branches:0
Covered methods:4
Total methods:5
Method coverage:80% (4 of 5)

Coverage History

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
WatchSettings()0%110100%
SaveToFile()0%12300%
TryGetValue(...)0%3.113076.92%
UpdateFromFile()0%32.77019.35%
GetWatchesSaveFile()0%110100%

File(s)

./Packages/com.dotbunny.gdx/GDX/Developer/WatchSettings.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.IO;
 7using GDX.Collections.Generic;
 8
 9namespace GDX.Developer
 10{
 11#if UNITY_2022_2_OR_NEWER
 12    public static class WatchSettings
 13    {
 214        static StringKeyDictionary<bool> s_ParsedState = new StringKeyDictionary<bool>(50);
 15
 16        static bool s_HasReadFile;
 17
 18        public static void SaveToFile()
 019        {
 020            int count = WatchProvider.GetTotalCount();
 021            TextGenerator textGenerator = new TextGenerator();
 022            WatchProvider.WatchList watches = WatchProvider.GetWatchList();
 023            textGenerator.AppendLine("# Generated file of Watches states.");
 024            textGenerator.AppendLine("# All non supported content will be removed on save.");
 025            textGenerator.AppendLine("");
 26
 027            for (int i = 0; i < count; i++)
 028            {
 029                textGenerator.AppendLine(watches.IsActive[i]
 30                    ? $"{watches.Identfiers[i]} 1"
 31                    : $"{watches.Identfiers[i]} 0");
 032            }
 33
 34            try
 035            {
 036                File.WriteAllTextAsync(GetWatchesSaveFile(), textGenerator.ToString());
 037            }
 038            catch (Exception)
 039            {
 40                // ignored
 041            }
 042        }
 43
 44        public static bool TryGetValue(string name, out bool foundValue)
 245        {
 246            if (!s_HasReadFile)
 247            {
 248                UpdateFromFile();
 249                s_HasReadFile = true;
 250            }
 51
 252            if (s_ParsedState.ContainsKey(name))
 053            {
 054                foundValue = s_ParsedState[name];
 055                return true;
 56            }
 57
 258            foundValue = false;
 259            return false;
 260        }
 61
 62        public static void UpdateFromFile()
 963        {
 64            // Read in the settings from the cvars saved file
 965            string settingsFile = GetWatchesSaveFile();
 966            if (!File.Exists(settingsFile))
 967            {
 968                return;
 69            }
 70
 071            string[] lines = File.ReadAllLines(settingsFile);
 072            int lineCount = lines.Length;
 073            for (int i = 0; i < lineCount; i++)
 074            {
 075                string line = lines[i].Trim();
 076                if ( string.IsNullOrEmpty(line) || line[0] == '#') // Skip comments
 077                {
 078                    continue;
 79                }
 80
 81                // Update settings cache
 082                string[] split = line.Split(' ', 2, StringSplitOptions.RemoveEmptyEntries);
 083                bool value = split[1].IsBooleanPositiveValue();
 084                if (!s_ParsedState.ContainsKey(split[0]))
 085                {
 086                    s_ParsedState.AddWithExpandCheck(split[0], value);
 087                }
 88                else
 089                {
 090                    s_ParsedState[split[0]] = value;
 091                }
 92
 093                WatchBase watch = WatchProvider.GetWatch(split[0]);
 094                if (watch != null)
 095                {
 096                    WatchProvider.SetState(watch, value);
 097                }
 098            }
 999        }
 100
 101        static string GetWatchesSaveFile()
 9102        {
 9103            return Path.Combine(Platform.GetOutputFolder(), "watches.gdx");
 9104        }
 105    }
 106#endif // UNITY_2022_2_OR_NEWER
 107}

Coverage by test methods







Methods/Properties

WatchSettings()
SaveToFile()
TryGetValue(System.String, System.Boolean&)
UpdateFromFile()
GetWatchesSaveFile()