mirror of
https://github.com/WWhiteDreamProject/wwdpublic.git
synced 2026-04-18 05:59:03 +03:00
# 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>  </p> </details> --> # Changelog No cl --------- Co-authored-by: VMSolidus <evilexecutive@gmail.com>
77 lines
2.7 KiB
C#
77 lines
2.7 KiB
C#
using Content.Server.Administration;
|
|
using Content.Shared.Administration;
|
|
using Content.Shared.Language;
|
|
using Content.Shared.Language.Components;
|
|
using Content.Shared.Language.Systems;
|
|
using Robust.Shared.Prototypes;
|
|
using Robust.Shared.Toolshed;
|
|
using Robust.Shared.Toolshed.Syntax;
|
|
using Robust.Shared.Toolshed.TypeParsers;
|
|
|
|
namespace Content.Server.Language.Commands;
|
|
|
|
[ToolshedCommand(Name = "language"), AdminCommand(AdminFlags.Admin)]
|
|
public sealed class AdminLanguageCommand : ToolshedCommand
|
|
{
|
|
private LanguageSystem? _languagesField;
|
|
private LanguageSystem Languages => _languagesField ??= GetSys<LanguageSystem>();
|
|
|
|
[CommandImplementation("add")]
|
|
public EntityUid AddLanguage(
|
|
[CommandInvocationContext] IInvocationContext ctx,
|
|
[PipedArgument] EntityUid input,
|
|
[CommandArgument] ValueRef<string, Prototype<LanguagePrototype>> @ref,
|
|
[CommandArgument] bool canSpeak = true,
|
|
[CommandArgument] bool canUnderstand = true
|
|
)
|
|
{
|
|
var language = @ref.Evaluate(ctx)!;
|
|
|
|
if (language == SharedLanguageSystem.UniversalPrototype)
|
|
{
|
|
EnsureComp<UniversalLanguageSpeakerComponent>(input);
|
|
Languages.UpdateEntityLanguages(input);
|
|
}
|
|
else
|
|
{
|
|
EnsureComp<LanguageSpeakerComponent>(input);
|
|
Languages.AddLanguage(input, language, canSpeak, canUnderstand);
|
|
}
|
|
|
|
return input;
|
|
}
|
|
|
|
[CommandImplementation("rm")]
|
|
public EntityUid RemoveLanguage(
|
|
[CommandInvocationContext] IInvocationContext ctx,
|
|
[PipedArgument] EntityUid input,
|
|
[CommandArgument] ValueRef<string, Prototype<LanguagePrototype>> @ref,
|
|
[CommandArgument] bool removeSpeak = true,
|
|
[CommandArgument] bool removeUnderstand = true
|
|
)
|
|
{
|
|
var language = @ref.Evaluate(ctx)!;
|
|
if (language == SharedLanguageSystem.UniversalPrototype && HasComp<UniversalLanguageSpeakerComponent>(input))
|
|
{
|
|
RemComp<UniversalLanguageSpeakerComponent>(input);
|
|
EnsureComp<LanguageSpeakerComponent>(input);
|
|
}
|
|
// We execute this branch even in case of universal so that it gets removed if it was added manually to the LanguageKnowledge
|
|
Languages.RemoveLanguage(input, language, removeSpeak, removeUnderstand);
|
|
|
|
return input;
|
|
}
|
|
|
|
[CommandImplementation("lsspoken")]
|
|
public IEnumerable<ProtoId<LanguagePrototype>> ListSpoken([PipedArgument] EntityUid input)
|
|
{
|
|
return Languages.GetSpokenLanguages(input);
|
|
}
|
|
|
|
[CommandImplementation("lsunderstood")]
|
|
public IEnumerable<ProtoId<LanguagePrototype>> ListUnderstood([PipedArgument] EntityUid input)
|
|
{
|
|
return Languages.GetUnderstoodLanguages(input);
|
|
}
|
|
}
|