feat: Updates to Serialization Generator v2.2 (#1157)

* Adds `SerializationProperty` - This will generate the private variable for serialization. Also provides an option `useField` to specify your own. Example:
  ```cs
  [SerializationProperty(0, useField: nameof(_resource)]
  ```
This commit is contained in:
Kamron Batman 2022-09-04 08:45:27 -07:00 • committed by GitHub
parent d82028a071
commit 89815ad4d3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
50 changed files with 242 additions and 361 deletions

View file

@ -24,9 +24,6 @@ namespace Server.Items
[SerializationGenerator(3, false)]
public abstract partial class BaseAddon : Item, IChoppable, IAddon
{
[SerializableField(1, "private", "private")]
private CraftResource _rawResource;
public BaseAddon() : base(1)
{
Movable = false;
@ -66,16 +63,17 @@ namespace Server.Items
}
}
[SerializableProperty(1)]
[CommandProperty(AccessLevel.GameMaster)]
public CraftResource Resource
{
get => _rawResource;
get => _resource;
set
{
if (_rawResource != value)
if (_resource != value)
{
RawResource = value;
Hue = CraftResources.GetHue(_rawResource);
_resource = value;
Hue = CraftResources.GetHue(_resource);
InvalidateProperties();
this.MarkDirty();
@ -285,7 +283,7 @@ namespace Server.Items
if (version == 2)
{
_rawResource = (CraftResource)reader.ReadEncodedInt();
_resource = (CraftResource)reader.ReadEncodedInt();
}
}
}

View file

@ -10,9 +10,6 @@ namespace Server.Items
[SerializableField(0, setter: "private")]
private List<AddonContainerComponent> _components;
[SerializableField(1, "private", "private")]
private CraftResource _rawResource;
public BaseAddonContainer(int itemID) : base(itemID)
{
AddonComponent.ApplyLightTo(this);
@ -44,16 +41,17 @@ namespace Server.Items
}
}
[SerializableProperty(1)]
[CommandProperty(AccessLevel.GameMaster)]
public CraftResource Resource
{
get => _rawResource;
get => _resource;
set
{
if (_rawResource != value)
if (_resource != value)
{
RawResource = value;
Hue = CraftResources.GetHue(_rawResource);
_resource = value;
Hue = CraftResources.GetHue(_resource);
InvalidateProperties();
this.MarkDirty();
@ -172,9 +170,9 @@ namespace Server.Items
{
base.GetProperties(list);
if (!CraftResources.IsStandard(_rawResource))
if (!CraftResources.IsStandard(_resource))
{
list.Add(CraftResources.GetLocalizationNumber(_rawResource));
list.Add(CraftResources.GetLocalizationNumber(_resource));
}
}
@ -205,7 +203,7 @@ namespace Server.Items
private void Deserialize(IGenericReader reader, int version)
{
_components = reader.ReadEntityList<AddonContainerComponent>();
_rawResource = version == 1 ? reader.ReadEnum<CraftResource>() : (CraftResource)reader.ReadInt();
_resource = version == 1 ? reader.ReadEnum<CraftResource>() : (CraftResource)reader.ReadInt();
}
[AfterDeserialization]

View file

@ -27,8 +27,6 @@ namespace Server.Items
new[] { 0x1924, 0x1924, 0x1928 }
};
private int _flour;
[Constructible]
public FlourMillEastAddon()
{
@ -40,10 +38,10 @@ namespace Server.Items
public override BaseAddonDeed Deed => new FlourMillEastDeed();
[CommandProperty(AccessLevel.GameMaster)]
public bool HasFlour => _flour > 0;
public bool HasFlour => _curFlour > 0;
[CommandProperty(AccessLevel.GameMaster)]
public bool IsFull => _flour >= MaxFlour;
public bool IsFull => _curFlour >= MaxFlour;
[CommandProperty(AccessLevel.GameMaster)]
public bool IsWorking { get; private set; }
@ -51,14 +49,14 @@ namespace Server.Items
[CommandProperty(AccessLevel.GameMaster)]
public int MaxFlour => 2;
[SerializableField(0)]
[SerializableProperty(0)]
[CommandProperty(AccessLevel.GameMaster)]
public int CurFlour
{
get => _flour;
get => _curFlour;
set
{
_flour = Math.Clamp(value, 0, MaxFlour);
_curFlour = Math.Clamp(value, 0, MaxFlour);
UpdateStage();
this.MarkDirty();
}
@ -86,7 +84,7 @@ namespace Server.Items
if (from.PlaceInBackpack(flour))
{
_flour = 0;
_curFlour = 0;
}
else
{

View file

@ -14,8 +14,6 @@ namespace Server.Items
new[] { 0x1930, 0x1930, 0x1934 }
};
private int _flour;
[Constructible]
public FlourMillSouthAddon()
{
@ -27,10 +25,10 @@ namespace Server.Items
public override BaseAddonDeed Deed => new FlourMillSouthDeed();
[CommandProperty(AccessLevel.GameMaster)]
public bool HasFlour => _flour > 0;
public bool HasFlour => _curFlour > 0;
[CommandProperty(AccessLevel.GameMaster)]
public bool IsFull => _flour >= MaxFlour;
public bool IsFull => _curFlour >= MaxFlour;
[CommandProperty(AccessLevel.GameMaster)]
public bool IsWorking { get; private set; }
@ -38,14 +36,14 @@ namespace Server.Items
[CommandProperty(AccessLevel.GameMaster)]
public int MaxFlour => 2;
[SerializableField(0)]
[SerializableProperty(0)]
[CommandProperty(AccessLevel.GameMaster)]
public int CurFlour
{
get => _flour;
get => _curFlour;
set
{
_flour = Math.Max(0, Math.Min(value, MaxFlour));
_curFlour = Math.Max(0, Math.Min(value, MaxFlour));
UpdateStage();
}
}
@ -74,7 +72,7 @@ namespace Server.Items
if (from.PlaceInBackpack(flour))
{
_flour = 0;
_curFlour = 0;
}
else
{

View file

@ -11,13 +11,6 @@ namespace Server.Items
[SerializableFieldAttr("[CommandProperty(AccessLevel.GameMaster)]")]
private Point3D _teleOffset;
//The extra custom processing done in the property setters causes deserialisation to fail.
//These hidden private members will auto generate properties with no processing which we can point to.
[SerializableField(0, getter: "private", setter: "private")]
private bool _rawActive;
[SerializableField(1, getter: "private", setter: "private")]
private SHTeleComponent _rawTeleDest;
[Constructible]
public SHTeleComponent(int itemID = 0x1775) : this(itemID, new Point3D(0, 0, 0))
{
@ -29,17 +22,18 @@ namespace Server.Items
Movable = false;
Hue = 1;
_rawActive = true;
TeleOffset = offset;
_active = true;
_teleOffset = offset;
}
[SerializableProperty(0)]
[CommandProperty(AccessLevel.GameMaster)]
public bool Active
{
get => RawActive;
get => _active;
set
{
RawActive = value;
_active = value;
if (Addon is SHTeleporter sourceAddon)
{
@ -48,13 +42,14 @@ namespace Server.Items
}
}
[SerializableProperty(1)]
[CommandProperty(AccessLevel.GameMaster)]
public SHTeleComponent TeleDest
{
get => RawTeleDest;
get => _teleDest;
set
{
RawTeleDest = value;
_teleDest = value;
if (Addon is SHTeleporter sourceAddon)
{
@ -74,15 +69,15 @@ namespace Server.Items
public override void OnDoubleClick(Mobile m)
{
if (!_rawActive || _rawTeleDest?.Deleted != false || _rawTeleDest.Map == Map.Internal)
if (!_active || _teleDest?.Deleted != false || _teleDest.Map == Map.Internal)
{
return;
}
if (m.InRange(this, 3))
{
var map = _rawTeleDest.Map;
var p = _rawTeleDest.TelePoint;
var map = _teleDest.Map;
var p = _teleDest.TelePoint;
BaseCreature.TeleportPets(m, p, map);