diff --git a/Elevator.Subtranslator.BackstoryReindexer/App.config b/Elevator.Subtranslator.BackstoryReindexer/App.config deleted file mode 100644 index 434b9af..0000000 --- a/Elevator.Subtranslator.BackstoryReindexer/App.config +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - diff --git a/Elevator.Subtranslator.BackstoryReindexer/Elevator.Subtranslator.BackstoryReindexer.csproj b/Elevator.Subtranslator.BackstoryReindexer/Elevator.Subtranslator.BackstoryReindexer.csproj deleted file mode 100644 index fe2fdd4..0000000 --- a/Elevator.Subtranslator.BackstoryReindexer/Elevator.Subtranslator.BackstoryReindexer.csproj +++ /dev/null @@ -1,68 +0,0 @@ - - - - - Debug - AnyCPU - {83C24E94-4D23-4FC8-9AEB-7B21BB8A5B15} - Exe - Properties - Elevator.Subtranslator.BackstoryReindexer - Elevator.Subtranslator.BackstoryReindexer - v4.6.1 - 512 - true - - - - AnyCPU - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - AnyCPU - none - true - ..\..\Subtranslator\ - TRACE - prompt - 4 - - - - ..\packages\FluentCommandLineParser.1.4.3\lib\net35\FluentCommandLineParser.dll - True - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/Elevator.Subtranslator.BackstoryReindexer/Program.cs b/Elevator.Subtranslator.BackstoryReindexer/Program.cs deleted file mode 100644 index ad51412..0000000 --- a/Elevator.Subtranslator.BackstoryReindexer/Program.cs +++ /dev/null @@ -1,211 +0,0 @@ -using Fclp; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Xml.Linq; - -namespace Elevator.Subtranslator.BackstoryReindexer -{ - class Program - { - public class ApplicationArguments - { - public string OldOrigBackstoriesFileName { get; set; } - public string NewOrigBackstoriesFileName { get; set; } - public string TranslatedBackstoriesInputFileName { get; set; } - public string TranslatedBackstoriesOutputFileName { get; set; } - } - - static void Main(string[] args) - { - // create a generic parser for the ApplicationArguments type - var p = new FluentCommandLineParser(); - - // specify which property the value will be assigned too. - p.Setup(arg => arg.OldOrigBackstoriesFileName) - .As('l', "old") // define the short and long option name - .Required() // using the standard fluent Api to declare this Option as required. - .WithDescription("Old backstories original file path"); // specify which property the value will be assigned too. - - p.Setup(arg => arg.NewOrigBackstoriesFileName) - .As('n', "new") - .Required() - .WithDescription("New backstories original file path"); - - p.Setup(arg => arg.TranslatedBackstoriesInputFileName) - .As('t', "translated") - .Required() - .WithDescription("Translated backstories input file path"); - - p.Setup(arg => arg.TranslatedBackstoriesOutputFileName) - .As('o', "output") - .Required() - .WithDescription("Translated backstories output file path"); - - ICommandLineParserResult result = p.Parse(args); - - if (result.HasErrors) - { - Console.WriteLine(result.ErrorText); - return; - } - - XDocument oldOrigStoriesDoc = XDocument.Load(p.Object.OldOrigBackstoriesFileName); - XDocument newOrigStoriesDoc = XDocument.Load(p.Object.NewOrigBackstoriesFileName); - XDocument oldTransStoriesDoc = XDocument.Load(p.Object.TranslatedBackstoriesInputFileName, LoadOptions.PreserveWhitespace); - - List oldStories = GetStories(oldOrigStoriesDoc).ToList(); - List newStories = GetStories(newOrigStoriesDoc).ToList(); - - Dictionary tagMap = new Dictionary(); - - StoryComparer comparer = new StoryComparer(); - - HashSet processedOld = new HashSet(); - HashSet processedNew = new HashSet(); - - Console.WriteLine("Renamed stories:"); - foreach (Story oldStory in oldStories) - { - if (tagMap.ContainsKey(oldStory.Name)) - { - Console.WriteLine("OLD {0} story already exists in map. It corresponds to NEW {1}", oldStory.Name, tagMap[oldStory.Name]); - continue; - } - - foreach (Story newStory in newStories) - { - if (comparer.Equals(oldStory, newStory)) - { - if (tagMap.ContainsValue(newStory.Name)) - { - Console.WriteLine("NEW {0} story already exists in map", newStory.Name); - continue; - } - - if (oldStory.Name != newStory.Name) - { - Console.WriteLine("{0} -> {1}", oldStory.Name, newStory.Name); - tagMap[oldStory.Name] = newStory.Name; - } - - processedOld.Add(oldStory.Name); - processedNew.Add(newStory.Name); - } - } - - } - - Console.WriteLine(); - - Console.WriteLine("Unmapped old stories:"); - foreach (Story oldStory in oldStories.Where(s => !processedOld.Contains(s.Name))) - { - Console.WriteLine(oldStory.Name); - } - - Console.WriteLine(); - - Console.WriteLine("Unmapped new stories:"); - foreach (Story newStory in newStories.Where(s => !processedNew.Contains(s.Name))) - { - Console.WriteLine(newStory.Name); - } - - RenameStories(oldTransStoriesDoc, tagMap); - AddNewStories(oldTransStoriesDoc, newStories.Where(s => !processedNew.Contains(s.Name))); - - oldTransStoriesDoc.Save(p.Object.TranslatedBackstoriesOutputFileName, SaveOptions.None); - } - - private static void AddNewStories(XDocument translatedStories, IEnumerable stories) - { - XElement root = translatedStories.Root; - - HashSet existingStories = new HashSet(root.Elements().Select(elem => elem.Name.LocalName)); - - XElement last = root.Elements().Last(); - - foreach (Story story in stories) - { - if (existingStories.Contains(story.Name)) - continue; - - XText newLine = new XText(Environment.NewLine); - XText tab = new XText("\t"); - XText tab2 = new XText("\t\t"); - - XElement newElement = new XElement(XName.Get(story.Name, last.Name.NamespaceName)); - XElement title = new XElement("title", story.Title); - XElement titleFemale = new XElement("titleFemale", story.Title); - XElement titleShort = new XElement("titleShort", story.TitleShort); - XElement titleShortFemale = new XElement("titleShortFemale", story.TitleShort); - XElement desc = new XElement("desc", story.Description); - - newElement.Add(newLine); - newElement.Add(tab2, title, newLine); - newElement.Add(tab2, titleFemale, newLine); - newElement.Add(tab2, titleShort, newLine); - newElement.Add(tab2, titleShortFemale, newLine); - newElement.Add(tab2, desc, newLine, tab); - - root.Add(tab, newElement, newLine, newLine); - } - } - - private static void RenameStories(XDocument translatedStories, Dictionary tagMap) - { - XElement root = translatedStories.Root; - - foreach (XElement element in root.Elements().ToArray()) - { - string newName; - if (tagMap.TryGetValue(element.Name.LocalName, out newName)) - { - XElement newElement = new XElement(XName.Get(newName, element.Name.NamespaceName)); - newElement.Add(element.Nodes()); - element.ReplaceWith(newElement); - - //RenameElement(storyElem, newName); - } - } - } - - private static void RenameElement(XElement element, string newName) - { - XElement newElement = new XElement(XName.Get(newName, element.Name.NamespaceName)); - if (element.HasAttributes) - { - IEnumerable attribs = element.Attributes(); - foreach (var attrib in attribs) - { - newElement.Add(new XAttribute(attrib)); - } - } - newElement.Add(element.Elements()); - element.ReplaceWith(newElement); - } - - private static IEnumerable GetStories(XDocument storiesDoc) - { - XElement root = storiesDoc.Root; - - foreach (XElement storyElem in root.Elements()) - { - yield return ReadStory(storyElem); - } - } - - - private static Story ReadStory(XElement storyElem) - { - return new Story() - { - Name = storyElem.Name.LocalName, - Title = storyElem.Element("title").Value, - TitleShort = storyElem.Element("titleShort").Value, - Description = storyElem.Element("desc").Value - }; - } - } -} diff --git a/Elevator.Subtranslator.BackstoryReindexer/Properties/AssemblyInfo.cs b/Elevator.Subtranslator.BackstoryReindexer/Properties/AssemblyInfo.cs deleted file mode 100644 index 919fd19..0000000 --- a/Elevator.Subtranslator.BackstoryReindexer/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,36 +0,0 @@ -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("Elevator.Subtranslator.BackstoryReindexer")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("Elevator.Subtranslator.BackstoryReindexer")] -[assembly: AssemblyCopyright("Copyright © 2018")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. -[assembly: ComVisible(false)] - -// The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("83c24e94-4d23-4fc8-9aeb-7b21bb8a5b15")] - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// You can specify all the values or you can default the Build and Revision Numbers -// by using the '*' as shown below: -// [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Elevator.Subtranslator.BackstoryReindexer/Story.cs b/Elevator.Subtranslator.BackstoryReindexer/Story.cs deleted file mode 100644 index 3be9c8e..0000000 --- a/Elevator.Subtranslator.BackstoryReindexer/Story.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace Elevator.Subtranslator.BackstoryReindexer -{ - public class Story - { - public string Name; - public string Title; - public string TitleShort; - public string Description; - } -} diff --git a/Elevator.Subtranslator.BackstoryReindexer/StoryComparer.cs b/Elevator.Subtranslator.BackstoryReindexer/StoryComparer.cs deleted file mode 100644 index ff8182a..0000000 --- a/Elevator.Subtranslator.BackstoryReindexer/StoryComparer.cs +++ /dev/null @@ -1,49 +0,0 @@ -using System.Collections.Generic; - -namespace Elevator.Subtranslator.BackstoryReindexer -{ - public class StoryComparer : IEqualityComparer - { - public bool Equals(Story x, Story y) - { - return - x.Title.ToLower() == y.Title.ToLower() && - x.TitleShort.ToLower() == y.TitleShort.ToLower() && - ReplaceVars(x.Description.ToUpper()) == ReplaceVars(y.Description.ToUpper()); - } - - //public bool Equals(Story x, Story y) - //{ - // string descX = ReplaceVars(x.Description).ToUpper(); - // string descY = ReplaceVars(y.Description).ToUpper(); - - // string titleX = x.Title.ToLower(); - // string titleY = y.Title.ToLower(); - - // string titleShortX = x.TitleShort.ToLower(); - // string titleShortY = y.TitleShort.ToLower(); - - // return - // titleX == titleY && - // titleShortX == titleShortY && - // descX == descY; - //} - - private static string ReplaceVars(string input) - { - return input - .Replace("NAME", "{PAWN_nameDef}") - .Replace("HECAP", "{PAWN_pronoun}") - .Replace("HE", "{PAWN_pronoun}") - .Replace("HISCAP", "{PAWN_possessive}") - .Replace("HIS", "{PAWN_possessive}") - .Replace("HIMCAP", "{PAWN_objective}") - .Replace("HIM", "{PAWN_objective}"); - } - - public int GetHashCode(Story obj) - { - return (obj.Title.ToLower() + obj.TitleShort.ToLower() + ReplaceVars(obj.Description.ToUpper())).GetHashCode(); - } - } -} diff --git a/Elevator.Subtranslator.BackstoryReindexer/packages.config b/Elevator.Subtranslator.BackstoryReindexer/packages.config deleted file mode 100644 index 29962cd..0000000 --- a/Elevator.Subtranslator.BackstoryReindexer/packages.config +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/Elevator.Subtranslator.BackstorySolidAnalyzer/Analyzer.cs b/Elevator.Subtranslator.BackstorySolidAnalyzer/Analyzer.cs deleted file mode 100644 index 3a6c923..0000000 --- a/Elevator.Subtranslator.BackstorySolidAnalyzer/Analyzer.cs +++ /dev/null @@ -1,72 +0,0 @@ -using System.Collections.Generic; -using System.Linq; -using System.Xml.Linq; - -namespace Elevator.Subtranslator.BackstorySolidAnalyzer -{ - public class Analyzer - { - public IEnumerable GetSolidPawns(XDocument creations) - { - XElement root = creations.Root; - - foreach (XElement pawnBio in root.Elements("PawnBio")) - { - List elements = pawnBio.Elements().ToList(); - XElement name = pawnBio.Element("Name"); - XElement gender = pawnBio.Element("Gender"); - XElement childhood = pawnBio.Element("Childhood"); - XElement adulthood = pawnBio.Element("Adulthood"); - - if (name != null && gender != null && childhood != null && adulthood != null) - { - yield return new SolidPawn - { - FirstName = name.Element("First").Value.Trim(), - LastName = name.Element("Last").Value.Trim(), - NickName = name.Element("Nick").Value.Trim(), - Gender = gender.Value, - ChildhoodTag = null, - ChildhoodTitle = childhood.Element("Title").Value.Trim(), - ChildhoodDescription = childhood.Element("BaseDesc").Value.Trim(), - AdulthoodTag = null, - AdulthoodTitle = adulthood.Element("Title").Value.Trim(), - AdulthoodDescription = adulthood.Element("BaseDesc").Value.Trim(), - }; - } - } - } - - public List FillSolidPawnTags(XDocument cleanBackstories, List solidPawns) - { - XElement root = cleanBackstories.Root; - - Dictionary childhoodDescMap = new Dictionary(); - Dictionary adulthoodDescMap = new Dictionary(); - - foreach (SolidPawn solidPawn in solidPawns) - { - childhoodDescMap[solidPawn.ChildhoodDescription] = solidPawn; - adulthoodDescMap[solidPawn.AdulthoodDescription] = solidPawn; - } - - foreach (XElement backstory in root.Elements()) - { - string backstoryTag = backstory.Name.LocalName; - string backstoryTitle = backstory.Element("title").Value.Trim(); - string backstoryDesc = backstory.Element("desc").Value.Trim(); - - SolidPawn solidPawn; - if (childhoodDescMap.TryGetValue(backstoryDesc, out solidPawn)) - { - solidPawn.ChildhoodTag = backstoryTag; - } - else if (adulthoodDescMap.TryGetValue(backstoryDesc, out solidPawn)) - { - solidPawn.AdulthoodTag = backstoryTag; - } - } - return solidPawns; - } - } -} diff --git a/Elevator.Subtranslator.BackstorySolidAnalyzer/App.config b/Elevator.Subtranslator.BackstorySolidAnalyzer/App.config deleted file mode 100644 index 434b9af..0000000 --- a/Elevator.Subtranslator.BackstorySolidAnalyzer/App.config +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - diff --git a/Elevator.Subtranslator.BackstorySolidAnalyzer/Elevator.Subtranslator.BackstorySolidAnalyzer.csproj b/Elevator.Subtranslator.BackstorySolidAnalyzer/Elevator.Subtranslator.BackstorySolidAnalyzer.csproj deleted file mode 100644 index abb29b9..0000000 --- a/Elevator.Subtranslator.BackstorySolidAnalyzer/Elevator.Subtranslator.BackstorySolidAnalyzer.csproj +++ /dev/null @@ -1,69 +0,0 @@ - - - - - Debug - AnyCPU - {D4DDFBB8-7F47-408B-87DB-F1018CB2BE8D} - Exe - Properties - Elevator.Subtranslator.BackstorySolidAnalyzer - Elevator.Subtranslator.BackstorySolidAnalyzer - v4.6.1 - 512 - true - - - - AnyCPU - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - AnyCPU - none - true - ..\..\Subtranslator\ - TRACE - prompt - 4 - - - - ..\packages\FluentCommandLineParser.1.4.3\lib\net35\FluentCommandLineParser.dll - True - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/Elevator.Subtranslator.BackstorySolidAnalyzer/Program.cs b/Elevator.Subtranslator.BackstorySolidAnalyzer/Program.cs deleted file mode 100644 index 912d3f1..0000000 --- a/Elevator.Subtranslator.BackstorySolidAnalyzer/Program.cs +++ /dev/null @@ -1,119 +0,0 @@ -using System; -using Fclp; -using System.IO; -using System.Xml.Linq; -using System.Collections.Generic; -using System.Linq; - -namespace Elevator.Subtranslator.BackstorySolidAnalyzer -{ - class Program - { - public class ApplicationArguments - { - public string CreationsFileName { get; set; } - public string BackstoriesInputFileName { get; set; } - public string TranslatedBackstoriesInputFileName { get; set; } - public string BackstoriesOutputFileName { get; set; } - } - - static void Main(string[] args) - { - // create a generic parser for the ApplicationArguments type - var p = new FluentCommandLineParser(); - - // specify which property the value will be assigned too. - p.Setup(arg => arg.CreationsFileName) - .As('c', "creations") // define the short and long option name - .Required() // using the standard fluent Api to declare this Option as required. - .WithDescription("Rimworld creations file path"); // specify which property the value will be assigned too. - - p.Setup(arg => arg.BackstoriesInputFileName) - .As('b', "backstories") // define the short and long option name - .Required() // using the standard fluent Api to declare this Option as required. - .WithDescription("Backstories input file path"); - - p.Setup(arg => arg.TranslatedBackstoriesInputFileName) - .As('t', "translated") // define the short and long option name - .Required() // using the standard fluent Api to declare this Option as required. - .WithDescription("Translated backstories input file path"); - - p.Setup(arg => arg.BackstoriesOutputFileName) - .As('o', "output") - .Required() - .WithDescription("Backstories output file path"); - - ICommandLineParserResult result = p.Parse(args); - - if (result.HasErrors) - { - Console.WriteLine(result.ErrorText); - return; - } - - XDocument solidPawnsDoc = XDocument.Load(p.Object.CreationsFileName, LoadOptions.PreserveWhitespace); - XDocument origStoriesDoc = XDocument.Load(p.Object.BackstoriesInputFileName, LoadOptions.PreserveWhitespace); - XDocument transStoriesDoc = XDocument.Load(p.Object.TranslatedBackstoriesInputFileName, LoadOptions.PreserveWhitespace); - - Analyzer analyzer = new Analyzer(); - SolidStoryHiglighter highlighter = new SolidStoryHiglighter(); - - List solidPawns = analyzer.GetSolidPawns(solidPawnsDoc).ToList(); - solidPawns = analyzer.FillSolidPawnTags(origStoriesDoc, solidPawns); - - XDocument outputStories = highlighter.HighlightSolidStories(transStoriesDoc, solidPawns); - outputStories.Save(p.Object.BackstoriesOutputFileName, SaveOptions.None); - } - - static void FillWithNewElements(XDocument recipient, XDocument donor) - { - HashSet tagsDonor = new HashSet(); - HashSet tagsRecipient = new HashSet(); - - foreach (XElement story in donor.Root.Elements()) - { - tagsDonor.Add(story.Name.LocalName); - } - - foreach (XElement story in recipient.Root.Elements()) - { - tagsRecipient.Add(story.Name.LocalName); - } - - tagsRecipient.IntersectWith(tagsDonor); - tagsDonor.ExceptWith(tagsRecipient); - - foreach (string newTag in tagsDonor) - { - XElement newElement = new XElement(donor.Root.Element(newTag)); - recipient.Root.Add(newElement); - recipient.Root.Add(Environment.NewLine); - recipient.Root.Add(Environment.NewLine); - } - } - - static void RemoveOldElements(XDocument recipient, XDocument donor) - { - HashSet tagsDonor = new HashSet(); - HashSet tagsRecipient = new HashSet(); - - foreach (XElement story in donor.Root.Elements()) - { - tagsDonor.Add(story.Name.LocalName); - } - - foreach (XElement story in recipient.Root.Elements()) - { - tagsRecipient.Add(story.Name.LocalName); - } - - tagsDonor.IntersectWith(tagsRecipient); - tagsRecipient.ExceptWith(tagsDonor); - - foreach (string oldTag in tagsRecipient) - { - recipient.Root.Element(oldTag).Remove(); - } - } - } -} diff --git a/Elevator.Subtranslator.BackstorySolidAnalyzer/Properties/AssemblyInfo.cs b/Elevator.Subtranslator.BackstorySolidAnalyzer/Properties/AssemblyInfo.cs deleted file mode 100644 index 0b24fc2..0000000 --- a/Elevator.Subtranslator.BackstorySolidAnalyzer/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,36 +0,0 @@ -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("Elevator.Subtranslator.BackstorySolidAnalyzer")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("Microsoft")] -[assembly: AssemblyProduct("Elevator.Subtranslator.BackstorySolidAnalyzer")] -[assembly: AssemblyCopyright("Copyright © Microsoft 2017")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. -[assembly: ComVisible(false)] - -// The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("d4ddfbb8-7f47-408b-87db-f1018cb2be8d")] - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// You can specify all the values or you can default the Build and Revision Numbers -// by using the '*' as shown below: -// [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Elevator.Subtranslator.BackstorySolidAnalyzer/SolidPawn.cs b/Elevator.Subtranslator.BackstorySolidAnalyzer/SolidPawn.cs deleted file mode 100644 index 4db7b8d..0000000 --- a/Elevator.Subtranslator.BackstorySolidAnalyzer/SolidPawn.cs +++ /dev/null @@ -1,16 +0,0 @@ -namespace Elevator.Subtranslator.BackstorySolidAnalyzer -{ - public class SolidPawn - { - public string FirstName { get; set; } - public string LastName { get; set; } - public string NickName { get; set; } - public string Gender { get; set; } - public string ChildhoodTag { get; set; } - public string ChildhoodTitle { get; set; } - public string ChildhoodDescription { get; set; } - public string AdulthoodTag { get; set; } - public string AdulthoodTitle { get; set; } - public string AdulthoodDescription { get; set; } - } -} \ No newline at end of file diff --git a/Elevator.Subtranslator.BackstorySolidAnalyzer/SolidStoryHiglighter.cs b/Elevator.Subtranslator.BackstorySolidAnalyzer/SolidStoryHiglighter.cs deleted file mode 100644 index c6ece17..0000000 --- a/Elevator.Subtranslator.BackstorySolidAnalyzer/SolidStoryHiglighter.cs +++ /dev/null @@ -1,128 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; -using System.Xml.Linq; - -namespace Elevator.Subtranslator.BackstorySolidAnalyzer -{ - public class SolidStoryHiglighter - { - public XDocument HighlightSolidStories(XDocument origBackstories, List solidPawns) - { - XDocument backstories = new XDocument(origBackstories); - XElement backstoryTranslations = backstories.Root; - - Dictionary> storyTagMap = GenerateStoryTagMap(solidPawns); - - XText tab = new XText(Environment.NewLine + "\t"); - XText newLine = new XText(Environment.NewLine); - - foreach (XElement backstory in backstoryTranslations.Elements()) - { - XNode prevSibling = backstory.PreviousNode?.PreviousNode; - bool hintExists = prevSibling != null && prevSibling is XProcessingInstruction; - - if (!hintExists && GenerateHint(backstory.Name.LocalName, storyTagMap, out XProcessingInstruction hint)) - { - backstory.AddBeforeSelf(hint, tab); - } - } - - return backstories; - } - - private bool GenerateHint(string backstoryTag, Dictionary> storyTagMap, out XProcessingInstruction hint) - { - List solidPawns; - if (storyTagMap.TryGetValue(backstoryTag, out solidPawns)) - { - hint = new XProcessingInstruction("solid", GenerateHintText(solidPawns)); - return true; - } - - hint = null; - return false; - } - - private string GenerateHintText(List stories) - { - if (stories.Count == 0) - return null; - - if (stories.Count == 1) - { - return string.Format("{0} ({1}) ", FormatName(stories[0]), stories[0].Gender); - } - - StringBuilder sb = new StringBuilder(); - foreach (SolidPawn story in stories) - { - sb.AppendFormat("{0} ({1}); ", FormatName(story), story.Gender); - } - return sb.ToString(); - } - - private string FormatName(SolidPawn pawn) - { - return - string.IsNullOrWhiteSpace(pawn.NickName) - ? string.Format("{0} {1}", pawn.FirstName, pawn.LastName) - : string.Format("{0} \"{1}\" {2}", pawn.FirstName, pawn.NickName, pawn.LastName); - } - - private static Dictionary> GenerateStoryTagMap(IEnumerable solidPawns) - { - Dictionary> storyMap = new Dictionary>(StringComparer.InvariantCultureIgnoreCase); - - foreach (SolidPawn pawn in solidPawns) - { - AddValueItem(storyMap, pawn.ChildhoodTag, pawn); - AddValueItem(storyMap, pawn.AdulthoodTag, pawn); - } - - return storyMap; - } - - private static void AddValueItem(Dictionary> dictionary, TKey key, TValueItem item) - { - if (dictionary.ContainsKey(key)) - { - dictionary[key].Add(item); - } - else - { - dictionary[key] = new List() { item }; - } - } - - private static IEnumerable SplitPacalStyle(string input) - { - int prevCapIndex = 0; - - foreach (int capIndex in GetIndicesOfCapitalLetters(input)) - { - if (capIndex > prevCapIndex) - { - yield return input.Substring(prevCapIndex, capIndex - prevCapIndex); - } - prevCapIndex = capIndex; - } - yield return input.Substring(prevCapIndex, input.Length - prevCapIndex); - } - - private static IEnumerable GetIndicesOfCapitalLetters(string input) - { - for (int i = 0; i < input.Length; ++i) - { - if (!char.IsLower(input[i])) - yield return i; - } - } - - private static string TrimDigits(string input) - { - int indexOfFirstDigit = input.IndexOfAny(new char[] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' }); - return input.Substring(0, indexOfFirstDigit); - } - } -} diff --git a/Elevator.Subtranslator.BackstorySolidAnalyzer/packages.config b/Elevator.Subtranslator.BackstorySolidAnalyzer/packages.config deleted file mode 100644 index 29962cd..0000000 --- a/Elevator.Subtranslator.BackstorySolidAnalyzer/packages.config +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/Elevator.Subtranslator.sln b/Elevator.Subtranslator.sln index 0343bf3..cd727aa 100644 --- a/Elevator.Subtranslator.sln +++ b/Elevator.Subtranslator.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 15 -VisualStudioVersion = 15.0.28307.168 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.32106.194 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Elevator.Subtranslator.BlueprintsAndFrames", "Elevator.Subtranslator.BlueprintsAndFrames\Elevator.Subtranslator.BlueprintsAndFrames.csproj", "{3361A470-FEA4-4B2D-98CD-53D86C7FB3E5}" EndProject @@ -13,10 +13,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Elevator.Subtranslator.Repo EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Elevator.Subtranslator.BackstoryIssueGenerator", "Elevator.Subtranslator.BackstoryIssueGenerator\Elevator.Subtranslator.BackstoryIssueGenerator.csproj", "{B153E2F1-5109-4E60-AF40-9BF40904992F}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Elevator.Subtranslator.BackstoryReindexer", "Elevator.Subtranslator.BackstoryReindexer\Elevator.Subtranslator.BackstoryReindexer.csproj", "{83C24E94-4D23-4FC8-9AEB-7B21BB8A5B15}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Elevator.Subtranslator.BackstorySolidAnalyzer", "Elevator.Subtranslator.BackstorySolidAnalyzer\Elevator.Subtranslator.BackstorySolidAnalyzer.csproj", "{D4DDFBB8-7F47-408B-87DB-F1018CB2BE8D}" -EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Elevator.Subtranslator.BackstoryTitleWidthChecker", "Elevator.Subtranslator.BackstoryTitleWidthChecker\Elevator.Subtranslator.BackstoryTitleWidthChecker.csproj", "{EC9F27A4-3008-41F4-A4E9-86B4C2E6E26D}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Elevator.Subtranslator.LabelGenderer", "Elevator.Subtranslator.LabelGenderer\Elevator.Subtranslator.LabelGenderer.csproj", "{DAE5433E-599F-46A0-AD96-8E6E968227A2}" @@ -53,14 +49,6 @@ Global {B153E2F1-5109-4E60-AF40-9BF40904992F}.Debug|Any CPU.Build.0 = Debug|Any CPU {B153E2F1-5109-4E60-AF40-9BF40904992F}.Release|Any CPU.ActiveCfg = Release|Any CPU {B153E2F1-5109-4E60-AF40-9BF40904992F}.Release|Any CPU.Build.0 = Release|Any CPU - {83C24E94-4D23-4FC8-9AEB-7B21BB8A5B15}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {83C24E94-4D23-4FC8-9AEB-7B21BB8A5B15}.Debug|Any CPU.Build.0 = Debug|Any CPU - {83C24E94-4D23-4FC8-9AEB-7B21BB8A5B15}.Release|Any CPU.ActiveCfg = Release|Any CPU - {83C24E94-4D23-4FC8-9AEB-7B21BB8A5B15}.Release|Any CPU.Build.0 = Release|Any CPU - {D4DDFBB8-7F47-408B-87DB-F1018CB2BE8D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {D4DDFBB8-7F47-408B-87DB-F1018CB2BE8D}.Debug|Any CPU.Build.0 = Debug|Any CPU - {D4DDFBB8-7F47-408B-87DB-F1018CB2BE8D}.Release|Any CPU.ActiveCfg = Release|Any CPU - {D4DDFBB8-7F47-408B-87DB-F1018CB2BE8D}.Release|Any CPU.Build.0 = Release|Any CPU {EC9F27A4-3008-41F4-A4E9-86B4C2E6E26D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {EC9F27A4-3008-41F4-A4E9-86B4C2E6E26D}.Debug|Any CPU.Build.0 = Debug|Any CPU {EC9F27A4-3008-41F4-A4E9-86B4C2E6E26D}.Release|Any CPU.ActiveCfg = Release|Any CPU