예제 #1
0
    protected override void OnClickPreviewButton()
    {
        ChromaSDKAnimation1D animation = GetAnimation();

        EditorUtility.SetDirty(animation);
        var frames = animation.Frames; //copy

        Unload();

        if (ChromaConnectionManager.Instance.Connected)
        {
            if (_mCurrentFrame >= 0 &&
                _mCurrentFrame < frames.Count)
            {
                ChromaDevice1DEnum device = animation.Device;
                EffectArray1dInput colors = frames[_mCurrentFrame];
                EffectResponseId   effect = ChromaUtils.CreateEffectCustom1D(device, colors);
                if (null != effect &&
                    effect.Result == 0)
                {
                    ChromaUtils.SetEffect(effect.Id);
                    ChromaUtils.RemoveEffect(effect.Id);
                }
            }
        }
    }
    private void OnClickFillRow(int row)
    {
        ChromaSDKAnimation2D animation = GetAnimation();

        EditorUtility.SetDirty(animation);
        var frames = animation.Frames; //copy

        Unload();

        if (_mCurrentFrame >= 0 &&
            _mCurrentFrame < frames.Count)
        {
            ChromaDevice2DEnum device = animation.Device;
            int maxRow    = ChromaUtils.GetMaxRow(device);
            int maxColumn = ChromaUtils.GetMaxColumn(device);
            var rows      = frames[_mCurrentFrame];
            if (row < rows.Count && row < maxRow)
            {
                var colors = rows[row];
                for (int j = 0; j < maxColumn; ++j)
                {
                    colors[j] = ChromaUtils.ToBGR(_mColor);
                }
            }
            frames[_mCurrentFrame] = rows;
        }
        animation.Frames = frames;
    }
