Move chrome extraction utility to common and reuse code
This commit is contained in:
committed by
Matthias Mailänder
parent
b267374d20
commit
6386e96134
@@ -17,7 +17,7 @@ using OpenRA.FileSystem;
|
|||||||
|
|
||||||
namespace OpenRA.Mods.Common.UpdateRules
|
namespace OpenRA.Mods.Common.UpdateRules
|
||||||
{
|
{
|
||||||
using YamlFileSet = List<(IReadWritePackage, string, List<MiniYamlNodeBuilder>)>;
|
using YamlFileSet = List<(IReadWritePackage Package, string File, List<MiniYamlNodeBuilder> Nodes)>;
|
||||||
|
|
||||||
public static class UpdateUtils
|
public static class UpdateUtils
|
||||||
{
|
{
|
||||||
@@ -219,19 +219,19 @@ namespace OpenRA.Mods.Common.UpdateRules
|
|||||||
var mapRulesNode = yaml.NodeWithKeyOrDefault("Rules");
|
var mapRulesNode = yaml.NodeWithKeyOrDefault("Rules");
|
||||||
if (mapRulesNode != null)
|
if (mapRulesNode != null)
|
||||||
foreach (var f in LoadExternalMapYaml(modData, mapRulesNode.Value, externalFilenames))
|
foreach (var f in LoadExternalMapYaml(modData, mapRulesNode.Value, externalFilenames))
|
||||||
if (!modRules.Any(m => m.Item1 == f.Item1 && m.Item2 == f.Item2))
|
if (!modRules.Any(m => m.Package == f.Package && m.File == f.File))
|
||||||
modRules.Add(f);
|
modRules.Add(f);
|
||||||
|
|
||||||
var mapWeaponsNode = yaml.NodeWithKeyOrDefault("Weapons");
|
var mapWeaponsNode = yaml.NodeWithKeyOrDefault("Weapons");
|
||||||
if (mapWeaponsNode != null)
|
if (mapWeaponsNode != null)
|
||||||
foreach (var f in LoadExternalMapYaml(modData, mapWeaponsNode.Value, externalFilenames))
|
foreach (var f in LoadExternalMapYaml(modData, mapWeaponsNode.Value, externalFilenames))
|
||||||
if (!modWeapons.Any(m => m.Item1 == f.Item1 && m.Item2 == f.Item2))
|
if (!modWeapons.Any(m => m.Package == f.Package && m.File == f.File))
|
||||||
modWeapons.Add(f);
|
modWeapons.Add(f);
|
||||||
|
|
||||||
var mapSequencesNode = yaml.NodeWithKeyOrDefault("Sequences");
|
var mapSequencesNode = yaml.NodeWithKeyOrDefault("Sequences");
|
||||||
if (mapSequencesNode != null)
|
if (mapSequencesNode != null)
|
||||||
foreach (var f in LoadExternalMapYaml(modData, mapSequencesNode.Value, externalFilenames))
|
foreach (var f in LoadExternalMapYaml(modData, mapSequencesNode.Value, externalFilenames))
|
||||||
if (!modSequences.Any(m => m.Item1 == f.Item1 && m.Item2 == f.Item2))
|
if (!modSequences.Any(m => m.Package == f.Package && m.File == f.File))
|
||||||
modSequences.Add(f);
|
modSequences.Add(f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -298,8 +298,8 @@ namespace OpenRA.Mods.Common.UpdateRules
|
|||||||
if (transform == null)
|
if (transform == null)
|
||||||
yield break;
|
yield break;
|
||||||
|
|
||||||
foreach (var file in files)
|
foreach (var (_, _, nodes) in files)
|
||||||
foreach (var node in file.Item3)
|
foreach (var node in nodes)
|
||||||
if (node.Key != null)
|
if (node.Key != null)
|
||||||
foreach (var manualStep in ApplyChromeTransformInner(modData, node, transform))
|
foreach (var manualStep in ApplyChromeTransformInner(modData, node, transform))
|
||||||
yield return manualStep;
|
yield return manualStep;
|
||||||
@@ -310,8 +310,8 @@ namespace OpenRA.Mods.Common.UpdateRules
|
|||||||
if (transform == null)
|
if (transform == null)
|
||||||
yield break;
|
yield break;
|
||||||
|
|
||||||
foreach (var file in files)
|
foreach (var (_, _, nodes) in files)
|
||||||
foreach (var node in file.Item3)
|
foreach (var node in nodes)
|
||||||
if (node.Key != null)
|
if (node.Key != null)
|
||||||
foreach (var manualStep in transform(modData, node))
|
foreach (var manualStep in transform(modData, node))
|
||||||
yield return manualStep;
|
yield return manualStep;
|
||||||
@@ -328,14 +328,14 @@ namespace OpenRA.Mods.Common.UpdateRules
|
|||||||
{
|
{
|
||||||
public static void Save(this YamlFileSet files)
|
public static void Save(this YamlFileSet files)
|
||||||
{
|
{
|
||||||
foreach (var file in files)
|
foreach (var (package, file, nodes) in files)
|
||||||
{
|
{
|
||||||
if (file.Item1 == null)
|
if (package == null)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
var textData = Encoding.UTF8.GetBytes(file.Item3.WriteToString());
|
var textData = Encoding.UTF8.GetBytes(nodes.WriteToString());
|
||||||
if (!Enumerable.SequenceEqual(textData, file.Item1.GetStream(file.Item2).ReadAllBytes()))
|
if (!Enumerable.SequenceEqual(textData, package.GetStream(file).ReadAllBytes()))
|
||||||
file.Item1.Update(file.Item2, textData);
|
package.Update(file, textData);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -14,10 +14,14 @@ using System.Collections.Generic;
|
|||||||
using System.Collections.Immutable;
|
using System.Collections.Immutable;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using OpenRA.FileSystem;
|
||||||
|
using OpenRA.Mods.Common.UpdateRules;
|
||||||
using OpenRA.Widgets;
|
using OpenRA.Widgets;
|
||||||
|
|
||||||
namespace OpenRA.UtilityCommands
|
namespace OpenRA.Mods.Common.UtilityCommands
|
||||||
{
|
{
|
||||||
|
using YamlFileSet = List<(IReadWritePackage Package, string File, List<MiniYamlNodeBuilder> Nodes)>;
|
||||||
|
|
||||||
sealed class ExtractChromeStringsCommand : IUtilityCommand
|
sealed class ExtractChromeStringsCommand : IUtilityCommand
|
||||||
{
|
{
|
||||||
string IUtilityCommand.Name { get { return "--extract-chrome-strings"; } }
|
string IUtilityCommand.Name { get { return "--extract-chrome-strings"; } }
|
||||||
@@ -51,7 +55,8 @@ namespace OpenRA.UtilityCommands
|
|||||||
|
|
||||||
var unsortedCandidates = new List<TranslationCandidate>();
|
var unsortedCandidates = new List<TranslationCandidate>();
|
||||||
var groupedCandidates = new Dictionary<HashSet<string>, List<TranslationCandidate>>();
|
var groupedCandidates = new Dictionary<HashSet<string>, List<TranslationCandidate>>();
|
||||||
var chromeFiles = new List<(string Path, List<MiniYamlNodeBuilder> Nodes)>();
|
|
||||||
|
var yamlSet = new YamlFileSet();
|
||||||
|
|
||||||
// Get all translations.
|
// Get all translations.
|
||||||
foreach (var chrome in layout)
|
foreach (var chrome in layout)
|
||||||
@@ -60,7 +65,7 @@ namespace OpenRA.UtilityCommands
|
|||||||
var chromePath = Path.Combine(chromePackage.Name, chromeName);
|
var chromePath = Path.Combine(chromePackage.Name, chromeName);
|
||||||
|
|
||||||
var yaml = MiniYaml.FromFile(chromePath, false).ConvertAll(n => new MiniYamlNodeBuilder(n));
|
var yaml = MiniYaml.FromFile(chromePath, false).ConvertAll(n => new MiniYamlNodeBuilder(n));
|
||||||
chromeFiles.Add((chromePath, yaml));
|
yamlSet.Add(((IReadWritePackage)chromePackage, chromeName, yaml));
|
||||||
|
|
||||||
var translationCandidates = new List<TranslationCandidate>();
|
var translationCandidates = new List<TranslationCandidate>();
|
||||||
foreach (var node in yaml)
|
foreach (var node in yaml)
|
||||||
@@ -125,7 +130,7 @@ namespace OpenRA.UtilityCommands
|
|||||||
groupedCandidates[newHash] = new List<TranslationCandidate>() { candidate };
|
groupedCandidates[newHash] = new List<TranslationCandidate>() { candidate };
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write to translation and yaml files.
|
// Write to translation files.
|
||||||
Directory.CreateDirectory(Path.GetDirectoryName(fluentPath));
|
Directory.CreateDirectory(Path.GetDirectoryName(fluentPath));
|
||||||
using (var fluentWriter = new StreamWriter(fluentPath, append: true))
|
using (var fluentWriter = new StreamWriter(fluentPath, append: true))
|
||||||
{
|
{
|
||||||
@@ -184,11 +189,7 @@ namespace OpenRA.UtilityCommands
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (var chromeFile in chromeFiles)
|
yamlSet.Save();
|
||||||
{
|
|
||||||
using (var chromeLayoutWriter = new StreamWriter(chromeFile.Path))
|
|
||||||
chromeLayoutWriter.WriteLine(chromeFile.Nodes.WriteToString());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Reference in New Issue
Block a user