-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Also added validation for all other arguments for their serialization.
- Loading branch information
Showing
4 changed files
with
95 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
MultiplayerMod/Platform/Steam/Network/Messaging/Surrogates/RoomSurrogate.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Runtime.Serialization; | ||
|
||
namespace MultiplayerMod.Platform.Steam.Network.Messaging.Surrogates; | ||
|
||
public class RoomSurrogate : ISerializationSurrogate, ISurrogateType { | ||
|
||
public Type Type => typeof(Room); | ||
|
||
public void GetObjectData(object obj, SerializationInfo info, StreamingContext context) { | ||
var room = obj as Room; | ||
var allIds = new List<KPrefabID>(room!.primary_buildings); | ||
allIds.AddRange(room.buildings); | ||
allIds.AddRange(room.plants); | ||
var firstGo = allIds.First().gameObject!; | ||
var cell = Grid.PosToCell(firstGo); | ||
info.AddValue("cell", cell); | ||
} | ||
|
||
public object? SetObjectData( | ||
object obj, | ||
SerializationInfo info, | ||
StreamingContext context, | ||
ISurrogateSelector selector | ||
) { | ||
var cell = info.GetInt32("cell"); | ||
return global::Game.Instance.roomProber.GetCavityForCell(cell)?.room; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters