Exemplo n.º 1
0
        internal static void DeserializeBeatmapData(IReadonlyBeatmapData beatmapData)
        {
            _chromaEventDatas = new Dictionary <BeatmapEventData, ChromaEventData>();
            foreach (BeatmapEventData beatmapEventData in beatmapData.beatmapEventsData)
            {
                try
                {
                    if (beatmapEventData is CustomBeatmapEventData customBeatmapEventData)
                    {
                        Dictionary <string, object?> customData = customBeatmapEventData.customData;
                        ChromaEventData chromaEventData         = new ChromaEventData(
                            customData.Get <object>(LIGHTID),
                            customData.Get <object>(PROPAGATIONID),
                            ChromaUtils.GetColorFromData(customData),
                            customData.Get <bool?>(LOCKPOSITION).GetValueOrDefault(false),
                            customData.Get <string>(NAMEFILTER),
                            customData.Get <int?>(DIRECTION),
                            customData.Get <bool?>(COUNTERSPIN),
                            customData.Get <bool?>(RESET),
                            customData.Get <float?>(STEP),
                            customData.Get <float?>(PROP),
                            customData.Get <float?>(SPEED) ?? customData.Get <float?>(PRECISESPEED),
                            customData.Get <float?>(ROTATION),
                            customData.Get <float?>(STEPMULT).GetValueOrDefault(1f),
                            customData.Get <float?>(PROPMULT).GetValueOrDefault(1f),
                            customData.Get <float?>(SPEEDMULT).GetValueOrDefault(1f));

                        Dictionary <string, object?>?gradientObject = customData.Get <Dictionary <string, object?> >(LIGHTGRADIENT);
                        if (gradientObject != null)
                        {
                            string?   easingstring = gradientObject.Get <string>(EASING);
                            Functions easing;
                            if (string.IsNullOrEmpty(easingstring))
                            {
                                easing = Functions.easeLinear;
                            }
                            else
                            {
                                easing = (Functions)Enum.Parse(typeof(Functions), easingstring);
                            }

                            chromaEventData.GradientObject = new ChromaEventData.GradientObjectData(
                                gradientObject.Get <float>(DURATION),
                                ChromaUtils.GetColorFromData(gradientObject, STARTCOLOR) ?? Color.white,
                                ChromaUtils.GetColorFromData(gradientObject, ENDCOLOR) ?? Color.white,
                                easing);
                        }

                        _chromaEventDatas.Add(beatmapEventData, chromaEventData);
                    }
                }
                catch (Exception e)
                {
                    Plugin.Logger.Log($"Could not create ChromaEventData for event {beatmapEventData.type} at {beatmapEventData.time}", IPA.Logging.Logger.Level.Error);
                    Plugin.Logger.Log(e, IPA.Logging.Logger.Level.Error);
                }
            }
        }
Exemplo n.º 2
0
        internal static void DeserializeBeatmapData(IReadonlyBeatmapData beatmapData)
        {
            ChromaObjectDatas = new Dictionary <BeatmapObjectData, ChromaObjectData>();
            if (NoodleExtensionsInstalled)
            {
                ChromaNoodleDatas = new Dictionary <BeatmapObjectData, ChromaNoodleData>();
            }

            foreach (BeatmapObjectData beatmapObjectData in beatmapData.beatmapObjectsData)
            {
                ChromaObjectData chromaObjectData;
                dynamic          customData;

                switch (beatmapObjectData)
                {
                case CustomNoteData customNoteData:
                    customData       = customNoteData.customData;
                    chromaObjectData = new ChromaNoteData()
                    {
                        Color = ChromaUtils.GetColorFromData(customData),
                        DisableSpawnEffect = Trees.at(customData, DISABLESPAWNEFFECT),
                    };
                    break;

                case CustomObstacleData customObstacleData:
                    customData       = customObstacleData.customData;
                    chromaObjectData = new ChromaObjectData()
                    {
                        Color = ChromaUtils.GetColorFromData(customData),
                    };
                    break;

                case CustomWaypointData customWaypointData:
                    customData       = customWaypointData.customData;
                    chromaObjectData = new ChromaObjectData();
                    break;

                default:
                    continue;
                }

                if (NoodleExtensionsInstalled)
                {
                    ApplyNoodleData(customData, beatmapObjectData, beatmapData);
                }

                ChromaObjectDatas.Add(beatmapObjectData, chromaObjectData);
            }
        }
