Skip to content

Commit

Permalink
Added localization of groups and types: damage, metabolism (#27368)
Browse files Browse the repository at this point in the history
* Added localization of groups and types: damage, metabolism (displayed in the guide book). The text for the health analyzer, weapon damage inspection is now taken from damage prototypes

* fix damage tests

* fix damage test yml

* fix damage test prototypes

* Update Content.Shared/Damage/Prototypes/DamageGroupPrototype.cs

* Update Content.Shared/Damage/Prototypes/DamageTypePrototype.cs

---------

Co-authored-by: metalgearsloth <[email protected]>
  • Loading branch information
KrasnoshchekovPavel and metalgearsloth authored Apr 28, 2024
1 parent f5b8b5f commit 3fcbbc0
Show file tree
Hide file tree
Showing 24 changed files with 150 additions and 51 deletions.
3 changes: 2 additions & 1 deletion Content.Client/Guidebook/Controls/GuideReagentEmbed.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Content.Client.Guidebook.Richtext;
using Content.Client.Message;
using Content.Client.UserInterface.ControlExtensions;
using Content.Shared.Body.Prototypes;
using Content.Shared.Chemistry.Reaction;
using Content.Shared.Chemistry.Reagent;
using JetBrains.Annotations;
Expand Down Expand Up @@ -128,7 +129,7 @@ private void GenerateControl(ReagentPrototype reagent)

var groupLabel = new RichTextLabel();
groupLabel.SetMarkup(Loc.GetString("guidebook-reagent-effects-metabolism-group-rate",
("group", group), ("rate", effect.MetabolismRate)));
("group", _prototype.Index<MetabolismGroupPrototype>(group).LocalizedName), ("rate", effect.MetabolismRate)));
var descriptionLabel = new RichTextLabel
{
Margin = new Thickness(25, 0, 10, 0)
Expand Down
4 changes: 2 additions & 2 deletions Content.Client/HealthAnalyzer/UI/HealthAnalyzerWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ private void DrawDiagnosticGroups(

var groupTitleText = $"{Loc.GetString(
"health-analyzer-window-damage-group-text",
("damageGroup", Loc.GetString("health-analyzer-window-damage-group-" + damageGroupId)),
("damageGroup", _prototypes.Index<DamageGroupPrototype>(damageGroupId).LocalizedName),
("amount", damageAmount)
)}";

Expand Down Expand Up @@ -170,7 +170,7 @@ private void DrawDiagnosticGroups(

var damageString = Loc.GetString(
"health-analyzer-window-damage-type-text",
("damageType", Loc.GetString("health-analyzer-window-damage-type-" + type)),
("damageType", _prototypes.Index<DamageTypePrototype>(type).LocalizedName),
("amount", typeAmount)
);

Expand Down
9 changes: 9 additions & 0 deletions Content.IntegrationTests/Tests/Damageable/DamageableTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,36 +19,45 @@ public sealed class DamageableTest
# Define some damage groups
- type: damageType
id: TestDamage1
name: damage-type-blunt
- type: damageType
id: TestDamage2a
name: damage-type-blunt
- type: damageType
id: TestDamage2b
name: damage-type-blunt
- type: damageType
id: TestDamage3a
name: damage-type-blunt
- type: damageType
id: TestDamage3b
name: damage-type-blunt
- type: damageType
id: TestDamage3c
name: damage-type-blunt
# Define damage Groups with 1,2,3 damage types
- type: damageGroup
id: TestGroup1
name: damage-group-brute
damageTypes:
- TestDamage1
- type: damageGroup
id: TestGroup2
name: damage-group-brute
damageTypes:
- TestDamage2a
- TestDamage2b
- type: damageGroup
id: TestGroup3
name: damage-group-brute
damageTypes:
- TestDamage3a
- TestDamage3b
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,31 +12,39 @@ public static class DestructibleTestPrototypes
public const string DamagePrototypes = $@"
- type: damageType
id: TestBlunt
name: damage-type-blunt
- type: damageType
id: TestSlash
name: damage-type-slash
- type: damageType
id: TestPiercing
name: damage-type-piercing
- type: damageType
id: TestHeat
name: damage-type-heat
- type: damageType
id: TestShock
name: damage-type-shock
- type: damageType
id: TestCold
name: damage-type-cold
- type: damageGroup
id: TestBrute
name: damage-group-brute
damageTypes:
- TestBlunt
- TestSlash
- TestPiercing
- type: damageGroup
id: TestBurn
name: damage-group-burn
damageTypes:
- TestHeat
- TestShock
Expand Down
4 changes: 2 additions & 2 deletions Content.Server/Chemistry/ReagentEffectConditions/OrganType.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Content.Server.Body.Components;
using Content.Server.Body.Components;
using Content.Shared.Body.Prototypes;
using Content.Shared.Chemistry.Reagent;
using Robust.Shared.Prototypes;
Expand Down Expand Up @@ -35,7 +35,7 @@ public override bool Condition(ReagentEffectArgs args)
public override string GuidebookExplanation(IPrototypeManager prototype)
{
return Loc.GetString("reagent-effect-condition-guidebook-organ-type",
("name", prototype.Index<MetabolizerTypePrototype>(Type).Name),
("name", prototype.Index<MetabolizerTypePrototype>(Type).LocalizedName),
("shouldhave", ShouldHave));
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Content.Shared.Chemistry.Reagent;
using Content.Shared.Chemistry.Reagent;
using Content.Shared.FixedPoint;
using Robust.Shared.Prototypes;

Expand Down Expand Up @@ -43,7 +43,7 @@ public override string GuidebookExplanation(IPrototypeManager prototype)
prototype.TryIndex(Reagent, out reagentProto);

return Loc.GetString("reagent-effect-condition-guidebook-reagent-threshold",
("reagent", reagentProto?.LocalizedName ?? "this reagent"),
("reagent", reagentProto?.LocalizedName ?? Loc.GetString("reagent-effect-condition-guidebook-this-reagent")),
("max", Max == FixedPoint2.MaxValue ? (float) int.MaxValue : Max.Float()),
("min", Min.Float()));
}
Expand Down
4 changes: 2 additions & 2 deletions Content.Server/Chemistry/ReagentEffects/AdjustReagent.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Content.Shared.Body.Prototypes;
using Content.Shared.Body.Prototypes;
using Content.Shared.Chemistry.Reagent;
using Content.Shared.FixedPoint;
using JetBrains.Annotations;
Expand Down Expand Up @@ -74,7 +74,7 @@ public override void Effect(ReagentEffectArgs args)
return Loc.GetString("reagent-effect-guidebook-adjust-reagent-group",
("chance", Probability),
("deltasign", MathF.Sign(Amount.Float())),
("group", groupProto.ID),
("group", groupProto.LocalizedName),
("amount", MathF.Abs(Amount.Float())));
}

