make name identifier prefix LocId (#39035)

This commit is contained in:
lzk
2025-07-18 20:59:49 +02:00
committed by GitHub
parent e7b68d9722
commit ffbc813179
4 changed files with 37 additions and 19 deletions

View File

@@ -82,8 +82,8 @@ public sealed class NameIdentifierSystem : EntitySystem
randomVal = set[^1]; randomVal = set[^1];
set.RemoveAt(set.Count - 1); set.RemoveAt(set.Count - 1);
return proto.Prefix is not null return proto.Format is not null
? $"{proto.Prefix}-{randomVal}" ? Loc.GetString(proto.Format, ("number", randomVal))
: $"{randomVal}"; : $"{randomVal}";
} }
@@ -104,8 +104,8 @@ public sealed class NameIdentifierSystem : EntitySystem
ids.Remove(ent.Comp.Identifier)) ids.Remove(ent.Comp.Identifier))
{ {
id = ent.Comp.Identifier; id = ent.Comp.Identifier;
uniqueName = group.Prefix is not null uniqueName = group.Format is not null
? $"{group.Prefix}-{id}" ? Loc.GetString(group.Format, ("number", id))
: $"{id}"; : $"{id}";
} }
else else

View File

@@ -1,4 +1,4 @@
using Robust.Shared.Prototypes; using Robust.Shared.Prototypes;
namespace Content.Shared.NameIdentifier; namespace Content.Shared.NameIdentifier;
@@ -11,15 +11,25 @@ public sealed partial class NameIdentifierGroupPrototype : IPrototype
/// <summary> /// <summary>
/// Should the identifier become the full name, or just append? /// Should the identifier become the full name, or just append?
/// </summary> /// </summary>
[DataField("fullName")] [DataField]
public bool FullName = false; public bool FullName = false;
[DataField("prefix")] /// <summary>
public string? Prefix; /// Optional format identifier. If set, the name will be formatted using it (e.g., "MK-500").
/// If not set, only the numeric part will be used (e.g., "500").
/// </summary>
[DataField]
public LocId? Format;
[DataField("maxValue")] /// <summary>
/// The maximal value appearing in an identifier.
/// </summary>
[DataField]
public int MaxValue = 1000; public int MaxValue = 1000;
[DataField("minValue")] /// <summary>
/// The minimal value appearing in an identifier.
/// </summary>
[DataField]
public int MinValue = 0; public int MinValue = 0;
} }

View File

@@ -0,0 +1,8 @@
name-identifier-format-monkey = MK-{$number}
name-identifier-format-kobold = KB-{$number}
name-identifier-format-holoparasite = HOLO-{$number}
name-identifier-format-mmi = MMI-{$number}
name-identifier-format-positronic-brain = PB-{$number}
name-identifier-format-silicon = Si-{$number}
name-identifier-format-station-ai = AI-{$number}
name-identifier-format-telepad = TELE-{$number}

View File

@@ -1,37 +1,37 @@
# Non-fungible apes, anyone? # Non-fungible apes, anyone?
- type: nameIdentifierGroup - type: nameIdentifierGroup
id: Monkey id: Monkey
prefix: MK format: name-identifier-format-monkey
- type: nameIdentifierGroup - type: nameIdentifierGroup
id: Kobold id: Kobold
prefix: KB format: name-identifier-format-kobold
- type: nameIdentifierGroup - type: nameIdentifierGroup
id: Holoparasite id: Holoparasite
prefix: HOLO format: name-identifier-format-holoparasite
- type: nameIdentifierGroup - type: nameIdentifierGroup
id: MMI id: MMI
prefix: MMI format: name-identifier-format-mmi
minValue: 100 minValue: 100
maxValue: 999 maxValue: 999
- type: nameIdentifierGroup - type: nameIdentifierGroup
id: PositronicBrain id: PositronicBrain
prefix: PB format: name-identifier-format-positronic-brain
minValue: 10 minValue: 10
maxValue: 99 maxValue: 99
- type: nameIdentifierGroup - type: nameIdentifierGroup
id: Silicon id: Silicon
prefix: Si format: name-identifier-format-silicon
minValue: 1000 minValue: 1000
maxValue: 9999 maxValue: 9999
- type: nameIdentifierGroup - type: nameIdentifierGroup
id: StationAi id: StationAi
prefix: AI format: name-identifier-format-station-ai
minValue: 100 minValue: 100
maxValue: 999 maxValue: 999
@@ -51,6 +51,6 @@
- type: nameIdentifierGroup - type: nameIdentifierGroup
id: CargoTelepads id: CargoTelepads
prefix: TELE format: name-identifier-format-telepad
minValue: 0 minValue: 0
maxValue: 999 maxValue: 999