Skip to content

Commit

Permalink
Sync slot groups and storage groups
Browse files Browse the repository at this point in the history
  • Loading branch information
Zetrith committed Apr 5, 2024
1 parent d77273d commit e51220f
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 26 deletions.
4 changes: 3 additions & 1 deletion Source/Client/Debug/DebugActions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,10 @@ public static void DumpSyncTypes()
{
var dict = new Dictionary<string, Type[]>() {
{"Designator", RwImplSerialization.designatorTypes},
{"IStoreSettingsParent", RwImplSerialization.storageParents},
{"IStoreSettingsParent", RwImplSerialization.storageSettingsParent},
{"IPlantToGrowSettable", RwImplSerialization.plantToGrowSettables},
{"ISlotGroup", RwImplSerialization.slotGroupTypes},
{"ISlotGroupParent", RwImplSerialization.slotGroupParents},

{"ThingComp", CompSerialization.thingCompTypes},
{"AbilityComp", CompSerialization.abilityCompTypes},
Expand Down
4 changes: 3 additions & 1 deletion Source/Client/MultiplayerData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,10 @@ internal static void CollectDefInfos()
dict["AbilityComp"] = GetDefInfo(CompSerialization.abilityCompTypes, TypeHash);
dict["WorldObjectComp"] = GetDefInfo(CompSerialization.worldObjectCompTypes, TypeHash);
dict["HediffComp"] = GetDefInfo(CompSerialization.hediffCompTypes, TypeHash);
dict["IStoreSettingsParent"] = GetDefInfo(RwImplSerialization.storageParents, TypeHash);
dict["IStoreSettingsParent"] = GetDefInfo(RwImplSerialization.storageSettingsParent, TypeHash);
dict["IPlantToGrowSettable"] = GetDefInfo(RwImplSerialization.plantToGrowSettables, TypeHash);
dict["ISlotGroup"] = GetDefInfo(RwImplSerialization.slotGroupTypes, TypeHash);
dict["ISlotGroupParent"] = GetDefInfo(RwImplSerialization.slotGroupParents, TypeHash);
dict["Designator"] = GetDefInfo(RwImplSerialization.designatorTypes, TypeHash);
dict["DefTypes"] = GetDefInfo(DefSerialization.DefTypes, TypeHash);

Expand Down
77 changes: 59 additions & 18 deletions Source/Client/Syncing/Dict/SyncDictRimWorld.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1047,6 +1047,65 @@ public static class SyncDictRimWorld
},
#endregion

#region Storage
{
(ByteWriter data, IStoreSettingsParent obj) => {
WriteWithImpl<IStoreSettingsParent>(data, obj, storageSettingsParent);
},
(ByteReader data) => {
return ReadWithImpl<IStoreSettingsParent>(data, storageSettingsParent);
}
},
{
(ByteWriter data, SlotGroup obj) => {
WriteSync(data, obj.parent);
},
(ByteReader data) =>
{
var parent = ReadSync<ISlotGroupParent>(data);
return parent.GetSlotGroup();
}
},
{
(ByteWriter data, StorageGroup obj) =>
{
data.MpContext().map = obj.Map;
WriteSync(data, obj.loadID);
},
(ByteReader data) =>
{
var loadId = data.ReadInt32();
return data.MpContext().map.storageGroups.groups.Find(g => g.loadID == loadId);
}
},
{
(ByteWriter data, ISlotGroup obj) => {
WriteWithImpl<ISlotGroup>(data, obj, slotGroupTypes);
},
(ByteReader data) => {
return ReadWithImpl<ISlotGroup>(data, slotGroupTypes);
}
},
{
(ByteWriter data, ISlotGroupParent obj) => {
WriteWithImpl<ISlotGroupParent>(data, obj, slotGroupParents);
},
(ByteReader data) => {
return ReadWithImpl<ISlotGroupParent>(data, slotGroupParents);
}
},
{
(ByteWriter data, IStorageGroupMember obj) =>
{
if (obj is Thing thing)
WriteSync(data, thing);
else
throw new SerializationException($"Unknown IStorageGroupMember type: {obj.GetType()}");
},
(ByteReader data) => (IStorageGroupMember)ReadSync<Thing>(data)
},
#endregion

#region Interfaces
{
(ByteWriter data, ISelectable obj) => {
Expand Down Expand Up @@ -1087,14 +1146,6 @@ public static class SyncDictRimWorld
};
}, true
},
{
(ByteWriter data, IStoreSettingsParent obj) => {
WriteWithImpl<IStoreSettingsParent>(data, obj, storageParents);
},
(ByteReader data) => {
return ReadWithImpl<IStoreSettingsParent>(data, storageParents);
}
},
{
(ByteWriter data, IPlantToGrowSettable obj) => {
WriteWithImpl<IPlantToGrowSettable>(data, obj, plantToGrowSettables);
Expand All @@ -1111,16 +1162,6 @@ public static class SyncDictRimWorld
return ReadWithImpl<IThingHolder>(data, supportedThingHolders);
}
},
{
(ByteWriter data, IStorageGroupMember obj) =>
{
if (obj is Thing thing)
WriteSync(data, thing);
else
throw new SerializationException($"Unknown IStorageGroupMember type: {obj.GetType()}");
},
(ByteReader data) => (IStorageGroupMember)ReadSync<Thing>(data)
},
#endregion