예제 #3
0
        public void OnEnable()
        {
            _harmonyInstanceCore.PatchAll(Assembly.GetExecutingAssembly());

            GameplaySetup.instance.AddTab("Chroma", "Chroma.Settings.modifiers.bsml", ChromaSettingsUI.instance);
            if (ChromaConfig.Instance.LightshowMenu)
            {
                GameplaySetup.instance.AddTab("Lightshow Modifiers", "Chroma.Settings.lightshow.bsml", ChromaSettingsUI.instance);
            }

            ChromaUtils.SetSongCoreCapability(REQUIREMENTNAME, ChromaConfig.Instance.CustomColorEventsEnabled);

            SceneManager.activeSceneChanged += ChromaController.OnActiveSceneChanged;

            // Legacy support
            ChromaUtils.SetSongCoreCapability("Chroma Lighting Events");

            if (ChromaUtils.IsModInstalled("NoodleExtensions"))
            {
                AnimationHelper.SubscribeColorEvents();
                NoodleExtensionsInstalled = true;
            }
            else
            {
                NoodleExtensionsInstalled = false;
            }
        }
    private void OnClickDarkenButton()
    {
        ChromaSDKAnimation2D animation = GetAnimation();

        EditorUtility.SetDirty(animation);
        var frames = animation.Frames; //copy

        Unload();

        if (_mCurrentFrame >= 0 &&
            _mCurrentFrame < frames.Count)
        {
            ChromaDevice2DEnum device = animation.Device;
            int maxRow    = ChromaUtils.GetMaxRow(device);
            int maxColumn = ChromaUtils.GetMaxColumn(device);
            var frame     = frames[_mCurrentFrame];
            for (int i = 0; i < maxRow; ++i)
            {
                var row = frame[i];
                for (int j = 0; j < maxColumn; ++j)
                {
                    Color color = ChromaUtils.ToRGB(row[j]);
                    color.r *= 0.75f;
                    color.g *= 0.75f;
                    color.b *= 0.75f;
                    row[j]   = ChromaUtils.ToBGR(color);
                }
            }
        }
        animation.Frames = frames;
    }
    /// <summary>
    /// Load the effects before playing
    /// </summary>
    public void Load()
    {
        //Debug.Log("Load:");

        if (_mIsLoaded)
        {
            //Debug.LogError("Animation has already been loaded!");
            return;
        }

        if (ChromaConnectionManager.Instance.Connected)
        {
            //Debug.Log(string.Format("Create {0} Frames.", Frames.Count));
            for (int i = 0; i < Frames.Count; ++i)
            {
                EffectArray2dInput frame = Frames[i];
                //Debug.Log("Create Effect.");
                EffectResponseId effect = ChromaUtils.CreateEffectCustom2D(Device, frame);

                /*
                 * // app can check the effect list for null or non-zero result
                 * if (null == effect ||
                 *  effect.Result != 0)
                 * {
                 *  Debug.LogError("Failed to create effect!");
                 * }
                 */
                _mEffects.Add(effect);
            }

            _mIsLoaded = true;
        }
    }
    private void OnClickShiftButton(int y, int x)
    {
        ChromaSDKAnimation2D animation = GetAnimation();

        EditorUtility.SetDirty(animation);
        var frames = animation.Frames; //copy

        Unload();

        if (_mCurrentFrame >= 0 &&
            _mCurrentFrame < frames.Count)
        {
            ChromaDevice2DEnum device = animation.Device;
            int maxRow    = ChromaUtils.GetMaxRow(device);
            int maxColumn = ChromaUtils.GetMaxColumn(device);
            int offsetX   = maxColumn - x;
            int offsetY   = maxRow - y;
            var oldFrame  = frames[_mCurrentFrame];
            var newFrame  = ChromaUtils.CreateColors2D(device);
            for (int i = 0; i < maxRow; ++i)
            {
                var oldRow = oldFrame[(i + offsetY) % maxRow];
                var newRow = newFrame[i];
                for (int j = 0; j < maxColumn; ++j)
                {
                    int color = oldRow[(j + offsetX) % maxColumn];
                    newRow[j] = color;
                }
            }
            frames[_mCurrentFrame] = newFrame;
        }
        animation.Frames = frames;
    }
    private void OnClickPasteButton()
    {
        ChromaSDKAnimation2D animation = GetAnimation();

        EditorUtility.SetDirty(animation);
        var frames = animation.Frames; //copy

        Unload();

        if (_mCurrentFrame >= 0 &&
            _mCurrentFrame < frames.Count)
        {
            ChromaDevice2DEnum device = animation.Device;
            int maxRow    = ChromaUtils.GetMaxRow(device);
            int maxColumn = ChromaUtils.GetMaxColumn(device);
            if (null != _mColors &&
                _mColors.Count == maxRow &&
                null != _mColors[0] &&
                _mColors[0].Count == maxColumn)
            {
                var frame = ChromaUtils.CreateColors2D(device);
                for (int i = 0; i < maxRow; ++i)
                {
                    for (int j = 0; j < maxColumn; ++j)
                    {
                        frame[i][j] = _mColors[i][j];
                    }
                }
                frames[_mCurrentFrame] = frame;
            }
        }
        animation.Frames = frames;
    }
    private void OnClickSaturateButton()
    {
        ChromaSDKAnimation2D animation = GetAnimation();

        EditorUtility.SetDirty(animation);
        var frames = animation.Frames; //copy

        Unload();

        if (_mCurrentFrame >= 0 &&
            _mCurrentFrame < frames.Count)
        {
            ChromaDevice2DEnum device = animation.Device;
            int maxRow    = ChromaUtils.GetMaxRow(device);
            int maxColumn = ChromaUtils.GetMaxColumn(device);
            var frame     = frames[_mCurrentFrame];
            for (int i = 0; i < maxRow; ++i)
            {
                var row = frame[i];
                for (int j = 0; j < maxColumn; ++j)
                {
                    Color color = ChromaUtils.ToRGB(row[j]);
                    float max   = Mathf.Max(Mathf.Max(color.r, color.g), color.b);
                    color  = Color.Lerp(Color.black, _mColor, max);
                    row[j] = ChromaUtils.ToBGR(color);
                }
            }
        }
        animation.Frames = frames;
    }
    private void OnClickFillColumn(int column)
    {
        ChromaSDKAnimation2D animation = GetAnimation();

        EditorUtility.SetDirty(animation);
        var frames = animation.Frames; //copy

        Unload();

        if (_mCurrentFrame >= 0 &&
            _mCurrentFrame < frames.Count)
        {
            ChromaDevice2DEnum device = animation.Device;
            int maxRow    = ChromaUtils.GetMaxRow(device);
            int maxColumn = ChromaUtils.GetMaxColumn(device);
            var rows      = frames[_mCurrentFrame];
            for (int i = 0; i < maxRow; ++i)
            {
                var row = rows[i];
                if (column < row.Count && column < maxColumn)
                {
                    row[column] = ChromaUtils.ToBGR(_mColor);
                }
            }
            frames[_mCurrentFrame] = rows;
        }
        animation.Frames = frames;
    }
