quantum-space-buddies/QSB/SaveSync/Events/GameStateMessage.cs

67 lines
1.7 KiB
C#
Raw Normal View History

2021-12-05 14:06:43 +00:00
using QSB.Messaging;
using QuantumUNET.Transport;
using System;
2021-12-05 23:35:33 +00:00
using System.Collections.Generic;
2021-12-05 14:06:43 +00:00
namespace QSB.SaveSync.Events
{
internal class GameStateMessage : PlayerMessage
{
public bool InSolarSystem { get; set; }
public bool InEye { get; set; }
2021-12-12 00:00:46 +00:00
public bool LaunchCodesGiven { get; set; }
2021-12-05 14:06:43 +00:00
public int LoopCount { get; set; }
public bool[] KnownFrequencies { get; set; }
2021-12-05 23:35:33 +00:00
public Dictionary<int, bool> KnownSignals { get; set; } = new();
2021-12-05 14:06:43 +00:00
public override void Deserialize(QNetworkReader reader)
{
base.Deserialize(reader);
InSolarSystem = reader.ReadBoolean();
InEye = reader.ReadBoolean();
2021-12-12 00:00:46 +00:00
LaunchCodesGiven = reader.ReadBoolean();
2021-12-05 14:06:43 +00:00
LoopCount = reader.ReadInt32();
var frequenciesLength = reader.ReadInt32();
var knownFrequencies = KnownFrequencies;
Array.Resize(ref knownFrequencies, frequenciesLength);
KnownFrequencies = knownFrequencies;
for (var i = 0; i < frequenciesLength; i++)
{
KnownFrequencies[i] = reader.ReadBoolean();
}
2021-12-05 23:35:33 +00:00
var signalsLength = reader.ReadInt32();
KnownSignals.Clear();
for (var i = 0; i < signalsLength; i++)
{
var key = reader.ReadInt32();
var value = reader.ReadBoolean();
KnownSignals.Add(key, value);
}
2021-12-05 14:06:43 +00:00
}
public override void Serialize(QNetworkWriter writer)
{
base.Serialize(writer);
writer.Write(InSolarSystem);
writer.Write(InEye);
2021-12-12 00:00:46 +00:00
writer.Write(LaunchCodesGiven);
2021-12-05 14:06:43 +00:00
writer.Write(LoopCount);
writer.Write(KnownFrequencies.Length);
foreach (var item in KnownFrequencies)
{
writer.Write(item);
}
2021-12-05 23:35:33 +00:00
writer.Write(KnownSignals.Count);
foreach (var item in KnownSignals)
{
writer.Write(item.Key);
writer.Write(item.Value);
}
2021-12-05 14:06:43 +00:00
}
}
}