Beispiel #1
0
        public void OnEvent(BeatmapEventData eventData)
        {
            if (eventData.type != eventTypeForThisEffect)
            {
                return;
            }

            CustomBeatmapEventData customEventData = eventData as CustomBeatmapEventData;

            float direction     = customEventData?.direction ?? (Random.value > 0.5f ? 1f : -1f);
            float speed         = customEventData?.rotationSpeed ?? eventData.value;
            bool  lockPosition  = customEventData?.rotationLockPosition ?? false;
            float?startPosition = customEventData?.rotationStartPosition;

            if (eventData.type != BeatmapEventType.Event12)
            {
                direction = -direction;
            }

            if (startPosition.HasValue)
            {
                transform.localRotation = startRotation;
                transform.Rotate(rotationVector, startPosition.Value, Space.Self);
            }

            if (eventData.value == 0)
            {
                enabled = false;

                if (!lockPosition && !startPosition.HasValue)
                {
                    transform.localRotation = startRotation;
                }
            }
            else if (eventData.value > 0)
            {
                enabled = true;

                if (!lockPosition && !startPosition.HasValue)
                {
                    transform.localRotation = startRotation;
                    transform.Rotate(rotationVector, Random.Range(0f, 180f), Space.Self);
                }

                rotationSpeed = speed * direction * 20f;
            }
        }
        public void OnEvent(BeatmapEventData eventData)
        {
            if (eventData.type != eventTypeForThisEffect)
            {
                return;
            }

            CustomBeatmapEventData customEventData = eventData as CustomBeatmapEventData;

            string nameFilter = customEventData?.ringsNameFilter;

            if (nameFilter != null && !nameFilter.Equals(name, StringComparison.OrdinalIgnoreCase))
            {
                return;
            }

            float direction   = -(customEventData?.direction ?? (Random.value > 0.5f ? 1f : -1f));
            bool  counterSpin = customEventData?.ringsCounterSpin ?? false;
            bool  reset       = customEventData?.ringsReset ?? false;

            if (counterSpin && isBig)
            {
                direction = -direction;
            }

            float step;

            switch (stepType)
            {
            case RotationStepType.Range0ToMax:
                step = Random.Range(0f, stepMax);
                break;

            case RotationStepType.Range:
                step = Random.Range(-stepMax, stepMax);
                break;

            case RotationStepType.MaxOr0:
                step = Random.value > 0.5f ? stepMax : 0f;
                break;

            default:
                step = 0f;
                break;
            }

            step = customEventData?.ringsStep ?? step;
            float propagationSpeed = customEventData?.ringsPropagationSpeed ?? this.propagationSpeed;
            float flexySpeed       = customEventData?.ringsFlexySpeed ?? this.flexySpeed;

            float?stepMultiplier             = customEventData?.ringsStepMultiplier;
            float?propagationSpeedMultiplier = customEventData?.ringsPropagationSpeedMultiplier;
            float?flexySpeedMultiplier       = customEventData?.ringsFlexySpeedMultiplier;

            if (stepMultiplier.HasValue)
            {
                step *= stepMultiplier.Value;
            }

            if (propagationSpeedMultiplier.HasValue)
            {
                propagationSpeed *= propagationSpeedMultiplier.Value;
            }

            if (flexySpeedMultiplier.HasValue)
            {
                flexySpeed *= flexySpeedMultiplier.Value;
            }

            if (reset)
            {
                step             = 0;
                propagationSpeed = 50;
                flexySpeed       = 50;
            }

            RotationEffect rotationEffect = new RotationEffect {
                progress         = 0,
                angle            = manager.Rings[0].GetDestinationRotation() + rotation * direction,
                step             = step,
                propagationSpeed = propagationSpeed,
                flexySpeed       = flexySpeed
            };

            activeRotationEffects.Add(rotationEffect);
        }
