Thanks to visit codestin.com
Credit goes to github.com

Skip to content
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
13 changes: 13 additions & 0 deletions Heck/Animation/Events/CoroutineEventManager.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using CustomJSONData.CustomBeatmap;
using JetBrains.Annotations;
using UnityEngine;
Expand Down Expand Up @@ -41,6 +43,17 @@ internal void StartEventCoroutine(CustomEventData customEventData, EventType eve
return;
}

IEnumerable<Trigger> triggers = heckData.Triggers;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick but use triggers.Any(x => x.isTriggered) for more declarative syntax here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done, thanks!

if (triggers != null && !triggers.Any(x => x.isTriggered))
{
foreach (Trigger t in triggers)
{
t.isTriggered = false;
}

return;
}

float duration = 60f * heckData.Duration / _bpmController.currentBpm; // Convert to real time;
Functions easing = heckData.Easing;
int repeat = heckData.Repeat;
Expand Down
44 changes: 43 additions & 1 deletion Heck/Animation/Events/EventController.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
using System;
using System.Collections.Generic;
using System.Linq;
using CustomJSONData.CustomBeatmap;
using JetBrains.Annotations;
using UnityEngine;
using Zenject;
using static AlphabetScrollInfo;
using static Heck.HeckController;

namespace Heck.Animation.Events
Expand All @@ -11,20 +15,58 @@ internal class EventController : IDisposable
private readonly BeatmapCallbacksController _callbacksController;
private readonly LazyInject<CoroutineEventManager> _coroutineEventManager;
private readonly BeatmapDataCallbackWrapper _callbackWrapper;
private readonly BeatmapObjectManager _beatmapObjectManager;

[UsedImplicitly]
private EventController(
BeatmapCallbacksController callbacksController,
LazyInject<CoroutineEventManager> coroutineEventManager)
LazyInject<CoroutineEventManager> coroutineEventManager,
BeatmapObjectManager beatmapObjectManager)
{
_callbacksController = callbacksController;
_coroutineEventManager = coroutineEventManager;
_callbackWrapper = callbacksController.AddBeatmapCallback<CustomEventData>(HandleCallback);
_beatmapObjectManager = beatmapObjectManager;
_beatmapObjectManager.noteWasCutEvent += BeatmapObjectManager_noteWasCutEvent;
_beatmapObjectManager.noteWasMissedEvent += BeatmapObjectManager_noteWasMissedEvent;
}

private void BeatmapObjectManager_noteWasMissedEvent(NoteController noteController)
{
CustomNoteData noteData = (CustomNoteData)noteController._noteData;
IEnumerable<Trigger> triggers = Trigger.GetTriggers(noteData.customData, "triggerOnMiss");
if (triggers == null)
{
return;
}

foreach (Trigger trigger in triggers)
{
trigger.isTriggered = true;
}
}

private void BeatmapObjectManager_noteWasCutEvent(NoteController noteController, in NoteCutInfo _)
{
CustomNoteData noteData = (CustomNoteData)noteController._noteData;
IEnumerable<Trigger> triggers = Trigger.GetTriggers(noteData.customData, "triggerOnCut");
if (triggers == null)
{
return;
}

foreach (Trigger trigger in triggers)
{
trigger.isTriggered = true;
}
}

public void Dispose()
{
_callbacksController.RemoveBeatmapCallback(_callbackWrapper);
_beatmapObjectManager.noteWasCutEvent -= BeatmapObjectManager_noteWasCutEvent;
_beatmapObjectManager.noteWasMissedEvent -= BeatmapObjectManager_noteWasMissedEvent;
Trigger.triggers.Clear();
}

private void HandleCallback(CustomEventData customEventData)
Expand Down
58 changes: 58 additions & 0 deletions Heck/Animation/Trigger.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
using CustomJSONData.CustomBeatmap;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Heck.Animation
{
internal class Trigger
{
public static Dictionary<string, Trigger> triggers = new Dictionary<string, Trigger>();

public Trigger(string _name) {
name = _name;
}

public bool isTriggered = false;

public string name;

public static IEnumerable<Trigger> GetTriggers(CustomData data, string field)
{
object? triggerNameRaw = data.Get<object>(field);
if (triggerNameRaw == null)
{
return null;
}

IEnumerable<string> triggerNames;
if (triggerNameRaw is List<object> listTrack)
{
triggerNames = listTrack.Cast<string>();
}
else
{
triggerNames = new[] { (string)triggerNameRaw };
}

HashSet<Trigger> result = new();
foreach (string triggerName in triggerNames)
{
if (triggers.ContainsKey(triggerName))
{
result.Add(triggers[triggerName]);
}
else
{
Trigger trigger = new Trigger(triggerName);
result.Add(trigger);
triggers.Add(triggerName, trigger);
}
}

return result;
}
}
}
1 change: 1 addition & 0 deletions Heck/HeckController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public static class HeckController
public const string V2_LOCAL_POSITION = "_localPosition";
public const string V2_SCALE = "_scale";

public const string TRIGGER = "trigger";
public const string REPEAT = "repeat";
public const string DURATION = "duration";
public const string EASING = "easing";
Expand Down
5 changes: 4 additions & 1 deletion Heck/HeckImplementation/CustomDataTypes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ internal HeckCoroutineEventData(

IEnumerable<Track> tracks = data.GetTrackArray(beatmapTracks, v2);

string[] excludedStrings = { V2_TRACK, V2_DURATION, V2_EASING, TRACK, DURATION, EASING, REPEAT };
string[] excludedStrings = { V2_TRACK, V2_DURATION, V2_EASING, TRACK, DURATION, EASING, REPEAT, TRIGGER };
IEnumerable<string> propertyKeys = data.Keys.Where(n => excludedStrings.All(m => m != n)).ToList();
List<CoroutineInfo> coroutineInfos = new();
foreach (Track track in tracks)
Expand Down Expand Up @@ -97,6 +97,7 @@ void CreateInfo(BaseProperty property, IPropertyBuilder builder, string name, st
if (!v2)
{
Repeat = data.Get<int?>(REPEAT) ?? 0;
Triggers = Trigger.GetTriggers(data, TRIGGER);
}
}

Expand All @@ -106,6 +107,8 @@ void CreateInfo(BaseProperty property, IPropertyBuilder builder, string name, st

internal int Repeat { get; }

internal IEnumerable<Trigger> Triggers { get; }

internal List<CoroutineInfo> CoroutineInfos { get; }

internal readonly struct CoroutineInfo
Expand Down