예제 #10
0
    private void OnClickSaturateButton()
    {
        ChromaSDKAnimation1D animation = GetAnimation();

        EditorUtility.SetDirty(animation);
        var frames = animation.Frames; //copy

        Unload();

        if (_mCurrentFrame >= 0 &&
            _mCurrentFrame < frames.Count)
        {
            ChromaDevice1DEnum device = animation.Device;
            int maxLeds = ChromaUtils.GetMaxLeds(device);
            var frame   = frames[_mCurrentFrame];
            for (int i = 0; i < maxLeds; ++i)
            {
                Color color = ChromaUtils.ToRGB((int)frame[i]);
                float max   = Mathf.Max(Mathf.Max(color.r, color.g), color.b);
                color    = Color.Lerp(Color.black, _mColor, max);
                frame[i] = ChromaUtils.ToBGR(color);
            }
        }
        animation.Frames = frames;
    }
    public override void Update()
    {
        base.Update();

        if (_mTime == DateTime.MinValue)
        {
            return;
        }

        float time     = (float)(DateTime.Now - _mTime).TotalSeconds;
        float nextTime = GetTime(_mCurrentFrame);

        if (nextTime < time)
        {
            ++_mCurrentFrame;
            if (_mCurrentFrame < _mEffects.Count)
            {
                if (!_mIsPaused &&
                    ChromaConnectionManager.Instance.Connected)
                {
                    //Debug.Log("SetEffect.");
                    EffectResponseId effect = _mEffects[_mCurrentFrame];
                    if (null != effect)
                    {
                        ChromaUtils.SetEffect(effect.Id);
                    }

                    /*
                     * //Silently fail
                     * if (null != effect)
                     * {
                     *  EffectIdentifierResponse result = ChromaUtils.SetEffect(effect.Id);
                     *  if (null == result ||
                     *      result.Result != 0)
                     *  {
                     *      Debug.LogError("Failed to set effect!");
                     *  }
                     * }
                     * else
                     * {
                     *  Debug.LogError("Failed to set effect!");
                     * }
                     */
                }
            }
            else
            {
                //UE_LOG(LogTemp, Log, TEXT("UChromaSDKPluginAnimation2DObject::Tick Animation Complete."));
                _mIsPlaying    = false;
                _mTime         = DateTime.MinValue; //reset
                _mCurrentFrame = 0;

                // execute the complete event if set
                if (null != _mOnComplete)
                {
                    _mOnComplete.Invoke(this);
                }
            }
        }
    }
예제 #12
0
    private void OnClickPasteButton()
    {
        ChromaSDKAnimation1D animation = GetAnimation();

        EditorUtility.SetDirty(animation);
        var frames = animation.Frames; //copy

        Unload();

        if (_mCurrentFrame >= 0 &&
            _mCurrentFrame < frames.Count)
        {
            ChromaDevice1DEnum device = animation.Device;
            int maxLeds = ChromaUtils.GetMaxLeds(device);
            if (_mColors.Count == maxLeds)
            {
                var frame = ChromaUtils.CreateColors1D(device);
                for (int i = 0; i < maxLeds; ++i)
                {
                    frame[i] = _mColors[i];
                }
                frames[_mCurrentFrame] = frame;
            }
        }
        animation.Frames = frames;
    }
