Maybe fix invalid loadout prototypes (#28734)

* Maybe fix invalid loadout prototypes

So if we have existing data SetDefault is not normally called iirc. So what I think is happening is that if we have old loadout groups that get saved to DB and loaded these get dropped entirely and nothing is used to replace the group unless the person specifically looks at their loadout.

Need someone affected to send me their loadout to confirm it's fixed.

* Better fix
This commit is contained in:
metalgearsloth
2024-06-09 04:48:09 +10:00
committed by GitHub
parent 1fdbf9403a
commit e3c37f6e9b
2 changed files with 13 additions and 2 deletions

View File

@@ -467,10 +467,10 @@ namespace Content.Shared.Preferences
var configManager = collection.Resolve<IConfigurationManager>(); var configManager = collection.Resolve<IConfigurationManager>();
var prototypeManager = collection.Resolve<IPrototypeManager>(); var prototypeManager = collection.Resolve<IPrototypeManager>();
if (!prototypeManager.TryIndex<SpeciesPrototype>(Species, out var speciesPrototype) || speciesPrototype.RoundStart == false) if (!prototypeManager.TryIndex(Species, out var speciesPrototype) || speciesPrototype.RoundStart == false)
{ {
Species = SharedHumanoidAppearanceSystem.DefaultSpecies; Species = SharedHumanoidAppearanceSystem.DefaultSpecies;
speciesPrototype = prototypeManager.Index<SpeciesPrototype>(Species); speciesPrototype = prototypeManager.Index(Species);
} }
var sex = Sex switch var sex = Sex switch

View File

@@ -59,6 +59,16 @@ public sealed partial class RoleLoadout : IEquatable<RoleLoadout>
return; return;
} }
// In some instances we might not have picked up a new group for existing data.
foreach (var groupProto in roleProto.Groups)
{
if (SelectedLoadouts.ContainsKey(groupProto))
continue;
// Data will get set below.
SelectedLoadouts[groupProto] = new List<Loadout>();
}
// Reset points to recalculate. // Reset points to recalculate.
Points = roleProto.Points; Points = roleProto.Points;
@@ -156,6 +166,7 @@ public sealed partial class RoleLoadout : IEquatable<RoleLoadout>
/// <summary> /// <summary>
/// Resets the selected loadouts to default if no data is present. /// Resets the selected loadouts to default if no data is present.
/// </summary> /// </summary>
/// <param name="force">Clear existing data first</param>
public void SetDefault(IPrototypeManager protoManager, bool force = false) public void SetDefault(IPrototypeManager protoManager, bool force = false)
{ {
if (force) if (force)