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

@ -227,23 +227,17 @@ public abstract partial class BaseBeverage : Item, IHasQuantity
[SerializableFieldAttr("[CommandProperty(AccessLevel.GameMaster)]")]
private Mobile _poisoner;
[SerializableField(2, getter: "private", setter: "private")]
private BeverageType _rawContent;
[SerializableField(3, getter: "private", setter: "private")]
private int _rawQuantity;
public BaseBeverage() => ItemID = ComputeItemID();
public BaseBeverage(BeverageType type)
{
_rawContent = type;
_rawQuantity = MaxQuantity;
_content = type;
_quantity = MaxQuantity;
ItemID = ComputeItemID();
}
public override int LabelNumber =>
IsEmpty || BaseLabelNumber == 0 ? EmptyLabelNumber : BaseLabelNumber + (int)_rawContent;
IsEmpty || BaseLabelNumber == 0 ? EmptyLabelNumber : BaseLabelNumber + (int)_content;
public virtual bool ShowQuantity => MaxQuantity > 1;
public virtual bool Fillable => true;
@ -255,21 +249,22 @@ public abstract partial class BaseBeverage : Item, IHasQuantity
public abstract int MaxQuantity { get; }
[CommandProperty(AccessLevel.GameMaster)]
public bool IsEmpty => _rawQuantity <= 0;
public bool IsEmpty => _quantity <= 0;
[CommandProperty(AccessLevel.GameMaster)]
public bool ContainsAlcohol => !IsEmpty && _rawContent is not BeverageType.Milk and not BeverageType.Water;
public bool ContainsAlcohol => !IsEmpty && _content is not BeverageType.Milk and not BeverageType.Water;
[CommandProperty(AccessLevel.GameMaster)]
public bool IsFull => _rawQuantity >= MaxQuantity;
public bool IsFull => _quantity >= MaxQuantity;
[SerializableProperty(2)]
[CommandProperty(AccessLevel.GameMaster)]
public BeverageType Content
{
get => _rawContent;
get => _content;
set
{
RawContent = value;
_content = value;
InvalidateProperties();
@ -286,13 +281,14 @@ public abstract partial class BaseBeverage : Item, IHasQuantity
}
}
[SerializableProperty(3)]
[CommandProperty(AccessLevel.GameMaster)]
public int Quantity
{
get => _rawQuantity;
get => _quantity;
set
{
RawQuantity = Math.Clamp(value, 0, MaxQuantity);
_quantity = Math.Clamp(value, 0, MaxQuantity);
InvalidateProperties();
@ -313,7 +309,7 @@ public abstract partial class BaseBeverage : Item, IHasQuantity
public virtual int GetQuantityDescription()
{
return (_rawQuantity * 100 / MaxQuantity) switch
return (_quantity * 100 / MaxQuantity) switch
{
<= 0 => 1042975,
<= 33 => 1042974,
@ -715,8 +711,8 @@ public abstract partial class BaseBeverage : Item, IHasQuantity
{
_poison = reader.ReadPoison();
_poisoner = reader.ReadEntity<Mobile>();
_rawContent = (BeverageType)reader.ReadInt();
_rawQuantity = reader.ReadInt();
_content = (BeverageType)reader.ReadInt();
_quantity = reader.ReadInt();
}
public static void Initialize()

View file

@ -58,8 +58,6 @@ public partial class WoodenBowl : Item
[SerializationGenerator(0, false)]
public partial class SackFlour : Item, IHasQuantity
{
private int _quantity;
[Constructible]
public SackFlour() : base(0x1039)
{
@ -68,7 +66,7 @@ public partial class SackFlour : Item, IHasQuantity
}
[CommandProperty(AccessLevel.GameMaster)]
[SerializableField(0)]
[SerializableProperty(0)]
public int Quantity
{
get => _quantity;