예제 #13
0
    private void OnClickAddButton()
    {
        ChromaSDKAnimation1D animation = GetAnimation();

        EditorUtility.SetDirty(animation);
        var frames = animation.Frames; //copy

        Unload();

        if (_mCurrentFrame < 0 ||
            _mCurrentFrame >= frames.Count)
        {
            _mCurrentFrame = 0;
        }
        EffectArray1dInput frame = ChromaUtils.CreateColors1D(animation.Device);

        if (_mCurrentFrame == frames.Count ||
            (_mCurrentFrame + 1) == frames.Count)
        {
            frames.Add(frame);
            _mCurrentFrame = frames.Count - 1;
        }
        else
        {
            ++_mCurrentFrame;
            frames.Insert(_mCurrentFrame, frame);
        }
        animation.Frames = frames;
        animation.RefreshCurve();
    }
예제 #14
0
    private void OnClickShiftButton(int x)
    {
        ChromaSDKAnimation1D animation = GetAnimation();

        EditorUtility.SetDirty(animation);
        var frames = animation.Frames; //copy

        Unload();

        if (_mCurrentFrame >= 0 &&
            _mCurrentFrame < frames.Count)
        {
            ChromaDevice1DEnum device = animation.Device;
            int maxLeds  = ChromaUtils.GetMaxLeds(device);
            int offsetX  = maxLeds - x;
            var oldFrame = frames[_mCurrentFrame];
            var newFrame = ChromaUtils.CreateColors1D(device);
            for (int i = 0; i < maxLeds; ++i)
            {
                int color = (int)oldFrame[(i + offsetX) % maxLeds];
                newFrame[i] = color;
            }
            frames[_mCurrentFrame] = newFrame;
        }
        animation.Frames = frames;
    }
예제 #15
0
    private void OnClickDarkenButton()
    {
        ChromaSDKAnimation1D animation = GetAnimation();

        EditorUtility.SetDirty(animation);
        var frames = animation.Frames; //copy

        Unload();

        if (_mCurrentFrame >= 0 &&
            _mCurrentFrame < frames.Count)
        {
            ChromaDevice1DEnum device = animation.Device;
            int maxLeds = ChromaUtils.GetMaxLeds(device);
            var frame   = frames[_mCurrentFrame];
            for (int i = 0; i < maxLeds; ++i)
            {
                Color color = ChromaUtils.ToRGB((int)frame[i]);
                color.r *= 0.75f;
                color.g *= 0.75f;
                color.b *= 0.75f;
                frame[i] = ChromaUtils.ToBGR(color);
            }
        }
        animation.Frames = frames;
    }
 public void OnApplicationQuit()
 {
     if (ChromaUtils.IsPlatformSupported())
     {
         Disconnect();
     }
 }
예제 #17
0
 /// <summary>
 /// Deactivate on non-windows platforms
 /// </summary>
 public void Awake()
 {
     if (!ChromaUtils.IsPlatformSupported())
     {
         ChromaUtils.SetActive(gameObject, false);
         return;
     }
 }
예제 #18
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);
                }
            }
        }
    private void OnClickAddButton()
    {
        ChromaSDKAnimation2D animation = GetAnimation();

        EditorUtility.SetDirty(animation);
        var frames = animation.Frames; //copy

        Unload();

        if (_mCurrentFrame < 0 ||
            _mCurrentFrame >= frames.Count)
        {
            _mCurrentFrame = 0;
        }
        EffectArray2dInput oldFrame;

        if (frames.Count > 0)
        {
            oldFrame = frames[_mCurrentFrame];
        }
        else
        {
            oldFrame = ChromaUtils.CreateColors2D(animation.Device);
        }
        EffectArray2dInput frame = ChromaUtils.CreateColors2D(animation.Device);

        if (_mCurrentFrame == frames.Count ||
            (_mCurrentFrame + 1) == frames.Count)
        {
            frames.Add(frame);
            _mCurrentFrame = frames.Count - 1;
        }
        else
        {
            ++_mCurrentFrame;
            frames.Insert(_mCurrentFrame, frame);
        }
        // copy colors
        if (_mCurrentFrame >= 0 &&
            _mCurrentFrame < frames.Count)
        {
            ChromaDevice2DEnum device = animation.Device;
            int maxRow    = ChromaUtils.GetMaxRow(device);
            int maxColumn = ChromaUtils.GetMaxColumn(device);
            for (int i = 0; i < maxRow; ++i)
            {
                var row = frame[i];
                for (int j = 0; j < maxColumn; ++j)
                {
                    row[j] = oldFrame[i][j];
                }
            }
        }
        animation.Frames = frames;
        animation.RefreshCurve();
    }
