-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added codeword highlighting * Updated to support more codeword roles, color is set serverside * Review feedback * Change to a Component-based system using SessionSpecific * Tidied up CanGetState, set Access restrictions on component * Clean-up * Makes the injection ignore brackets, restore some codewords, remove "Taste/Touch" from adjectives
- Loading branch information
1 parent
7b5c6be
commit 61a1e89
Showing
9 changed files
with
146 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
using Content.Shared.Roles.RoleCodeword; | ||
|
||
namespace Content.Client.Roles; | ||
|
||
public sealed class RoleCodewordSystem : SharedRoleCodewordSystem | ||
{ | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
using Content.Shared.Roles.RoleCodeword; | ||
|
||
namespace Content.Server.Roles.RoleCodeword; | ||
|
||
public sealed class RoleCodewordSystem : SharedRoleCodewordSystem | ||
{ | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
Content.Shared/Roles/RoleCodeword/RoleCodewordComponent.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
using Robust.Shared.GameStates; | ||
using Robust.Shared.Prototypes; | ||
using Robust.Shared.Serialization; | ||
|
||
namespace Content.Shared.Roles.RoleCodeword; | ||
|
||
/// <summary> | ||
/// Used to display and highlight codewords in chat messages on the client. | ||
/// </summary> | ||
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState, Access(typeof(SharedRoleCodewordSystem), Other = AccessPermissions.Read)] | ||
public sealed partial class RoleCodewordComponent : Component | ||
{ | ||
/// <summary> | ||
/// Contains the codewords tied to a role. | ||
/// Key string should be unique for the role. | ||
/// </summary> | ||
[DataField, AutoNetworkedField] | ||
public Dictionary<string, CodewordsData> RoleCodewords = new(); | ||
|
||
public override bool SessionSpecific => true; | ||
} | ||
|
||
[DataDefinition, Serializable, NetSerializable] | ||
public partial struct CodewordsData | ||
{ | ||
[DataField] | ||
public Color Color; | ||
|
||
[DataField] | ||
public List<string> Codewords; | ||
|
||
public CodewordsData(Color color, List<string> codewords) | ||
{ | ||
Color = color; | ||
Codewords = codewords; | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
Content.Shared/Roles/RoleCodeword/SharedRoleCodewordSystem.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
using Content.Shared.Mind; | ||
using Robust.Shared.GameStates; | ||
using Robust.Shared.Player; | ||
|
||
namespace Content.Shared.Roles.RoleCodeword; | ||
|
||
public abstract class SharedRoleCodewordSystem : EntitySystem | ||
{ | ||
[Dependency] private readonly SharedMindSystem _mindSystem = default!; | ||
|
||
public override void Initialize() | ||
{ | ||
base.Initialize(); | ||
|
||
SubscribeLocalEvent<RoleCodewordComponent, ComponentGetStateAttemptEvent>(OnCodewordCompGetStateAttempt); | ||
} | ||
|
||
/// <summary> | ||
/// Determines if a codeword component should be sent to the client. | ||
/// </summary> | ||
private void OnCodewordCompGetStateAttempt(EntityUid uid, RoleCodewordComponent comp, ref ComponentGetStateAttemptEvent args) | ||
{ | ||
args.Cancelled = !CanGetState(args.Player, comp); | ||
} | ||
|
||
/// <summary> | ||
/// The criteria that determine whether a codeword component should be sent to a client. | ||
/// Sends the component if its owner is the player mind. | ||
/// </summary> | ||
/// <param name="player"> The Player the component will be sent to.</param> | ||
/// <param name="comp"> The component being checked against</param> | ||
/// <returns></returns> | ||
private bool CanGetState(ICommonSession? player, RoleCodewordComponent comp) | ||
{ | ||
if (!_mindSystem.TryGetMind(player, out EntityUid mindId, out var _)) | ||
return false; | ||
|
||
if (!TryComp(mindId, out RoleCodewordComponent? playerComp) && comp != playerComp) | ||
return false; | ||
|
||
return true; | ||
} | ||
|
||
public void SetRoleCodewords(RoleCodewordComponent comp, string key, List<string> codewords, Color color) | ||
{ | ||
var data = new CodewordsData(color, codewords); | ||
comp.RoleCodewords[key] = data; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -314,7 +314,6 @@ | |
- slow | ||
- swift | ||
- young | ||
- Taste/Touch | ||
- bitter | ||
- delicious | ||
- fresh | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters