Skip to content

Commit

Permalink
Merge pull request #164 from Evgencheg/master
Browse files Browse the repository at this point in the history
цена+апстрим
  • Loading branch information
Evgencheg authored Sep 20, 2024
2 parents dee96f4 + f5dade1 commit 5d1239a
Show file tree
Hide file tree
Showing 21 changed files with 502 additions and 143 deletions.
8 changes: 5 additions & 3 deletions Content.Client/Standing/LayingDownSystem.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Content.Shared.ActionBlocker;
using Content.Shared.Buckle;
using Content.Shared.Rotation;
using Content.Shared.Standing;
using Robust.Client.GameObjects;
Expand All @@ -11,8 +11,9 @@ public sealed class LayingDownSystem : SharedLayingDownSystem
{
[Dependency] private readonly IGameTiming _timing = default!;
[Dependency] private readonly IEyeManager _eyeManager = default!;
[Dependency] private readonly StandingStateSystem _standing = default!;
[Dependency] private readonly AnimationPlayerSystem _animation = default!;
[Dependency] private readonly ActionBlockerSystem _actionBlocker = default!;
[Dependency] private readonly SharedBuckleSystem _buckle = default!;

public override void Initialize()
{
Expand All @@ -26,7 +27,8 @@ public override void Initialize()
private void OnMovementInput(EntityUid uid, LayingDownComponent component, MoveEvent args)
{
if (!_timing.IsFirstTimePredicted
|| !_actionBlocker.CanMove(uid)
|| !_standing.IsDown(uid)
|| _buckle.IsBuckled(uid)
|| _animation.HasRunningAnimation(uid, "rotate")
|| !TryComp<TransformComponent>(uid, out var transform)
|| !TryComp<SpriteComponent>(uid, out var sprite)
Expand Down
2 changes: 1 addition & 1 deletion Content.Server/Chemistry/ReagentEffects/MakeSentient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public override void Effect(ReagentEffectArgs args)
if (!knowledge.SpokenLanguages.Contains(fallback))
knowledge.SpokenLanguages.Add(fallback);

IoCManager.Resolve<IEntitySystemManager>().GetEntitySystem<LanguageSystem>().UpdateEntityLanguages(uid, speaker);
IoCManager.Resolve<IEntitySystemManager>().GetEntitySystem<LanguageSystem>().UpdateEntityLanguages(uid);

// Stops from adding a ghost role to things like people who already have a mind
if (entityManager.TryGetComponent<MindContainerComponent>(uid, out var mindContainer) && mindContainer.HasMind)
Expand Down
7 changes: 1 addition & 6 deletions Content.Server/Language/LanguageSystem.Networking.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,7 @@ private void SendLanguageStateToClient(ICommonSession session, LanguageSpeakerCo
// TODO this is really stupid and can be avoided if we just make everything shared...
private void SendLanguageStateToClient(EntityUid uid, ICommonSession session, LanguageSpeakerComponent? component = null)
{
var isUniversal = HasComp<UniversalLanguageSpeakerComponent>(uid);
if (!isUniversal)
Resolve(uid, ref component, logMissing: false);

// I really don't want to call 3 getter methods here, so we'll just have this slightly hardcoded solution
var message = isUniversal || component == null
var message = !Resolve(uid, ref component, logMissing: false)
? new LanguagesUpdatedMessage(UniversalPrototype, [UniversalPrototype], [UniversalPrototype])
: new LanguagesUpdatedMessage(component.CurrentLanguage, component.SpokenLanguages, component.UnderstoodLanguages);

Expand Down
70 changes: 34 additions & 36 deletions Content.Server/Language/LanguageSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using Content.Server.Language.Events;
using Content.Shared.Language;
using Content.Shared.Language.Components;
using Content.Shared.Language.Events;
using Content.Shared.Language.Systems;
using UniversalLanguageSpeakerComponent = Content.Shared.Language.Components.UniversalLanguageSpeakerComponent;

Expand All @@ -16,8 +15,19 @@ public override void Initialize()
InitializeNet();

SubscribeLocalEvent<LanguageSpeakerComponent, ComponentInit>(OnInitLanguageSpeaker);
SubscribeLocalEvent<UniversalLanguageSpeakerComponent, MapInitEvent>(OnUniversalInit);
SubscribeLocalEvent<UniversalLanguageSpeakerComponent, ComponentShutdown>(OnUniversalShutdown);
}

private void OnUniversalShutdown(EntityUid uid, UniversalLanguageSpeakerComponent component, ComponentShutdown args)
{
RemoveLanguage(uid, UniversalPrototype);
}

private void OnUniversalInit(EntityUid uid, UniversalLanguageSpeakerComponent component, MapInitEvent args)
{
AddLanguage(uid, UniversalPrototype);
}

#region public api

Expand Down Expand Up @@ -48,10 +58,9 @@ public bool CanSpeak(EntityUid speaker, string language, LanguageSpeakerComponen
/// </summary>
public LanguagePrototype GetLanguage(EntityUid speaker, LanguageSpeakerComponent? component = null)
{
if (HasComp<UniversalLanguageSpeakerComponent>(speaker) || !Resolve(speaker, ref component, logMissing: false))
return Universal; // Serves both as a fallback and uhhh something (TODO: fix this comment)

if (string.IsNullOrEmpty(component.CurrentLanguage) || !_prototype.TryIndex<LanguagePrototype>(component.CurrentLanguage, out var proto))
if (!Resolve(speaker, ref component, logMissing: false)
|| string.IsNullOrEmpty(component.CurrentLanguage)
|| !_prototype.TryIndex<LanguagePrototype>(component.CurrentLanguage, out var proto))
return Universal;

return proto;
Expand All @@ -63,13 +72,10 @@ public LanguagePrototype GetLanguage(EntityUid speaker, LanguageSpeakerComponent
/// <remarks>Typically, checking <see cref="LanguageSpeakerComponent.SpokenLanguages"/> is sufficient.</remarks>
public List<string> GetSpokenLanguages(EntityUid uid)
{
if (HasComp<UniversalLanguageSpeakerComponent>(uid))
return [UniversalPrototype];
if (!TryComp<LanguageSpeakerComponent>(uid, out var component))
return [];

if (TryComp<LanguageSpeakerComponent>(uid, out var component))
return component.SpokenLanguages;

return [];
return component.SpokenLanguages;
}

/// <summary>
Expand All @@ -78,21 +84,17 @@ public List<string> GetSpokenLanguages(EntityUid uid)
/// <remarks>Typically, checking <see cref="LanguageSpeakerComponent.UnderstoodLanguages"/> is sufficient.</remarks>
public List<string> GetUnderstoodLanguages(EntityUid uid)
{
if (HasComp<UniversalLanguageSpeakerComponent>(uid))
return [UniversalPrototype]; // This one is tricky because... well, they understand all of them, not just one.

if (TryComp<LanguageSpeakerComponent>(uid, out var component))
return component.UnderstoodLanguages;
if (!TryComp<LanguageSpeakerComponent>(uid, out var component))
return [];

return [];
return component.UnderstoodLanguages;
}

public void SetLanguage(EntityUid speaker, string language, LanguageSpeakerComponent? component = null)
{
if (!CanSpeak(speaker, language) || (HasComp<UniversalLanguageSpeakerComponent>(speaker) && language != UniversalPrototype))
return;

if (!Resolve(speaker, ref component) || component.CurrentLanguage == language)
if (!CanSpeak(speaker, language)
|| !Resolve(speaker, ref component)
|| component.CurrentLanguage == language)
return;

component.CurrentLanguage = language;
Expand All @@ -106,20 +108,18 @@ public void AddLanguage(
EntityUid uid,
string language,
bool addSpoken = true,
bool addUnderstood = true,
LanguageKnowledgeComponent? knowledge = null,
LanguageSpeakerComponent? speaker = null)
bool addUnderstood = true)
{
if (knowledge == null)
knowledge = EnsureComp<LanguageKnowledgeComponent>(uid);
EnsureComp<LanguageKnowledgeComponent>(uid, out var knowledge);
EnsureComp<LanguageSpeakerComponent>(uid);

if (addSpoken && !knowledge.SpokenLanguages.Contains(language))
knowledge.SpokenLanguages.Add(language);

if (addUnderstood && !knowledge.UnderstoodLanguages.Contains(language))
knowledge.UnderstoodLanguages.Add(language);

UpdateEntityLanguages(uid, speaker);
UpdateEntityLanguages(uid);
}

/// <summary>
Expand All @@ -129,20 +129,18 @@ public void RemoveLanguage(
EntityUid uid,
string language,
bool removeSpoken = true,
bool removeUnderstood = true,
LanguageKnowledgeComponent? knowledge = null,
LanguageSpeakerComponent? speaker = null)
bool removeUnderstood = true)
{
if (knowledge == null)
knowledge = EnsureComp<LanguageKnowledgeComponent>(uid);
if (!TryComp<LanguageKnowledgeComponent>(uid, out var knowledge))
return;

if (removeSpoken)
knowledge.SpokenLanguages.Remove(language);

if (removeUnderstood)
knowledge.UnderstoodLanguages.Remove(language);

UpdateEntityLanguages(uid, speaker);
UpdateEntityLanguages(uid);
}

/// <summary>
Expand All @@ -168,9 +166,9 @@ public bool EnsureValidLanguage(EntityUid entity, LanguageSpeakerComponent? comp
/// <summary>
/// Immediately refreshes the cached lists of spoken and understood languages for the given entity.
/// </summary>
public void UpdateEntityLanguages(EntityUid entity, LanguageSpeakerComponent? languages = null)
public void UpdateEntityLanguages(EntityUid entity)
{
if (!Resolve(entity, ref languages))
if (!TryComp<LanguageSpeakerComponent>(entity, out var languages))
return;

var ev = new DetermineEntityLanguagesEvent();
Expand Down Expand Up @@ -205,7 +203,7 @@ private void OnInitLanguageSpeaker(EntityUid uid, LanguageSpeakerComponent compo
if (string.IsNullOrEmpty(component.CurrentLanguage))
component.CurrentLanguage = component.SpokenLanguages.FirstOrDefault(UniversalPrototype);

UpdateEntityLanguages(uid, component);
UpdateEntityLanguages(uid);
}

#endregion
Expand Down
10 changes: 5 additions & 5 deletions Content.Server/Language/TranslatorSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ private void OnTranslatorParentChanged(EntityUid translator, HandheldTranslatorC
// If that is not the case, then OnProxyDetermineLanguages will remove this translator from HoldsTranslatorComponent.Translators.
Timer.Spawn(0, () =>
{
if (Exists(args.OldParent) && TryComp<LanguageSpeakerComponent>(args.OldParent, out var speaker))
_language.UpdateEntityLanguages(args.OldParent.Value, speaker);
if (Exists(args.OldParent) && HasComp<LanguageSpeakerComponent>(args.OldParent))
_language.UpdateEntityLanguages(args.OldParent.Value);
});
}

Expand All @@ -108,7 +108,7 @@ private void OnTranslatorToggle(EntityUid translator, HandheldTranslatorComponen
{
// The first new spoken language added by this translator, or null
var firstNewLanguage = translatorComp.SpokenLanguages.FirstOrDefault(it => !languageComp.SpokenLanguages.Contains(it));
_language.UpdateEntityLanguages(holder, languageComp);
_language.UpdateEntityLanguages(holder);

// Update the current language of the entity if necessary
if (isEnabled && translatorComp.SetLanguageOnInteract && firstNewLanguage is {})
Expand All @@ -131,8 +131,8 @@ private void OnPowerCellSlotEmpty(EntityUid translator, HandheldTranslatorCompon
_powerCell.SetPowerCellDrawEnabled(translator, false);
OnAppearanceChange(translator, component);

if (_containers.TryGetContainingContainer(translator, out var holderCont) && TryComp<LanguageSpeakerComponent>(holderCont.Owner, out var languageComp))
_language.UpdateEntityLanguages(holderCont.Owner, languageComp);
if (_containers.TryGetContainingContainer(translator, out var holderCont) && HasComp<LanguageSpeakerComponent>(holderCont.Owner))
_language.UpdateEntityLanguages(holderCont.Owner);
}

private void CopyLanguages(BaseTranslatorComponent from, DetermineEntityLanguagesEvent to, LanguageKnowledgeComponent knowledge)
Expand Down
2 changes: 1 addition & 1 deletion Content.Server/Traits/Assorted/ForeignerTraitSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ private void OnSpawn(Entity<ForeignerTraitComponent> entity, ref ComponentInit a

if (TryGiveTranslator(entity.Owner, entity.Comp.BaseTranslator, entity.Comp.BaseLanguage, alternateLanguage, out var translator))
{
_languages.RemoveLanguage(entity, entity.Comp.BaseLanguage, entity.Comp.CantSpeak, entity.Comp.CantUnderstand, knowledge);
_languages.RemoveLanguage(entity, entity.Comp.BaseLanguage, entity.Comp.CantSpeak, entity.Comp.CantUnderstand);
}
}

Expand Down

This file was deleted.

35 changes: 0 additions & 35 deletions Content.Server/Traits/Assorted/LanguageKnowledgeModifierSystem.cs

This file was deleted.

Loading

0 comments on commit 5d1239a

Please sign in to comment.