Files
wwdpublic/Content.Shared/Language/Components/LanguageSpeakerComponent.cs
Mnemotechnican 82cbea2aef Language Refactor 3 (#937)
# Description
This significantly improves the quality of the language system by fixing
the mistakes I've made almost a year ago while developing it.

Mainly, this throws away the old half-broken way of networking in favor
of the component state system provided by RT. Language speaker comp is
now shared with SendOnlyToOwner = true, and its state is handled
manually.

In addition to that, this brings the following changes:
- UniversalLanguageSpeaker and LanguageKnowledge are now server-side
- DetermineLanguagesEvent and LanguagesUpdateEvent are now shared (so
that future systems can be built in shared, if needed)
- Everything now uses the ProtoId<LanguagePrototype> type instead of raw
strings (god, I hated those so much)
- The server-side language system now accepts Entity<T?> arguments
instead of EntityUid + T
- UniversalLanguageSpeaker is now based on DetermineEntityLanguagesEvent
and gets an Enabled field, which allows to turn it off. This may have
some use in the future.
- Some minor cleanup

<!--
TODO MEDIA

<details><summary><h1>Media</h1></summary>
<p>

![Example Media Embed](https://example.com/thisimageisntreal.png)

</p>
</details>

-->

# Changelog
No cl

---------

Co-authored-by: VMSolidus <evilexecutive@gmail.com>
2024-10-19 13:41:35 +07:00

47 lines
1.6 KiB
C#

using Robust.Shared.GameStates;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization;
using Robust.Shared.Serialization.TypeSerializers.Implementations;
namespace Content.Shared.Language.Components;
/// <summary>
/// Stores the current state of the languages the entity can speak and understand.
/// </summary>
/// <remarks>
/// All fields of this component are populated during a DetermineEntityLanguagesEvent.
/// They are not to be modified externally.
/// </remarks>
[RegisterComponent, NetworkedComponent]
public sealed partial class LanguageSpeakerComponent : Component
{
public override bool SendOnlyToOwner => true;
/// <summary>
/// The current language the entity uses when speaking.
/// Other listeners will hear the entity speak in this language.
/// </summary>
[DataField]
public string CurrentLanguage = ""; // The language system will override it on mapinit
/// <summary>
/// List of languages this entity can speak at the current moment.
/// </summary>
[DataField]
public List<ProtoId<LanguagePrototype>> SpokenLanguages = [];
/// <summary>
/// List of languages this entity can understand at the current moment.
/// </summary>
[DataField]
public List<ProtoId<LanguagePrototype>> UnderstoodLanguages = [];
[Serializable, NetSerializable]
public sealed class State : ComponentState
{
public string CurrentLanguage = default!;
public List<ProtoId<LanguagePrototype>> SpokenLanguages = default!;
public List<ProtoId<LanguagePrototype>> UnderstoodLanguages = default!;
}
}