Skip to content

Commit

Permalink
Merge pull request #40 from Auros/auros/sandrie
Browse files Browse the repository at this point in the history
Update for SiraUtil 3
  • Loading branch information
rithik-b authored Jan 5, 2022
2 parents 2750087 + a04cffe commit bbadd6a
Show file tree
Hide file tree
Showing 24 changed files with 237 additions and 293 deletions.
3 changes: 1 addition & 2 deletions CustomNotes/CustomNotes.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,7 @@
<Compile Include="Managers\MenuButtonManager.cs" />
<Compile Include="Managers\CustomNoteManager.cs" />
<Compile Include="Overrides\CustomNoteColorNoteVisuals.cs" />
<Compile Include="Providers\CustomBombNoteProvider.cs" />
<Compile Include="Providers\CustomGameNoteProvider.cs" />
<Compile Include="Protocol.cs" />
<Compile Include="Settings\UI\NoteDetailsViewController.cs" />
<Compile Include="Settings\UI\NoteModifierViewController.cs" />
<Compile Include="Settings\UI\NotePreviewViewController.cs" />
Expand Down
2 changes: 1 addition & 1 deletion CustomNotes/HarmonyPatches/CustomNotesPatches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ internal static void RemoveHarmonyPatches()
{
if (instance != null && IsPatched)
{
instance.UnpatchAll(InstanceId);
instance.UnpatchSelf();
IsPatched = false;
}
}
Expand Down
22 changes: 3 additions & 19 deletions CustomNotes/Installers/CustomNotesCoreInstaller.cs
Original file line number Diff line number Diff line change
@@ -1,29 +1,13 @@
using Zenject;
using SiraUtil.Interfaces;
using CustomNotes.Managers;
using CustomNotes.Providers;
using CustomNotes.Settings.Utilities;
using CustomNotes.Utilities;
using CustomNotes.Managers;
using Zenject;

namespace CustomNotes.Installers
{
internal class CustomNotesCoreInstaller : Installer<PluginConfig, CustomNotesCoreInstaller>
internal class CustomNotesCoreInstaller : Installer
{
private readonly PluginConfig _pluginConfig;

public CustomNotesCoreInstaller(PluginConfig pluginConfig)
{
_pluginConfig = pluginConfig;
LayerUtils.pluginConfig = pluginConfig;
}

public override void InstallBindings()
{
Container.BindInstance(_pluginConfig).AsSingle();
Container.BindInterfacesAndSelfTo<NoteAssetLoader>().AsSingle();

Container.Bind(typeof(IModelProvider), typeof(CustomGameNoteProvider)).To<CustomGameNoteProvider>().AsSingle();
Container.Bind(typeof(IModelProvider), typeof(CustomBombNoteProvider)).To<CustomBombNoteProvider>().AsSingle();
}
}
}
94 changes: 91 additions & 3 deletions CustomNotes/Installers/CustomNotesGameInstaller.cs
Original file line number Diff line number Diff line change
@@ -1,24 +1,112 @@
using Zenject;
using CustomNotes.Data;
using CustomNotes.Managers;
using CustomNotes.Overrides;
using CustomNotes.Settings.Utilities;
using CustomNotes.Utilities;
using SiraUtil.Extras;
using SiraUtil.Objects;
using SiraUtil.Objects.Beatmap;
using System.Reflection;
using UnityEngine;
using Zenject;