Exemplo n.º 3
0
        private static void Prefix(ObstacleController __instance, ObstacleData obstacleData)
        {
            if (obstacleData is CustomObstacleData customData)
            {
                dynamic dynData = customData.customData;

                Color?color = ChromaUtils.GetColorFromData(dynData);

                if (color.HasValue)
                {
                    __instance.SetObstacleColor(color.Value);
                }
                else
                {
                    __instance.Reset();
                }
            }
        }
Exemplo n.º 4
0
#pragma warning disable SA1313 // Parameter names should begin with lower-case letter
        private static void Prefix(ObstacleController __instance, ObstacleData obstacleData)
#pragma warning restore SA1313 // Parameter names should begin with lower-case letter
        {
            if (obstacleData is CustomObstacleData customData)
            {
                dynamic dynData = customData.customData;

                Color?color = ChromaUtils.GetColorFromData(dynData);

                if (color.HasValue)
                {
                    __instance.SetObstacleColor(color.Value);
                }
                else
                {
                    __instance.Reset();
                }
            }
        }
Exemplo n.º 5
0
        private static void Prefix(NoteController noteController)
        {
            if (noteController.noteData is CustomNoteData customData)
            {
                dynamic dynData = customData.customData;

                Color?color = ChromaUtils.GetColorFromData(dynData);

                if (color.HasValue)
                {
                    noteController.SetNoteColors(color.Value, color.Value);
                    dynData.color0 = color.Value;
                    dynData.color1 = color.Value;
                }
                else
                {
                    noteController.Reset();
                }
            }
        }
Exemplo n.º 6
0
        private static void Prefix(BombNoteController __instance, NoteData noteData)
        {
            // They said it couldn't be done, they called me a madman
            Color?color = null;

            if (noteData is CustomNoteData customData)
            {
                dynamic dynData = customData.customData;

                color = ChromaUtils.GetColorFromData(dynData) ?? color;
            }

            if (color.HasValue)
            {
                __instance.SetBombColor(color);
            }
            else
            {
                __instance.Reset();
            }
        }
Exemplo n.º 7
0
#pragma warning disable SA1313 // Parameter names should begin with lower-case letter
        private static void Prefix(BombNoteController __instance, NoteData noteData)
#pragma warning restore SA1313 // Parameter names should begin with lower-case letter
        {
            // They said it couldn't be done, they called me a madman
            Color?color = null;

            if (noteData is CustomNoteData customData)
            {
                dynamic dynData = customData.customData;

                color = ChromaUtils.GetColorFromData(dynData) ?? color;
            }

            if (color.HasValue)
            {
                __instance.SetBombColor(color);
            }
            else
            {
                __instance.Reset();
            }
        }
Exemplo n.º 8
0
        internal static Color AddGradient(dynamic gradientObject, BeatmapEventType id, float time)
        {
            CancelGradient(id);

            float     duration     = (float)Trees.at(gradientObject, DURATION);
            Color     initcolor    = ChromaUtils.GetColorFromData(gradientObject, STARTCOLOR);
            Color     endcolor     = ChromaUtils.GetColorFromData(gradientObject, ENDCOLOR);
            string    easingstring = (string)Trees.at(gradientObject, EASING);
            Functions easing;

            if (string.IsNullOrEmpty(easingstring))
            {
                easing = Functions.easeLinear;
            }
            else
            {
                easing = (Functions)Enum.Parse(typeof(Functions), easingstring);
            }

            ChromaGradientEvent gradientEvent = new ChromaGradientEvent(initcolor, endcolor, time, duration, id, easing);

            Instance.Gradients[id] = gradientEvent;
            return(gradientEvent.Interpolate());
        }
Exemplo n.º 9
0
#pragma warning disable SA1313 // Parameter names should begin with lower-case letter
        internal static void ColorLightSwitch(MonoBehaviour monobehaviour, BeatmapEventData beatmapEventData)
