< Summary

Class:GDX.DataTables.CellValues.Vector2IntCellValue
Assembly:GDX
File(s):./Packages/com.dotbunny.gdx/GDX/DataTables/CellValues/Vector2IntCellValue.cs
Covered lines:0
Uncovered lines:32
Coverable lines:32
Total lines:127
Line coverage:0% (0 of 32)
Covered branches:0
Total branches:0
Covered methods:0
Total methods:6
Method coverage:0% (0 of 6)

Coverage History

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
Vector2IntCellValue(...)0%2100%
Get()0%6200%
GetDataVersion()0%2100%
GetUnsafe()0%2100%
Set(...)0%6200%
GetSupportedType()0%2100%

File(s)

./Packages/com.dotbunny.gdx/GDX/DataTables/CellValues/Vector2IntCellValue.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 UnityEngine;
 7
 8namespace GDX.DataTables.CellValues
 9{
 10    /// <summary>
 11    ///     A <see cref="DataTableBase" /> <see cref="Vector2Int" /> cell reference.
 12    /// </summary>
 13    [Serializable]
 14    public struct Vector2IntCellValue
 15    {
 16        /// <summary>
 17        ///     The cached struct of the referenced <see cref="DataTable" /> cell.
 18        /// </summary>
 19        Vector2Int m_CachedValue;
 20
 21        /// <summary>
 22        ///     The cached <see cref="DataTable" /> version found when last updating <see cref="m_CachedValue" />.
 23        /// </summary>
 24        ulong m_TableVersion;
 25#pragma warning disable IDE1006
 26        // ReSharper disable InconsistentNaming
 27        /// <summary>
 28        ///     The <see cref="DataTableBase" /> polled for cell data.
 29        /// </summary>
 30        public DataTableBase DataTable;
 31
 32        /// <summary>
 33        ///     The unique column identifier used when accessing the <see cref="DataTable" />.
 34        /// </summary>
 35        public int ColumnIdentifier;
 36
 37        /// <summary>
 38        ///     The unique row identifier used when accessing the <see cref="DataTable" />.
 39        /// </summary>
 40        public int RowIdentifier;
 41        // ReSharper enable InconsistentNaming
 42#pragma warning restore IDE1006
 43
 44        /// <summary>
 45        ///     Creates a <see cref="Vector2IntCellValue" />.
 46        /// </summary>
 47        /// <param name="dataTable">The referenced <see cref="DataTableBase" />.</param>
 48        /// <param name="rowIdentifier">The unique row identifier to use when polling the <paramref name="dataTable" />.
 49        /// <param name="columnIdentifier">The unique column identifier to use when polling the <paramref name="dataTabl
 50        public Vector2IntCellValue(DataTableBase dataTable, int rowIdentifier, int columnIdentifier)
 051        {
 052            DataTable = dataTable;
 053            RowIdentifier = rowIdentifier;
 054            ColumnIdentifier = columnIdentifier;
 055            m_TableVersion = 0;
 056            m_CachedValue = default;
 057            Get();
 058        }
 59
 60        /// <summary>
 61        ///     Get the <see cref="Vector2Int" /> value referenced from the <see cref="DataTableBase" />.
 62        /// </summary>
 63        /// <remarks>
 64        ///     This will evaluate if the version of the table matches the internally cached version, and will update
 65        ///     the cached reference if necessary.
 66        /// </remarks>
 67        /// <returns>A <see cref="Vector2Int" /> struct.</returns>
 68        public Vector2Int Get()
 069        {
 070            if (m_TableVersion == DataTable.GetDataVersion())
 071            {
 072                return m_CachedValue;
 73            }
 74
 075            m_CachedValue = DataTable.GetVector2Int(RowIdentifier, ColumnIdentifier);
 076            m_TableVersion = DataTable.GetDataVersion();
 077            return m_CachedValue;
 078        }
 79
 80        /// <summary>
 81        ///     Get the internally cached version of the <see cref="DataTableBase" />'s data version.
 82        /// </summary>
 83        /// <returns>A version number.</returns>
 84        public ulong GetDataVersion()
 085        {
 086            return m_TableVersion;
 087        }
 88
 89        /// <summary>
 90        ///     Get the cached value without a version check.
 91        /// </summary>
 92        /// <remarks>
 93        ///     This can respond with a default value if a <see cref="Get" /> call has not been made yet to populate the
 94        ///     internally cached value.
 95        /// </remarks>
 96        /// <returns>A <see cref="Vector2Int" /> struct.</returns>
 97        public Vector2Int GetUnsafe()
 098        {
 099            return m_CachedValue;
 0100        }
 101
 102
 103        /// <summary>
 104        ///     Sets the cached value of the struct and by default, updates the associated <see cref="DataTableBase" />.
 105        /// </summary>
 106        /// <remarks>Updating the <see cref="DataTableBase" /> will update the cached table version.</remarks>
 107        /// <param name="newValue">A <see cref="Vector2Int" /> struct.</param>
 108        /// <param name="updateTable">Should the value be pushed back to the referenced <see cref="DataTableBase" /> cel
 109        public void Set(Vector2Int newValue, bool updateTable = true)
 0110        {
 0111            m_CachedValue = newValue;
 0112            if (updateTable)
 0113            {
 0114                m_TableVersion = DataTable.SetVector2Int(RowIdentifier, ColumnIdentifier, newValue);
 0115            }
 0116        }
 117
 118        /// <summary>
 119        ///     Get the <see cref="Serializable.SerializableTypes" /> which this struct supports.
 120        /// </summary>
 121        /// <returns>A <see cref="Serializable.SerializableTypes" />.</returns>
 122        public static Serializable.SerializableTypes GetSupportedType()
 0123        {
 0124            return Serializable.SerializableTypes.Vector2Int;
 0125        }
 126    }
 127}