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, EntityUid Entity,
string Job, string Job,
Dictionary<string, List<ConditionInfo>> Objectives, Dictionary<string, List<ConditionInfo>> Objectives,
string Briefing, string? Briefing,
string EntityName string EntityName
); );

View File

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

View File

@@ -29,7 +29,7 @@ public sealed class CharacterInfoSystem : EntitySystem
var conditions = new Dictionary<string, List<ConditionInfo>>(); var conditions = new Dictionary<string, List<ConditionInfo>>();
var jobTitle = "No Profession"; 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)) if (_minds.TryGetMind(entity, out var mindId, out var mind))
{ {
// Get objectives // Get objectives
@@ -48,7 +48,7 @@ public sealed class CharacterInfoSystem : EntitySystem
jobTitle = jobName; jobTitle = jobName;
// Get briefing // Get briefing
briefing = _roles.MindGetBriefing(mindId) ?? string.Empty; briefing = _roles.MindGetBriefing(mindId);
} }
RaiseNetworkEvent(new CharacterInfoEvent(entity, jobTitle, conditions, briefing), args.SenderSession); 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 var traitorRole = new TraitorRoleComponent
{ {
PrototypeId = traitorRule.TraitorPrototypeId, PrototypeId = traitorRule.TraitorPrototypeId,
Briefing = briefing
}; };
// Assign traitor roles // 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); SendTraitorBriefing(mindId, traitorRule.Codewords, code);
traitorRule.TraitorMinds.Add(mindId); 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) public string? MindGetBriefing(EntityUid? mindId)
{ {
// TODO this should be an event if (mindId == null)
return CompOrNull<TraitorRoleComponent>(mindId)?.Briefing; 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] [RegisterComponent]
public sealed partial class TraitorRoleComponent : AntagonistRoleComponent 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 EntityUid EntityUid;
public readonly string JobTitle; public readonly string JobTitle;
public readonly Dictionary<string, List<ConditionInfo>> Objectives; 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; EntityUid = entityUid;
JobTitle = jobTitle; JobTitle = jobTitle;