namespace CustomNotes.Installers
{
internal class CustomNotesGameInstaller : Installer
{
private readonly PluginConfig _pluginConfig;
private readonly NoteAssetLoader _noteAssetLoader;
private readonly GameplayCoreSceneSetupData _gameplayCoreSceneSetupData;

public CustomNotesGameInstaller(NoteAssetLoader noteAssetLoader)
private bool _shouldSetup;

private const int DECORATION_PRIORITY = 300;

public CustomNotesGameInstaller(PluginConfig pluginConfig, NoteAssetLoader noteAssetLoader, GameplayCoreSceneSetupData gameplayCoreSceneSetupData)
{
_pluginConfig = pluginConfig;
_noteAssetLoader = noteAssetLoader;
_gameplayCoreSceneSetupData = gameplayCoreSceneSetupData;
}

public override void InstallBindings()
{
if (_noteAssetLoader.SelectedNote != 0)
bool autoDisable = _pluginConfig.AutoDisable && (_gameplayCoreSceneSetupData.gameplayModifiers.ghostNotes || _gameplayCoreSceneSetupData.gameplayModifiers.disappearingArrows || _gameplayCoreSceneSetupData.gameplayModifiers.smallCubes || Utils.IsNoodleMap(_gameplayCoreSceneSetupData.difficultyBeatmap));
_shouldSetup = !autoDisable && (!(_gameplayCoreSceneSetupData.gameplayModifiers.ghostNotes || _gameplayCoreSceneSetupData.gameplayModifiers.disappearingArrows) || !Container.HasBinding<MultiplayerLevelSceneSetupData>());
if (_pluginConfig.Enabled && _noteAssetLoader.SelectedNote != 0 && _shouldSetup)
{
Container.BindInterfacesAndSelfTo<GameCameraManager>().AsSingle();
Container.Bind<IInitializable>().To<CustomNoteManager>().AsSingle();
CustomNote note = _noteAssetLoader.CustomNoteObjects[_noteAssetLoader.SelectedNote];

#region Note Setup

Container.RegisterRedecorator(new BasicNoteRegistration(DecorateNote, DECORATION_PRIORITY));
MaterialSwapper.GetMaterials();
MaterialSwapper.ReplaceMaterialsForGameObject(note.NoteLeft);
MaterialSwapper.ReplaceMaterialsForGameObject(note.NoteRight);
MaterialSwapper.ReplaceMaterialsForGameObject(note.NoteDotLeft);
MaterialSwapper.ReplaceMaterialsForGameObject(note.NoteDotRight);
Utils.AddMaterialPropertyBlockController(note.NoteLeft);
Utils.AddMaterialPropertyBlockController(note.NoteRight);
Utils.AddMaterialPropertyBlockController(note.NoteDotLeft);
Utils.AddMaterialPropertyBlockController(note.NoteDotRight);

Container.BindMemoryPool<SiraPrefabContainer, SiraPrefabContainer.Pool>().WithId(Protocol.LeftArrowPool).WithInitialSize(25).FromComponentInNewPrefab(NotePrefabContainer(note.NoteLeft));
Container.BindMemoryPool<SiraPrefabContainer, SiraPrefabContainer.Pool>().WithId(Protocol.RightArrowPool).WithInitialSize(25).FromComponentInNewPrefab(NotePrefabContainer(note.NoteRight));
if (note.NoteDotLeft != null)
Container.BindMemoryPool<SiraPrefabContainer, SiraPrefabContainer.Pool>().WithId(Protocol.LeftDotPool).WithInitialSize(10).FromComponentInNewPrefab(NotePrefabContainer(note.NoteDotLeft));
if (note.NoteDotRight != null)
Container.BindMemoryPool<SiraPrefabContainer, SiraPrefabContainer.Pool>().WithId(Protocol.RightDotPool).WithInitialSize(10).FromComponentInNewPrefab(NotePrefabContainer(note.NoteDotRight));

#endregion

#region Bomb Setup

if (note.NoteBomb != null)
{
MaterialSwapper.GetMaterials();
MaterialSwapper.ReplaceMaterialsForGameObject(note.NoteBomb);
Container.BindMemoryPool<SiraPrefabContainer, SiraPrefabContainer.Pool>().WithId(Protocol.BombPool).WithInitialSize(10).FromComponentInNewPrefab(NotePrefabContainer(note.NoteBomb));
Container.RegisterRedecorator(new BombNoteRegistration(DecorateBombs, DECORATION_PRIORITY));
}

#endregion
}
}

private GameNoteController DecorateNote(GameNoteController original)
{
if (!_shouldSetup)
return original;

original.gameObject.AddComponent<CustomNoteController>();

ColorNoteVisuals originalVisuals = original.GetComponent<ColorNoteVisuals>();

CustomNoteColorNoteVisuals customVisuals = original.gameObject.AddComponent<CustomNoteColorNoteVisuals>();
customVisuals.enabled = false;
foreach (FieldInfo info in originalVisuals.GetType().GetFields(BindingFlags.Public | BindingFlags.Instance | BindingFlags.NonPublic))
info.SetValue(customVisuals, info.GetValue(originalVisuals));
UnityEngine.Object.Destroy(originalVisuals);

return original;
}

public BombNoteController DecorateBombs(BombNoteController original)
{
if (!_shouldSetup)
return original;

original.gameObject.AddComponent<CustomBombController>();
return original;
}

private SiraPrefabContainer NotePrefabContainer(GameObject initialPrefab)
{
var prefab = new GameObject("CustomNotes" + initialPrefab.name).AddComponent<SiraPrefabContainer>();
prefab.Prefab = initialPrefab;
return prefab;
}
}
}
12 changes: 4 additions & 8 deletions CustomNotes/Installers/CustomNotesMenuInstaller.cs
Original file line number Diff line number Diff line change
@@ -1,25 +1,21 @@
using Zenject;
using SiraUtil;
using CustomNotes.Managers;
using CustomNotes.Managers;
using CustomNotes.Settings;
using CustomNotes.Settings.UI;
using Zenject;

