SiliconLawsetPrototype.cs 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. using Content.Shared.FixedPoint;
  2. using Robust.Shared.Prototypes;
  3. using Robust.Shared.Serialization;
  4. using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.List;
  5. namespace Content.Shared.Silicons.Laws;
  6. /// <summary>
  7. /// Lawset data used internally.
  8. /// </summary>
  9. [DataDefinition, Serializable, NetSerializable]
  10. public sealed partial class SiliconLawset
  11. {
  12. /// <summary>
  13. /// List of laws in this lawset.
  14. /// </summary>
  15. [DataField(required: true), ViewVariables(VVAccess.ReadWrite)]
  16. public List<SiliconLaw> Laws = new();
  17. /// <summary>
  18. /// What entity the lawset considers as a figure of authority.
  19. /// </summary>
  20. [DataField(required: true), ViewVariables(VVAccess.ReadWrite)]
  21. public string ObeysTo = string.Empty;
  22. /// <summary>
  23. /// A single line used in logging laws.
  24. /// </summary>
  25. public string LoggingString()
  26. {
  27. var laws = new List<string>(Laws.Count);
  28. foreach (var law in Laws)
  29. {
  30. laws.Add($"{law.Order}: {Loc.GetString(law.LawString)}");
  31. }
  32. return string.Join(" / ", laws);
  33. }
  34. /// <summary>
  35. /// Do a clone of this lawset.
  36. /// It will have unique laws but their strings are still shared.
  37. /// </summary>
  38. public SiliconLawset Clone()
  39. {
  40. var laws = new List<SiliconLaw>(Laws.Count);
  41. foreach (var law in Laws)
  42. {
  43. laws.Add(law.ShallowClone());
  44. }
  45. return new SiliconLawset()
  46. {
  47. Laws = laws,
  48. ObeysTo = ObeysTo
  49. };
  50. }
  51. }
  52. /// <summary>
  53. /// This is a prototype for a <see cref="SiliconLawPrototype"/> list.
  54. /// Cannot be used directly since it is a list of prototype ids rather than List<Siliconlaw>.
  55. /// </summary>
  56. [Prototype, Serializable, NetSerializable]
  57. public sealed partial class SiliconLawsetPrototype : IPrototype
  58. {
  59. /// <inheritdoc/>
  60. [IdDataField]
  61. public string ID { get; private set; } = default!;
  62. /// <summary>
  63. /// List of law prototype ids in this lawset.
  64. /// </summary>
  65. [DataField(required: true, customTypeSerializer: typeof(PrototypeIdListSerializer<SiliconLawPrototype>))]
  66. public List<string> Laws = new();
  67. /// <summary>
  68. /// What entity the lawset considers as a figure of authority.
  69. /// </summary>
  70. [DataField(required: true), ViewVariables(VVAccess.ReadWrite)]
  71. public string ObeysTo = string.Empty;
  72. }