#region Storage
Expand Down
14 changes: 9 additions & 5 deletions Source/Client/Syncing/RwImplSerialization.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@ namespace Multiplayer.Client
{
public static class RwImplSerialization
{
public static Type[] storageParents;
public static Type[] plantToGrowSettables;
public static Type[] designatorTypes;
public static Type[] storageSettingsParent; // IStoreSettingsParent
public static Type[] plantToGrowSettables; // IPlantToGrowSettable
public static Type[] slotGroupTypes; // ISlotGroup
public static Type[] slotGroupParents; // ISlotGroupParent
public static Type[] designatorTypes; // Designator

internal static Type[] supportedThingHolders =
internal static Type[] supportedThingHolders = // IThingHolder
{
typeof(Map),
typeof(Thing),
Expand All @@ -37,8 +39,10 @@ internal enum VerbOwnerType : byte

public static void Init()
{
storageParents = TypeUtil.AllImplementationsOrdered(typeof(IStoreSettingsParent));
storageSettingsParent = TypeUtil.AllImplementationsOrdered(typeof(IStoreSettingsParent));
plantToGrowSettables = TypeUtil.AllImplementationsOrdered(typeof(IPlantToGrowSettable));
slotGroupTypes = TypeUtil.AllImplementationsOrdered(typeof(ISlotGroup));
slotGroupParents = TypeUtil.AllImplementationsOrdered(typeof(ISlotGroupParent));
designatorTypes = TypeUtil.AllSubclassesNonAbstractOrdered(typeof(Designator));
}

Expand Down
4 changes: 3 additions & 1 deletion Source/Client/Syncing/RwTypeHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ internal static class RwTypeHelper

public static void Init()
{
cache[typeof(IStoreSettingsParent)] = RwImplSerialization.storageParents;
cache[typeof(IStoreSettingsParent)] = RwImplSerialization.storageSettingsParent;
cache[typeof(IPlantToGrowSettable)] = RwImplSerialization.plantToGrowSettables;
cache[typeof(ISlotGroup)] = RwImplSerialization.slotGroupTypes;
cache[typeof(ISlotGroupParent)] = RwImplSerialization.slotGroupParents;
cache[typeof(Designator)] = RwImplSerialization.designatorTypes;

cache[typeof(ThingComp)] = CompSerialization.thingCompTypes;
Expand Down

0 comments on commit e51220f

Please sign in to comment.