예제 #20
0
    private static EffectInput GetEffectChromaStatic(Color color)
    {
        EffectInput effectInput = new EffectInput(EffectType.CHROMA_NONE, null);

        effectInput.Effect = EffectType.CHROMA_STATIC;
        int value = ChromaUtils.ToBGR(color);

        effectInput.Param = new EffectInputParam(new int?(value), null, null, null, null, null);
        return(effectInput);
    }
예제 #21
0
    /// <summary>
    /// Get Effect: CHROMA_STATIC
    /// </summary>
    /// <param name="color"></param>
    /// <returns></returns>
    private static EffectInput GetEffectChromaStatic(Color color)
    {
        var input = new EffectInput();

        input.Effect = EffectType.CHROMA_STATIC;
        int bgrInt = ChromaUtils.ToBGR(color);

        input.Param = new EffectInputParam(bgrInt);
        return(input);
    }
예제 #22
0
파일: Plugin.cs 프로젝트: JonnyXDA/Chroma
        public void OnDisable()
        {
            _harmonyInstanceCore.UnpatchAll(HARMONYID);

            GameplaySetup.instance.RemoveTab("Chroma");

            ChromaUtils.SetSongCoreCapability(REQUIREMENTNAME, false);

            SceneManager.activeSceneChanged -= ChromaController.OnActiveSceneChanged;

            // Legacy support
            ChromaUtils.SetSongCoreCapability("Chroma Lighting Events", false);
        }
 public void Awake()
 {
     if (!ChromaUtils.IsPlatformSupported())
     {
         ChromaUtils.SetActive(gameObject, false);
         return;
     }
     if (Application.isPlaying)
     {
         DontDestroyOnLoad(gameObject);
     }
     Connect();
 }
    private void LoadImage(string path)
    {
        ChromaSDKAnimation2D animation = GetAnimation();

        EditorUtility.SetDirty(animation);
        Unload();

        if (!string.IsNullOrEmpty(path))
        {
            ImageManager.LoadImage(path);

            int frameCount = ImageManager.PluginGetFrameCount();
            if (frameCount == 0)
            {
                Debug.LogError("Failed to read frames from image! Please try again!");
            }

            ChromaDevice2DEnum device = animation.Device;
            var colors = ChromaUtils.CreateColors2D(device);

            for (int frameIndex = 0; frameIndex < frameCount; ++frameIndex)
            {
                if (frameIndex > 0)
                {
                    OnClickAddButton();
                }
                var frames = animation.Frames; //copy
                if (_mCurrentFrame >= 0 &&
                    _mCurrentFrame < animation.Frames.Count)
                {
                    //Debug.Log(string.Format("Frame count: {0}", frameCount));

                    int height = ImageManager.PluginGetHeight();
                    int width  = ImageManager.PluginGetWidth();

                    for (int y = 0; y < colors.Count && y < height; y++)
                    {
                        var row = colors[y];
                        for (int x = 0; x < row.Count && x < width; x++)
                        {
                            int color = ImageManager.PluginGetPixel(frameIndex, x, y);
                            row[x] = color;
                        }
                    }

                    frames[_mCurrentFrame] = colors;
                }
                animation.Frames = frames;
            }
        }
    }
예제 #25
0
    public void ClearFrames()
    {
        int maxLeds = ChromaUtils.GetMaxLeds(this.Device);

        this._mFrames = new ChromaSDKBaseAnimation.ColorArray[1];
        ChromaSDKBaseAnimation.ColorArray colorArray = new ChromaSDKBaseAnimation.ColorArray();
        int[] array = new int[maxLeds];
        for (int i = 0; i < maxLeds; i++)
        {
            array[i] = 0;
        }
        colorArray.Colors = array;
        this._mFrames[0]  = colorArray;
    }
