Skip to content

Commit

Permalink
Environment JSON dump
Browse files Browse the repository at this point in the history
  • Loading branch information
Fernthedev committed Feb 8, 2022
1 parent 1967771 commit f89b584
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -32,6 +34,8 @@ internal static class EnvironmentEnhancementManager

private static List<GameObjectInfo> _gameObjectInfos = new();

private static string EnvironmentName = string.Empty;

internal static Dictionary<TrackLaneRing, Quaternion> RingRotationOffsets { get; private set; } = new();

internal static Dictionary<BeatmapObjectsAvoidance, Vector3> AvoidancePosition { get; private set; } = new();
Expand Down Expand Up @@ -309,10 +313,14 @@ private static void GetAllGameObjects()

List<string> objectsToPrint = new();

Dictionary<string, GameObjectJSON> 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
Expand All @@ -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<Transform> children)
Expand All @@ -340,5 +364,10 @@ private static void GetChildRecursive(Transform gameObject, ref List<Transform>
GetChildRecursive(child, ref children);
}
}

internal static void SetEnvironment(string environmentName)
{
EnvironmentName = environmentName;
}
}
}
53 changes: 53 additions & 0 deletions Chroma/Lighting/EnvironmentEnhancement/EnvironmentJSONDump.cs
Original file line number Diff line number Diff line change
@@ -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);
}
}
}

0 comments on commit f89b584

Please # to comment.