From f89b5840caee133b8c4723ba3e65371f8c7758f6 Mon Sep 17 00:00:00 2001 From: FernTheDev <15272073+Fernthedev@users.noreply.github.com> Date: Tue, 8 Feb 2022 18:00:35 -0400 Subject: [PATCH] Environment JSON dump --- .../ScenesTransition/SceneTransitionHelper.cs | 6 ++- .../EnvironmentEnhancementManager.cs | 31 ++++++++++- .../EnvironmentJSONDump.cs | 53 +++++++++++++++++++ 3 files changed, 88 insertions(+), 2 deletions(-) create mode 100644 Chroma/Lighting/EnvironmentEnhancement/EnvironmentJSONDump.cs diff --git a/Chroma/HarmonyPatches/ScenesTransition/SceneTransitionHelper.cs b/Chroma/HarmonyPatches/ScenesTransition/SceneTransitionHelper.cs index 059542c7..048679b4 100644 --- a/Chroma/HarmonyPatches/ScenesTransition/SceneTransitionHelper.cs +++ b/Chroma/HarmonyPatches/ScenesTransition/SceneTransitionHelper.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Linq; using Chroma.Lighting; +using Chroma.Lighting.EnvironmentEnhancement; using Chroma.Settings; using CustomJSONData; using CustomJSONData.CustomBeatmap; @@ -62,7 +63,10 @@ private static bool BasicPatch(IDifficultyBeatmap difficultyBeatmap, CustomBeatm ToggleChromaPatches((chromaRequirement || legacyOverride) && !ChromaConfig.Instance.ChromaEventsDisabled); DoColorizerSabers = chromaRequirement && !ChromaConfig.Instance.ChromaEventsDisabled; - LightIDTableManager.SetEnvironment(difficultyBeatmap.GetEnvironmentInfo().serializedName); + // I cannot be bothered to do this properly + string environmentName = difficultyBeatmap.GetEnvironmentInfo().serializedName; + LightIDTableManager.SetEnvironment(environmentName); + EnvironmentEnhancementManager.SetEnvironment(environmentName); return chromaRequirement; } diff --git a/Chroma/Lighting/EnvironmentEnhancement/EnvironmentEnhancementManager.cs b/Chroma/Lighting/EnvironmentEnhancement/EnvironmentEnhancementManager.cs index af63cacf..c2a996f8 100644 --- a/Chroma/Lighting/EnvironmentEnhancement/EnvironmentEnhancementManager.cs +++ b/Chroma/Lighting/EnvironmentEnhancement/EnvironmentEnhancementManager.cs @@ -1,11 +1,13 @@ using System; using System.Collections.Generic; +using System.IO; using System.Linq; using System.Runtime.InteropServices; using Chroma.Settings; using CustomJSONData; using CustomJSONData.CustomBeatmap; using IPA.Utilities; +using Newtonsoft.Json; using UnityEngine; using UnityEngine.SceneManagement; using static Chroma.ChromaController; @@ -32,6 +34,8 @@ internal static class EnvironmentEnhancementManager private static List _gameObjectInfos = new(); + private static string EnvironmentName = string.Empty; + internal static Dictionary RingRotationOffsets { get; private set; } = new(); internal static Dictionary AvoidancePosition { get; private set; } = new(); @@ -309,10 +313,14 @@ private static void GetAllGameObjects() List objectsToPrint = new(); + Dictionary objectMap = new(); + foreach (GameObject gameObject in gameObjects) { GameObjectInfo gameObjectInfo = new(gameObject); - _gameObjectInfos.Add(new GameObjectInfo(gameObject)); + _gameObjectInfos.Add(gameObjectInfo); + objectMap[gameObjectInfo.FullID] = new GameObjectJSON(gameObject); + objectsToPrint.Add(gameObjectInfo.FullID); // seriously what the fuck beat games @@ -330,6 +338,22 @@ private static void GetAllGameObjects() objectsToPrint.Sort(); objectsToPrint.ForEach(n => Log.Logger.Log(n)); + + string fileDumpPath = $@"UserData\Chroma\{EnvironmentName}.json"; + + if (!File.Exists(fileDumpPath)) + { + Directory.CreateDirectory(Path.GetDirectoryName(fileDumpPath) ?? throw new InvalidOperationException()); + } + + Log.Logger.Log($"Writing to {fileDumpPath}", Logger.Level.Info); + + string str = JsonConvert.SerializeObject(objectMap); + + using FileStream file = new(fileDumpPath, FileMode.Create, FileAccess.Write); + using StreamWriter stream = new(file); + + stream.WriteLine(str); } private static void GetChildRecursive(Transform gameObject, ref List children) @@ -340,5 +364,10 @@ private static void GetChildRecursive(Transform gameObject, ref List GetChildRecursive(child, ref children); } } + + internal static void SetEnvironment(string environmentName) + { + EnvironmentName = environmentName; + } } } diff --git a/Chroma/Lighting/EnvironmentEnhancement/EnvironmentJSONDump.cs b/Chroma/Lighting/EnvironmentEnhancement/EnvironmentJSONDump.cs new file mode 100644 index 00000000..9c4c5489 --- /dev/null +++ b/Chroma/Lighting/EnvironmentEnhancement/EnvironmentJSONDump.cs @@ -0,0 +1,53 @@ +using UnityEngine; + +namespace Chroma.Lighting.EnvironmentEnhancement +{ + struct Vector3Json + { + public float x; + public float y; + public float z; + + public Vector3Json(Vector3 vector3) + { + x = vector3.x; + y = vector3.y; + z = vector3.z; + } + } + + struct QuaternionJson + { + public float x; + public float y; + public float z; + public float w; + + public QuaternionJson(Quaternion quaternion) + { + x = quaternion.x; + y = quaternion.y; + z = quaternion.z; + w = quaternion.w; + } + } + + struct GameObjectJSON + { + public readonly Vector3Json position; + public readonly Vector3Json localPosition; + public readonly QuaternionJson rotation; + public readonly QuaternionJson localRotation; + public readonly Vector3Json localScale; + + public GameObjectJSON(GameObject gameObject) + { + Transform transform = gameObject.transform; + localPosition = new Vector3Json(transform.localPosition); + position = new Vector3Json(transform.position); + rotation = new QuaternionJson(transform.rotation); + localRotation = new QuaternionJson(transform.localRotation); + localScale = new Vector3Json(transform.localScale); + } + } +}