From 1cbf75b30f25a8fc66d428f1da8a0e79ac5d304d Mon Sep 17 00:00:00 2001 From: Peptide90 Date: Mon, 11 Nov 2024 20:31:18 +0000 Subject: [PATCH] Language Refactor 3 (#937) 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 type instead of raw strings (god, I hated those so much) - The server-side language system now accepts Entity 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 No cl --------- Co-authored-by: VMSolidus (cherry picked from commit 8c5faf34027b83d1435bb96df644a8a467a7740a) --- .../Components/LanguageKnowledgeComponent.cs | 24 ------------------- .../UniversalLanguageSpeakerComponent.cs | 11 --------- .../Events/LanguagesUpdatedMessage.cs | 15 ------------ .../Events/RequestLanguagesMessage.cs | 10 -------- 4 files changed, 60 deletions(-) delete mode 100644 Content.Shared/Language/Components/LanguageKnowledgeComponent.cs delete mode 100644 Content.Shared/Language/Components/UniversalLanguageSpeakerComponent.cs delete mode 100644 Content.Shared/Language/Events/LanguagesUpdatedMessage.cs delete mode 100644 Content.Shared/Language/Events/RequestLanguagesMessage.cs diff --git a/Content.Shared/Language/Components/LanguageKnowledgeComponent.cs b/Content.Shared/Language/Components/LanguageKnowledgeComponent.cs deleted file mode 100644 index ddbdc742be4..00000000000 --- a/Content.Shared/Language/Components/LanguageKnowledgeComponent.cs +++ /dev/null @@ -1,24 +0,0 @@ -using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.List; - -namespace Content.Shared.Language.Components; - -// TODO: move to server side, it's never synchronized! - -/// -/// Stores data about entities' intrinsic language knowledge. -/// -[RegisterComponent] -public sealed partial class LanguageKnowledgeComponent : Component -{ - /// - /// List of languages this entity can speak without any external tools. - /// - [DataField("speaks", customTypeSerializer: typeof(PrototypeIdListSerializer), required: true)] - public List SpokenLanguages = new(); - - /// - /// List of languages this entity can understand without any external tools. - /// - [DataField("understands", customTypeSerializer: typeof(PrototypeIdListSerializer), required: true)] - public List UnderstoodLanguages = new(); -} diff --git a/Content.Shared/Language/Components/UniversalLanguageSpeakerComponent.cs b/Content.Shared/Language/Components/UniversalLanguageSpeakerComponent.cs deleted file mode 100644 index 6f5ad1178b8..00000000000 --- a/Content.Shared/Language/Components/UniversalLanguageSpeakerComponent.cs +++ /dev/null @@ -1,11 +0,0 @@ -namespace Content.Shared.Language.Components; - -// -// Signifies that this entity can speak and understand any language. -// Applies to such entities as ghosts. -// -[RegisterComponent] -public sealed partial class UniversalLanguageSpeakerComponent : Component -{ - -} diff --git a/Content.Shared/Language/Events/LanguagesUpdatedMessage.cs b/Content.Shared/Language/Events/LanguagesUpdatedMessage.cs deleted file mode 100644 index 563f036df6d..00000000000 --- a/Content.Shared/Language/Events/LanguagesUpdatedMessage.cs +++ /dev/null @@ -1,15 +0,0 @@ -using Robust.Shared.Serialization; - -namespace Content.Shared.Language.Events; - -/// -/// Sent to the client when its list of languages changes. -/// The client should in turn update its HUD and relevant systems. -/// -[Serializable, NetSerializable] -public sealed class LanguagesUpdatedMessage(string currentLanguage, List spoken, List understood) : EntityEventArgs -{ - public string CurrentLanguage = currentLanguage; - public List Spoken = spoken; - public List Understood = understood; -} diff --git a/Content.Shared/Language/Events/RequestLanguagesMessage.cs b/Content.Shared/Language/Events/RequestLanguagesMessage.cs deleted file mode 100644 index aead1f4cd1a..00000000000 --- a/Content.Shared/Language/Events/RequestLanguagesMessage.cs +++ /dev/null @@ -1,10 +0,0 @@ -using Robust.Shared.Serialization; - -namespace Content.Shared.Language.Events; - -/// -/// Sent from the client to the server when it needs to learn the list of languages its entity knows. -/// This event should always be followed by a , unless the client doesn't have an entity. -/// -[Serializable, NetSerializable] -public sealed class RequestLanguagesMessage : EntityEventArgs;