Add loadout names (#31303)

* Add loadout names

Did it for AI, breaking change for pgsql + migrations in general. Nothing atm uses it.

* the box

* Spawning cherry pick

* Fix nit

* revert

* Final cleanup

* Real

* Name UI fix

* Migrations

* a

* Review

* Re-run migrations

---------

Co-authored-by: Pieter-Jan Briers <pieterjan.briers+git@gmail.com>
This commit is contained in:
metalgearsloth
2025-02-12 04:30:24 +11:00
committed by GitHub
parent c197d3db37
commit 15b28936df
17 changed files with 4314 additions and 5 deletions

View File

@@ -22,6 +22,11 @@ public sealed partial class RoleLoadout : IEquatable<RoleLoadout>
[DataField]
public Dictionary<ProtoId<LoadoutGroupPrototype>, List<Loadout>> SelectedLoadouts = new();
/// <summary>
/// Loadout specific name.
/// </summary>
public string? EntityName;
/*
* Loadout-specific data used for validation.
*/
@@ -42,6 +47,8 @@ public sealed partial class RoleLoadout : IEquatable<RoleLoadout>
weh.SelectedLoadouts.Add(selected.Key, new List<Loadout>(selected.Value));
}
weh.EntityName = EntityName;
return weh;
}
@@ -55,10 +62,34 @@ public sealed partial class RoleLoadout : IEquatable<RoleLoadout>
if (!protoManager.TryIndex(Role, out var roleProto))
{
EntityName = null;
SelectedLoadouts.Clear();
return;
}
// Remove name not allowed.
if (!roleProto.CanCustomizeName)
{
EntityName = null;
}
// Validate name length
// TODO: Probably allow regex to be supplied?
if (EntityName != null)
{
var name = EntityName.Trim();
if (name.Length > HumanoidCharacterProfile.MaxNameLength)
{
EntityName = name[..HumanoidCharacterProfile.MaxNameLength];
}
if (name.Length == 0)
{
EntityName = null;
}
}
// In some instances we might not have picked up a new group for existing data.
foreach (var groupProto in roleProto.Groups)
{
@@ -322,7 +353,8 @@ public sealed partial class RoleLoadout : IEquatable<RoleLoadout>
if (!Role.Equals(other.Role) ||
SelectedLoadouts.Count != other.SelectedLoadouts.Count ||
Points != other.Points)
Points != other.Points ||
EntityName != other.EntityName)
{
return false;
}