public string SerializeSong(P9Song song, AppState appState) { var jsonSettings = new Newtonsoft.Json.JsonSerializerSettings(); jsonSettings.Formatting = Newtonsoft.Json.Formatting.Indented; jsonSettings.Converters.Add(new Newtonsoft.Json.Converters.StringEnumConverter()); jsonSettings.Converters.Add(new SingleLineFloatArrayConverter()); return(Newtonsoft.Json.JsonConvert.SerializeObject(song, jsonSettings)); //return JsonSerializer.Serialize(song, appState.JsonSerializerOptions); }
public void Parse(Milo2ProjectOptions op) { var appState = AppState.FromFile(op.InputPath); appState.UpdateSystemInfo(GetSystemInfo(op)); var inputMiloPath = Path.GetFullPath(op.InputPath); // Use abs path until AppState is updated var milo = appState.OpenMiloFile(inputMiloPath); // Create output directory var outputDir = Path.GetFullPath(op.OutputPath); if (!Directory.Exists(outputDir)) { Directory.CreateDirectory(outputDir); } var entries = GetEntries(milo); ExtractLipsync(entries, outputDir); var serializer = appState.GetSerializer(); var propAnims = entries .Where(x => x.Type == "PropAnim") .Select(y => serializer.ReadFromMiloObjectBytes <PropAnim>(y as MiloObjectBytes)) .ToList(); var songPref = entries .Where(x => x.Type == "P9SongPref") .Select(y => serializer.ReadFromMiloObjectBytes <P9SongPref>(y as MiloObjectBytes)) .FirstOrDefault(); if (songPref is null) { throw new UnsupportedMiloException("No P9SongPref entry was found"); } // Write song json var song = new P9Song() { Name = milo.Name, Preferences = ConvertFromP9SongPref(songPref), LyricConfigurations = Array.Empty <LyricConfig>() }; // Convert lyric config var lyricConfig = propAnims .FirstOrDefault(x => x.Name == "lyric_config.anim"); if (!(lyricConfig is null)) { song.LyricConfigurations = ConvertFromPropAnim(lyricConfig); } var songJson = SerializeSong(song, appState); var songJsonPath = Path.Combine(outputDir, "song.json"); File.WriteAllText(songJsonPath, songJson); Console.WriteLine($"Wrote \"song.json\""); // Export midi var songAnim = propAnims .First(x => x.Name == "song.anim"); var converter = new Anim2Midi(songAnim, op.BaseMidiPath); converter.ExportMidi(Path.Combine(outputDir, "venue.mid")); Console.WriteLine($"Wrote \"venue.mid\""); // Export whatever remaining files var remaining = entries .Where(x => x.Name != songAnim.Name && x.Type != "CharLipSync" && x.Type != "P9SongPref" && x.Name != "lyric_config.anim") .ToList(); var extraDirPath = Path.Combine(outputDir, "extra"); if (!Directory.Exists(extraDirPath)) { Directory.CreateDirectory(extraDirPath); } foreach (var entry in remaining) { var entryPath = Path.Combine(extraDirPath, entry.Name); var miloObj = entry as MiloObjectBytes; File.WriteAllBytes(entryPath, miloObj.Data); Console.WriteLine($"Extracted \"{miloObj.Name}\""); } Console.WriteLine($"Successfully created project in \"{outputDir}\""); }