quantum-space-buddies/QSB/Events/FullStateMessage.cs
AmazingAlek 485698e93b
Alek/simplify name messages (#88)
* Showing player markers

* Marker above head

* Use player name on marker

* Sync full state on init

* Sync game state on start

* removed name from death and leave message

Co-authored-by: Ricardo Lopes <raicuparta@gmail.com>
2020-05-19 20:05:15 +02:00

39 lines
1.1 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using QSB.Messaging;
using UnityEngine.Networking;
namespace QSB.Events
{
public class FullStateMessage : PlayerMessage
{
public override MessageType MessageType => MessageType.FullState;
public Dictionary<uint, string> PlayerNames;
public override void Deserialize(NetworkReader reader)
{
base.Deserialize(reader);
PlayerNames = new Dictionary<uint, string>();
reader.ReadString().Split(',').ToList().ForEach(pair =>
{
var splitPair = pair.Split(':');
var key = Convert.ToUInt16(splitPair[0]);
var value = splitPair[1];
PlayerNames[key] = value;
});
}
public override void Serialize(NetworkWriter writer)
{
base.Serialize(writer);
var playerNamePairs = PlayerNames.ToList().Select(pair => $"{pair.Key}:{pair.Value}").ToArray();
writer.Write(string.Join(",", playerNamePairs));
}
}
}