Expand Down
4 changes: 2 additions & 2 deletions Content.Server/Chemistry/ReagentEffects/HealthChange.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ protected override string ReagentEffectGuidebookText(IPrototypeManager prototype

damages.Add(
Loc.GetString("health-change-display",
("kind", group.ID),
("kind", group.LocalizedName),
("amount", MathF.Abs(amount.Float())),
("deltasign", sign)
));
Expand All @@ -96,7 +96,7 @@ protected override string ReagentEffectGuidebookText(IPrototypeManager prototype

damages.Add(
Loc.GetString("health-change-display",
("kind", kind),
("kind", prototype.Index<DamageTypePrototype>(kind).LocalizedName),
("amount", MathF.Abs(amount.Float())),
("deltasign", sign)
));
Expand Down
8 changes: 7 additions & 1 deletion Content.Shared/Body/Prototypes/MetabolismGroupPrototype.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Robust.Shared.Prototypes;
using Robust.Shared.Prototypes;

namespace Content.Shared.Body.Prototypes
{
Expand All @@ -7,5 +7,11 @@ public sealed partial class MetabolismGroupPrototype : IPrototype
{
[IdDataField]
public string ID { get; private set; } = default!;

[DataField("name", required: true)]
private LocId Name { get; set; }

[ViewVariables(VVAccess.ReadOnly)]
public string LocalizedName => Loc.GetString(Name);
}
}
7 changes: 5 additions & 2 deletions Content.Shared/Body/Prototypes/MetabolizerTypePrototype.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Robust.Shared.Prototypes;
using Robust.Shared.Prototypes;

namespace Content.Shared.Body.Prototypes
{
Expand All @@ -9,6 +9,9 @@ public sealed partial class MetabolizerTypePrototype : IPrototype
public string ID { get; private set; } = default!;

[DataField("name", required: true)]
public string Name { get; private set; } = default!;
private LocId Name { get; set; }

[ViewVariables(VVAccess.ReadOnly)]
public string LocalizedName => Loc.GetString(Name);
}
}
6 changes: 6 additions & 0 deletions Content.Shared/Damage/Prototypes/DamageGroupPrototype.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ public sealed partial class DamageGroupPrototype : IPrototype
{
[IdDataField] public string ID { get; } = default!;

[DataField(required: true)]
private LocId Name { get; set; }

[ViewVariables(VVAccess.ReadOnly)]
public string LocalizedName => Loc.GetString(Name);

[DataField("damageTypes", required: true, customTypeSerializer: typeof(PrototypeIdListSerializer<DamageTypePrototype>))]
public List<string> DamageTypes { get; private set; } = default!;
}
Expand Down
6 changes: 6 additions & 0 deletions Content.Shared/Damage/Prototypes/DamageTypePrototype.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ public sealed partial class DamageTypePrototype : IPrototype
[IdDataField]
public string ID { get; private set; } = default!;

[DataField(required: true)]
private LocId Name { get; set; }

[ViewVariables(VVAccess.ReadOnly)]
public string LocalizedName => Loc.GetString(Name);

/// <summary>
/// The price for each 1% damage reduction in armors
/// </summary>
Expand Down
5 changes: 4 additions & 1 deletion Content.Shared/Damage/Systems/DamageExamineSystem.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
using Content.Shared.Damage.Components;
using Content.Shared.Damage.Events;
using Content.Shared.Damage.Prototypes;
using Content.Shared.Examine;
using Content.Shared.FixedPoint;
using Content.Shared.Verbs;
using Robust.Shared.Prototypes;
using Robust.Shared.Utility;

namespace Content.Shared.Damage.Systems;

public sealed class DamageExamineSystem : EntitySystem
{
[Dependency] private readonly ExamineSystemShared _examine = default!;
[Dependency] private readonly IPrototypeManager _prototype = default!;

public override void Initialize()
{
Expand Down Expand Up @@ -66,7 +69,7 @@ private FormattedMessage GetDamageExamine(DamageSpecifier damageSpecifier, strin
if (damage.Value != FixedPoint2.Zero)
{
msg.PushNewline();
msg.AddMarkup(Loc.GetString("damage-value", ("type", damage.Key), ("amount", damage.Value)));
msg.AddMarkup(Loc.GetString("damage-value", ("type", _prototype.Index<DamageTypePrototype>(damage.Key).LocalizedName), ("amount", damage.Value)));
}
}

Expand Down
16 changes: 16 additions & 0 deletions Content.Tests/Shared/DamageTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -168,52 +168,65 @@ public void ModifierSetTest()
private string _damagePrototypes = @"
- type: damageType
id: Blunt
name: damage-type-blunt
- type: damageType
id: Slash
name: damage-type-slash
- type: damageType
id: Piercing
name: damage-type-piercing
- type: damageType
id: Heat
name: damage-type-heat
- type: damageType
id: Shock
name: damage-type-shock
- type: damageType
id: Cold
name: damage-type-cold
# Poison damage. Generally caused by various reagents being metabolised.
- type: damageType
id: Poison
name: damage-type-poison
- type: damageType
id: Radiation
name: damage-type-radiation
# Damage due to being unable to breathe.
# Represents not enough oxygen (or equivalent) getting to the blood.
# Usually healed automatically if entity can breathe
- type: damageType
id: Asphyxiation
name: damage-type-asphyxiation
# Damage representing not having enough blood.
# Represents there not enough blood to supply oxygen (or equivalent).
- type: damageType
id: Bloodloss
name: damage-type-bloodloss
- type: damageType
id: Cellular
name: damage-type-cellular
- type: damageGroup
id: Brute
name: damage-group-brute
damageTypes:
- Blunt
- Slash
- Piercing
- type: damageGroup
id: Burn
name: damage-group-burn
damageTypes:
- Heat
- Shock
Expand All @@ -225,6 +238,7 @@ public void ModifierSetTest()
# bloodloss, not this whole group, unless you have a wonder drug that affects both.
- type: damageGroup
id: Airloss
name: damage-group-airloss
damageTypes:
- Asphyxiation
- Bloodloss
Expand All @@ -233,12 +247,14 @@ public void ModifierSetTest()
# Though there are probably some radioactive poisons.
- type: damageGroup
id: Toxin
name: damage-group-toxin
damageTypes:
- Poison
- Radiation
- type: damageGroup
id: Genetic
name: damage-group-genetic
damageTypes:
- Cellular
Expand Down
5 changes: 5 additions & 0 deletions Resources/Locale/en-US/damage/damage-groups.ftl
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
damage-group-brute = Brute
damage-group-burn = Burn
damage-group-airloss = Airloss
damage-group-toxin = Toxin
damage-group-genetic = Genetic
13 changes: 13 additions & 0 deletions Resources/Locale/en-US/damage/damage-types.ftl
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
damage-type-asphyxiation = Asphyxiation
damage-type-bloodloss = Bloodloss
damage-type-blunt = Blunt
damage-type-cellular = Cellular
damage-type-caustic = Caustic
damage-type-cold = Cold
damage-type-heat = Heat
damage-type-piercing = Piercing
damage-type-poison = Poison
damage-type-radiation = Radiation
damage-type-shock = Shock
damage-type-slash = Slash
damage-type-structural = Structural
4 changes: 3 additions & 1 deletion Resources/Locale/en-US/guidebook/chemistry/conditions.ftl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
reagent-effect-condition-guidebook-total-damage =
reagent-effect-condition-guidebook-total-damage =
{ $max ->
[2147483648] it has at least {NATURALFIXED($min, 2)} total damage
*[other] { $min ->
Expand Down Expand Up @@ -57,3 +57,5 @@ reagent-effect-condition-guidebook-has-tag =
[true] does not have
*[false] has
} the tag {$tag}
reagent-effect-condition-guidebook-this-reagent = this reagent
Loading

0 comments on commit 3fcbbc0

Please sign in to comment.