Skip to content

Commit

Permalink
componentsssss
Browse files Browse the repository at this point in the history
  • Loading branch information
Aeroluna committed Jun 20, 2022
1 parent 9cc88fe commit 8368e0a
Show file tree
Hide file tree
Showing 21 changed files with 543 additions and 164 deletions.
8 changes: 4 additions & 4 deletions Chroma/Animation/AnimationHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ internal static void OnTrackCreated(Track track)
track.AddPathProperty(COLOR, PropertyType.Vector4, V2_COLOR);

// For Fog Control
track.AddProperty(ATTENUATION, PropertyType.Linear, V2_ATTENUATION);
track.AddProperty(OFFSET, PropertyType.Linear, V2_OFFSET);
track.AddProperty(HEIGHT_FOG_STARTY, PropertyType.Linear, V2_HEIGHT_FOG_STARTY);
track.AddProperty(HEIGHT_FOG_HEIGHT, PropertyType.Linear, V2_HEIGHT_FOG_HEIGHT);
track.AddProperty(V2_ATTENUATION, PropertyType.Linear, V2_ATTENUATION);
track.AddProperty(V2_OFFSET, PropertyType.Linear, V2_OFFSET);
track.AddProperty(V2_HEIGHT_FOG_STARTY, PropertyType.Linear, V2_HEIGHT_FOG_STARTY);
track.AddProperty(V2_HEIGHT_FOG_HEIGHT, PropertyType.Linear, V2_HEIGHT_FOG_HEIGHT);
}
}
}
4 changes: 2 additions & 2 deletions Chroma/Animation/EventController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ internal class EventController : IDisposable
{
private readonly BeatmapCallbacksController _callbacksController;
private readonly DeserializedData _deserializedData;
private readonly LazyInject<ChromaFogController> _fogController;
private readonly LazyInject<FogAnimatorV2> _fogController;
private readonly BeatmapDataCallbackWrapper _callbackWrapper;

[UsedImplicitly]
internal EventController(
BeatmapCallbacksController callbacksController,
[Inject(Id = ID)] DeserializedData deserializedData,
LazyInject<ChromaFogController> fogController)
LazyInject<FogAnimatorV2> fogController)
{
_callbacksController = callbacksController;
_deserializedData = deserializedData;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@

namespace Chroma.Animation
{
[UsedImplicitly]
internal class ChromaFogController : ITickable, IDisposable
internal class FogAnimatorV2 : ITickable, IDisposable
{
private static readonly FieldAccessor<BloomFogSO, float>.Accessor _transitionAccessor = FieldAccessor<BloomFogSO, float>.GetAccessor("_transition");

Expand All @@ -19,7 +18,8 @@ internal class ChromaFogController : ITickable, IDisposable
private readonly BloomFogEnvironmentParams _transitionFogParams;
private Track? _track;

private ChromaFogController(BloomFogSO bloomFog)
[UsedImplicitly]
private FogAnimatorV2(BloomFogSO bloomFog)
{
_bloomFog = bloomFog;

Expand All @@ -45,25 +45,25 @@ public void Tick()
return;
}

float? attenuation = _track.GetProperty<float?>(ATTENUATION);
float? attenuation = _track.GetProperty<float?>(V2_ATTENUATION);
if (attenuation.HasValue)
{
_transitionFogParams.attenuation = attenuation.Value;
}

float? offset = _track.GetProperty<float?>(OFFSET);
float? offset = _track.GetProperty<float?>(V2_OFFSET);
if (offset.HasValue)
{
_transitionFogParams.offset = offset.Value;
}

float? startY = _track.GetProperty<float?>(HEIGHT_FOG_STARTY);
float? startY = _track.GetProperty<float?>(V2_HEIGHT_FOG_STARTY);
if (startY.HasValue)
{
_transitionFogParams.heightFogStartY = startY.Value;
}

float? height = _track.GetProperty<float?>(HEIGHT_FOG_HEIGHT);
float? height = _track.GetProperty<float?>(V2_HEIGHT_FOG_HEIGHT);
if (height.HasValue)
{
_transitionFogParams.heightFogHeight = height.Value;
Expand Down
8 changes: 1 addition & 7 deletions Chroma/ChromaController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,19 +58,13 @@ internal static class ChromaController
internal const string ENVIRONMENT = "environment";
internal const string GEOMETRY = "geometry";
internal const string GEOMETRY_TYPE = "type";
internal const string SHADER_PRESET = "shaderPreset";
internal const string SHADER_PRESET = "shader";
internal const string SHADER_KEYWORDS = "shaderKeywords";
internal const string COLLISION = "collision";
internal const string GAMEOBJECT_ID = "id";
internal const string LOOKUP_METHOD = "lookupMethod";
internal const string DUPLICATION_AMOUNT = "duplicate";
internal const string ACTIVE = "active";

internal const string ATTENUATION = "attenuation";
internal const string OFFSET = "offset";
internal const string HEIGHT_FOG_STARTY = "startY";
internal const string HEIGHT_FOG_HEIGHT = "height";

internal const string ASSIGN_FOG_TRACK = "AssignFogTrack";

internal const string CAPABILITY = "Chroma";
Expand Down
56 changes: 56 additions & 0 deletions Chroma/EnvironmentEnhancement/Component/BloomFogCustomizer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
using System.Collections.Generic;
using System.Linq;
using CustomJSONData.CustomBeatmap;
using IPA.Utilities;
using static Chroma.EnvironmentEnhancement.Component.ComponentConstants;

namespace Chroma.EnvironmentEnhancement.Component
{
internal static class BloomFogCustomizer
{
private static readonly FieldAccessor<BloomFogEnvironment, BloomFogEnvironmentParams>.Accessor _fogParamsAccessor = FieldAccessor<BloomFogEnvironment, BloomFogEnvironmentParams>.GetAccessor("_fogParams");

internal static void BloomFogEnvironmentInit(List<UnityEngine.Component> allComponents, CustomData customData)
{
BloomFogEnvironment[] bloomFogEnvironments = allComponents
.OfType<BloomFogEnvironment>()
.ToArray();
if (bloomFogEnvironments.Length == 0)
{
Log.Logger.Log($"No [{BLOOM_FOG_ENVIRONMENT}] component found.");
return;
}

float? attenuation = customData.Get<float?>(ATTENUATION);
float? offset = customData.Get<float?>(OFFSET);
float? heightFogStartY = customData.Get<float?>(HEIGHT_FOG_STARTY);
float? heightFogHeight = customData.Get<float?>(HEIGHT_FOG_HEIGHT);

foreach (BloomFogEnvironment bloomFogEnvironment in bloomFogEnvironments)
{
BloomFogEnvironment fuckref = bloomFogEnvironment;
BloomFogEnvironmentParams fogParams = _fogParamsAccessor(ref fuckref);

if (attenuation.HasValue)
{
fogParams.attenuation = attenuation.Value;
}

if (offset.HasValue)
{
fogParams.offset = offset.Value;
}

if (heightFogStartY.HasValue)
{
fogParams.heightFogStartY = heightFogStartY.Value;
}

if (heightFogHeight.HasValue)
{
fogParams.heightFogHeight = heightFogHeight.Value;
}
}
}
}
}
21 changes: 21 additions & 0 deletions Chroma/EnvironmentEnhancement/Component/ComponentConstants.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
namespace Chroma.EnvironmentEnhancement.Component
{
internal static class ComponentConstants
{
internal const string COMPONENTS = "components";

internal const string LIGHT_WITH_ID = "ILightWithId";
internal const string LIGHT_ID = "lightID";
internal const string LIGHT_TYPE = "type";

internal const string BLOOM_FOG_ENVIRONMENT = "BloomFogEnvironment";
internal const string ATTENUATION = "attenuation";
internal const string OFFSET = "offset";
internal const string HEIGHT_FOG_STARTY = "startY";
internal const string HEIGHT_FOG_HEIGHT = "height";

internal const string TUBE_BLOOM_PRE_PASS_LIGHT = "TubeBloomPrePassLight";
internal const string COLOR_ALPHA_MULTIPLIER = "colorAlphaMultiplier";
internal const string BLOOM_FOG_INTENSITY_MULTIPLIER = "bloomFogIntensityMultiplier";
}
}
54 changes: 54 additions & 0 deletions Chroma/EnvironmentEnhancement/Component/ComponentCustomizer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
using System.Collections.Generic;
using CustomJSONData.CustomBeatmap;
using JetBrains.Annotations;
using UnityEngine;
using static Chroma.EnvironmentEnhancement.Component.ComponentConstants;

namespace Chroma.EnvironmentEnhancement.Component
{
internal class ComponentCustomizer
{
private readonly ILightWithIdCustomizer _lightWithIdCustomizer;

[UsedImplicitly]
private ComponentCustomizer(
ILightWithIdCustomizer _lightWithIdCustomizer)
{
this._lightWithIdCustomizer = _lightWithIdCustomizer;
}

internal static void GetAllComponents(List<UnityEngine.Component> components, Transform root)
{
components.AddRange(root.GetComponents<UnityEngine.Component>());

foreach (Transform transform in root)
{
GetAllComponents(components, transform);
}
}

internal void Customize(Transform gameObject, CustomData customData)
{
List<UnityEngine.Component> allComponents = new();
GetAllComponents(allComponents, gameObject);

CustomData? lightWithID = customData.Get<CustomData>(LIGHT_WITH_ID);
if (lightWithID != null)
{
_lightWithIdCustomizer.ILightWithIdInit(allComponents, lightWithID);
}

CustomData? bloomFogEnvironment = customData.Get<CustomData>(BLOOM_FOG_ENVIRONMENT);
if (bloomFogEnvironment != null)
{
BloomFogCustomizer.BloomFogEnvironmentInit(allComponents, bloomFogEnvironment);
}

CustomData? tubeBloomPrePassLight = customData.Get<CustomData>(TUBE_BLOOM_PRE_PASS_LIGHT);
if (tubeBloomPrePassLight != null)
{
TubeBloomLightCustomizer.TubeBloomPrePassLightInit(allComponents, tubeBloomPrePassLight);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Chroma.EnvironmentEnhancement
namespace Chroma.EnvironmentEnhancement.Component
{
internal interface IComponentData
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Chroma.HarmonyPatches.Colorizer.Initialize;
using Chroma.HarmonyPatches.EnvironmentComponent;
using Chroma.Settings;
using HarmonyLib;
Expand All @@ -11,10 +10,10 @@
using UnityEngine;
using Object = UnityEngine.Object;

namespace Chroma.EnvironmentEnhancement
namespace Chroma.EnvironmentEnhancement.Component
{
[UsedImplicitly]
internal class ComponentInitializer
internal class DuplicateInitializer
{
private static readonly FieldAccessor<LightWithIdMonoBehaviour, LightWithIdManager>.Accessor _lightWithIdMonoBehaviourManagerAccessor = FieldAccessor<LightWithIdMonoBehaviour, LightWithIdManager>.GetAccessor("_lightManager");
private static readonly FieldAccessor<LightWithIds, LightWithIdManager>.Accessor _lightWithIdsManagerAccessor = FieldAccessor<LightWithIds, LightWithIdManager>.GetAccessor("_lightManager");
Expand All @@ -32,23 +31,19 @@ internal class ComponentInitializer
private static readonly FieldAccessor<TrackLaneRingsPositionStepEffectSpawner, TrackLaneRingsManager>.Accessor _stepSpawnerRingsManagerAccessor = FieldAccessor<TrackLaneRingsPositionStepEffectSpawner, TrackLaneRingsManager>.GetAccessor("_trackLaneRingsManager");
private static readonly FieldAccessor<TrackLaneRingsRotationEffectSpawner, TrackLaneRingsRotationEffect>.Accessor _trackLaneRingsRotationEffectAccessor = FieldAccessor<TrackLaneRingsRotationEffectSpawner, TrackLaneRingsRotationEffect>.GetAccessor("_trackLaneRingsRotationEffect");
private static readonly FieldAccessor<TrackLaneRingsRotationEffectSpawner, BeatmapCallbacksController>.Accessor _rotationEffectSpawnerCallbackControllerAccessor = FieldAccessor<TrackLaneRingsRotationEffectSpawner, BeatmapCallbacksController>.GetAccessor("_beatmapCallbacksController");
private static readonly FieldAccessor<LightWithIds, IEnumerable<LightWithIds.LightWithId>>.Accessor _lightWithIdsAccessor = FieldAccessor<LightWithIds, IEnumerable<LightWithIds.LightWithId>>.GetAccessor("_lightWithIds");

private static readonly FieldAccessor<TrackLaneRing, Transform>.Accessor _ringTransformAccessor = FieldAccessor<TrackLaneRing, Transform>.GetAccessor("_transform");
private static readonly FieldAccessor<TrackLaneRing, Vector3>.Accessor _positionOffsetAccessor = FieldAccessor<TrackLaneRing, Vector3>.GetAccessor("_positionOffset");
private static readonly FieldAccessor<TrackLaneRing, float>.Accessor _posZAccessor = FieldAccessor<TrackLaneRing, float>.GetAccessor("_posZ");

private readonly TrackLaneRingOffset _trackLaneRingOffset;
private readonly LightWithIdRegisterer _lightWithIdRegisterer;

private readonly HashSet<TrackLaneRingsManager> _trackLaneRingsManagers;

private ComponentInitializer(
TrackLaneRingOffset trackLaneRingOffset,
LightWithIdRegisterer lightWithIdRegisterer)
private DuplicateInitializer(
TrackLaneRingOffset trackLaneRingOffset)
{
_trackLaneRingOffset = trackLaneRingOffset;
_lightWithIdRegisterer = lightWithIdRegisterer;
_trackLaneRingsManagers = Resources.FindObjectsOfTypeAll<TrackLaneRingsManager>().ToHashSet();
}

Expand Down Expand Up @@ -104,7 +99,7 @@ internal void PostfillComponentsData(Transform root, Transform original, List<IC
internal void InitializeComponents(Transform root, Transform original, List<GameObjectInfo> gameObjectInfos, List<IComponentData> componentDatas, int? lightID)
{
void GetComponentAndOriginal<T>(Action<T, T> initializeDelegate)
where T : Component
where T : UnityEngine.Component
{
T[] rootComponents = root.GetComponents<T>();
T[] originalComponents = original.GetComponents<T>();
Expand All @@ -129,26 +124,11 @@ void GetComponentAndOriginal<T>(Action<T, T> initializeDelegate)
GetComponentAndOriginal<LightWithIdMonoBehaviour>((rootComponent, originalComponent) =>
{
_lightWithIdMonoBehaviourManagerAccessor(ref rootComponent) = _lightWithIdMonoBehaviourManagerAccessor(ref originalComponent);
_lightWithIdRegisterer.MarkForTableRegister(rootComponent);
if (lightID.HasValue)
{
_lightWithIdRegisterer.SetRequestedId(rootComponent, lightID.Value);
}
});

GetComponentAndOriginal<LightWithIds>((rootComponent, originalComponent) =>
{
_lightWithIdsManagerAccessor(ref rootComponent) = _lightWithIdsManagerAccessor(ref originalComponent);
IEnumerable<ILightWithId> lightsWithId = _lightWithIdsAccessor(ref rootComponent);
foreach (ILightWithId light in lightsWithId)
{
if (lightID.HasValue)
{
_lightWithIdRegisterer.SetRequestedId(light, lightID.Value);
}
_lightWithIdRegisterer.MarkForTableRegister(light);
}
});

GetComponentAndOriginal<TrackLaneRing>((rootComponent, originalComponent) =>
Expand Down
Loading

0 comments on commit 8368e0a

Please sign in to comment.