From c991eead896788390459566ecaa016bb0960fce1 Mon Sep 17 00:00:00 2001 From: Ottermandias Date: Sat, 3 Jun 2023 15:50:20 +0200 Subject: [PATCH] More readonlys. --- Penumbra.GameData/Structs/CharacterArmor.cs | 10 +++++----- Penumbra.GameData/Structs/CharacterWeapon.cs | 14 +++++++------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/Penumbra.GameData/Structs/CharacterArmor.cs b/Penumbra.GameData/Structs/CharacterArmor.cs index f44ae5e6..9027a5cf 100644 --- a/Penumbra.GameData/Structs/CharacterArmor.cs +++ b/Penumbra.GameData/Structs/CharacterArmor.cs @@ -9,7 +9,7 @@ public struct CharacterArmor : IEquatable public const int Size = 4; [FieldOffset(0)] - public uint Value; + public readonly uint Value; [FieldOffset(0)] public SetId Set; @@ -37,18 +37,18 @@ public struct CharacterArmor : IEquatable public readonly CharacterWeapon ToWeapon(StainId stain) => new(Set, 0, Variant, stain); - public override string ToString() + public override readonly string ToString() => $"{Set},{Variant},{Stain}"; public static readonly CharacterArmor Empty; - public bool Equals(CharacterArmor other) + public readonly bool Equals(CharacterArmor other) => Value == other.Value; - public override bool Equals(object? obj) + public override readonly bool Equals(object? obj) => obj is CharacterArmor other && Equals(other); - public override int GetHashCode() + public override readonly int GetHashCode() => (int)Value; public static bool operator ==(CharacterArmor left, CharacterArmor right) diff --git a/Penumbra.GameData/Structs/CharacterWeapon.cs b/Penumbra.GameData/Structs/CharacterWeapon.cs index 7b40f55f..a1f2dd11 100644 --- a/Penumbra.GameData/Structs/CharacterWeapon.cs +++ b/Penumbra.GameData/Structs/CharacterWeapon.cs @@ -16,12 +16,12 @@ public struct CharacterWeapon : IEquatable public ushort Variant; [FieldOffset(6)] - public StainId Stain; - - public ulong Value + public StainId Stain; + + public readonly ulong Value => (ulong)Set | ((ulong)Type << 16) | ((ulong)Variant << 32) | ((ulong)Stain << 48); - public override string ToString() + public override readonly string ToString() => $"{Set},{Type},{Variant},{Stain}"; public CharacterWeapon(SetId set, WeaponType type, ushort variant, StainId stain) @@ -48,13 +48,13 @@ public struct CharacterWeapon : IEquatable public static readonly CharacterWeapon Empty = new(0, 0, 0, 0); - public bool Equals(CharacterWeapon other) + public readonly bool Equals(CharacterWeapon other) => Value == other.Value; - public override bool Equals(object? obj) + public override readonly bool Equals(object? obj) => obj is CharacterWeapon other && Equals(other); - public override int GetHashCode() + public override readonly int GetHashCode() => Value.GetHashCode(); public static bool operator ==(CharacterWeapon left, CharacterWeapon right)