mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-02-15 03:30:53 +01:00
Raise an event when an entity's name is changed (#5216)
This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
namespace Robust.Shared.GameObjects;
|
||||
|
||||
/// <summary>
|
||||
/// Raised directed on an entity when its name is changed.
|
||||
/// </summary>
|
||||
[ByRefEvent]
|
||||
public readonly record struct EntityRenamedEvent(string NewName);
|
||||
@@ -42,12 +42,19 @@ public abstract class MetaDataSystem : EntitySystem
|
||||
component.PauseTime = state.PauseTime;
|
||||
}
|
||||
|
||||
public void SetEntityName(EntityUid uid, string value, MetaDataComponent? metadata = null)
|
||||
public void SetEntityName(EntityUid uid, string value, MetaDataComponent? metadata = null, bool raiseEvents = true)
|
||||
{
|
||||
if (!_metaQuery.Resolve(uid, ref metadata) || value.Equals(metadata.EntityName))
|
||||
return;
|
||||
|
||||
metadata._entityName = value;
|
||||
|
||||
if (raiseEvents)
|
||||
{
|
||||
var ev = new EntityRenamedEvent(value);
|
||||
RaiseLocalEvent(uid, ref ev);
|
||||
}
|
||||
|
||||
Dirty(uid, metadata, metadata);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user