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

@@ -1,8 +1,10 @@
using System.Linq;
using Content.Shared.Construction.Prototypes;
using Content.Shared.Preferences;
using Robust.Client;
using Robust.Client.Player;
using Robust.Shared.Network;
using Robust.Shared.Prototypes;
using Robust.Shared.Utility;
namespace Content.Client.Lobby
@@ -49,7 +51,7 @@ namespace Content.Client.Lobby
public void SelectCharacter(int slot)
{
Preferences = new PlayerPreferences(Preferences.Characters, slot, Preferences.AdminOOCColor);
Preferences = new PlayerPreferences(Preferences.Characters, slot, Preferences.AdminOOCColor, Preferences.ConstructionFavorites);
var msg = new MsgSelectCharacter
{
SelectedCharacterIndex = slot
@@ -62,7 +64,7 @@ namespace Content.Client.Lobby
var collection = IoCManager.Instance!;
profile.EnsureValid(_playerManager.LocalSession!, collection);
var characters = new Dictionary<int, ICharacterProfile>(Preferences.Characters) {[slot] = profile};
Preferences = new PlayerPreferences(characters, Preferences.SelectedCharacterIndex, Preferences.AdminOOCColor);
Preferences = new PlayerPreferences(characters, Preferences.SelectedCharacterIndex, Preferences.AdminOOCColor, Preferences.ConstructionFavorites);
var msg = new MsgUpdateCharacter
{
Profile = profile,
@@ -85,7 +87,7 @@ namespace Content.Client.Lobby
var l = lowest.Value;
characters.Add(l, profile);
Preferences = new PlayerPreferences(characters, Preferences.SelectedCharacterIndex, Preferences.AdminOOCColor);
Preferences = new PlayerPreferences(characters, Preferences.SelectedCharacterIndex, Preferences.AdminOOCColor, Preferences.ConstructionFavorites);
UpdateCharacter(profile, l);
}
@@ -98,7 +100,7 @@ namespace Content.Client.Lobby
public void DeleteCharacter(int slot)
{
var characters = Preferences.Characters.Where(p => p.Key != slot);
Preferences = new PlayerPreferences(characters, Preferences.SelectedCharacterIndex, Preferences.AdminOOCColor);
Preferences = new PlayerPreferences(characters, Preferences.SelectedCharacterIndex, Preferences.AdminOOCColor, Preferences.ConstructionFavorites);
var msg = new MsgDeleteCharacter
{
Slot = slot
@@ -106,6 +108,16 @@ namespace Content.Client.Lobby
_netManager.ClientSendMessage(msg);
}
public void UpdateConstructionFavorites(List<ProtoId<ConstructionPrototype>> favorites)
{
Preferences = new PlayerPreferences(Preferences.Characters, Preferences.SelectedCharacterIndex, Preferences.AdminOOCColor, favorites);
var msg = new MsgUpdateConstructionFavorites
{
Favorites = favorites
};
_netManager.ClientSendMessage(msg);
}
private void HandlePreferencesAndSettings(MsgPreferencesAndSettings message)
{
Preferences = message.Preferences;