diff --git a/CR2W2JSON.Core/AudioEventArrayParser.cs b/CR2W2JSON.Core/AudioEventArrayParser.cs deleted file mode 100644 index c2a2ee1..0000000 --- a/CR2W2JSON.Core/AudioEventArrayParser.cs +++ /dev/null @@ -1,167 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text.Json.Serialization; -using WolvenKit.Common.Model.Cr2w; - -namespace CR2W2JSON.Core -{ - class AudioEventArray - { - [JsonInclude] - [JsonPropertyName("isSortedByRedHash")] - public bool IsSortedByRedHash = true; - - [JsonInclude] - [JsonPropertyName("events")] - public List Events; - - [JsonInclude] - [JsonPropertyName("switchGroup")] - public List SwitchGroup; - - [JsonInclude] - [JsonPropertyName("switch")] - public List Switch; - - [JsonInclude] - [JsonPropertyName("stateGroup")] - public List StateGroup; - - [JsonInclude] - [JsonPropertyName("state")] - public List State; - - [JsonInclude] - [JsonPropertyName("gameParameter")] - public List GameParameter; - - [JsonInclude] - [JsonPropertyName("bus")] - public List Bus; - } - - class EventMetaData - { - [JsonPropertyName("redId")] - public string RedId { get; set; } - [JsonPropertyName("wwiseId")] - public UInt32 WwiseId { get; set; } - [JsonPropertyName("maxAttenuation")] - public float MaxAttenuation { get; set; } - [JsonPropertyName("minDuration")] - public float MinDuration { get; set; } - [JsonPropertyName("maxDuration")] - public float MaxDuration { get; set; } - [JsonPropertyName("isLooping")] - public bool IsLooping { get; set; } - [JsonPropertyName("stopActionEvents")] - public List StopActionEvents { get; set; } - [JsonPropertyName("tags")] - public List Tags { get; set; } - } - - public class AudioEventArrayParser : IParser - { - private readonly ICR2WExport _chunk; - - public AudioEventArrayParser(ICR2WExport chunk) - { - _chunk = chunk; - } - - public object GetData() - { - var output = new AudioEventArray(); - - foreach (var v in _chunk.data.ChildrEditableVariables) - { - switch (v.REDName) - { - case "events": - output.Events = GetMetaData(v); - break; - - case "switchGroup": - output.SwitchGroup = GetMetaData(v); - break; - - case "switch": - output.Switch = GetMetaData(v); - break; - - case "stateGroup": - output.StateGroup = GetMetaData(v); - break; - - case "state": - output.State = GetMetaData(v); - break; - - case "gameParameter": - output.GameParameter = GetMetaData(v); - break; - - case "bus": - output.Bus = GetMetaData(v); - break; - } - } - - return output; - } - - private List GetMetaData(IEditableVariable evar) - { - var metaList = new List(); - - foreach (var sVariable in evar.ChildrEditableVariables) - { - var obj = new EventMetaData(); - foreach (var editableVariable in sVariable.ChildrEditableVariables) - { - var rv = editableVariable.REDValue; - switch (editableVariable.REDName) - { - case "redId": - obj.RedId = rv; - break; - case "wwiseId": - obj.WwiseId = UInt32.Parse(rv); - break; - case "maxAttenuation": - obj.MaxAttenuation = float.Parse(rv); - break; - case "minDuration": - obj.MinDuration = float.Parse(rv); - break; - case "maxDuration": - obj.MaxDuration = float.Parse(rv); - break; - case "isLooping": - obj.IsLooping = bool.Parse(rv); - break; - case "stopActionEvents": - var evList = new List(); - foreach (var ev in editableVariable.ChildrEditableVariables) - { - evList.Add(ev.REDValue); - } - obj.StopActionEvents = evList; - break; - case "tags": - var tagList = new List(); - foreach (var ev in editableVariable.ChildrEditableVariables) - { - tagList.Add(ev.REDValue); - } - obj.Tags = tagList; - break; - } - } - metaList.Add(obj); - } - - return metaList; - } - } -} \ No newline at end of file diff --git a/CR2W2JSON.Core/IParser.cs b/CR2W2JSON.Core/IParser.cs deleted file mode 100644 index 6b4bde0..0000000 --- a/CR2W2JSON.Core/IParser.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace CR2W2JSON.Core -{ - public interface IParser - { - public object GetData(); - } -} \ No newline at end of file diff --git a/CR2W2JSON.Core/LocDataMapParser.cs b/CR2W2JSON.Core/LocDataMapParser.cs deleted file mode 100644 index 30996d0..0000000 --- a/CR2W2JSON.Core/LocDataMapParser.cs +++ /dev/null @@ -1,80 +0,0 @@ -using System.Collections.Generic; -using System.Text.Json.Serialization; -using WolvenKit.Common.Model.Cr2w; - -namespace CR2W2JSON.Core -{ - public class LocDataMapParser : IParser - { - class Entry - { - [JsonInclude] - [JsonPropertyName("langCode")] - public string LangCode; - - [JsonInclude] - [JsonPropertyName("onscreensPath")] - public string OnscreensPath; - - [JsonInclude] - [JsonPropertyName("subtitlePath")] - public string SubtitlePath; - } - - class EntriesArray - { - [JsonInclude] - [JsonPropertyName("entries")] - public List Entries; - } - - private readonly ICR2WExport _chunk; - - public LocDataMapParser(ICR2WExport chunk) - { - _chunk = chunk; - } - - public object GetData() - { - var output = new EntriesArray(); - - foreach (var v in _chunk.data.ChildrEditableVariables) - { - //"entries": - output.Entries = GetMetaData(v); - } - - return output; - } - - private List GetMetaData(IEditableVariable evar) - { - var metaList = new List(); - - foreach (var sVariable in evar.ChildrEditableVariables) - { - var obj = new Entry(); - foreach (var editableVariable in sVariable.ChildrEditableVariables) - { - var rv = editableVariable.REDValue; - switch (editableVariable.REDName) - { - case "langCode": - obj.LangCode = rv; - break; - case "onscreensPath": - obj.OnscreensPath = rv.Replace("[Soft]", ""); - break; - case "subtitlePath": - obj.SubtitlePath = rv.Replace("[Soft]", ""); - break; - } - } - metaList.Add(obj); - } - - return metaList; - } - } -} diff --git a/CR2W2JSON.Core/OnScreenParser.cs b/CR2W2JSON.Core/OnScreenParser.cs deleted file mode 100644 index fed96de..0000000 --- a/CR2W2JSON.Core/OnScreenParser.cs +++ /dev/null @@ -1,70 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text.Json.Serialization; -using WolvenKit.Common.Model.Cr2w; - -namespace CR2W2JSON.Core -{ - class OnScreenEntries - { - [JsonInclude][JsonPropertyName("entries")] - public List Entries = new(); - } - - class OnScreenEntry - { - [JsonInclude][JsonPropertyName("primaryKey")] - public UInt64 PrimaryKey; - - [JsonInclude][JsonPropertyName("secondaryKey")] - public string SecondaryKey; - - [JsonInclude][JsonPropertyName("femaleVariant")] - public string FemaleVariant; - - [JsonInclude][JsonPropertyName("maleVariant")] - public string MaleVariant; - } - - public class OnScreenParser : IParser - { - private ICR2WExport _chunk; - - public OnScreenParser(ICR2WExport chunk) - { - _chunk = chunk; - } - - public object GetData() - { - var entries = new OnScreenEntries(); - - foreach (var childr in _chunk.data.ChildrEditableVariables[0].ChildrEditableVariables) - { - var entry = new OnScreenEntry(); - foreach (var ev in childr.ChildrEditableVariables) - { - switch (ev.REDName) - { - case "primaryKey": - entry.PrimaryKey = UInt64.Parse(ev.REDValue); - break; - case "secondaryKey": - entry.SecondaryKey = ev.REDValue != null ? ev.REDValue : ""; - break; - case "femaleVariant": - entry.FemaleVariant = ev.REDValue != null ? ev.REDValue : ""; - break; - case "maleVariant": - entry.MaleVariant = ev.REDValue != null ? ev.REDValue : ""; - break; - } - } - - entries.Entries.Add(entry); - } - - return entries; - } - } -} \ No newline at end of file diff --git a/CR2W2JSON.Core/Parser/AbstractParser.cs b/CR2W2JSON.Core/Parser/AbstractParser.cs new file mode 100644 index 0000000..c593915 --- /dev/null +++ b/CR2W2JSON.Core/Parser/AbstractParser.cs @@ -0,0 +1,21 @@ +using System.Collections.Generic; +using System.Runtime.Serialization; +using WolvenKit.Common.Model.Cr2w; + +namespace CR2W2JSON.Core.Parser +{ + public abstract class AbstractParser + { + protected ICR2WExport Chunk; + + protected AbstractParser(ICR2WExport chunk) + { + Chunk = chunk; + } + + public abstract ISerializable GetData(); + + protected Dictionary>> GetEntriesDictionary(List> entryList) => + new() {{"entries", entryList}}; + } +} \ No newline at end of file diff --git a/CR2W2JSON.Core/Parser/AudioEventArrayParser.cs b/CR2W2JSON.Core/Parser/AudioEventArrayParser.cs new file mode 100644 index 0000000..d57304e --- /dev/null +++ b/CR2W2JSON.Core/Parser/AudioEventArrayParser.cs @@ -0,0 +1,69 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Runtime.Serialization; +using WolvenKit.Common.Model.Cr2w; + +namespace CR2W2JSON.Core.Parser +{ + public class AudioEventArrayParser : AbstractParser + { + public override ISerializable GetData() + { + return Chunk.data.ChildrEditableVariables.ToDictionary( + v => v.REDName, v => GetMetaData(v) + ); + } + + private List> GetMetaData(IEditableVariable evar) + { + var metaList = new List>(); + + foreach (var sVariable in evar.ChildrEditableVariables) + { + var obj = new Dictionary(); + foreach (var editableVariable in sVariable.ChildrEditableVariables) + { + var rv = editableVariable.REDValue; + var redName = editableVariable.REDName; + switch (editableVariable.REDName) + { + case "redId": + obj.Add(redName, rv); + break; + case "wwiseId": + obj.Add(redName, UInt32.Parse(rv)); + break; + case "maxAttenuation": + case "minDuration": + case "maxDuration": + obj.Add(redName, float.Parse(rv)); + break; + case "isLooping": + obj.Add(redName, bool.Parse(rv)); + break; + case "stopActionEvents": + case "tags": + obj.Add(redName, GetListFromEdVars(editableVariable.ChildrEditableVariables)); + break; + } + } + metaList.Add(obj); + } + + return metaList; + } + + private List GetListFromEdVars(List vars) + { + var varList = new List(); + foreach (var ev in vars) + { + varList.Add(ev.REDValue); + } + return varList; + } + + public AudioEventArrayParser(ICR2WExport chunk) : base(chunk) {} + } +} \ No newline at end of file diff --git a/CR2W2JSON.Core/Parser/LocDataMapParser.cs b/CR2W2JSON.Core/Parser/LocDataMapParser.cs new file mode 100644 index 0000000..5de9460 --- /dev/null +++ b/CR2W2JSON.Core/Parser/LocDataMapParser.cs @@ -0,0 +1,31 @@ +using System.Collections.Generic; +using System.Runtime.Serialization; +using WolvenKit.Common.Model.Cr2w; + +namespace CR2W2JSON.Core.Parser +{ + public class LocDataMapAbstractParser : AbstractParser + { + public override ISerializable GetData() => + GetEntriesDictionary(GetLocDataMapEntries(Chunk.data.ChildrEditableVariables[0])); + + private List> GetLocDataMapEntries(IEditableVariable evar) + { + var entries = new List>(); + + foreach (var sVariable in evar.ChildrEditableVariables) + { + var entry = new Dictionary(); + foreach (var ev in sVariable.ChildrEditableVariables) + { + entry.Add(ev.REDName, ev.REDValue.Replace("[Soft]", "")); + } + entries.Add(entry); + } + + return entries; + } + + public LocDataMapAbstractParser(ICR2WExport chunk) : base(chunk) {} + } +} diff --git a/CR2W2JSON.Core/Parser/OnScreenParser.cs b/CR2W2JSON.Core/Parser/OnScreenParser.cs new file mode 100644 index 0000000..a954592 --- /dev/null +++ b/CR2W2JSON.Core/Parser/OnScreenParser.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +using System.Runtime.Serialization; +using System.Text.Json.Serialization; +using WolvenKit.Common.Model.Cr2w; + +namespace CR2W2JSON.Core.Parser +{ + public class OnScreenParser : AbstractParser + { + public override ISerializable GetData() + { + var entries = new List>(); + + foreach (var childr in Chunk.data.ChildrEditableVariables[0].ChildrEditableVariables) + { + var entry = new Dictionary(); + foreach (var ev in childr.ChildrEditableVariables) + { + switch (ev.REDName) + { + case "primaryKey": + entry.Add(ev.REDName, UInt64.Parse(ev.REDValue)); + break; + case "secondaryKey": + case "femaleVariant": + case "maleVariant": + entry.Add(ev.REDName, ev.REDValue ?? ""); + break; + } + } + + entries.Add(entry); + } + + return GetEntriesDictionary(entries); + } + + public OnScreenParser(ICR2WExport chunk) : base(chunk) {} + } +} \ No newline at end of file diff --git a/CR2W2JSON.Core/Parser/StringIdVariantLengthsReportParser.cs b/CR2W2JSON.Core/Parser/StringIdVariantLengthsReportParser.cs new file mode 100644 index 0000000..8c6f576 --- /dev/null +++ b/CR2W2JSON.Core/Parser/StringIdVariantLengthsReportParser.cs @@ -0,0 +1,37 @@ +using System.Collections.Generic; +using System.Runtime.Serialization; +using WolvenKit.Common.Model.Cr2w; +using WolvenKit.RED4.CR2W; + +namespace CR2W2JSON.Core.Parser +{ + public class StringIdVariantLengthsReportParser : AbstractParser + { + public override ISerializable GetData() + { + return GetEntriesDictionary(GetReportEntries(Chunk.data.ChildrEditableVariables[0])); + } + + private List> GetReportEntries(IEditableVariable evar) + { + var metaList = new List>(); + + foreach (var sVariable in evar.ChildrEditableVariables) + { + var entry = new Dictionary(); + foreach (var editableVariable in sVariable.ChildrEditableVariables) + { + var redValue = editableVariable.REDValue; + var redName = editableVariable.REDName; + entry.Add(redName, redName == "stringId" ? $"{ulong.Parse(redValue):X}" : float.Parse(redValue)); + + } + metaList.Add(entry); + } + + return metaList; + } + + public StringIdVariantLengthsReportParser(ICR2WExport chunk) : base(chunk) {} + } +} diff --git a/CR2W2JSON.Core/Parser/SubtitlesMapParser.cs b/CR2W2JSON.Core/Parser/SubtitlesMapParser.cs new file mode 100644 index 0000000..d174927 --- /dev/null +++ b/CR2W2JSON.Core/Parser/SubtitlesMapParser.cs @@ -0,0 +1,71 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Runtime.Serialization; +using System.Text.Json; +using WolvenKit.Common.Model.Cr2w; +using WolvenKit.RED4.CR2W; + +namespace CR2W2JSON.Core.Parser +{ + public class SubtitlesMapParser : AbstractParser + { + public override ISerializable GetData() + { + return GetEntriesDictionary(GetSubtitleEntries(Chunk.data.ChildrEditableVariables[0])); + } + + public void ParseSubtitleFiles(DirectoryInfo input, DirectoryInfo output) + { + var entries = GetSubtitleEntries(Chunk.data.ChildrEditableVariables[0]); + var cr2wReader = new Cp77FileService(); + var subtitleJson = new Json(); + var subtitlesParser = new SubtitlesParser(null); + + foreach (var entry in entries) + { + try + { + var subFileName = (string)entry["subtitleFile"]; + var relPath = subFileName[subFileName.IndexOf(entry["subtitleGroup"])..]; + var subFile = new FileInfo(Path.Combine(input.FullName, relPath)); + var subOutFile = new FileInfo(Path.Combine(output.FullName, relPath)); + var subCr2w = cr2wReader.TryReadCr2WFile(File.OpenRead(subFile.FullName)); + var vcc = subCr2w.Chunks[0].VirtualChildrenChunks[0]; + + subtitlesParser.SetChunk(vcc); + subtitleJson.Data = subtitlesParser.GetData(); + subtitleJson.RootType = vcc.REDType; + + Directory.CreateDirectory(subOutFile.DirectoryName); + + File.WriteAllText(subOutFile.FullName, JsonSerializer.Serialize(subtitleJson)); + } catch (Exception e) + { + Console.WriteLine(e.Message); + } + } + } + + private List> GetSubtitleEntries(IEditableVariable evar) + { + var entryList = new List>(); + + foreach (var sVariable in evar.ChildrEditableVariables) + { + var entry = new Dictionary(); + foreach (var editableVariable in sVariable.ChildrEditableVariables) + { + var redValue = editableVariable.REDValue; + var redName = editableVariable.REDName; + entry.Add(redName, redName == "subtitleGroup" ? redValue : redValue.Replace("[Soft]", "")); + } + entryList.Add(entry); + } + + return entryList; + } + + public SubtitlesMapParser(ICR2WExport chunk) : base(chunk) {} + } +} diff --git a/CR2W2JSON.Core/Parser/SubtitlesParser.cs b/CR2W2JSON.Core/Parser/SubtitlesParser.cs new file mode 100644 index 0000000..d9d59cc --- /dev/null +++ b/CR2W2JSON.Core/Parser/SubtitlesParser.cs @@ -0,0 +1,37 @@ +using System.Collections.Generic; +using System.Runtime.Serialization; +using WolvenKit.Common.Model.Cr2w; + +namespace CR2W2JSON.Core.Parser +{ + public class SubtitlesParser : AbstractParser + { + public override ISerializable GetData() + { + return GetEntriesDictionary(GetMetaData(Chunk.data.ChildrEditableVariables[0])); + } + + private List> GetMetaData(IEditableVariable evar) + { + var entries = new List>(); + + foreach (var sVariable in evar.ChildrEditableVariables) + { + var obj = new Dictionary(); + foreach (var editableVariable in sVariable.ChildrEditableVariables) + { + var redName = editableVariable.REDName; + var redValue = editableVariable.REDValue; + obj.Add(redName, redName == "stringId" ? $"{ulong.Parse(redValue):X}" : redValue ?? ""); + } + entries.Add(obj); + } + + return entries; + } + + public void SetChunk(ICR2WExport chunk) { Chunk = chunk; } + + public SubtitlesParser(ICR2WExport chunk) : base(chunk) {} + } +} diff --git a/CR2W2JSON.Core/Parser/VoLanguageDataMapParser.cs b/CR2W2JSON.Core/Parser/VoLanguageDataMapParser.cs new file mode 100644 index 0000000..8a7ab99 --- /dev/null +++ b/CR2W2JSON.Core/Parser/VoLanguageDataMapParser.cs @@ -0,0 +1,52 @@ +using System.Collections.Generic; +using System.Runtime.Serialization; +using System.Text.Json.Serialization; +using WolvenKit.Common.Model.Cr2w; + +namespace CR2W2JSON.Core.Parser +{ + public class VoLanguageDataMapParser : AbstractParser + { + public override ISerializable GetData() + { + return GetEntriesDictionary(GetMetaData(Chunk.data.ChildrEditableVariables[0])); + } + + private List> GetMetaData(IEditableVariable evar) + { + var metaList = new List>(); + + foreach (var sVariable in evar.ChildrEditableVariables) + { + var obj = new Dictionary(); + var voMapChunks = new List(); + foreach (var editableVariable in sVariable.ChildrEditableVariables) + { + var redValue = editableVariable.REDValue; + var redName = editableVariable.REDName; + switch (redName) + { + case "languageCode": + obj.Add(redName, redValue); + break; + case "lenghtMapReport": + case "voiceverMapReport": + obj.Add(redName, redValue.Replace("[Default]", " ").Replace("[Soft]", "")); + break; + case "voMapChunks": + foreach (var entrs in editableVariable.ChildrEditableVariables) + { + voMapChunks.Add(entrs.REDValue.Replace("[Soft]", "")); + } + break; + } + } + metaList.Add(obj); + } + + return metaList; + } + + public VoLanguageDataMapParser(ICR2WExport chunk) : base(chunk) {} + } +} diff --git a/CR2W2JSON.Core/Parser/VoMapParser.cs b/CR2W2JSON.Core/Parser/VoMapParser.cs new file mode 100644 index 0000000..7fa58c0 --- /dev/null +++ b/CR2W2JSON.Core/Parser/VoMapParser.cs @@ -0,0 +1,34 @@ +using System.Collections.Generic; +using System.Runtime.Serialization; +using WolvenKit.Common.Model.Cr2w; + +namespace CR2W2JSON.Core.Parser +{ + public class VoMapParser : AbstractParser + { + public override ISerializable GetData() => + GetEntriesDictionary(GetVoMapEntries(Chunk.data.ChildrEditableVariables[0])); + + private List> GetVoMapEntries(IEditableVariable evar) + { + var entries = new List>(); + + foreach (var sVariable in evar.ChildrEditableVariables) + { + var entry = new Dictionary(); + foreach (var ev in sVariable.ChildrEditableVariables) + { + var name = ev.REDName; + var rv = ev.REDValue; + entry.Add(name, name == "stringId" ? $"{ulong.Parse(rv):X}" : rv.Replace("[Soft]", "")); + + } + entries.Add(entry); + } + + return entries; + } + + public VoMapParser(ICR2WExport chunk) : base(chunk) {} + } +} diff --git a/CR2W2JSON.Core/Program.cs b/CR2W2JSON.Core/Program.cs index d0c3856..73152be 100644 --- a/CR2W2JSON.Core/Program.cs +++ b/CR2W2JSON.Core/Program.cs @@ -1,5 +1,4 @@ -#nullable enable -using System; +using System; using System.CommandLine; using System.CommandLine.Invocation; using System.Diagnostics.CodeAnalysis; @@ -7,27 +6,23 @@ using System.Text.Json; using System.Text.Json.Serialization; using Catel.IoC; +using CR2W2JSON.Core.Parser; using WolvenKit.Common.Model.Cr2w; using WolvenKit.Common.Services; using WolvenKit.RED4.CR2W; namespace CR2W2JSON.Core { - class Json + internal class Json { - [JsonInclude] - [JsonPropertyName("RootType")] - public string RootType; - - [JsonInclude] - [JsonPropertyName("Data")] - public object Data; + [JsonInclude] [JsonPropertyName("RootType")] public string RootType; + [JsonInclude] [JsonPropertyName("Data")] public object Data; } - - class Program + + internal static class Program { [SuppressMessage("ReSharper.DPA", "DPA0002: Excessive memory allocations in SOH", MessageId = "type: System.Reflection.CustomAttributeNamedParameter[]")] - static int Main(string[] args) + private static int Main(string[] args) { var rootCommand = new RootCommand { @@ -62,41 +57,19 @@ static int Main(string[] args) Data = parser.GetData() }; - //process subtitles from subtitles map file if (parser.GetType() == typeof(SubtitlesMapParser)) { - //iterate through all SubtitlesMap entries - foreach (var entrs in ((SubtitlesMapParser)parser).GetEntries()) + if (input.DirectoryName == output.DirectoryName) { - //define input subtitle file location - //define output subtitle file location - string sbtlRelPath = entrs.SubtitleFile.Substring(entrs.SubtitleFile.IndexOf(entrs.SubtitleGroup)); - FileInfo sbtlInPath = new FileInfo(input.DirectoryName + "\\" + sbtlRelPath); - FileInfo sbtlOutPath = new FileInfo(output.DirectoryName + "\\" + sbtlRelPath); - try - { - CR2W = s.TryReadCr2WFile(File.OpenRead(sbtlInPath.FullName)); - var subtitleVCChunks = CR2W.Chunks[0].VirtualChildrenChunks[0]; - SubtitlesParser sp = new SubtitlesParser(subtitleVCChunks); - var subtitleJson = new Json - { - RootType = subtitleVCChunks.REDType, - Data = sp.GetData() - }; - - if (!Directory.Exists(sbtlOutPath.DirectoryName)) - { - Directory.CreateDirectory(sbtlOutPath.DirectoryName); - } - File.WriteAllText(sbtlOutPath.FullName, JsonSerializer.Serialize(subtitleJson)); - } - catch (Exception e) - { - Console.WriteLine(e.Message); - } + Console.WriteLine("To convert subtitles the output directory must be " + + "different from the input directory."); + Environment.Exit(2); } + + ((SubtitlesMapParser)parser). + ParseSubtitleFiles(input.Directory, output.Directory); } - + File.WriteAllText(output.FullName, JsonSerializer.Serialize(json)); } catch (Exception e) @@ -108,29 +81,20 @@ static int Main(string[] args) return rootCommand.InvokeAsync(args).Result; } - private static IParser? GetParserByType(string type, ICR2WExport chunk) + private static AbstractParser GetParserByType(string type, ICR2WExport chunk) { - switch (type) + return type switch { - case "audioAudioEventArray": - return new AudioEventArrayParser(chunk); - case "localizationPersistenceOnScreenEntries": - return new OnScreenParser(chunk); - case "localizationPersistenceLocDataMap": - return new LocDataMapParser(chunk); - case "locVoLanguageDataMap": - return new VOLanguageDataMapParser(chunk); - case "locVoiceoverMap": - return new VOMapParser(chunk); - case "locVoiceoverLengthMap": - return new StringIDVariantLengthsReportParser(chunk); - case "localizationPersistenceSubtitleEntries": - return new SubtitlesParser(chunk); - case "localizationPersistenceSubtitleMap": - return new SubtitlesMapParser(chunk); - } - - return null; + "audioAudioEventArray" => new AudioEventArrayParser(chunk), + "localizationPersistenceOnScreenEntries" => new OnScreenParser(chunk), + "localizationPersistenceLocDataMap" => new LocDataMapAbstractParser(chunk), + "locVoLanguageDataMap" => new VoLanguageDataMapParser(chunk), + "locVoiceoverMap" => new VoMapParser(chunk), + "locVoiceoverLengthMap" => new StringIdVariantLengthsReportParser(chunk), + "localizationPersistenceSubtitleEntries" => new SubtitlesParser(chunk), + "localizationPersistenceSubtitleMap" => new SubtitlesMapParser(chunk), + _ => null + }; } } } diff --git a/CR2W2JSON.Core/StringIDVariantLengthsReportParser.cs b/CR2W2JSON.Core/StringIDVariantLengthsReportParser.cs deleted file mode 100644 index 1da2c61..0000000 --- a/CR2W2JSON.Core/StringIDVariantLengthsReportParser.cs +++ /dev/null @@ -1,80 +0,0 @@ -using System.Collections.Generic; -using System.Text.Json.Serialization; -using WolvenKit.Common.Model.Cr2w; - -namespace CR2W2JSON.Core -{ - public class StringIDVariantLengthsReportParser : IParser - { - class Entry - { - [JsonInclude] - [JsonPropertyName("femaleLength")] - public float FemaleLength; - - [JsonInclude] - [JsonPropertyName("maleLength")] - public float MaleLength; - - [JsonInclude] - [JsonPropertyName("stringId")] - public string StringId; - } - - class EntriesArray - { - [JsonInclude] - [JsonPropertyName("entries")] - public List Entries; - } - - private readonly ICR2WExport _chunk; - - public StringIDVariantLengthsReportParser(ICR2WExport chunk) - { - _chunk = chunk; - } - - public object GetData() - { - var output = new EntriesArray(); - - foreach (var v in _chunk.data.ChildrEditableVariables) - { - //"entries": - output.Entries = GetMetaData(v); - } - - return output; - } - - private List GetMetaData(IEditableVariable evar) - { - var metaList = new List(); - - foreach (var sVariable in evar.ChildrEditableVariables) - { - var obj = new Entry(); - foreach (var editableVariable in sVariable.ChildrEditableVariables) - { - var rv = editableVariable.REDValue; - switch (editableVariable.REDName) - { - case "femaleLength": - obj.FemaleLength = float.Parse(rv); - break; - case "maleLength": - obj.MaleLength = float.Parse(rv); - break; - case "stringId": - obj.StringId = $"{ulong.Parse(rv):X}"; - break; - } - } - metaList.Add(obj); - } - - return metaList; - } - } -} diff --git a/CR2W2JSON.Core/SubtitlesMapParser.cs b/CR2W2JSON.Core/SubtitlesMapParser.cs deleted file mode 100644 index c504363..0000000 --- a/CR2W2JSON.Core/SubtitlesMapParser.cs +++ /dev/null @@ -1,80 +0,0 @@ -using System.Collections.Generic; -using System.Text.Json.Serialization; -using WolvenKit.Common.Model.Cr2w; - -namespace CR2W2JSON.Core -{ - public class SubtitlesMapParser : IParser - { - public class Entry - { - [JsonInclude] - [JsonPropertyName("subtitleFile")] - public string SubtitleFile; - - [JsonInclude] - [JsonPropertyName("subtitleGroup")] - public string SubtitleGroup; - } - - class EntriesArray - { - [JsonInclude] - [JsonPropertyName("entries")] - public List Entries; - } - - private readonly ICR2WExport _chunk; - private List entries; - - public SubtitlesMapParser(ICR2WExport chunk) - { - _chunk = chunk; - } - - public object GetData() - { - var output = new EntriesArray(); - - foreach (var v in _chunk.data.ChildrEditableVariables) - { - //"entries": - entries = GetMetaData(v); - output.Entries = entries; - } - - return output; - } - - public List GetEntries() - { - return entries; - } - - private List GetMetaData(IEditableVariable evar) - { - var metaList = new List(); - - foreach (var sVariable in evar.ChildrEditableVariables) - { - var obj = new Entry(); - foreach (var editableVariable in sVariable.ChildrEditableVariables) - { - var rv = editableVariable.REDValue; - switch (editableVariable.REDName) - { - case "subtitleFile": - obj.SubtitleFile = rv.Replace("[Soft]", ""); - break; - case "subtitleGroup": - obj.SubtitleGroup = rv; - break; - } - } - metaList.Add(obj); - } - - return metaList; - } - } -} diff --git a/CR2W2JSON.Core/SubtitlesParser.cs b/CR2W2JSON.Core/SubtitlesParser.cs deleted file mode 100644 index de3313d..0000000 --- a/CR2W2JSON.Core/SubtitlesParser.cs +++ /dev/null @@ -1,80 +0,0 @@ -using System.Collections.Generic; -using System.Text.Json.Serialization; -using WolvenKit.Common.Model.Cr2w; - -namespace CR2W2JSON.Core -{ - public class SubtitlesParser : IParser - { - class Entry - { - [JsonInclude] - [JsonPropertyName("femaleVariant")] - public string FemaleVariant; - - [JsonInclude] - [JsonPropertyName("maleVariant")] - public string MaleVariant; - - [JsonInclude] - [JsonPropertyName("stringId")] - public string StringId; - } - - class EntriesArray - { - [JsonInclude] - [JsonPropertyName("entries")] - public List Entries; - } - - private readonly ICR2WExport _chunk; - - public SubtitlesParser(ICR2WExport chunk) - { - _chunk = chunk; - } - - public object GetData() - { - var output = new EntriesArray(); - - foreach (var v in _chunk.data.ChildrEditableVariables) - { - //"entries": - output.Entries = GetMetaData(v); - } - - return output; - } - - private List GetMetaData(IEditableVariable evar) - { - var metaList = new List(); - - foreach (var sVariable in evar.ChildrEditableVariables) - { - var obj = new Entry(); - foreach (var editableVariable in sVariable.ChildrEditableVariables) - { - var rv = editableVariable.REDValue; - switch (editableVariable.REDName) - { - case "femaleVariant": - obj.FemaleVariant = rv != null ? rv : ""; - break; - case "maleVariant": - obj.MaleVariant = rv != null ? rv : ""; - break; - case "stringId": - obj.StringId = $"{ulong.Parse(rv):X}"; - break; - } - } - metaList.Add(obj); - } - - return metaList; - } - } -} diff --git a/CR2W2JSON.Core/VOLanguageDataMapParser.cs b/CR2W2JSON.Core/VOLanguageDataMapParser.cs deleted file mode 100644 index 7893c66..0000000 --- a/CR2W2JSON.Core/VOLanguageDataMapParser.cs +++ /dev/null @@ -1,93 +0,0 @@ -using System.Collections.Generic; -using System.Text.Json.Serialization; -using WolvenKit.Common.Model.Cr2w; - -namespace CR2W2JSON.Core -{ - public class VOLanguageDataMapParser : IParser - { - class Entry - { - [JsonInclude] - [JsonPropertyName("languageCode")] - public string LanguageCode; - - //there is a bug from REDs in naming: "lenghtMapReport" instead of "lengthMapReport" - [JsonInclude] - [JsonPropertyName("lenghtMapReport")] - public string LengthMapReport; - - //there is a bug from REDs in naming: "voiceverMapReport" instead of "voiceoverMapReport" - [JsonInclude] - [JsonPropertyName("voiceverMapReport")] - public string VoiceoverMapReport; - - [JsonInclude] - [JsonPropertyName("voMapChunks")] - public List VoMapChunks; - } - - class EntriesArray - { - [JsonInclude] - [JsonPropertyName("entries")] - public List Entries; - } - - private readonly ICR2WExport _chunk; - - public VOLanguageDataMapParser(ICR2WExport chunk) - { - _chunk = chunk; - } - - public object GetData() - { - var output = new EntriesArray(); - - foreach (var v in _chunk.data.ChildrEditableVariables) - { - //"entries": - output.Entries = GetMetaData(v); - } - - return output; - } - - private List GetMetaData(IEditableVariable evar) - { - var metaList = new List(); - - foreach (var sVariable in evar.ChildrEditableVariables) - { - var obj = new Entry(); - obj.VoMapChunks = new List(); - foreach (var editableVariable in sVariable.ChildrEditableVariables) - { - var rv = editableVariable.REDValue; - switch (editableVariable.REDName) - { - case "languageCode": - obj.LanguageCode = rv; - break; - case "lenghtMapReport": - obj.LengthMapReport = rv.Replace("[Soft]", "").Replace("[Default]", " "); - break; - case "voiceverMapReport": - obj.VoiceoverMapReport = rv.Replace("[Default]", " ").Replace("[Soft]", ""); - break; - case "voMapChunks": - foreach (var entrs in editableVariable.ChildrEditableVariables) - { - obj.VoMapChunks.Add(entrs.REDValue.Replace("[Soft]", "")); - } - break; - } - } - metaList.Add(obj); - } - - return metaList; - } - } -} diff --git a/CR2W2JSON.Core/VOMapParser.cs b/CR2W2JSON.Core/VOMapParser.cs deleted file mode 100644 index 5596d0d..0000000 --- a/CR2W2JSON.Core/VOMapParser.cs +++ /dev/null @@ -1,80 +0,0 @@ -using System.Collections.Generic; -using System.Text.Json.Serialization; -using WolvenKit.Common.Model.Cr2w; - -namespace CR2W2JSON.Core -{ - public class VOMapParser : IParser - { - class Entry - { - [JsonInclude] - [JsonPropertyName("femaleResPath")] - public string FemaleResPath; - - [JsonInclude] - [JsonPropertyName("maleResPath")] - public string MaleResPath; - - [JsonInclude] - [JsonPropertyName("stringId")] - public string StringId; - } - - class EntriesArray - { - [JsonInclude] - [JsonPropertyName("entries")] - public List Entries; - } - - private readonly ICR2WExport _chunk; - - public VOMapParser(ICR2WExport chunk) - { - _chunk = chunk; - } - - public object GetData() - { - var output = new EntriesArray(); - - foreach (var v in _chunk.data.ChildrEditableVariables) - { - //"entries": - output.Entries = GetMetaData(v); - } - - return output; - } - - private List GetMetaData(IEditableVariable evar) - { - var metaList = new List(); - - foreach (var sVariable in evar.ChildrEditableVariables) - { - var obj = new Entry(); - foreach (var editableVariable in sVariable.ChildrEditableVariables) - { - var rv = editableVariable.REDValue; - switch (editableVariable.REDName) - { - case "femaleResPath": - obj.FemaleResPath = rv.Replace("[Soft]", ""); - break; - case "maleResPath": - obj.MaleResPath = rv.Replace("[Soft]", ""); - break; - case "stringId": - obj.StringId = $"{ulong.Parse(rv):X}"; - break; - } - } - metaList.Add(obj); - } - - return metaList; - } - } -}