예제 #26
0
    private void OnClickInsertButton()
    {
        ChromaSDKAnimation1D animation = GetAnimation();

        EditorUtility.SetDirty(animation);
        var frames = animation.Frames; //copy

        Unload();

        if (_mCurrentFrame < 0 ||
            _mCurrentFrame >= frames.Count)
        {
            _mCurrentFrame = 0;
        }
        EffectArray1dInput oldFrame;

        if (frames.Count > 0)
        {
            oldFrame = frames[_mCurrentFrame];
        }
        else
        {
            oldFrame = ChromaUtils.CreateColors1D(animation.Device);
        }
        EffectArray1dInput frame = ChromaUtils.CreateColors1D(animation.Device);

        if (frames.Count == 0)
        {
            frames.Add(frame);
            _mCurrentFrame = frames.Count - 1;
        }
        else
        {
            frames.Insert(_mCurrentFrame, frame);
        }
        // copy colors
        if (_mCurrentFrame >= 0 &&
            _mCurrentFrame < frames.Count)
        {
            ChromaDevice1DEnum device = animation.Device;
            int maxLeds = ChromaUtils.GetMaxLeds(device);
            for (int i = 0; i < maxLeds; ++i)
            {
                frame[i] = oldFrame[i];
            }
        }
        animation.Frames = frames;
        animation.RefreshCurve();
    }
    /// <summary>
    /// Play the animation and fire the OnComplete event
    /// </summary>
    /// <param name="onComplete"></param>
    public void PlayWithOnComplete(ChomaOnComplete2D onComplete)
    {
        //Debug.Log("PlayWithOnComplete");

        if (!_mIsLoaded)
        {
            // auto load if not loaded
            Load();
            //Debug.LogError("Animation has not been loaded!");
            //return;
        }

        _mOnComplete = onComplete;

        _mTime         = DateTime.Now; //Time when animation started
        _mIsPlaying    = true;
        _mCurrentFrame = 0;

        if (_mCurrentFrame < _mEffects.Count)
        {
            if (!_mIsPaused &&
                ChromaConnectionManager.Instance.Connected)
            {
                //Debug.Log("SetEffect.");
                EffectResponseId effect = _mEffects[_mCurrentFrame];
                if (null != effect)
                {
                    ChromaUtils.SetEffect(effect.Id);
                }

                /*
                 * //Silently fail
                 * if (null != effect)
                 * {
                 *  EffectIdentifierResponse result = ChromaUtils.SetEffect(effect.Id);
                 *  if (null == result ||
                 *      result.Result != 0)
                 *  {
                 *      Debug.LogError("Failed to set effect!");
                 *  }
                 * }
                 * else
                 * {
                 *  Debug.LogError("Failed to set effect!");
                 * }
                 */
            }
        }
    }
    /// <summary>
    /// Play the animation
    /// </summary>
    public override void Play()
    {
        //Debug.Log("Play");

        if (!_mIsLoaded)
        {
            Load();
            //Debug.LogError("Play Animation has not been loaded!");
            //return;
        }

        // clear on play to avoid unsetting on a loop
        _mOnComplete = null;

        _mTime         = DateTime.Now; //Time when animation started
        _mIsPlaying    = true;
        _mCurrentFrame = 0;

        if (_mCurrentFrame < _mEffects.Count)
        {
            if (!_mIsPaused &&
                ChromaConnectionManager.Instance.Connected)
            {
                //Debug.Log("SetEffect.");
                EffectResponseId effect = _mEffects[_mCurrentFrame];
                if (null != effect)
                {
                    ChromaUtils.SetEffect(effect.Id);
                }

                /*
                 * //Silently fail
                 * if (null != effect)
                 * {
                 *  EffectIdentifierResponse result = ChromaUtils.SetEffect(effect.Id);
                 *  if (null == result ||
                 *      result.Result != 0)
                 *  {
                 *      Debug.LogError("Failed to set effect!");
                 *  }
                 * }
                 * else
                 * {
                 *  Debug.LogError("Failed to set effect!");
                 * }
                 */
            }
        }
    }
예제 #29
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);
            }
        }
    /// <summary>
    /// Set frames to the default state
    /// </summary>
    public void ClearFrames()
    {
        int maxLeds = ChromaUtils.GetMaxLeds(Device);

        _mFrames = new ColorArray[1];
        var frame    = new ColorArray();
        var elements = new int[maxLeds];

        for (int i = 0; i < maxLeds; ++i)
        {
            elements[i] = 0;
        }
        frame.Colors = elements;
        _mFrames[0]  = frame;
    }