Persist construction menu favorites server-side (#35867)

* Persist construction menu favorites to player profile

* Use `ProtoId`s for construction favorites

* Validate construction favorites updates from the client

* Actually await the async database call
This commit is contained in:
YotaXP
2025-05-17 13:37:19 -04:00
committed by GitHub
parent 1141dcb868
commit e404e45ffc
16 changed files with 4424 additions and 25 deletions

View File

@@ -0,0 +1,36 @@
using Content.Shared.Construction.Prototypes;
using Lidgren.Network;
using Robust.Shared.Network;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization;
namespace Content.Shared.Preferences;
/// <summary>
/// The client sends this to update their construction favorites.
/// </summary>
public sealed class MsgUpdateConstructionFavorites : NetMessage
{
public override MsgGroups MsgGroup => MsgGroups.Command;
public List<ProtoId<ConstructionPrototype>> Favorites = [];
public override void ReadFromBuffer(NetIncomingMessage buffer, IRobustSerializer serializer)
{
var length = buffer.ReadVariableInt32();
Favorites.Clear();
for (var i = 0; i < length; i++)
{
Favorites.Add(new ProtoId<ConstructionPrototype>(buffer.ReadString()));
}
}
public override void WriteToBuffer(NetOutgoingMessage buffer, IRobustSerializer serializer)
{
buffer.WriteVariableInt32(Favorites.Count);
foreach (var favorite in Favorites)
{
buffer.Write(favorite);
}
}
}

View File

@@ -1,3 +1,5 @@
using Content.Shared.Construction.Prototypes;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization;
using Robust.Shared.Utility;
@@ -13,11 +15,12 @@ namespace Content.Shared.Preferences
{
private Dictionary<int, ICharacterProfile> _characters;
public PlayerPreferences(IEnumerable<KeyValuePair<int, ICharacterProfile>> characters, int selectedCharacterIndex, Color adminOOCColor)
public PlayerPreferences(IEnumerable<KeyValuePair<int, ICharacterProfile>> characters, int selectedCharacterIndex, Color adminOOCColor, List<ProtoId<ConstructionPrototype>> constructionFavorites)
{
_characters = new Dictionary<int, ICharacterProfile>(characters);
SelectedCharacterIndex = selectedCharacterIndex;
AdminOOCColor = adminOOCColor;
ConstructionFavorites = constructionFavorites;
}
/// <summary>
@@ -42,6 +45,11 @@ namespace Content.Shared.Preferences
public Color AdminOOCColor { get; set; }
/// <summary>
/// List of favorite items in the construction menu.
/// </summary>
public List<ProtoId<ConstructionPrototype>> ConstructionFavorites { get; set; } = [];
public int IndexOfCharacter(ICharacterProfile profile)
{
return _characters.FirstOrNull(p => p.Value == profile)?.Key ?? -1;