Skip to content

Commit

Permalink
Extract strings from resource renderer.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mailaender authored and PunkPun committed Apr 30, 2024
1 parent 6c9e33b commit 97c61e0
Show file tree
Hide file tree
Showing 11 changed files with 41 additions and 9 deletions.
1 change: 1 addition & 0 deletions OpenRA.Mods.Cnc/Traits/World/TSVeinsRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public class TSVeinsRendererInfo : TraitInfo, Requires<IResourceLayerInfo>, IMap
public readonly string Palette = TileSet.TerrainPaletteInternalName;

[FieldLoader.Require]
[TranslationReference]
[Desc("Resource name used by tooltips.")]
public readonly string Name = null;

Expand Down
14 changes: 14 additions & 0 deletions OpenRA.Mods.Common/Lint/CheckTranslationReference.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
using System.Text.RegularExpressions;
using Linguini.Syntax.Ast;
using Linguini.Syntax.Parser;
using OpenRA.Mods.Common.Traits;
using OpenRA.Traits;
using OpenRA.Widgets;

Expand Down Expand Up @@ -136,6 +137,19 @@ static TranslationKeys GetUsedTranslationKeysInRuleset(Ruleset rules)
foreach (var speed in gameSpeeds.Speeds.Values)
usedKeys.Add(speed.Name, gameSpeedTranslationReference, $"`{nameof(GameSpeed)}.{nameof(GameSpeed.Name)}`");

// TODO: linter does not work with LoadUsing
foreach (var actorInfo in modData.DefaultRules.Actors)
{
foreach (var info in actorInfo.Value.TraitInfos<ResourceRendererInfo>())
{
var resourceTypeNameField = typeof(ResourceRendererInfo.ResourceTypeInfo).GetField(nameof(ResourceRendererInfo.ResourceTypeInfo.Name));
var resourceTypeTranslationReference = Utility.GetCustomAttributes<TranslationReferenceAttribute>(resourceTypeNameField, true)[0];
testedFields.Add(resourceTypeNameField);
foreach (var resourceTypes in info.ResourceTypes)
usedKeys.Add(resourceTypes.Value.Name, resourceTypeTranslationReference, $"`{nameof(ResourceRendererInfo.ResourceTypeInfo)}.{nameof(ResourceRendererInfo.ResourceTypeInfo.Name)}`");
}
}

foreach (var modType in modData.ObjectCreator.GetTypes())
{
const BindingFlags Binding = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static;
Expand Down
10 changes: 9 additions & 1 deletion OpenRA.Mods.Common/Traits/World/ResourceRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public class ResourceTypeInfo

[FieldLoader.Require]
[Desc("Resource name used by tooltips.")]
[TranslationReference]
public readonly string Name = null;

public ResourceTypeInfo(MiniYaml yaml)
Expand Down Expand Up @@ -266,7 +267,14 @@ protected virtual ISpriteSequence ChooseVariant(string resourceType, CPos cell)

protected virtual string GetRenderedResourceType(CPos cell) { return RenderContents[cell].Type; }

protected virtual string GetRenderedResourceTooltip(CPos cell) { return RenderContents[cell].Info?.Name; }
protected virtual string GetRenderedResourceTooltip(CPos cell)
{
var info = RenderContents[cell].Info;
if (info == null)
return null;

return TranslationProvider.GetString(info.Name);
}

IEnumerable<string> IResourceRenderer.ResourceTypes => Info.ResourceTypes.Keys;

Expand Down
2 changes: 2 additions & 0 deletions mods/cnc/languages/rules/en.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ dropdown-map-creeps =
.label = Creep Actors
.description = Hostile forces spawn on the battlefield
resource-tiberium = Tiberium
## defaults.yaml
notification-unit-lost = Unit lost.
notification-unit-promoted = Unit promoted.
Expand Down
4 changes: 2 additions & 2 deletions mods/cnc/rules/world.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,11 @@
Tiberium:
Sequences: ti1, ti2, ti3, ti4, ti5, ti6, ti7, ti8, ti9, ti10, ti11, ti12
Palette: staticterrain
Name: Tiberium
Name: resource-tiberium
BlueTiberium:
Sequences: bti1, bti2, bti3, bti4, bti5, bti6, bti7, bti8, bti9, bti10, bti11, bti12
Palette: bluetiberium
Name: Tiberium
Name: resource-tiberium

World:
Inherits: ^BaseWorld
Expand Down
2 changes: 2 additions & 0 deletions mods/d2k/languages/rules/en.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ options-starting-units =
.light-support = Light Support
.heavy-support = Heavy Support
resource-spice = Spice
## defaults.yaml
notification-unit-lost = Unit lost.
notification-unit-promoted = Unit promoted.
Expand Down
2 changes: 1 addition & 1 deletion mods/d2k/rules/world.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@
Spice:
Sequences: spicea, spiceb, spicec, spiced
Palette: d2k
Name: Spice
Name: resource-spice

World:
Inherits: ^BaseWorld
Expand Down
2 changes: 2 additions & 0 deletions mods/ra/languages/rules/en.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ options-starting-units =
.light-support = Light Support
.heavy-support = Heavy Support
resource-minerals = Valuable Minerals
## aircraft.yaml
actor-badr-name = Badger
Expand Down
4 changes: 2 additions & 2 deletions mods/ra/rules/world.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -155,11 +155,11 @@
Ore:
Sequences: gold01, gold02, gold03, gold04
Palette: player
Name: Valuable Minerals
Name: resource-minerals
Gems:
Sequences: gem01, gem02, gem03, gem04
Palette: player
Name: Valuable Minerals
Name: resource-minerals

World:
Inherits: ^BaseWorld
Expand Down
3 changes: 3 additions & 0 deletions mods/ts/languages/rules/en.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ dropdown-map-creeps =
.label = Creep Actors
.description = Hostile forces spawn on the battlefield
resource-veins = Veins
resource-tiberium = Tiberium
## Structures
notification-construction-complete = Construction complete.
notification-unit-ready = Unit ready.
Expand Down
6 changes: 3 additions & 3 deletions mods/ts/rules/world.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -209,11 +209,11 @@
Tiberium:
Sequences: tib01, tib02, tib03, tib04, tib05, tib06, tib07, tib08, tib09, tib10, tib11, tib12
Palette: greentiberium
Name: Tiberium
Name: resource-tiberium
BlueTiberium:
Sequences: tib01, tib02, tib03, tib04, tib05, tib06, tib07, tib08, tib09, tib10, tib11, tib12
Palette: bluetiberium
Name: Tiberium
Name: resource-tiberium
Ramp1Sequences:
Tiberium: tib13, tib14
BlueTiberium: tib13, tib14
Expand All @@ -228,7 +228,7 @@
BlueTiberium: tib19, tib20
TSVeinsRenderer:
ResourceType: Veins
Name: Veins
Name: resource-veins
Palette: player
VeinholeActors: veinhole

Expand Down

0 comments on commit 97c61e0

Please sign in to comment.