fix: Fixes serialization and dirty tracking conveniences (#1627)

### Summary
- Fixes issues with non-_ISerializable_ objects having bad serialization (Skill/Stat. Mods)
- Fixes issues with MarkDirty and namespaces: https://github.com/modernuo/SerializationGenerator/issues/29
- Fixes missing dirty tracking for some data structures.
- Fixes cascading MarkDirty for non-serializable types that have owners that are also non-serializable types.

### New Codegenned API
When a data structure (Array, List, Dictionary, HashSet, etc) is source generated for serialization, new methods are added which will handle dirty tracking. Use these instead of the built in methods for that data structure.

_All Data Structures_
```cs
public void Clear<PropertyName>();
```

_Lists and Sets_
```cs
public void AddTo<PropertyName>(V value);
public void RemoveFrom<PropertyName>(V value);
```

_Lists_
```cs
public void InsertInto<PropertyName>(int index, V value);
public void RemoveFrom<PropertyName>At(int index);
```

_Dictionaries_
```cs
public void AddTo<PropertyName>(T key, V value);
public void RemoveFrom<PropertyName>(T key);
public void ReplaceIn<PropertyName>(T key, V value);
```

Over time, they will be cleaned up and more variants added such as `bool RemoveFrom<PropertyName>(T key, out V value)`
This commit is contained in:
Kamron Batman 2023-12-03 18:55:31 -05:00 • committed by GitHub
parent 3a0d4b171b
commit b7882df136
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
25 changed files with 64 additions and 77 deletions

View file

@ -146,13 +146,13 @@ public partial class BroadcastCrystal : Item
public void AddReceiver(ReceiverCrystal receiver)
{
this.Add(Receivers, receiver);
AddToReceivers(receiver);
InvalidateProperties();
}
public void RemoveReceiver(ReceiverCrystal receiver)
{
this.Remove(Receivers, receiver);
RemoveFromReceivers(receiver);
InvalidateProperties();
}

View file

@ -675,7 +675,7 @@ public partial class Corpse : Container, ICarvable
from.CriminalAction(true);
}
this.Add(_looters, from);
AddToLooters(from);
_instancedItems?.Remove(item);
@ -695,7 +695,7 @@ public partial class Corpse : Container, ICarvable
from.CriminalAction(true);
}
this.Add(_looters, from);
AddToLooters(from);
_instancedItems?.Remove(item);
}

View file

@ -124,7 +124,7 @@ public class FlippableAddonAttribute : Attribute
c.Delete();
}
addon.Clear(addon.Components);
addon.ClearComponents();
}
else if (item is BaseAddonContainer addonContainer)
{
@ -134,7 +134,7 @@ public class FlippableAddonAttribute : Attribute
c.Delete();
}
addonContainer.Clear(addonContainer.Components);
addonContainer.ClearComponents();
}
}
}

View file

@ -66,13 +66,13 @@ public partial class KeyRing : Item
key.Delete();
}
this.Clear(_keys);
ClearKeys();
}
public void Add(Key key)
{
key.Internalize();
this.Add(_keys, key);
AddToKeys(key);
UpdateItemID();
}
@ -93,7 +93,7 @@ public partial class KeyRing : Item
break;
}
this.RemoveAt(_keys, i);
RemoveFromKeysAt(i);
}
UpdateItemID();
@ -108,7 +108,7 @@ public partial class KeyRing : Item
if (key.KeyValue == keyValue)
{
key.Delete();
this.RemoveAt(_keys, i);
RemoveFromKeysAt(i);
}
}

View file

@ -153,11 +153,11 @@ public abstract partial class BasePlayerBB : Item, ISecurable
}
else
{
board.Add(board.Messages, message);
board.AddToMessages(message);
if (board.Messages.Count > 50)
{
board.RemoveAt(board.Messages, 0);
board.RemoveFromMessagesAt(0);
if (page > 0)
{
@ -491,7 +491,7 @@ public class PlayerBBGump : Gump
{
if (page >= 1 && page <= board.Messages.Count)
{
board.RemoveAt(board.Messages, page - 1);
board.RemoveFromMessagesAt(page - 1);
}
from.SendGump(new PlayerBBGump(from, house, board, 0));