SiliconLawPrototype.cs 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. using Content.Shared.FixedPoint;
  2. using Robust.Shared.Prototypes;
  3. using Robust.Shared.Serialization;
  4. namespace Content.Shared.Silicons.Laws;
  5. [Virtual, DataDefinition]
  6. [Serializable, NetSerializable]
  7. public partial class SiliconLaw : IComparable<SiliconLaw>, IEquatable<SiliconLaw>
  8. {
  9. /// <summary>
  10. /// A locale string which is the actual text of the law.
  11. /// </summary>
  12. [DataField(required: true), ViewVariables(VVAccess.ReadWrite)]
  13. public string LawString = string.Empty;
  14. /// <summary>
  15. /// The order of the law in the sequence.
  16. /// Also is the identifier if <see cref="LawIdentifierOverride"/> is null.
  17. /// </summary>
  18. /// <remarks>
  19. /// This is a fixedpoint2 only for the niche case of supporting laws that go between 0 and 1.
  20. /// Funny.
  21. /// </remarks>
  22. [DataField(required: true), ViewVariables(VVAccess.ReadWrite)]
  23. public FixedPoint2 Order;
  24. /// <summary>
  25. /// An identifier that overrides <see cref="Order"/> in the law menu UI.
  26. /// </summary>
  27. [DataField, ViewVariables(VVAccess.ReadWrite)]
  28. public string? LawIdentifierOverride;
  29. public int CompareTo(SiliconLaw? other)
  30. {
  31. if (other == null)
  32. return -1;
  33. return Order.CompareTo(other.Order);
  34. }
  35. public bool Equals(SiliconLaw? other)
  36. {
  37. if (other == null)
  38. return false;
  39. return LawString == other.LawString
  40. && Order == other.Order
  41. && LawIdentifierOverride == other.LawIdentifierOverride;
  42. }
  43. public override bool Equals(object? obj)
  44. {
  45. if (obj == null)
  46. return false;
  47. return Equals(obj as SiliconLaw);
  48. }
  49. public override int GetHashCode()
  50. {
  51. return HashCode.Combine(LawString, Order, LawIdentifierOverride);
  52. }
  53. /// <summary>
  54. /// Return a shallow clone of this law.
  55. /// </summary>
  56. public SiliconLaw ShallowClone()
  57. {
  58. return new SiliconLaw()
  59. {
  60. LawString = LawString,
  61. Order = Order,
  62. LawIdentifierOverride = LawIdentifierOverride
  63. };
  64. }
  65. }
  66. /// <summary>
  67. /// This is a prototype for a law governing the behavior of silicons.
  68. /// </summary>
  69. [Prototype]
  70. [Serializable, NetSerializable]
  71. public sealed partial class SiliconLawPrototype : SiliconLaw, IPrototype
  72. {
  73. /// <inheritdoc/>
  74. [IdDataField]
  75. public string ID { get; private set; } = default!;
  76. }