Skip to content

Commit

Permalink
Make EntityRenamedEvent contain Entity info and previous name. Make i…
Browse files Browse the repository at this point in the history
…t broadcast when raised.
  • Loading branch information
nikthechampiongr committed Aug 30, 2024
1 parent 2178707 commit 25d3727
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ namespace Robust.Shared.GameObjects;

/// <summary>
/// Raised directed on an entity when its name is changed.
/// Contains the EntityUid as systems may need to subscribe to it without targeting a specific component.
/// </summary>
[ByRefEvent]
public readonly record struct EntityRenamedEvent(string NewName);
public readonly record struct EntityRenamedEvent(EntityUid Uid, string OldName, string NewName);
6 changes: 4 additions & 2 deletions Robust.Shared/GameObjects/Systems/MetaDataSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,14 @@ public void SetEntityName(EntityUid uid, string value, MetaDataComponent? metada
if (!_metaQuery.Resolve(uid, ref metadata) || value.Equals(metadata.EntityName))
return;

var oldName = metadata.EntityName;

metadata._entityName = value;

if (raiseEvents)
{
var ev = new EntityRenamedEvent(value);
RaiseLocalEvent(uid, ref ev);
var ev = new EntityRenamedEvent(uid, oldName, value);
RaiseLocalEvent(uid, ref ev, true);
}

Dirty(uid, metadata, metadata);
Expand Down

0 comments on commit 25d3727

Please sign in to comment.