forked from Grimbly-Station/Grimbly-Station
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge Upstream 13.10.2024 (Grimbly-Station#108)
<!-- This is a semi-strict format, you can add/remove sections as needed but the order/format should be kept the same Remove these comments before submitting --> # Description <!-- Explain this PR in as much detail as applicable Some example prompts to consider: How might this affect the game? The codebase? What might be some alternatives to this? How/Who does this benefit/hurt [the game/codebase]? --> Merges the most recent EE upstream, now with 100% more bugfixing! --- # TODO <!-- A list of everything you have to do before this PR is "complete" You probably won't have to complete everything before merging but it's good to leave future references --> - [ ] Task - [x] Completed Task --- <!-- This is default collapsed, readers click to expand it and see all your media The PR media section can get very large at times, so this is a good way to keep it clean The title is written using HTML tags The title must be within the <summary> tags or you won't see it --> <details><summary><h1>Media</h1></summary> <p> ![Example Media Embed](https://example.com/thisimageisntreal.png) </p> </details> --- # Changelog <!-- You can add an author after the `:cl:` to change the name that appears in the changelog (ex: `:cl: Death`) Leaving it blank will default to your GitHub display name This includes all available types for the changelog -->
- Loading branch information
Showing
561 changed files
with
313,973 additions
and
2,372 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
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 |
---|---|---|
@@ -1,81 +1,61 @@ | ||
using Content.Shared.Language; | ||
using Content.Shared.Language.Components; | ||
using Content.Shared.Language.Events; | ||
using Content.Shared.Language.Systems; | ||
using Robust.Client; | ||
using Robust.Client.Player; | ||
using Robust.Shared.GameStates; | ||
using Robust.Shared.Prototypes; | ||
|
||
namespace Content.Client.Language.Systems; | ||
|
||
/// <summary> | ||
/// Client-side language system. | ||
/// </summary> | ||
/// <remarks> | ||
/// Unlike the server, the client is not aware of other entities' languages; it's only notified about the entity that it posesses. | ||
/// Due to that, this system stores such information in a static manner. | ||
/// </remarks> | ||
public sealed class LanguageSystem : SharedLanguageSystem | ||
{ | ||
[Dependency] private readonly IBaseClient _client = default!; | ||
[Dependency] private readonly IPlayerManager _playerManager = default!; | ||
|
||
/// <summary> | ||
/// The current language of the entity currently possessed by the player. | ||
/// Invoked when the languages of the local player entity change, for use in UI. | ||
/// </summary> | ||
public string CurrentLanguage { get; private set; } = default!; | ||
/// <summary> | ||
/// The list of languages the currently possessed entity can speak. | ||
/// </summary> | ||
public List<string> SpokenLanguages { get; private set; } = new(); | ||
/// <summary> | ||
/// The list of languages the currently possessed entity can understand. | ||
/// </summary> | ||
public List<string> UnderstoodLanguages { get; private set; } = new(); | ||
|
||
public event EventHandler<LanguagesUpdatedMessage>? OnLanguagesChanged; | ||
public event Action? OnLanguagesChanged; | ||
|
||
public override void Initialize() | ||
{ | ||
base.Initialize(); | ||
|
||
SubscribeNetworkEvent<LanguagesUpdatedMessage>(OnLanguagesUpdated); | ||
_client.RunLevelChanged += OnRunLevelChanged; | ||
_playerManager.LocalPlayerAttached += NotifyUpdate; | ||
SubscribeLocalEvent<LanguageSpeakerComponent, ComponentHandleState>(OnHandleState); | ||
} | ||
|
||
private void OnLanguagesUpdated(LanguagesUpdatedMessage message) | ||
private void OnHandleState(Entity<LanguageSpeakerComponent> ent, ref ComponentHandleState args) | ||
{ | ||
// TODO this entire thing is horrible. If someone is willing to refactor this, LanguageSpeakerComponent should become shared with SendOnlyToOwner = true | ||
// That way, this system will be able to use the existing networking infrastructure instead of relying on this makeshift... whatever this is. | ||
CurrentLanguage = message.CurrentLanguage; | ||
SpokenLanguages = message.Spoken; | ||
UnderstoodLanguages = message.Understood; | ||
if (args.Current is not LanguageSpeakerComponent.State state) | ||
return; | ||
|
||
OnLanguagesChanged?.Invoke(this, message); | ||
} | ||
ent.Comp.CurrentLanguage = state.CurrentLanguage; | ||
ent.Comp.SpokenLanguages = state.SpokenLanguages; | ||
ent.Comp.UnderstoodLanguages = state.UnderstoodLanguages; | ||
|
||
private void OnRunLevelChanged(object? sender, RunLevelChangedEventArgs args) | ||
{ | ||
// Request an update when entering a game | ||
if (args.NewLevel == ClientRunLevel.InGame) | ||
RequestStateUpdate(); | ||
if (ent.Owner == _playerManager.LocalEntity) | ||
NotifyUpdate(ent); | ||
} | ||
|
||
/// <summary> | ||
/// Sends a network request to the server to update this system's state. | ||
/// The server may ignore the said request if the player is not possessing an entity. | ||
/// Returns the LanguageSpeakerComponent of the local player entity. | ||
/// Will return null if the player does not have an entity, or if the client has not yet received the component state. | ||
/// </summary> | ||
public void RequestStateUpdate() | ||
public LanguageSpeakerComponent? GetLocalSpeaker() | ||
{ | ||
RaiseNetworkEvent(new RequestLanguagesMessage()); | ||
return CompOrNull<LanguageSpeakerComponent>(_playerManager.LocalEntity); | ||
} | ||
|
||
public void RequestSetLanguage(LanguagePrototype language) | ||
public void RequestSetLanguage(ProtoId<LanguagePrototype> language) | ||
{ | ||
if (language.ID == CurrentLanguage) | ||
if (GetLocalSpeaker()?.CurrentLanguage?.Equals(language) == true) | ||
return; | ||
|
||
RaiseNetworkEvent(new LanguagesSetMessage(language.ID)); | ||
RaiseNetworkEvent(new LanguagesSetMessage(language)); | ||
} | ||
|
||
// May cause some minor desync... | ||
// So to reduce the probability of desync, we replicate the change locally too | ||
if (SpokenLanguages.Contains(language.ID)) | ||
CurrentLanguage = language.ID; | ||
private void NotifyUpdate(EntityUid localPlayer) | ||
{ | ||
RaiseLocalEvent(localPlayer, new LanguagesUpdateEvent(), broadcast: true); | ||
OnLanguagesChanged?.Invoke(); | ||
} | ||
} |
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
Oops, something went wrong.