Add JSON exporter to debug builds
This commit is contained in:
parent
ad0a20cc7e
commit
a74bbfaee2
|
|
@ -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<string, object>();
|
||||||
|
var tracksList = new List<object>();
|
||||||
|
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<string, object?> SerializeTrack(ISelectableTrack selectableTrack, IAudioTrack audioTrack)
|
||||||
|
{
|
||||||
|
var obj = new Dictionary<string, object?>
|
||||||
|
{
|
||||||
|
["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<string>(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<T>(TimeSeries<T> 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
|
||||||
|
}
|
||||||
|
|
@ -61,6 +61,9 @@
|
||||||
<Reference Include="Unity.RenderPipelines.Core.Runtime" Publicize="true" Private="false">
|
<Reference Include="Unity.RenderPipelines.Core.Runtime" Publicize="true" Private="false">
|
||||||
<HintPath>$(LethalCompanyDir)Lethal Company_Data\Managed\Unity.RenderPipelines.Core.Runtime.dll</HintPath>
|
<HintPath>$(LethalCompanyDir)Lethal Company_Data\Managed\Unity.RenderPipelines.Core.Runtime.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
|
<Reference Include="Newtonsoft.Json" Publicize="false" Private="false">
|
||||||
|
<HintPath>$(LethalCompanyDir)Lethal Company_Data\Managed\Newtonsoft.Json.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup Condition="'$(TargetFramework.TrimEnd(`0123456789`))' == 'net'">
|
<ItemGroup Condition="'$(TargetFramework.TrimEnd(`0123456789`))' == 'net'">
|
||||||
|
|
|
||||||
|
|
@ -936,6 +936,7 @@ namespace MuzikaGromche
|
||||||
{
|
{
|
||||||
track.Debug();
|
track.Debug();
|
||||||
}
|
}
|
||||||
|
Exporter.ExportTracksJSON(Tracks);
|
||||||
#endif
|
#endif
|
||||||
Config = new Config(base.Config);
|
Config = new Config(base.Config);
|
||||||
DiscoBallManager.Load();
|
DiscoBallManager.Load();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue