Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Environment JSON dump #22

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

6 changes: 5 additions & 1 deletion Chroma/HeckImplementation/ModuleCallbacks.cs
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 @@ -37,7 +38,10 @@ private static bool ConditionFeatures(
Log.Logger.Log("Please do not use Legacy Chroma Lights for new maps as it is deprecated and its functionality in future versions of Chroma cannot be guaranteed", Logger.Level.Warning);
}

LightIDTableManager.SetEnvironment(difficultyBeatmap.GetEnvironmentInfo().serializedName);
string? environmentName = difficultyBeatmap.GetEnvironmentInfo().serializedName;
LightIDTableManager.SetEnvironment(environmentName);
EnvironmentEnhancementManager.SetEnvironment(environmentName);


return (chromaRequirement || legacyOverride) && !ChromaConfig.Instance.ChromaEventsDisabled;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text.RegularExpressions;
Expand All @@ -10,6 +11,7 @@
using Heck.Animation;
using IPA.Utilities;
using JetBrains.Annotations;
using Newtonsoft.Json;
using UnityEngine;
using UnityEngine.SceneManagement;
using Zenject;
Expand Down Expand Up @@ -72,6 +74,8 @@ private EnvironmentEnhancementManager(
spawnController.StartCoroutine(DelayedStart());
}

private static string EnvironmentName = string.Empty;

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

internal Dictionary<BeatmapObjectsAvoidance, Vector3> AvoidancePosition { get; } = new();
Expand Down Expand Up @@ -440,10 +444,14 @@ private 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 @@ -461,6 +469,27 @@ private 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);
}

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);
}
}
}