From a74bbfaee2730826766ed916d7a8a1f3d21b7d57 Mon Sep 17 00:00:00 2001 From: ivan tkachenko Date: Thu, 13 Nov 2025 03:26:03 +0200 Subject: [PATCH] Add JSON exporter to debug builds --- MuzikaGromche/Exporter.cs | 97 ++++++++++++++++++++++++++++++ MuzikaGromche/MuzikaGromche.csproj | 3 + MuzikaGromche/Plugin.cs | 1 + 3 files changed, 101 insertions(+) create mode 100644 MuzikaGromche/Exporter.cs diff --git a/MuzikaGromche/Exporter.cs b/MuzikaGromche/Exporter.cs new file mode 100644 index 0000000..6b4953d --- /dev/null +++ b/MuzikaGromche/Exporter.cs @@ -0,0 +1,97 @@ +using System.Collections.Generic; +using System.IO; +using System.Linq; +using Newtonsoft.Json; +using UnityEngine; + +namespace MuzikaGromche +{ +#if DEBUG + // Dumps list of tracks as a JSON on launch. + static class Exporter + { + public static void ExportTracksJSON(ISelectableTrack[] tracks) + { + // Same directory where save files are located: + // C:\Users\user\AppData\LocalLow\ZeekerssRBLX\Lethal Company\ + string directory = Application.persistentDataPath; + string fileName = "MuzikaGromcheTracks.json"; + string filePath = Path.Join(directory, fileName); + + var jsonObject = new Dictionary(); + var tracksList = new List(); + jsonObject["version"] = PluginInfo.PLUGIN_VERSION; + jsonObject["tracks"] = tracksList; + foreach (var (selectableTrack, audioTrack) in SelectTracks(tracks)) + { + tracksList.Add(SerializeTrack(selectableTrack, audioTrack)); + } + + using StreamWriter sw = new(filePath); + using JsonWriter writer = new JsonTextWriter(sw) + { + Formatting = Formatting.Indented, + }; + JsonSerializer serializer = new() + { + NullValueHandling = NullValueHandling.Include, + }; + serializer.Serialize(writer, jsonObject); + } + + private static IEnumerable<(ISelectableTrack selectableTrack, IAudioTrack audioTrack)> SelectTracks(ISelectableTrack[] tracks) + { + foreach (var selectableTrack in tracks) + { + foreach (var audioTrack in selectableTrack.GetTracks()) + { + yield return (selectableTrack, audioTrack); + } + } + } + + private static Dictionary SerializeTrack(ISelectableTrack selectableTrack, IAudioTrack audioTrack) + { + var obj = new Dictionary + { + ["Name"] = audioTrack.Name, // may be different from selectableTrack.Name, if selectable track is a group + ["IsExplicit"] = selectableTrack.IsExplicit, + ["Language"] = selectableTrack.Language.Full, + ["WindUpTimer"] = audioTrack.WindUpTimer, + ["Bpm"] = audioTrack.Bpm, + ["Beats"] = audioTrack.Beats, + ["LoopOffset"] = audioTrack.LoopOffset, + ["Ext"] = audioTrack.Ext, + ["FileDurationIntro"] = audioTrack.LoadedIntro.length, + ["FileDurationLoop"] = audioTrack.LoadedLoop.length, + ["FileNameIntro"] = audioTrack.FileNameIntro, + ["FileNameLoop"] = audioTrack.FileNameLoop, + ["BeatsOffset"] = audioTrack.BeatsOffset, + ["FadeOutBeat"] = audioTrack.FadeOutBeat, + ["FadeOutDuration"] = audioTrack.FadeOutDuration, + ["ColorTransitionIn"] = audioTrack.ColorTransitionIn, + ["ColorTransitionOut"] = audioTrack.ColorTransitionOut, + ["ColorTransitionEasing"] = audioTrack.ColorTransitionEasing.Name, + ["FlickerLightsTimeSeries"] = audioTrack.FlickerLightsTimeSeries, + ["Lyrics"] = SerializeTimeSeries(new TimeSeries(audioTrack.LyricsTimeSeries, audioTrack.LyricsLines)), + ["DrunknessLoopOffsetTimeSeries"] = SerializeTimeSeries(audioTrack.DrunknessLoopOffsetTimeSeries), + ["CondensationLoopOffsetTimeSeries"] = SerializeTimeSeries(audioTrack.CondensationLoopOffsetTimeSeries), + ["Palette"] = audioTrack.Palette.Colors.Select(SerializeColor).ToList(), + ["GameOverText"] = audioTrack.GameOverText, + }; + return obj; + } + + private static object SerializeTimeSeries(TimeSeries timeSeries) + { + return timeSeries.Beats.Zip(timeSeries.Values, (one, two) => new object?[] { one, two }).ToList(); + } + + private static string SerializeColor(Color color) + { + string colorHex = $"#{ColorUtility.ToHtmlStringRGB(color)}"; + return colorHex; + } + } +#endif +} diff --git a/MuzikaGromche/MuzikaGromche.csproj b/MuzikaGromche/MuzikaGromche.csproj index d77defa..503ed15 100644 --- a/MuzikaGromche/MuzikaGromche.csproj +++ b/MuzikaGromche/MuzikaGromche.csproj @@ -61,6 +61,9 @@ $(LethalCompanyDir)Lethal Company_Data\Managed\Unity.RenderPipelines.Core.Runtime.dll + + $(LethalCompanyDir)Lethal Company_Data\Managed\Newtonsoft.Json.dll + diff --git a/MuzikaGromche/Plugin.cs b/MuzikaGromche/Plugin.cs index 4aa3287..96db54d 100644 --- a/MuzikaGromche/Plugin.cs +++ b/MuzikaGromche/Plugin.cs @@ -936,6 +936,7 @@ namespace MuzikaGromche { track.Debug(); } + Exporter.ExportTracksJSON(Tracks); #endif Config = new Config(base.Config); DiscoBallManager.Load();