public static void TryGetPointData(dynamic customData, string pointName, out PointDefinition pointData, Dictionary <string, PointDefinition> pointDefinitions)
        {
            dynamic pointString = Trees.at(customData, pointName);

            switch (pointString)
            {
            case null:
                pointData = null;
                break;

            case PointDefinition castedData:
                pointData = castedData;
                break;

            case string castedString:
                if (!pointDefinitions.TryGetValue(castedString, out pointData))
                {
                    NoodleLogger.Log($"Could not find point definition {castedString}!", IPA.Logging.Logger.Level.Error);
                    pointData = null;
                }

                break;

            default:
                pointData = PointDefinition.DynamicToPointData(pointString);
                if (pointData != null)
                {
                    ((IDictionary <string, object>)customData)[pointName] = pointData;
                }

                break;
            }
        }
Esempio n. 2
0
        internal static IEnumerator AnimateTrackCoroutine(PointDefinition points, Property property, float duration, float startTime, Functions easing)
        {
            while (true)
            {
                float elapsedTime = Instance.CustomEventCallbackController._audioTimeSource.songTime - startTime;
                float time        = Easings.Interpolate(Mathf.Min(elapsedTime / duration, 1f), easing);
                switch (property.PropertyType)
                {
                case PropertyType.Linear:
                    property.Value = points.InterpolateLinear(time);
                    break;

                case PropertyType.Vector3:
                    property.Value = points.Interpolate(time);
                    break;

                case PropertyType.Vector4:
                    property.Value = points.InterpolateVector4(time);
                    break;

                case PropertyType.Quaternion:
                    property.Value = points.InterpolateQuaternion(time);
                    break;
                }

                if (elapsedTime < duration)
                {
                    yield return(null);
                }
                else
                {
                    break;
                }
            }
        }
 internal void AddPoint(string pointDataName, PointDefinition pointData)
 {
     if (!PointData.TryGetValue(pointDataName, out _))
     {
         PointData.Add(pointDataName, pointData);
     }
     else
     {
         NoodleLogger.Log($"Duplicate point defintion name, {pointDataName} could not be registered!", IPA.Logging.Logger.Level.Error);
     }
 }
        internal static void StartEventCoroutine(CustomEventData customEventData, EventType eventType)
        {
            NoodleCoroutineEventData noodleData = (NoodleCoroutineEventData)NoodleEventDatas[customEventData];

            if (noodleData == null)
            {
                return;
            }

            float duration = noodleData.Duration;

            duration = 60f * duration / Instance.BeatmapObjectSpawnController.currentBpm; // Convert to real time;

            Functions easing = noodleData.Easing;

            foreach (NoodleCoroutineEventData.CoroutineInfo coroutineInfo in noodleData.CoroutineInfos)
            {
                Property        property  = coroutineInfo.Property;
                PointDefinition pointData = coroutineInfo.PointDefinition;

                if (property.Coroutine != null)
                {
                    Instance.StopCoroutine(property.Coroutine);
                }

                if (pointData == null)
                {
                    switch (eventType)
                    {
                    case EventType.AnimateTrack:
                        property.Value = null;
                        break;

                    case EventType.AssignPathAnimation:
                        ((PointDefinitionInterpolation)property.Value).Init(null);
                        break;
                    }
                }
                else
                {
                    switch (eventType)
                    {
                    case EventType.AnimateTrack:
                        property.Coroutine = Instance.StartCoroutine(AnimateTrack.AnimateTrackCoroutine(pointData, property, duration, customEventData.time, easing));
                        break;

                    case EventType.AssignPathAnimation:
                        ((PointDefinitionInterpolation)property.Value).Init(pointData);
                        property.Coroutine = Instance.StartCoroutine(AssignPathAnimation.AssignPathAnimationCoroutine(property, duration, customEventData.time, easing));
                        break;
                    }
                }
            }
        }
