static Byte[] UpdateScenarioFile(FileReader reader, String jsonpath, List <TextItem> stringtableitems) { Assert.IsNotNull(reader, nameof(reader)); Assert.IsValidString(jsonpath, nameof(jsonpath)); Assert.IsNotNull(stringtableitems, nameof(stringtableitems)); var scenariofile = new ScenarioFile(reader); var textitems = JsonTextItemFileIO.ReadFromFile(jsonpath); var scenariotext_index = 0; scenariofile.VisitOperands(x => x.Type == Bytecode.OperandType.String, x => new Bytecode.Operand(Bytecode.OperandType.String, textitems[scenariotext_index++].GetBestText())); var stringtable = scenariofile.GetStringTable(); for (var i = 0; i != stringtable.Count; ++i) { var textitem = stringtableitems.FirstOrDefault(x => x.Text == stringtable[i]); if (textitem != null && textitem.Translation != "") { stringtable[i] = textitem.Translation; } } scenariofile.UpdateStringTable(stringtable); scenariofile.Fix(); return(scenariofile.Write(reader.Encoding)); }
public static void Run(String translationPath) { foreach (var filepath in Directory.EnumerateFiles(translationPath, "*.json", SearchOption.AllDirectories)) { var textitems = JsonTextItemFileIO.ReadFromFile(filepath); JsonTextItemFileIO.WriteToFile(textitems, filepath); } }
static Byte[] UpdateTextFile(FileReader reader, Text.FilePointerDelegate filepointerfunc, Int32 recordcount, String jsonpath) { Assert.IsNotNull(reader, nameof(reader)); Assert.IsNotNull(filepointerfunc, nameof(filepointerfunc)); Assert.IsValidString(jsonpath, nameof(jsonpath)); var textitems = JsonTextItemFileIO.ReadFromFile(jsonpath); var strings = textitems.Select(x => x.Translation).ToList(); return(Text.TextFileIO.Write(reader, filepointerfunc, recordcount, strings)); }
static Byte[] UpdateMonsterFile(FileReader reader, String jsonpath) { Assert.IsNotNull(reader, nameof(reader)); Assert.IsValidString(jsonpath, nameof(jsonpath)); var monsterfile = new MonsterDefinitionFile(reader); var json = JsonTextItemFileIO.ReadFromFile(jsonpath); var strings = json.Select(x => x.GetBestText()).ToList(); monsterfile.SetStrings(strings); return(monsterfile.Write(reader.Encoding)); }
public static void Run(CommandLine.FormatJsonArgs args) { Assert.IsNotNull(args, nameof(args)); Console.WriteLine("Formatting JSON Files"); Console.WriteLine($"Translation Location: {args.TranslationPath}"); Console.WriteLine(); foreach (var filepath in Directory.EnumerateFiles(args.TranslationPath, "*.json", SearchOption.AllDirectories)) { var textitems = JsonTextItemFileIO.ReadFromFile(filepath); JsonTextItemFileIO.WriteToFile(textitems, filepath); } }
static void Run(IO.IFileSystem filesystem, Encoding encoding, String datapath) { Assert.IsNotNull(filesystem, nameof(filesystem)); Assert.IsNotNull(encoding, nameof(encoding)); Assert.IsValidString(datapath, nameof(datapath)); var data_text = Text.TextFileDescription.GetTextFileData_AoK(); var stringtableitems = JsonTextItemFileIO.ReadFromFile(Path.Combine(datapath, "stringtable.json")); foreach (var item in data_text) { var textfilepath = Path.Combine(@"data\text", item.FileName); var jsonfilepath = Path.ChangeExtension(Path.Combine(datapath, "text", item.FileName), ".json"); if (File.Exists(jsonfilepath) == true) { Console.WriteLine(item.FileName); using (var reader = filesystem.OpenFile(textfilepath, encoding)) { var buffer = UpdateTextFile(reader, item.FilePointerDelegate, item.RecordCount, jsonfilepath); filesystem.SaveFile(textfilepath, buffer); } } } foreach (var filepath in filesystem.GetChildren(@"data\battle\dat", "ms*.dat")) { var filename = Path.GetFileName(filepath); var jsonfilepath = Path.ChangeExtension(Path.Combine(datapath, "monster", filename), ".json"); if (File.Exists(jsonfilepath) == true) { Console.WriteLine(filename); using (var reader = filesystem.OpenFile(filepath, encoding)) { var buffer = UpdateMonsterFile(reader, jsonfilepath); filesystem.SaveFile(filepath, buffer); } } } UpdateMonsterNote(filesystem, encoding); }