Skip to content

Commit

Permalink
Fix sponsors prototypes
Browse files Browse the repository at this point in the history
  • Loading branch information
Morb0 committed Feb 26, 2024
1 parent fe48e6d commit cea2689
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Content.Client/Preferences/ClientPreferencesManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public void SelectCharacter(int slot)
public void UpdateCharacter(ICharacterProfile profile, int slot)
{
// Corvax-Sponsors-Start
var sponsorPrototypes = _sponsorsManager?.Prototypes.ToArray() ?? new string[]{};
var sponsorPrototypes = _sponsorsManager?.Prototypes.ToArray() ?? [];
profile.EnsureValid(_cfg, _prototypes, sponsorPrototypes);
// Corvax-Sponsors-End
var characters = new Dictionary<int, ICharacterProfile>(Preferences.Characters) {[slot] = profile};
Expand Down
15 changes: 9 additions & 6 deletions Content.Server/Preferences/Managers/ServerPreferencesManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ private async void HandleUpdateCharacterMessage(MsgUpdateCharacter message)
// WARN! It's not removing markings from DB!
var sponsorPrototypes = _sponsors != null && _sponsors.TryGetPrototypes(message.MsgChannel.UserId, out var prototypes)
? prototypes.ToArray()
: new string[]{};
: [];
profile.EnsureValid(_cfg, _protos, sponsorPrototypes);
// Corvax-Sponsors-End
var profiles = new Dictionary<int, ICharacterProfile>(curPrefs.Characters)
Expand Down Expand Up @@ -206,8 +206,8 @@ async Task LoadPrefs()
{
var sponsorPrototypes = _sponsors != null && _sponsors.TryGetPrototypes(session.UserId, out var prototypes)
? prototypes.ToArray()
: new string[]{};
profile.EnsureValid(sponsorPrototypes);
: [];
profile.EnsureValid(_cfg, _protos, sponsorPrototypes);
}
// Corvax-Sponsors-End
prefsData.Prefs = prefs;
Expand Down Expand Up @@ -285,17 +285,20 @@ private async Task<PlayerPreferences> GetOrCreatePreferencesAsync(NetUserId user
return await _db.InitPrefsAsync(userId, HumanoidCharacterProfile.Random());
}

return SanitizePreferences(prefs);
// Corvax-Sponsors-Start
var sponsorPrototypes = _sponsors != null && _sponsors.TryGetPrototypes(userId, out var prototypes) ? prototypes.ToArray() : []; // Corvax-Sponsors
return SanitizePreferences(prefs, sponsorPrototypes);
// Corvax-Sponsors-End
}

private PlayerPreferences SanitizePreferences(PlayerPreferences prefs)
private PlayerPreferences SanitizePreferences(PlayerPreferences prefs, string[] sponsorPrototypes)
{
// Clean up preferences in case of changes to the game,
// such as removed jobs still being selected.

return new PlayerPreferences(prefs.Characters.Select(p =>
{
return new KeyValuePair<int, ICharacterProfile>(p.Key, p.Value.Validated(_cfg, _protos));
return new KeyValuePair<int, ICharacterProfile>(p.Key, p.Value.Validated(_cfg, _protos, sponsorPrototypes));
}), prefs.SelectedCharacterIndex, prefs.AdminOOCColor);
}

Expand Down
4 changes: 2 additions & 2 deletions Content.Shared/Preferences/HumanoidCharacterProfile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -564,10 +564,10 @@ public static bool CanHaveVoice(TTSVoicePrototype voice, Sex sex)
}
// Corvax-TTS-End

public ICharacterProfile Validated(IConfigurationManager configManager, IPrototypeManager prototypeManager)
public ICharacterProfile Validated(IConfigurationManager configManager, IPrototypeManager prototypeManager, string[] sponsorPrototypes)
{
var profile = new HumanoidCharacterProfile(this);
profile.EnsureValid(configManager, prototypeManager);
profile.EnsureValid(configManager, prototypeManager, sponsorPrototypes); // Corvax-Sponsors
return profile;
}

Expand Down
2 changes: 1 addition & 1 deletion Content.Shared/Preferences/ICharacterProfile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ public interface ICharacterProfile
/// <summary>
/// Gets a copy of this profile that has <see cref="EnsureValid"/> applied, i.e. no invalid data.
/// </summary>
ICharacterProfile Validated(IConfigurationManager configManager, IPrototypeManager prototypeManager);
ICharacterProfile Validated(IConfigurationManager configManager, IPrototypeManager prototypeManager, string[] sponsorPrototypes);
}
}

0 comments on commit cea2689

Please sign in to comment.