decouple briefing from traitor (#19668)

Co-authored-by: deltanedas <@deltanedas:kde.org>
This commit is contained in:
deltanedas
2023-08-31 22:29:45 +01:00
committed by GitHub
parent 31282a3fc6
commit 7842f0d055
9 changed files with 70 additions and 14 deletions

View 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;
}

View 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;
}
}
}

View File

@@ -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);

View File

@@ -5,5 +5,4 @@ namespace Content.Server.Roles;
[RegisterComponent]
public sealed partial class TraitorRoleComponent : AntagonistRoleComponent
{
public string? Briefing;
}