#pragma warning restore SA1313 // Parameter names should begin with lower-case letter
        {
            monobehaviour.SetLastValue(beatmapEventData.value);

            Color?color = null;

            // legacy was a mistake
            color = LegacyLightHelper.GetLegacyColor(beatmapEventData) ?? color;

            if (beatmapEventData is CustomBeatmapEventData customData)
            {
                dynamic dynData = customData.customData;
                if (monobehaviour is LightSwitchEventEffect lightSwitchEventEffect)
                {
                    object lightID = Trees.at(dynData, LIGHTID);
                    if (lightID != null)
                    {
                        ILightWithId[] lights     = lightSwitchEventEffect.GetLights();
                        int            lightCount = lights.Length;
                        switch (lightID)
                        {
                        case List <object> lightIDobjects:
                            int[] lightIDArray = lightIDobjects.Select(n => System.Convert.ToInt32(n)).ToArray();
                            List <ILightWithId> overrideLights = new List <ILightWithId>();
                            for (int i = 0; i < lightIDArray.Length; i++)
                            {
                                if (lightCount > lightIDArray[i])
                                {
                                    overrideLights.Add(lights[lightIDArray[i]]);
                                }
                            }

                            SetOverrideLightWithIds(overrideLights.ToArray());

                            break;

                        case long lightIDint:
                            if (lightCount > lightIDint)
                            {
                                SetOverrideLightWithIds(lights[lightIDint]);
                            }

                            break;
                        }
                    }

                    object propID = Trees.at(dynData, PROPAGATIONID);
                    if (propID != null)
                    {
                        ILightWithId[][] lights = lightSwitchEventEffect.GetLightsPropagationGrouped();
                        int lightCount          = lights.Length;
                        switch (propID)
                        {
                        case List <object> propIDobjects:
                            int[] propIDArray = propIDobjects.Select(n => System.Convert.ToInt32(n)).ToArray();
                            List <ILightWithId> overrideLights = new List <ILightWithId>();
                            for (int i = 0; i < propIDArray.Length; i++)
                            {
                                if (lightCount > propIDArray[i])
                                {
                                    overrideLights.AddRange(lights[propIDArray[i]]);
                                }
                            }

                            SetOverrideLightWithIds(overrideLights.ToArray());

                            break;

                        case long propIDlong:
                            if (lightCount > propIDlong)
                            {
                                SetOverrideLightWithIds(lights[propIDlong]);
                            }

                            break;
                        }
                    }

                    dynamic gradientObject = Trees.at(dynData, LIGHTGRADIENT);
                    if (gradientObject != null)
                    {
                        color = ChromaGradientController.AddGradient(gradientObject, beatmapEventData.type, beatmapEventData.time);
                    }
                }

                Color?colorData = ChromaUtils.GetColorFromData(dynData);
                if (colorData.HasValue)
                {
                    color = colorData;
                    ChromaGradientController.CancelGradient(beatmapEventData.type);
                }
            }

            if (color.HasValue)
            {
                monobehaviour.SetLightingColors(color.Value, color.Value, color.Value, color.Value);
            }
            else if (!ChromaGradientController.IsGradientActive(beatmapEventData.type))
            {
                monobehaviour.Reset();
            }
        }
Exemplo n.º 10
0
        internal static void DeserializeBeatmapData(IReadonlyBeatmapData beatmapData)
        {
            ChromaEventDatas = new Dictionary <BeatmapEventData, ChromaEventData>();
            foreach (BeatmapEventData beatmapEventData in beatmapData.beatmapEventsData)
            {
                if (beatmapEventData is CustomBeatmapEventData customBeatmapEventData)
                {
                    ChromaEventData chromaEventData;
                    dynamic         customData = customBeatmapEventData.customData;

                    switch ((int)beatmapEventData.type)
                    {
                    case 0:
                    case 1:
                    case 2:
                    case 3:
                    case 4:
                        ChromaLightEventData chromaLightEventData = new ChromaLightEventData()
                        {
                            LightID   = Trees.at(customData, LIGHTID),
                            PropID    = Trees.at(customData, PROPAGATIONID),
                            ColorData = ChromaUtils.GetColorFromData(customData),
                        };

                        dynamic gradientObject = Trees.at(customData, LIGHTGRADIENT);
                        if (gradientObject != null)
                        {
                            string    easingstring = (string)Trees.at(gradientObject, EASING);
                            Functions easing;
                            if (string.IsNullOrEmpty(easingstring))
                            {
                                easing = Functions.easeLinear;
                            }
                            else
                            {
                                easing = (Functions)Enum.Parse(typeof(Functions), easingstring);
                            }

                            chromaLightEventData.GradientObject = new ChromaLightEventData.GradientObjectData()
                            {
                                Duration   = (float)Trees.at(gradientObject, DURATION),
                                StartColor = ChromaUtils.GetColorFromData(gradientObject, STARTCOLOR),
                                EndColor   = ChromaUtils.GetColorFromData(gradientObject, ENDCOLOR),
                                Easing     = easing,
                            };
                        }

                        chromaEventData = chromaLightEventData;

                        break;

                    case 8:
                    case 9:
                        chromaEventData = new ChromaRingRotationEventData()
                        {
                            NameFilter  = Trees.at(customData, NAMEFILTER),
                            Direction   = (int?)Trees.at(customData, DIRECTION),
                            CounterSpin = Trees.at(customData, COUNTERSPIN),
                            Reset       = Trees.at(customData, RESET),
                            Step        = (float?)Trees.at(customData, STEP),
                            Prop        = (float?)Trees.at(customData, PROP),
                            Speed       = (float?)Trees.at(customData, SPEED),
                            Rotation    = (float?)Trees.at(customData, ROTATION),
                            StepMult    = ((float?)Trees.at(customData, STEPMULT)).GetValueOrDefault(1f),
                            PropMult    = ((float?)Trees.at(customData, PROPMULT)).GetValueOrDefault(1f),
                            SpeedMult   = ((float?)Trees.at(customData, SPEEDMULT)).GetValueOrDefault(1f),
                        };
                        break;

                    case 12:
                    case 13:
                        chromaEventData = new ChromaLaserSpeedEventData()
                        {
                            LockPosition = ((bool?)Trees.at(customData, LOCKPOSITION)).GetValueOrDefault(false),
                            PreciseSpeed = ((float?)Trees.at(customData, PRECISESPEED)).GetValueOrDefault(beatmapEventData.value),
                            Direction    = ((int?)Trees.at(customData, DIRECTION)).GetValueOrDefault(-1),
                        };
                        break;

                    default:
                        continue;
                    }

                    ChromaEventDatas.Add(beatmapEventData, chromaEventData);
                }
            }
        }
