decouple briefing from traitor (#19668)
Co-authored-by: deltanedas <@deltanedas:kde.org>
This commit is contained in:
11
Content.Server/Roles/RoleBriefingComponent.cs
Normal file
11
Content.Server/Roles/RoleBriefingComponent.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
namespace Content.Server.Roles;
|
||||
|
||||
/// <summary>
|
||||
/// Adds a briefing to the character info menu, does nothing else.
|
||||
/// </summary>
|
||||
[RegisterComponent]
|
||||
public sealed partial class RoleBriefingComponent : Component
|
||||
{
|
||||
[DataField("briefing"), ViewVariables(VVAccess.ReadWrite)]
|
||||
public string Briefing;
|
||||
}
|
||||
25
Content.Server/Roles/RoleBriefingSystem.cs
Normal file
25
Content.Server/Roles/RoleBriefingSystem.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
namespace Content.Server.Roles;
|
||||
|
||||
public sealed class RoleBriefingSystem : EntitySystem
|
||||
{
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<RoleBriefingComponent, GetBriefingEvent>(OnGetBriefing);
|
||||
}
|
||||
|
||||
private void OnGetBriefing(EntityUid uid, RoleBriefingComponent comp, ref GetBriefingEvent args)
|
||||
{
|
||||
if (args.Briefing == null)
|
||||
{
|
||||
// no previous briefing so just set it
|
||||
args.Briefing = comp.Briefing;
|
||||
}
|
||||
else
|
||||
{
|
||||
// there is a previous briefing so append to it
|
||||
args.Briefing += "\n" + comp.Briefing;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -17,7 +17,18 @@ public sealed class RoleSystem : SharedRoleSystem
|
||||
|
||||
public string? MindGetBriefing(EntityUid? mindId)
|
||||
{
|
||||
// TODO this should be an event
|
||||
return CompOrNull<TraitorRoleComponent>(mindId)?.Briefing;
|
||||
if (mindId == null)
|
||||
return null;
|
||||
|
||||
var ev = new GetBriefingEvent();
|
||||
RaiseLocalEvent(mindId.Value, ref ev);
|
||||
return ev.Briefing;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Event raised on the mind to get its briefing.
|
||||
/// Handlers can either replace or append to the briefing, whichever is more appropriate.
|
||||
/// </summary>
|
||||
[ByRefEvent]
|
||||
public record struct GetBriefingEvent(string? Briefing = null);
|
||||
|
||||
@@ -5,5 +5,4 @@ namespace Content.Server.Roles;
|
||||
[RegisterComponent]
|
||||
public sealed partial class TraitorRoleComponent : AntagonistRoleComponent
|
||||
{
|
||||
public string? Briefing;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user