Beispiel #3
0
        public void OnEvent(BeatmapEventData eventData)
        {
            if (eventData.type == eventToggleRandomize)
            {
                randomizeValues = !randomizeValues;
            }

            int currentFrame = Time.frameCount;

            if (
                (eventData.type == eventL ||
                 eventData.type == eventR ||
                 eventData.type == eventToggleRandomize) &&
                currentFrame != lastValueGenerationFrame
                )
            {
                if (randomizeValues)
                {
                    startRotationGenerated = Random.Range(0f, 180f);
                    directionGenerated     = Random.value > 0.5f ? 1f : -1f;
                }
                else
                {
                    startRotationGenerated = eventData.type == eventL ? currentFrame : -currentFrame;

                    if (useZOffset)
                    {
                        startRotationGenerated += transform.position.z * zOffsetScale;
                    }

                    directionGenerated = eventData.type == eventL ? 1f : -1f;
                }

                lastValueGenerationFrame = currentFrame;
            }

            if (eventData.type == eventL || eventData.type == eventR)
            {
                CustomBeatmapEventData customEventData = eventData as CustomBeatmapEventData;

                float direction     = customEventData?.direction ?? directionGenerated;
                float speed         = customEventData?.rotationSpeed ?? eventData.value;
                bool  lockPosition  = customEventData?.rotationLockPosition ?? false;
                float?startPosition = customEventData?.rotationStartPosition;

                if (eventData.type != eventL)
                {
                    direction = -direction;
                }

                RotationData rotation = eventData.type == eventL ? rotationL : rotationR;

                if (startPosition.HasValue)
                {
                    rotation.rotationAngle = (eventData.type == eventL ? startPosition.Value : -startPosition.Value) + rotation.startRotationAngle;

                    rotation.transform.localRotation = rotation.startRotation * Quaternion.Euler(rotationVector * rotation.rotationAngle);
                }

                if (eventData.value == 0)
                {
                    rotation.enabled = false;

                    if (!lockPosition && !startPosition.HasValue)
                    {
                        rotation.transform.localRotation = rotation.startRotation * Quaternion.Euler(rotationVector * rotation.startRotationAngle);
                    }
                }
                else if (eventData.value > 0)
                {
                    rotation.enabled = true;

                    rotation.rotationSpeed = speed * direction * 20f;

                    if (!lockPosition && !startPosition.HasValue)
                    {
                        rotation.rotationAngle = (eventData.type == eventL ? startRotationGenerated : -startRotationGenerated) + rotation.startRotationAngle;

                        rotation.transform.localRotation = rotation.startRotation * Quaternion.Euler(rotationVector * rotation.rotationAngle);
                    }
                }
            }
            else if (eventData.type == eventToggleRandomize)
            {
                rotationL.rotationAngle = startRotationGenerated + rotationL.startRotationAngle;
                rotationL.rotationSpeed = Mathf.Abs(rotationL.rotationSpeed);
                rotationR.rotationAngle = -startRotationGenerated + rotationR.startRotationAngle;
                rotationR.rotationSpeed = -Mathf.Abs(rotationL.rotationSpeed);
            }

            enabled = rotationL.enabled || rotationR.enabled;
        }