Exemplo n.º 11
0
        internal static void ColorLightSwitch(MonoBehaviour monobehaviour, BeatmapEventData beatmapEventData)
        {
            monobehaviour.SetLastValue(beatmapEventData.value);

            Color?color = null;
            bool  gradi = false;

            // legacy was a mistake
            color = LegacyLightHelper.GetLegacyColor(beatmapEventData) ?? color;

            if (beatmapEventData is CustomBeatmapEventData customData)
            {
                dynamic dynData = customData.customData;
                if (monobehaviour is LightSwitchEventEffect lightSwitchEventEffect)
                {
                    object lightID = Trees.at(dynData, LIGHTID);
                    if (lightID != null)
                    {
                        switch (lightID)
                        {
                        case List <object> lightIDobjects:
                            LightIDOverride = lightIDobjects.Select(n => System.Convert.ToInt32(n)).ToList();

                            break;

                        case long lightIDint:
                            LightIDOverride = new List <int> {
                                (int)lightIDint
                            };

                            break;
                        }
                    }

                    // propID is now DEPRECATED!!!!!!!!
                    object propID = Trees.at(dynData, PROPAGATIONID);
                    if (propID != null)
                    {
                        ILightWithId[][] lights = lightSwitchEventEffect.GetLightsPropagationGrouped();
                        int lightCount          = lights.Length;
                        switch (propID)
                        {
                        case List <object> propIDobjects:
                            int[] propIDArray = propIDobjects.Select(n => System.Convert.ToInt32(n)).ToArray();
                            List <ILightWithId> overrideLights = new List <ILightWithId>();
                            for (int i = 0; i < propIDArray.Length; i++)
                            {
                                if (lightCount > propIDArray[i])
                                {
                                    overrideLights.AddRange(lights[propIDArray[i]]);
                                }
                            }

                            SetLegacyPropIdOverride(overrideLights.ToArray());

                            break;

                        case long propIDlong:
                            if (lightCount > propIDlong)
                            {
                                SetLegacyPropIdOverride(lights[propIDlong]);
                            }

                            break;
                        }
                    }

                    dynamic gradientObject = Trees.at(dynData, LIGHTGRADIENT);
                    if (gradientObject != null)
                    {
                        color = ChromaGradientController.AddGradient(gradientObject, beatmapEventData.type, beatmapEventData.time);
                        if (Settings.ChromaConfig.Instance.HueEnabled == true)
                        {
                            HueManager.ProcessEvent(beatmapEventData, null, gradientObject);
                        }
                        gradi = true;
                    }
                }

                Color?colorData = ChromaUtils.GetColorFromData(dynData);
                if (colorData.HasValue)
                {
                    color = colorData;
                    ChromaGradientController.CancelGradient(beatmapEventData.type);
                    gradi = false;
                }
            }

            if (color.HasValue)
            {
                monobehaviour.SetLightingColors(color.Value, color.Value, color.Value, color.Value);
            }
            else if (!ChromaGradientController.IsGradientActive(beatmapEventData.type))
            {
                monobehaviour.Reset();
            }
            if (Settings.ChromaConfig.Instance.HueEnabled == true && gradi == false)
            {
                HueManager.ProcessEvent(beatmapEventData, color);
            }
        }