namespace CustomNotes.Installers
{
internal class CustomNotesMenuInstaller : Installer
{
public override void InstallBindings()
{


Container.Bind<NotePreviewViewController>().FromNewComponentAsViewController().AsSingle();
Container.Bind<NoteDetailsViewController>().FromNewComponentAsViewController().AsSingle();
Container.Bind<NoteListViewController>().FromNewComponentAsViewController().AsSingle();
Container.BindInterfacesAndSelfTo<NoteModifierViewController>().AsSingle();
Container.Bind<NotesFlowCoordinator>().FromNewComponentOnNewGameObject().AsSingle();

Container.BindInterfacesTo<MenuButtonManager>().AsSingle();
Container.BindInterfacesAndSelfTo<NoteModifierViewController>().AsSingle();
Container.BindInterfacesTo<CustomNotesViewManager>().AsSingle();
Container.BindInterfacesTo<MenuButtonManager>().AsSingle();
}
}
}
10 changes: 6 additions & 4 deletions CustomNotes/Managers/CustomBombController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ internal class CustomBombController : MonoBehaviour, INoteControllerDidInitEvent
protected SiraPrefabContainer.Pool bombPool;

[Inject]
internal void Init(PluginConfig pluginConfig, NoteAssetLoader noteAssetLoader, [InjectOptional(Id = "cn.bomb")] SiraPrefabContainer.Pool bombContainerPool)
internal void Init(PluginConfig pluginConfig, NoteAssetLoader noteAssetLoader, [InjectOptional(Id = Protocol.BombPool)] SiraPrefabContainer.Pool bombContainerPool)
{
_pluginConfig = pluginConfig;

Expand All @@ -40,13 +40,13 @@ internal void Init(PluginConfig pluginConfig, NoteAssetLoader noteAssetLoader, [
_bombNoteController.noteWasMissedEvent.Add(this);
_bombNoteController.noteDidDissolveEvent.Add(this);
}

bombMesh = gameObject.transform.Find("Mesh");
MeshRenderer bm = GetComponentInChildren<MeshRenderer>();

if (_pluginConfig.HMDOnly || LayerUtils.HMDOverride)
{
if(bombPool == null)
if (bombPool == null)
{
// create fake bombs for Custom Notes without Custom Bombs
fakeFirstPersonBombMesh = Instantiate(bombMesh.gameObject);
Expand All @@ -58,7 +58,7 @@ internal void Init(PluginConfig pluginConfig, NoteAssetLoader noteAssetLoader, [
fakeFirstPersonBombMesh.transform.rotation = Quaternion.identity;
fakeFirstPersonBombMesh.layer = (int)LayerUtils.NoteLayer.FirstPerson;
}

}
else if (bombPool != null)
{
Expand All @@ -68,6 +68,7 @@ internal void Init(PluginConfig pluginConfig, NoteAssetLoader noteAssetLoader, [

private void DidFinish()
{
container.Prefab.SetActive(false);
container.transform.SetParent(null);
bombPool.Despawn(container);
}
Expand All @@ -90,6 +91,7 @@ private void ParentNote(GameObject fakeMesh)
private void SpawnThenParent(SiraPrefabContainer.Pool bombModelPool)
{
container = bombModelPool.Spawn();
container.Prefab.SetActive(true);
activeNote = container.Prefab;
bombPool = bombModelPool;
if (_pluginConfig.HMDOnly == true || LayerUtils.HMDOverride == true)
Expand Down
23 changes: 15 additions & 8 deletions CustomNotes/Managers/CustomNoteController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,19 @@ public class CustomNoteController : MonoBehaviour, IColorable, INoteControllerNo
private SiraPrefabContainer.Pool _leftArrowNotePool;
private SiraPrefabContainer.Pool _rightArrowNotePool;

public Color Color => _customNoteColorNoteVisuals != null ? _customNoteColorNoteVisuals.noteColor : Color.white;
public Color Color
{
get => _customNoteColorNoteVisuals != null ? _customNoteColorNoteVisuals.noteColor : Color.white;
set => SetColor(value);
}

[Inject]
internal void Init(PluginConfig pluginConfig,
NoteAssetLoader noteAssetLoader,
[Inject(Id = "cn.left.arrow")] SiraPrefabContainer.Pool leftArrowNotePool,
[Inject(Id = "cn.right.arrow")] SiraPrefabContainer.Pool rightArrowNotePool,
[InjectOptional(Id = "cn.left.dot")] SiraPrefabContainer.Pool leftDotNotePool,
[InjectOptional(Id = "cn.right.dot")] SiraPrefabContainer.Pool rightDotNotePool)
[Inject(Id = Protocol.LeftArrowPool)] SiraPrefabContainer.Pool leftArrowNotePool,
[Inject(Id = Protocol.RightArrowPool)] SiraPrefabContainer.Pool rightArrowNotePool,
[InjectOptional(Id = Protocol.LeftDotPool)] SiraPrefabContainer.Pool leftDotNotePool,
[InjectOptional(Id = Protocol.RightDotPool)] SiraPrefabContainer.Pool rightDotNotePool)
{
_pluginConfig = pluginConfig;
_leftArrowNotePool = leftArrowNotePool;
Expand All @@ -47,7 +51,8 @@ internal void Init(PluginConfig pluginConfig,
_customNote = noteAssetLoader.CustomNoteObjects[noteAssetLoader.SelectedNote];

_gameNoteController = GetComponent<GameNoteController>();
_customNoteColorNoteVisuals = gameObject.AddComponent<CustomNoteColorNoteVisuals>();
_customNoteColorNoteVisuals = gameObject.GetComponent<CustomNoteColorNoteVisuals>();
_customNoteColorNoteVisuals.enabled = true;

_gameNoteController.didInitEvent.Add(this);
_gameNoteController.noteWasCutEvent.Add(this);
Expand All @@ -65,7 +70,7 @@ internal void Init(PluginConfig pluginConfig,
}
else
{
noteMesh.gameObject.layer = (int) LayerUtils.NoteLayer.ThirdPerson;
noteMesh.gameObject.layer = (int)LayerUtils.NoteLayer.ThirdPerson;
}
}

Expand All @@ -79,6 +84,7 @@ public void HandleNoteControllerNoteWasMissed(NoteController nc)
case ColorType.ColorB:
if (container != null)
{
container.Prefab.SetActive(false);
activePool?.Despawn(container);
container = null;
}
Expand Down Expand Up @@ -108,6 +114,7 @@ private void ParentNote(GameObject fakeMesh)
private void SpawnThenParent(SiraPrefabContainer.Pool noteModelPool)
{
container = noteModelPool.Spawn();
container.Prefab.SetActive(true);
activeNote = container.Prefab;
activePool = noteModelPool;
if (_pluginConfig.HMDOnly == true || LayerUtils.HMDOverride == true)
Expand All @@ -134,7 +141,7 @@ private void Visuals_DidInit(ColorNoteVisuals visuals, NoteControllerBase noteCo
{
SetActiveThenColor(activeNote, (visuals as CustomNoteColorNoteVisuals).noteColor);
// Hide certain parts of the default note which is not required
if(_pluginConfig.HMDOnly == false && LayerUtils.HMDOverride == false)
if (_pluginConfig.HMDOnly == false && LayerUtils.HMDOverride == false)
{
_customNoteColorNoteVisuals.SetBaseGameVisualsLayer((int)LayerUtils.NoteLayer.Note);
if (_customNote.Descriptor.DisableBaseNoteArrows)
Expand Down
Loading

0 comments on commit bbadd6a

Please sign in to comment.