CNR API Internal Rework (#488)

* Prep stuff

* Tweezers now spawn in

* Started converting tweezers

* I hate <1 beat intervals

* Actually nvm

* fixed a bug

* You can chain intervals now, stack them if you really wanted

* Pass turn checks if crhandlerinstance exists

* Fixed hairs being deleted by onion switch

* Rockers rerewritten

* working dough rerewritten
This commit is contained in:
Rapandrasmus
2023-06-28 06:51:53 +02:00
committed by minenice55
parent 91ff7fefb7
commit cefb8161b9
10 changed files with 531 additions and 523 deletions

View File

@ -76,13 +76,6 @@ namespace HeavenStudio.Games
public double intervalStartBeat = -1; // the first beat of the interval
public float intervalLength = -1; // the duration of the interval in beats
public float defaultIntervalLength; // when an event is queued and the interval has not started yet, it will use this as the interval length.
public CallAndResponseHandler(float defaultIntervalLength)
{
this.defaultIntervalLength = defaultIntervalLength;
}
public List<CallAndResponseEvent> queuedEvents = new List<CallAndResponseEvent>();
/// <summary>
@ -95,7 +88,7 @@ namespace HeavenStudio.Games
public float GetIntervalProgressFromBeat(double beat, float lengthOffset = 0)
{
return (float)((beat - intervalStartBeat) / ((intervalStartBeat + intervalLength - lengthOffset) - intervalStartBeat));
return (float)((beat - intervalStartBeat) / Mathf.Max(1, intervalLength - lengthOffset));
}
/// <summary>
@ -114,28 +107,20 @@ namespace HeavenStudio.Games
/// <param name="length">The length of the interval.</param>
public void StartInterval(double beat, float length)
{
if (!IntervalIsActive())
{
if (queuedEvents.Count > 0) queuedEvents.Clear();
}
if (queuedEvents.Count > 0) queuedEvents.Clear();
intervalStartBeat = beat;
intervalLength = length;
defaultIntervalLength = length;
}
/// <summary>
/// Adds an event to the queued events list.
/// </summary>
/// <param name="beat">The current beat.</param>
/// <param name="length">The length of the event.</param>>
/// <param name="tag">The tag of the event.</param>
/// <param name="crParams">Extra properties to add to the event.</param>
/// <param name="ignoreInterval">If true, this function will not start a new interval if the interval isn't active.</param>
/// <param name="overrideInterval">If true, overrides the current interval.</param>
public void AddEvent(double beat, float length = 0, string tag = "", List<CallAndResponseEventParam> crParams = null, bool ignoreInterval = false, bool overrideInterval = false)
public void AddEvent(double beat, float length = 0, string tag = "", List<CallAndResponseEventParam> crParams = null)
{
if ((!IntervalIsActive() && !ignoreInterval) || overrideInterval)
{
StartInterval(beat, defaultIntervalLength);
}
CallAndResponseEvent addedEvent = new CallAndResponseEvent(beat, beat - intervalStartBeat, tag, length);
CallAndResponseEvent addedEvent = new(beat, beat - intervalStartBeat, tag, length);
if (crParams != null && crParams.Count > 0)
{
foreach (var param in crParams)
@ -163,7 +148,7 @@ namespace HeavenStudio.Games
/// <summary>
/// Check if an event exists at relativeBeat.
/// </summary>
/// <param name="beat">The beat to check.</param>
/// <param name="relativeBeat">The relativeBeat to check.</param>
public bool EventExistsAtRelativetBeat(double relativeBeat)
{
if (queuedEvents.Count == 0)