Extract strings from resource renderer.

This commit is contained in:
Matthias Mailänder
2024-04-02 12:57:55 +02:00
committed by Gustas
parent 6c9e33b76c
commit 97c61e0068
11 changed files with 41 additions and 9 deletions

View File

@@ -39,6 +39,7 @@ namespace OpenRA.Mods.Cnc.Traits
public readonly string Palette = TileSet.TerrainPaletteInternalName; public readonly string Palette = TileSet.TerrainPaletteInternalName;
[FieldLoader.Require] [FieldLoader.Require]
[TranslationReference]
[Desc("Resource name used by tooltips.")] [Desc("Resource name used by tooltips.")]
public readonly string Name = null; public readonly string Name = null;

View File

@@ -17,6 +17,7 @@ using System.Reflection;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using Linguini.Syntax.Ast; using Linguini.Syntax.Ast;
using Linguini.Syntax.Parser; using Linguini.Syntax.Parser;
using OpenRA.Mods.Common.Traits;
using OpenRA.Traits; using OpenRA.Traits;
using OpenRA.Widgets; using OpenRA.Widgets;
@@ -136,6 +137,19 @@ namespace OpenRA.Mods.Common.Lint
foreach (var speed in gameSpeeds.Speeds.Values) foreach (var speed in gameSpeeds.Speeds.Values)
usedKeys.Add(speed.Name, gameSpeedTranslationReference, $"`{nameof(GameSpeed)}.{nameof(GameSpeed.Name)}`"); 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()) foreach (var modType in modData.ObjectCreator.GetTypes())
{ {
const BindingFlags Binding = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static; const BindingFlags Binding = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static;

View File

@@ -39,6 +39,7 @@ namespace OpenRA.Mods.Common.Traits
[FieldLoader.Require] [FieldLoader.Require]
[Desc("Resource name used by tooltips.")] [Desc("Resource name used by tooltips.")]
[TranslationReference]
public readonly string Name = null; public readonly string Name = null;
public ResourceTypeInfo(MiniYaml yaml) public ResourceTypeInfo(MiniYaml yaml)
@@ -266,7 +267,14 @@ namespace OpenRA.Mods.Common.Traits
protected virtual string GetRenderedResourceType(CPos cell) { return RenderContents[cell].Type; } 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; IEnumerable<string> IResourceRenderer.ResourceTypes => Info.ResourceTypes.Keys;

View File

@@ -30,6 +30,8 @@ dropdown-map-creeps =
.label = Creep Actors .label = Creep Actors
.description = Hostile forces spawn on the battlefield .description = Hostile forces spawn on the battlefield
resource-tiberium = Tiberium
## defaults.yaml ## defaults.yaml
notification-unit-lost = Unit lost. notification-unit-lost = Unit lost.
notification-unit-promoted = Unit promoted. notification-unit-promoted = Unit promoted.

View File

@@ -142,11 +142,11 @@
Tiberium: Tiberium:
Sequences: ti1, ti2, ti3, ti4, ti5, ti6, ti7, ti8, ti9, ti10, ti11, ti12 Sequences: ti1, ti2, ti3, ti4, ti5, ti6, ti7, ti8, ti9, ti10, ti11, ti12
Palette: staticterrain Palette: staticterrain
Name: Tiberium Name: resource-tiberium
BlueTiberium: BlueTiberium:
Sequences: bti1, bti2, bti3, bti4, bti5, bti6, bti7, bti8, bti9, bti10, bti11, bti12 Sequences: bti1, bti2, bti3, bti4, bti5, bti6, bti7, bti8, bti9, bti10, bti11, bti12
Palette: bluetiberium Palette: bluetiberium
Name: Tiberium Name: resource-tiberium
World: World:
Inherits: ^BaseWorld Inherits: ^BaseWorld

View File

@@ -31,6 +31,8 @@ options-starting-units =
.light-support = Light Support .light-support = Light Support
.heavy-support = Heavy Support .heavy-support = Heavy Support
resource-spice = Spice
## defaults.yaml ## defaults.yaml
notification-unit-lost = Unit lost. notification-unit-lost = Unit lost.
notification-unit-promoted = Unit promoted. notification-unit-promoted = Unit promoted.

View File

@@ -114,7 +114,7 @@
Spice: Spice:
Sequences: spicea, spiceb, spicec, spiced Sequences: spicea, spiceb, spicec, spiced
Palette: d2k Palette: d2k
Name: Spice Name: resource-spice
World: World:
Inherits: ^BaseWorld Inherits: ^BaseWorld

View File

@@ -32,6 +32,8 @@ options-starting-units =
.light-support = Light Support .light-support = Light Support
.heavy-support = Heavy Support .heavy-support = Heavy Support
resource-minerals = Valuable Minerals
## aircraft.yaml ## aircraft.yaml
actor-badr-name = Badger actor-badr-name = Badger

View File

@@ -155,11 +155,11 @@
Ore: Ore:
Sequences: gold01, gold02, gold03, gold04 Sequences: gold01, gold02, gold03, gold04
Palette: player Palette: player
Name: Valuable Minerals Name: resource-minerals
Gems: Gems:
Sequences: gem01, gem02, gem03, gem04 Sequences: gem01, gem02, gem03, gem04
Palette: player Palette: player
Name: Valuable Minerals Name: resource-minerals
World: World:
Inherits: ^BaseWorld Inherits: ^BaseWorld

View File

@@ -29,6 +29,9 @@ dropdown-map-creeps =
.label = Creep Actors .label = Creep Actors
.description = Hostile forces spawn on the battlefield .description = Hostile forces spawn on the battlefield
resource-veins = Veins
resource-tiberium = Tiberium
## Structures ## Structures
notification-construction-complete = Construction complete. notification-construction-complete = Construction complete.
notification-unit-ready = Unit ready. notification-unit-ready = Unit ready.

View File

@@ -209,11 +209,11 @@
Tiberium: Tiberium:
Sequences: tib01, tib02, tib03, tib04, tib05, tib06, tib07, tib08, tib09, tib10, tib11, tib12 Sequences: tib01, tib02, tib03, tib04, tib05, tib06, tib07, tib08, tib09, tib10, tib11, tib12
Palette: greentiberium Palette: greentiberium
Name: Tiberium Name: resource-tiberium
BlueTiberium: BlueTiberium:
Sequences: tib01, tib02, tib03, tib04, tib05, tib06, tib07, tib08, tib09, tib10, tib11, tib12 Sequences: tib01, tib02, tib03, tib04, tib05, tib06, tib07, tib08, tib09, tib10, tib11, tib12
Palette: bluetiberium Palette: bluetiberium
Name: Tiberium Name: resource-tiberium
Ramp1Sequences: Ramp1Sequences:
Tiberium: tib13, tib14 Tiberium: tib13, tib14
BlueTiberium: tib13, tib14 BlueTiberium: tib13, tib14
@@ -228,7 +228,7 @@
BlueTiberium: tib19, tib20 BlueTiberium: tib19, tib20
TSVeinsRenderer: TSVeinsRenderer:
ResourceType: Veins ResourceType: Veins
Name: Veins Name: resource-veins
Palette: player Palette: player
VeinholeActors: veinhole VeinholeActors: veinhole