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

@@ -58,7 +58,7 @@ public sealed class CharacterInfoSystem : EntitySystem
EntityUid Entity,
string Job,
Dictionary<string, List<ConditionInfo>> Objectives,
string Briefing,
string? Briefing,
string EntityName
);

View File

@@ -141,11 +141,14 @@ public sealed class CharacterUIController : UIController, IOnStateEntered<Gamepl
objectiveControl.AddChild(conditionControl);
}
_window.Objectives.AddChild(objectiveControl);
}
if (briefing != null)
{
var briefingControl = new ObjectiveBriefingControl();
briefingControl.Label.Text = briefing;
objectiveControl.AddChild(briefingControl);
_window.Objectives.AddChild(objectiveControl);
_window.Objectives.AddChild(briefingControl);
}
var controls = _characterInfo.GetCharacterInfoControls(entity);
@@ -154,7 +157,7 @@ public sealed class CharacterUIController : UIController, IOnStateEntered<Gamepl
_window.Objectives.AddChild(control);
}
_window.RolePlaceholder.Visible = !controls.Any() && !objectives.Any();
_window.RolePlaceholder.Visible = briefing == null && !controls.Any() && !objectives.Any();
}
private void CharacterDetached()

View File

@@ -29,7 +29,7 @@ public sealed class CharacterInfoSystem : EntitySystem
var conditions = new Dictionary<string, List<ConditionInfo>>();
var jobTitle = "No Profession";
var briefing = "!!ERROR: No Briefing!!"; //should never show on the UI unless there's an issue
string? briefing = null;
if (_minds.TryGetMind(entity, out var mindId, out var mind))
{
// Get objectives
@@ -48,7 +48,7 @@ public sealed class CharacterInfoSystem : EntitySystem
jobTitle = jobName;
// Get briefing
briefing = _roles.MindGetBriefing(mindId) ?? string.Empty;
briefing = _roles.MindGetBriefing(mindId);
}
RaiseNetworkEvent(new CharacterInfoEvent(entity, jobTitle, conditions, briefing), args.SenderSession);

View File

@@ -254,11 +254,18 @@ public sealed class TraitorRuleSystem : GameRuleSystem<TraitorRuleComponent>
var traitorRole = new TraitorRoleComponent
{
PrototypeId = traitorRule.TraitorPrototypeId,
Briefing = briefing
};
// Assign traitor roles
_roleSystem.MindAddRole(mindId, traitorRole);
_roleSystem.MindAddRole(mindId, new TraitorRoleComponent
{
PrototypeId = traitorRule.TraitorPrototypeId
});
// Assign briefing
_roleSystem.MindAddRole(mindId, new RoleBriefingComponent
{
Briefing = briefing
});
SendTraitorBriefing(mindId, traitorRule.Codewords, code);
traitorRule.TraitorMinds.Add(mindId);

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

View File

@@ -20,9 +20,9 @@ public sealed class CharacterInfoEvent : EntityEventArgs
public readonly EntityUid EntityUid;
public readonly string JobTitle;
public readonly Dictionary<string, List<ConditionInfo>> Objectives;
public readonly string Briefing;
public readonly string? Briefing;
public CharacterInfoEvent(EntityUid entityUid, string jobTitle, Dictionary<string, List<ConditionInfo>> objectives, string briefing)
public CharacterInfoEvent(EntityUid entityUid, string jobTitle, Dictionary<string, List<ConditionInfo>> objectives, string? briefing)
{
EntityUid = entityUid;
JobTitle = jobTitle;