quantum-space-buddies/QSB/SaveSync/Messages/ShipLogFactSaveMessage.cs

53 lines
1.1 KiB
C#
Raw Normal View History

2022-01-14 22:30:54 +00:00
using Mirror;
using QSB.Messaging;
2022-01-08 11:41:55 +00:00
2022-03-03 03:46:33 +00:00
namespace QSB.SaveSync.Messages;
internal class ShipLogFactSaveMessage : QSBMessage
2022-01-08 11:41:55 +00:00
{
2022-03-03 03:46:33 +00:00
private string _id;
private int _revealOrder;
private bool _read;
private bool _newlyRevealed;
public ShipLogFactSaveMessage(ShipLogFactSave save)
2022-01-08 11:41:55 +00:00
{
2022-03-03 03:46:33 +00:00
_id = save.id;
_revealOrder = save.revealOrder;
_read = save.read;
_newlyRevealed = save.newlyRevealed;
}
2022-01-08 11:41:55 +00:00
2022-03-03 03:46:33 +00:00
public override void Serialize(NetworkWriter writer)
{
base.Serialize(writer);
writer.Write(_id);
writer.Write(_revealOrder);
writer.Write(_read);
writer.Write(_newlyRevealed);
}
2022-01-08 11:41:55 +00:00
2022-03-03 03:46:33 +00:00
public override void Deserialize(NetworkReader reader)
{
base.Deserialize(reader);
_id = reader.ReadString();
_revealOrder = reader.ReadInt();
_read = reader.ReadBool();
_newlyRevealed = reader.ReadBool();
}
2022-01-08 11:41:55 +00:00
2022-03-03 03:46:33 +00:00
public override void OnReceiveRemote()
{
var save = PlayerData.GetShipLogFactSave(_id);
2022-03-03 03:46:33 +00:00
if (save == null)
{
2022-03-03 03:46:33 +00:00
save = new ShipLogFactSave(_id);
PlayerData.AddShipLogFactSave(save);
}
2022-03-03 03:46:33 +00:00
save.revealOrder = _revealOrder;
save.read = _read;
save.newlyRevealed = _newlyRevealed;
2022-01-08 11:41:55 +00:00
}
}