< Summary

Information
Class: Lattice.ECS.Framework.SystemAuthoringContract
Assembly: Lattice
File(s): /home/runner/work/Sideline/Sideline/godot/scripts/lattice/ECS/Framework/SystemAuthoringContract.cs
Line coverage
81%
Covered lines: 22
Uncovered lines: 5
Coverable lines: 27
Total lines: 118
Line coverage: 81.4%
Branch coverage
72%
Covered branches: 16
Total branches: 22
Branch coverage: 72.7%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)75%9875%
get_Default()100%11100%
get_ReadOnly()100%210%
get_FrameAccess()100%11100%
get_GlobalAccess()100%11100%
get_StructuralChangeAccess()100%11100%
get_AllowsGlobalReads()100%11100%
get_AllowsGlobalWrites()100%11100%
get_AllowsStructuralChanges()100%11100%
Equals(...)50%44100%
Equals(...)0%620%
GetHashCode()100%210%
ValidateForPhase(...)100%88100%

File(s)

/home/runner/work/Sideline/Sideline/godot/scripts/lattice/ECS/Framework/SystemAuthoringContract.cs

#LineLine coverage
 1using System;
 2
 3namespace Lattice.ECS.Framework
 4{
 5    /// <summary>
 6    /// 系统对普通帧状态的访问意图。
 7    /// 当前主要用于声明系统作者契约,而不是提供一套更重的系统基类家族。
 8    /// </summary>
 9    public enum SystemFrameAccess
 10    {
 11        ReadOnly = 0,
 12        ReadWrite = 1
 13    }
 14
 15    /// <summary>
 16    /// 系统对全局状态 API 的访问意图。
 17    /// </summary>
 18    public enum SystemGlobalAccess
 19    {
 20        None = 0,
 21        ReadOnly = 1,
 22        ReadWrite = 2
 23    }
 24
 25    /// <summary>
 26    /// 系统是否允许发起结构性修改。
 27    /// 当前正式语义只有“不允许”与“允许发起延迟结构性修改”两档。
 28    /// </summary>
 29    public enum SystemStructuralChangeAccess
 30    {
 31        None = 0,
 32        Deferred = 1
 33    }
 34
 35    /// <summary>
 36    /// 轻量系统作者契约。
 37    /// 用于声明系统在 `OnUpdate(...)` 中允许使用的状态访问能力,
 38    /// 让 phase、global state 与结构性修改规则不再只靠团队默契维持。
 39    /// </summary>
 40    public readonly struct SystemAuthoringContract : IEquatable<SystemAuthoringContract>
 41    {
 42        public SystemAuthoringContract(
 43            SystemFrameAccess frameAccess = SystemFrameAccess.ReadWrite,
 44            SystemGlobalAccess globalAccess = SystemGlobalAccess.None,
 45            SystemStructuralChangeAccess structuralChangeAccess = SystemStructuralChangeAccess.None)
 46        {
 36547            if (frameAccess == SystemFrameAccess.ReadOnly && globalAccess == SystemGlobalAccess.ReadWrite)
 48            {
 049                throw new ArgumentException("Read-only systems cannot declare writable global state access.", nameof(glo
 50            }
 51
 36552            if (frameAccess == SystemFrameAccess.ReadOnly && structuralChangeAccess != SystemStructuralChangeAccess.None
 53            {
 054                throw new ArgumentException("Read-only systems cannot declare structural change access.", nameof(structu
 55            }
 56
 36557            FrameAccess = frameAccess;
 36558            GlobalAccess = globalAccess;
 36559            StructuralChangeAccess = structuralChangeAccess;
 36560        }
 61
 62        /// <summary>
 63        /// 默认系统契约:
 64        /// 允许读写普通组件数据,但不默认开放 global state 与结构性修改。
 65        /// </summary>
 348466        public static SystemAuthoringContract Default => new();
 67
 68        /// <summary>
 69        /// 只读系统默认契约。
 70        /// </summary>
 071        public static SystemAuthoringContract ReadOnly => new(SystemFrameAccess.ReadOnly);
 72
 273        public SystemFrameAccess FrameAccess { get; }
 74
 33175        public SystemGlobalAccess GlobalAccess { get; }
 76
 132277        public SystemStructuralChangeAccess StructuralChangeAccess { get; }
 78
 10479        public bool AllowsGlobalReads => GlobalAccess != SystemGlobalAccess.None;
 80
 22581        public bool AllowsGlobalWrites => GlobalAccess == SystemGlobalAccess.ReadWrite;
 82
 132083        public bool AllowsStructuralChanges => StructuralChangeAccess == SystemStructuralChangeAccess.Deferred;
 84
 85        public bool Equals(SystemAuthoringContract other)
 86        {
 187            return FrameAccess == other.FrameAccess &&
 188                   GlobalAccess == other.GlobalAccess &&
 189                   StructuralChangeAccess == other.StructuralChangeAccess;
 90        }
 91
 92        public override bool Equals(object? obj)
 93        {
 094            return obj is SystemAuthoringContract other && Equals(other);
 95        }
 96
 97        public override int GetHashCode()
 98        {
 099            return HashCode.Combine((int)FrameAccess, (int)GlobalAccess, (int)StructuralChangeAccess);
 100        }
 101
 102        internal void ValidateForPhase(SystemPhase phase, Type systemType)
 103        {
 129104            if (!AllowsGlobalWrites)
 105            {
 123106                return;
 107            }
 108
 6109            if (phase == SystemPhase.Input || phase == SystemPhase.Resolve || phase == SystemPhase.Cleanup)
 110            {
 5111                return;
 112            }
 113
 1114            throw new InvalidOperationException(
 1115                $"System {systemType.Name} declares writable global state access, but phase {phase} only supports global
 116        }
 117    }
 118}