Esempio n. 5
0
        internal static void GetAllPointData(dynamic customData, out PointDefinition position, out PointDefinition rotation, out PointDefinition scale, out PointDefinition localRotation, out PointDefinition dissolve, out PointDefinition dissolveArrow, out PointDefinition cuttable)
        {
            Dictionary <string, PointDefinition> pointDefinitions = PointDefinitions;

            TryGetPointData(customData, POSITION, out position, pointDefinitions);
            TryGetPointData(customData, ROTATION, out rotation, pointDefinitions);
            TryGetPointData(customData, SCALE, out scale, pointDefinitions);
            TryGetPointData(customData, LOCALROTATION, out localRotation, pointDefinitions);
            TryGetPointData(customData, DISSOLVE, out dissolve, pointDefinitions);
            TryGetPointData(customData, DISSOLVEARROW, out dissolveArrow, pointDefinitions);
            TryGetPointData(customData, CUTTABLE, out cuttable, pointDefinitions);
        }
        internal static void GetDefinitePositionOffset(NoodleObjectData.AnimationObjectData animationObject, Track track, float time, out Vector3?definitePosition)
        {
            PointDefinition localDefinitePosition = animationObject.LocalDefinitePosition;

            Vector3?pathDefinitePosition = localDefinitePosition?.Interpolate(time) ?? TryGetVector3PathProperty(track, DEFINITEPOSITION, time);

            if (pathDefinitePosition.HasValue)
            {
                Vector3?pathPosition   = animationObject.LocalPosition?.Interpolate(time) ?? TryGetVector3PathProperty(track, POSITION, time);
                Vector3?positionOffset = SumVectorNullables((Vector3?)TryGetPropertyAsObject(track, POSITION), pathPosition);
                definitePosition = SumVectorNullables(positionOffset, pathDefinitePosition) * NoteLinesDistance;

                if (NoodleController.LeftHandedMode)
                {
                    MirrorVectorNullable(ref definitePosition);
                }
            }
            else
            {
                definitePosition = null;
            }
        }
        public static PointDefinition DynamicToPointData(dynamic dyn)
        {
            IEnumerable <List <object> > points = ((IEnumerable <object>)dyn)
                                                  ?.Cast <List <object> >();

            if (points == null)
            {
                return(null);
            }

            PointDefinition pointData = new PointDefinition();

            foreach (List <object> rawPoint in points)
            {
                int flagIndex   = -1;
                int cachedCount = rawPoint.Count;
                for (int i = cachedCount - 1; i > 0; i--)
                {
                    if (rawPoint[i] is string)
                    {
                        flagIndex = i;
                    }
                    else
                    {
                        break;
                    }
                }

                Functions     easing     = Functions.easeLinear;
                bool          spline     = false;
                List <object> copiedList = rawPoint.ToList();
                if (flagIndex != -1)
                {
                    List <string> flags = rawPoint.GetRange(flagIndex, cachedCount - flagIndex).Cast <string>().ToList();
                    copiedList.RemoveRange(flagIndex, cachedCount - flagIndex);

                    string easingString = flags.Where(n => n.StartsWith("ease")).FirstOrDefault();
                    if (easingString != null)
                    {
                        easing = (Functions)Enum.Parse(typeof(Functions), easingString);
                    }

                    // TODO: add more spicy splines
                    string splineString = flags.Where(n => n.StartsWith("spline")).FirstOrDefault();
                    if (splineString == "splineCatmullRom")
                    {
                        spline = true;
                    }
                }

                if (copiedList.Count() == 2)
                {
                    Vector2 vector = new Vector2(Convert.ToSingle(copiedList[0]), Convert.ToSingle(copiedList[1]));
                    pointData.LinearAdd(new PointData(vector, easing));
                }
                else if (copiedList.Count() == 4)
                {
                    Vector4 vector = new Vector4(Convert.ToSingle(copiedList[0]), Convert.ToSingle(copiedList[1]), Convert.ToSingle(copiedList[2]), Convert.ToSingle(copiedList[3]));
                    pointData.Add(new PointData(vector, easing, spline));
                }
                else
                {
                    Vector5 vector = new Vector5(Convert.ToSingle(copiedList[0]), Convert.ToSingle(copiedList[1]), Convert.ToSingle(copiedList[2]), Convert.ToSingle(copiedList[3]), Convert.ToSingle(copiedList[4]));
                    pointData.Add(new PointData(vector, easing));
                }
            }

            return(pointData);
        }
Esempio n. 8
0
 internal void Finish()
 {
     _previousPointData = null;
 }
Esempio n. 9
0
 internal void Init(PointDefinition newPointData)
 {
     Time = 0;
     _previousPointData = _basePointData ?? new PointDefinition();
     _basePointData     = newPointData;
 }