Beispiel #4
0
        public static CustomLightshowData LoadLightshowDataFromJSON(JSONNode rootJSON, string name)
        {
            //just use the SimpleJSON library available in ChatCore

            if (!rootJSON.IsObject)
            {
                throw new InvalidJSONException("Root is not a JSON object");
            }

            float bpm = 120f;

            if (
                rootJSON.TryGetKey("_bpm", out JSONNode bpmJSON) &&
                bpmJSON is JSONNumber bpmJSONNumber &&
                bpmJSONNumber.AsFloat > 0f
                )
            {
                bpmJSON = bpmJSONNumber.AsFloat;
            }

            ColorPreset colorPreset = null;

            if (rootJSON.TryGetKey("colorPreset", out JSONNode colorPresetJSON))
            {
                if (colorPresetJSON is JSONString colorPresetJSONString)
                {
                    colorPreset = ColorPreset.GetColorPreset(colorPresetJSONString.Value);

                    if (colorPreset == null)
                    {
                        Logger.log.Warn("Couldn't find color preset for lightshow: " + name);
                    }
                }
                else
                {
                    try {
                        colorPreset = ColorPreset.LoadColorPresetFromJSON(colorPresetJSON);
                    } catch (InvalidJSONException e) {
                        Logger.log.Warn("Failed loading color preset for lightshow: " + name);
                        Logger.log.Warn("\tInvalid JSON data: " + e.errorMessage);
                    }
                }
            }

            bool eventsExists = rootJSON.TryGetKey("_events", out JSONNode eventsNodeJSON);

            if (!eventsExists || !eventsNodeJSON.IsArray)
            {
                throw new InvalidJSONException("No events JSON array found in root");
            }

            JSONArray eventsJSON = eventsNodeJSON.AsArray;

            List <BeatmapEventData> eventsList = new List <BeatmapEventData>();

            foreach (JSONNode eventJSON in eventsJSON)
            {
                bool timeExists  = eventJSON.TryGetKey("_time", out JSONNode timeJSON);
                bool typeExists  = eventJSON.TryGetKey("_type", out JSONNode typeJSON);
                bool valueExists = eventJSON.TryGetKey("_value", out JSONNode valueJSON);

                if (!timeExists || !typeExists || !valueExists)
                {
                    continue;
                }

                if (!timeJSON.IsNumber || !typeJSON.IsNumber || !valueJSON.IsNumber)
                {
                    continue;
                }

                float time  = timeJSON.AsFloat;
                int   type  = typeJSON.AsInt;
                int   value = valueJSON.AsInt;

                if (type < -1 || type > 15)
                {
                    continue;
                }

                if (
                    eventJSON.TryGetKey("_customData", out JSONNode customDataJSON) &&
                    customDataJSON is JSONObject customDataJSONObject
                    )
                {
                    Color?        color                           = null;
                    ColorGradient?colorGradient                   = null;
                    float?        direction                       = null;
                    float?        rotationSpeed                   = null;
                    bool?         rotationLockPosition            = null;
                    float?        rotationStartPosition           = null;
                    string        ringsNameFilter                 = null;
                    bool?         ringsCounterSpin                = null;
                    bool?         ringsReset                      = null;
                    float?        ringsStep                       = null;
                    float?        ringsPropagationSpeed           = null;
                    float?        ringsFlexySpeed                 = null;
                    float?        ringsStepMultiplier             = null;
                    float?        ringsPropagationSpeedMultiplier = null;
                    float?        ringsFlexySpeedMultiplier       = null;

                    if (
                        customDataJSONObject.TryGetKey("_color", out JSONNode colorJSON) &&
                        TryParseColor(colorJSON, out Color col)
                        )
                    {
                        color = col;
                    }

                    if (
                        customDataJSON.TryGetKey("_lightGradient", out JSONNode colorGradientJSON) &&
                        colorGradientJSON is JSONObject colorGradientJSONObject &&
                        colorGradientJSONObject.TryGetKey("_startColor", out JSONNode startColorJSON) &&
                        colorGradientJSONObject.TryGetKey("_endColor", out JSONNode endColorJSON) &&
                        colorGradientJSONObject.TryGetKey("_duration", out JSONNode durationJSON) &&
                        TryParseColor(startColorJSON, out Color startColor) &&
                        TryParseColor(endColorJSON, out Color endColor) &&
                        durationJSON is JSONNumber durationJSONNumber &&
                        durationJSONNumber.AsFloat > 0f
                        )
                    {
                        float currentBPM = bpm;

                        if (
                            colorGradientJSONObject.TryGetKey("_bpm", out JSONNode currentBPMJSON) &&
                            currentBPMJSON is JSONNumber currentBPMJSONNumber &&
                            currentBPMJSONNumber.AsFloat > 0f
                            )
                        {
                            currentBPM = currentBPMJSONNumber.AsFloat;
                        }

                        EasingFunction.Ease?easing = null;

                        if (
                            colorGradientJSONObject.TryGetKey("_easing", out JSONNode easingJSON) &&
                            easingJSON is JSONString easingJSONString &&
                            Enum.TryParse(easingJSONString.Value, out EasingFunction.Ease ease)
                            )
                        {
                            easing = ease;
                        }

                        colorGradient = new ColorGradient(
                            startColor,
                            endColor,
                            durationJSONNumber.AsFloat * 60f / currentBPM,
                            easing ?? EasingFunction.Ease.Linear
                            );
                    }

                    if (
                        customDataJSONObject.TryGetKey("_direction", out JSONNode directionJSON) &&
                        directionJSON is JSONNumber directionJSONNumber &&
                        (directionJSONNumber.AsInt == 0 || directionJSONNumber.AsInt == 1)
                        )
                    {
                        direction = directionJSONNumber.AsInt == 0 ? -1f : 1f;
                    }

                    if (
                        customDataJSONObject.TryGetKey("_preciseSpeed", out JSONNode rotationSpeedJSON) &&
                        rotationSpeedJSON is JSONNumber rotationSpeedJSONNumber
                        )
                    {
                        rotationSpeed = rotationSpeedJSONNumber.AsFloat;
                    }

                    if (
                        customDataJSONObject.TryGetKey("_lockPosition", out JSONNode rotationLockPositionJSON) &&
                        rotationLockPositionJSON is JSONBool rotationLockPositionJSONBool
                        )
                    {
                        rotationLockPosition = rotationLockPositionJSONBool.AsBool;
                    }

                    if (
                        customDataJSONObject.TryGetKey("_startPosition", out JSONNode rotationStartPositionJSON) &&
                        rotationStartPositionJSON is JSONNumber rotationStartPositionJSONNumber
                        )
                    {
                        rotationStartPosition = rotationStartPositionJSONNumber.AsFloat;
                    }

                    if (
                        customDataJSONObject.TryGetKey("_nameFilter", out JSONNode ringsNameFilterJSON) &&
                        ringsNameFilterJSON is JSONString ringsNameFilterJSONString
                        )
                    {
                        ringsNameFilter = ringsNameFilterJSONString.Value;
                    }

                    if (
                        customDataJSONObject.TryGetKey("_counterSpin", out JSONNode ringsCounterSpinJSON) &&
                        ringsCounterSpinJSON is JSONBool ringsCounterSpinJSONBool
                        )
                    {
                        ringsCounterSpin = ringsCounterSpinJSONBool.AsBool;
                    }

                    if (
                        customDataJSONObject.TryGetKey("_reset", out JSONNode ringsResetJSON) &&
                        ringsResetJSON is JSONBool ringsResetJSONBool
                        )
                    {
                        ringsReset = ringsResetJSONBool.AsBool;
                    }

                    if (
                        customDataJSONObject.TryGetKey("_step", out JSONNode ringsStepJSON) &&
                        ringsStepJSON is JSONNumber ringsStepJSONNumber
                        )
                    {
                        ringsStep = ringsStepJSONNumber.AsFloat;
                    }

                    if (
                        customDataJSONObject.TryGetKey("_prop", out JSONNode ringsPropagationSpeedJSON) &&
                        ringsPropagationSpeedJSON is JSONNumber ringsPropagationSpeedJSONNumber
                        )
                    {
                        ringsPropagationSpeed = ringsPropagationSpeedJSONNumber.AsFloat;
                    }

                    if (
                        customDataJSONObject.TryGetKey("_speed", out JSONNode ringsFlexySpeedJSON) &&
                        ringsFlexySpeedJSON is JSONNumber ringsFlexySpeedJSONNumber
                        )
                    {
                        ringsFlexySpeed = ringsFlexySpeedJSONNumber.AsFloat;
                    }

                    if (
                        customDataJSONObject.TryGetKey("_stepMult", out JSONNode ringsStepMultiplierJSON) &&
                        ringsStepMultiplierJSON is JSONNumber ringsStepMultiplierJSONNumber
                        )
                    {
                        ringsStepMultiplier = ringsStepMultiplierJSONNumber.AsFloat;
                    }

                    if (
                        customDataJSONObject.TryGetKey("_propMult", out JSONNode ringsPropagationSpeedMultiplierJSON) &&
                        ringsPropagationSpeedMultiplierJSON is JSONNumber ringsPropagationSpeedMultiplierJSONNumber
                        )
                    {
                        ringsPropagationSpeedMultiplier = ringsPropagationSpeedMultiplierJSONNumber.AsFloat;
                    }

                    if (
                        customDataJSONObject.TryGetKey("_speedMult", out JSONNode ringsFlexySpeedMultiplierJSON) &&
                        ringsFlexySpeedMultiplierJSON is JSONNumber ringsFlexySpeedMultiplierJSONNumber
                        )
                    {
                        ringsFlexySpeedMultiplier = ringsFlexySpeedMultiplierJSONNumber.AsFloat;
                    }

                    CustomBeatmapEventData customEventData = new CustomBeatmapEventData(
                        time,
                        (BeatmapEventType)type,
                        value,
                        color,
                        colorGradient,
                        direction,
                        rotationSpeed,
                        rotationLockPosition,
                        rotationStartPosition,
                        ringsNameFilter,
                        ringsCounterSpin,
                        ringsReset,
                        ringsStep,
                        ringsPropagationSpeed,
                        ringsFlexySpeed,
                        ringsStepMultiplier,
                        ringsPropagationSpeedMultiplier,
                        ringsFlexySpeedMultiplier
                        );

                    eventsList.Add(customEventData);

                    continue;
                }

                eventsList.Add(new BeatmapEventData(time, (BeatmapEventType)type, value));
            }

            if (eventsList.Count == 0)
            {
                throw new InvalidJSONException("No valid events found in events JSON array");
            }

            BeatmapEventData[] events = eventsList.OrderBy(beatmapEvent => beatmapEvent.time).ToArray();

            return(new CustomLightshowData(events, colorPreset));
        }