write and read work now with arrays and enums

This commit is contained in:
JohnCorby 2022-01-27 00:32:30 -08:00
parent 143098be36
commit 32329d9af7
6 changed files with 12 additions and 46 deletions

View File

@ -64,8 +64,6 @@ namespace Mirror.Weaver
MethodReference GenerateReader(TypeReference variableReference, ref bool WeavingFailed)
{
Log.Warning($"GenerateReader for {variableReference}");
// Arrays are special, if we resolve them, we get the element type,
// so the following ifs might choke on it for scriptable objects
// or other objects that require a custom serializer

View File

@ -75,8 +75,6 @@ namespace Mirror.Weaver
//Throws GenerateWriterException when writer could not be generated for type
MethodReference GenerateWriter(TypeReference variableReference, ref bool WeavingFailed)
{
Log.Warning($"GenerateWriter for {variableReference}");
if (variableReference.IsByReference)
{
throw new GenerateWriterException($"Cannot pass {variableReference.Name} by reference", variableReference);

View File

@ -25,7 +25,7 @@ namespace QSB.ConversationSync.Messages
{
base.Serialize(writer);
writer.Write(_inRemoteDialogue);
writer.WriteArray(_activatedDialogues);
writer.Write(_activatedDialogues);
writer.Write(_dialogueIndex);
writer.Write(_colliderEnabled);
}
@ -34,7 +34,7 @@ namespace QSB.ConversationSync.Messages
{
base.Deserialize(reader);
_inRemoteDialogue = reader.Read<bool>();
_activatedDialogues = reader.ReadArray<bool>();
_activatedDialogues = reader.Read<bool[]>();
_dialogueIndex = reader.Read<int>();
_colliderEnabled = reader.Read<bool>();
}

View File

@ -1,27 +1,12 @@
using Mirror;
using QSB.Messaging;
using QSB.Messaging;
using QSB.QuantumSync.WorldObjects;
namespace QSB.QuantumSync.Messages
{
internal class QuantumShuffleMessage : QSBWorldObjectMessage<QSBQuantumShuffleObject>
internal class QuantumShuffleMessage : QSBWorldObjectMessage<QSBQuantumShuffleObject, int[]>
{
private int[] IndexArray;
public QuantumShuffleMessage(int[] indexArray) => Value = indexArray;
public QuantumShuffleMessage(int[] indexArray) => IndexArray = indexArray;
public override void Serialize(NetworkWriter writer)
{
base.Serialize(writer);
writer.WriteArray(IndexArray);
}
public override void Deserialize(NetworkReader reader)
{
base.Deserialize(reader);
IndexArray = reader.ReadArray<int>();
}
public override void OnReceiveRemote() => WorldObject.ShuffleObjects(IndexArray);
public override void OnReceiveRemote() => WorldObject.ShuffleObjects(Value);
}
}

View File

@ -40,7 +40,7 @@ namespace QSB.SaveSync.Messages
writer.Write(LaunchCodesGiven);
writer.Write(LoopCount);
writer.WriteArray(KnownFrequencies);
writer.Write(KnownFrequencies);
writer.Write(KnownSignals.Count);
foreach (var (name, discovered) in KnownSignals)
@ -58,7 +58,7 @@ namespace QSB.SaveSync.Messages
LaunchCodesGiven = reader.Read<bool>();
LoopCount = reader.Read<int>();
KnownFrequencies = reader.ReadArray<bool>();
KnownFrequencies = reader.Read<bool[]>();
var signalsLength = reader.Read<int>();
KnownSignals = new Dictionary<int, bool>(signalsLength);

View File

@ -1,5 +1,4 @@
using Mirror;
using QSB.Messaging;
using QSB.Messaging;
using QSB.Player;
using QSB.TriggerSync.WorldObjects;
using System.Collections.Generic;
@ -10,28 +9,14 @@ namespace QSB.TriggerSync.Messages
/// <summary>
/// always sent by host
/// </summary>
public class TriggerInitialStateMessage : QSBWorldObjectMessage<IQSBTrigger>
public class TriggerInitialStateMessage : QSBWorldObjectMessage<IQSBTrigger, uint[]>
{
private uint[] _playerIds;
public TriggerInitialStateMessage(IEnumerable<PlayerInfo> occupants) =>
_playerIds = occupants.Select(x => x.PlayerId).ToArray();
public override void Serialize(NetworkWriter writer)
{
base.Serialize(writer);
writer.WriteArray(_playerIds);
}
public override void Deserialize(NetworkReader reader)
{
base.Deserialize(reader);
_playerIds = reader.ReadArray<uint>();
}
Value = occupants.Select(x => x.PlayerId).ToArray();
public override void OnReceiveRemote()
{
var serverOccupants = _playerIds.Select(QSBPlayerManager.GetPlayer).ToList();
var serverOccupants = Value.Select(QSBPlayerManager.GetPlayer).ToList();
foreach (var added in serverOccupants.Except(WorldObject.Occupants))
{
WorldObject.Enter(added);