Exemple #1
0
    void Setup(Animations.EditAnimation anim)
    {
        base.SetupHeader(false, false, anim.name, SetName);
        editAnimation    = anim;
        this.dieRenderer = DiceRendererManager.Instance.CreateDiceRenderer(anim.defaultPreviewSettings.design, 600);
        if (dieRenderer != null)
        {
            previewImage.texture = dieRenderer.renderTexture;
        }

        rotationSlider.Setup(this.dieRenderer);
        rotationControl.Setup(this.dieRenderer);

        animationSelector.Setup(
            "Lighting Pattern Type",
            () => editAnimation.type,
            (t) => SetAnimationType((Animations.AnimationType)t),
            null);

        // Setup all other parameters
        parameters = UIParameterManager.Instance.CreateControls(anim, parametersRoot);
        parameters.onParameterChanged += OnAnimParameterChanged;

        dieRenderer.SetAuto(true);
        dieRenderer.SetAnimation(anim);
        dieRenderer.Play(true);
    }
Exemple #2
0
 void DuplicateAnimation(Animations.EditAnimation anim)
 {
     AppDataSet.Instance.DuplicateAnimation(anim);
     patterns.Find(p => p.editAnimation == anim).Expand(false);
     AppDataSet.Instance.SaveData();
     RefreshView();
 }
    public bool LoadFromJson(DiceType diceType)
    {
        string path = GetJsonFilePathname(diceType);
        bool   ret  = File.Exists(path);

        if (ret)
        {
            string jsonText = File.ReadAllText(path);
            animationSet = JsonUtility.FromJson <Animations.EditAnimationSet>(jsonText);
            animationSet.FixupLedIndices();
            timeline.SetAnimations(diceType, animationSet);
            Debug.Log($"Loaded {diceType} animations from {path}");
        }
        else
        {
            animationSet            = new Animations.EditAnimationSet();
            animationSet.animations = new List <Animations.EditAnimation>();
            var anim = new Animations.EditAnimation();
            anim.Reset();
            animationSet.animations.Add(anim);
            timeline.SetAnimations(diceType, animationSet);
            Debug.Log($"Loaded empty {diceType} animation");
        }
        return(ret);
    }
Exemple #4
0
    public void AddNewAnimation()
    {
        var anim = new Animations.EditAnimation();

        anim.Reset();
        AddAnimation(anim);
    }
Exemple #5
0
        public static EditAnimationSet CreateTestSet()
        {
            EditAnimationSet set = new EditAnimationSet();

            for (int a = 0; a < 5; ++a)
            {
                EditAnimation anim = new EditAnimation();
                for (int i = 0; i < a + 1; ++i)
                {
                    var track = new EditTrack();
                    track.ledIndices = new List <int>();
                    track.ledIndices.Add(i);
                    for (int j = 0; j < 3; ++j)
                    {
                        var kf = new EditKeyframe();
                        kf.time  = j;
                        kf.color = Random.ColorHSV();
                        track.keyframes.Add(kf);
                    }
                    anim.tracks.Add(track);
                }
                set.animations.Add(anim);
            }

            return(set);
        }
Exemple #6
0
    public bool ShowAnimationPicker(string title, Animations.EditAnimation previousAnimation, System.Action <bool, Animations.EditAnimation> closeAction)
    {
        bool ret = !animationPicker.isShown;

        if (ret)
        {
            animationPicker.Show(title, previousAnimation, closeAction);
        }
        return(ret);
    }
Exemple #7
0
        public void FromAnimationSet(AnimationSet set)
        {
            // Reset the animations, and read them in!
            animations = new List <EditAnimation>();
            for (int i = 0; i < set.animations.Length; ++i)
            {
                var anim     = set.getAnimation((ushort)i);
                var editAnim = new EditAnimation();
                for (int j = 0; j < anim.trackCount; ++j)
                {
                    var track     = anim.GetTrack(set, (ushort)j);
                    var editTrack = new EditTrack();
                    editTrack.ledIndices = new List <int>();
                    editTrack.ledIndices.Add(track.ledIndex);
                    var rgbTrack = track.GetTrack(set);
                    for (int k = 0; k < rgbTrack.keyFrameCount; ++k)
                    {
                        var kf     = rgbTrack.GetKeyframe(set, (ushort)k);
                        var editKf = new EditKeyframe();
                        editKf.time = (float)kf.time() / 1000.0f;
                        if (kf.colorIndex() == AnimationSet.SPECIAL_COLOR_INDEX)
                        {
                            editKf.color = new Color32(255, 255, 255, 0); // Important part is alpha
                        }
                        else
                        {
                            editKf.color = ColorMapping.InverseRemap(set.getColor(kf.colorIndex()));
                        }
                        editTrack.keyframes.Add(editKf);
                    }
                    editAnim.tracks.Add(editTrack);
                }

                // De-duplicate tracks
                for (int l = 0; l < editAnim.tracks.Count; ++l)
                {
                    for (int m = l + 1; m < editAnim.tracks.Count; ++m)
                    {
                        if (editAnim.tracks[m].keyframes.SequenceEqual(editAnim.tracks[l].keyframes, EditKeyframe.DefaultComparer))
                        {
                            // Concatenate the leds
                            editAnim.tracks[l].ledIndices.AddRange(editAnim.tracks[m].ledIndices);

                            // Remove the second edit anim
                            editAnim.tracks.RemoveAt(m);
                            m--;
                        }
                    }
                }

                editAnim.@event            = (Die.AnimationEvent)anim.animationEvent;
                editAnim.@specialColorType = (Die.SpecialColor)anim.specialColorType;
                animations.Add(editAnim);
            }
        }
Exemple #8
0
    UIAnimationSelectorPatternToken CreatePatternToken(Animations.EditAnimation anim)
    {
        // Create the gameObject
        var ret = GameObject.Instantiate <UIAnimationSelectorPatternToken>(patternTokenPrefab, Vector3.zero, Quaternion.identity, contentRoot.transform);

        // When we click on the pattern main button, go to the edit page
        ret.onClick.AddListener(() => Hide(true, ret.editAnimation));

        addPatternButton.transform.SetAsLastSibling();
        // Initialize it
        ret.Setup(anim);
        return(ret);
    }
Exemple #9
0
 void ExpandAnimation(Animations.EditAnimation anim)
 {
     foreach (var uip in patterns)
     {
         if (uip.editAnimation == anim)
         {
             uip.Expand(!uip.isExpanded);
         }
         else
         {
             uip.Expand(false);
         }
     }
 }
Exemple #10
0
        public EditAnimation Duplicate()
        {
            var anim = new EditAnimation();

            anim.name             = name;
            anim.specialColorType = specialColorType;
            if (tracks != null)
            {
                anim.tracks = new List <EditTrack>(tracks.Count);
                foreach (var track in tracks)
                {
                    anim.tracks.Add(track.Duplicate());
                }
            }
            return(anim);
        }
Exemple #11
0
    UIPatternToken CreatePatternToken(Animations.EditAnimation anim)
    {
        // Create the gameObject
        var ret = GameObject.Instantiate <UIPatternToken>(patternTokenPrefab, Vector3.zero, Quaternion.identity, contentRoot.transform);

        // When we click on the pattern main button, go to the edit page
        ret.onClick.AddListener(() => NavigationManager.Instance.GoToPage(UIPage.PageId.Pattern, anim));
        ret.onEdit.AddListener(() => NavigationManager.Instance.GoToPage(UIPage.PageId.Pattern, anim));
        ret.onDuplicate.AddListener(() => DuplicateAnimation(anim));
        ret.onRemove.AddListener(() => DeleteAnimation(anim));
        ret.onExport.AddListener(() => { PixelsApp.Instance.ExportPattern(anim); ret.Expand(false); });
        ret.onExpand.AddListener(() => ExpandAnimation(anim));

        // Initialize it
        ret.Setup(anim);
        return(ret);
    }
Exemple #12
0
    void AddAnimation(Animations.EditAnimation anim)
    {
        var rolesTaken = _animationSet.animations.Select(a => a.@event).ToArray();

        foreach (var role in _animRoles)
        {
            if (!rolesTaken.Contains(role))
            {
                anim.@event = role;
                break;
            }
        }

        _animationSet.animations.Add(anim);

        RefreshNames();
        ShowAnimation(_animationSet.animations.Count - 1);
    }
Exemple #13
0
 public void SetAnimation(Animations.EditAnimation editAnimation)
 {
     if (editAnimation != null)
     {
         animations.Clear();
         animations.Add(editAnimation);
         currentAnimationIndex = 0;
         if (currentInstance != null)
         {
             // We're switching the animation from underneath the playback
             SetupInstance(currentAnimationIndex, currentInstance.startTime, currentInstance.remapFace);
         }
     }
     else
     {
         ClearAnimations();
     }
 }
Exemple #14
0
    void DeleteAnimation(Animations.EditAnimation anim)
    {
        PixelsApp.Instance.ShowDialogBox("Delete Lighting Pattern?", "Are you sure you want to delete " + anim.name + "?", "Ok", "Cancel", res =>
        {
            if (res)
            {
                var dependentPresets = AppDataSet.Instance.CollectPresetsForAnimation(anim);
                if (dependentPresets.Any())
                {
                    StringBuilder builder = new StringBuilder();
                    builder.Append("The following profiles depend on ");
                    builder.Append(anim.name);
                    builder.AppendLine(":");
                    foreach (var b in dependentPresets)
                    {
                        builder.Append("\t");
                        builder.AppendLine(b.name);
                    }
                    builder.Append("Are you sure you want to delete it?");

                    PixelsApp.Instance.ShowDialogBox("Pattern In Use!", builder.ToString(), "Ok", "Cancel", res2 =>
                    {
                        if (res2)
                        {
                            AppDataSet.Instance.DeleteAnimation(anim);
                            AppDataSet.Instance.SaveData();
                            RefreshView();
                        }
                    });
                }
                else
                {
                    AppDataSet.Instance.DeleteAnimation(anim);
                    AppDataSet.Instance.SaveData();
                    RefreshView();
                }
            }
        });
    }
Exemple #15
0
    public IEnumerable <Presets.EditPreset> CollectPresetsForAnimation(Animations.EditAnimation anim)
    {
        var behaviors = CollectBehaviorsForAnimation(anim);

        return(presets.Where(p => p.dieAssignments.Any(da => behaviors.Contains(da.behavior))));
    }
Exemple #16
0
 public void SetAnimation(Animations.EditAnimation animation) => die.SetAnimation(animation);
Exemple #17
0
 public IEnumerable <Behaviors.EditBehavior> CollectBehaviorsForAnimation(Animations.EditAnimation anim)
 {
     return(behaviors.Where(b => b.DependsOnAnimation(anim)));
 }
Exemple #18
0
    public void UpdateDieDataSet(Behaviors.EditBehavior behavior, Dice.EditDie die, System.Action <bool> callback)
    {
        // Make sure the die is ready!
        ShowProgrammingBox("Connecting to " + die.name + "...");
        DiceManager.Instance.ConnectDie(die, (editDie, res, message) =>
        {
            if (res)
            {
                // The die is ready to be uploaded to

                // Generate the data to be uploaded
                EditDataSet editSet = new EditDataSet();

                // Grab the behavior
                editSet.behavior = behavior.Duplicate();

                // And add the animations that this behavior uses
                var animations = editSet.behavior.CollectAnimations();

                // Add default rules and animations to behavior / set
                if (AppDataSet.Instance.defaultBehavior != null)
                {
                    // Rules that are in fact copied over
                    var copiedRules = new List <EditRule>();

                    foreach (var rule in AppDataSet.Instance.defaultBehavior.rules)
                    {
                        if (!editSet.behavior.rules.Any(r => r.condition.type == rule.condition.type))
                        {
                            var ruleCopy = rule.Duplicate();
                            copiedRules.Add(ruleCopy);
                            editSet.behavior.rules.Add(ruleCopy);
                        }
                    }

                    // Copied animations
                    var copiedAnims = new Dictionary <Animations.EditAnimation, Animations.EditAnimation>();

                    // Add animations used by default rules
                    foreach (var editAnim in AppDataSet.Instance.defaultBehavior.CollectAnimations())
                    {
                        foreach (var copiedRule in copiedRules)
                        {
                            if (copiedRule.DependsOnAnimation(editAnim))
                            {
                                Animations.EditAnimation copiedAnim = null;
                                if (!copiedAnims.TryGetValue(editAnim, out copiedAnim))
                                {
                                    copiedAnim = editAnim.Duplicate();
                                    animations.Add(copiedAnim);
                                    copiedAnims.Add(editAnim, copiedAnim);
                                }
                                copiedRule.ReplaceAnimation(editAnim, copiedAnim);
                            }
                        }
                    }
                }

                editSet.animations.AddRange(animations);

                foreach (var pattern in AppDataSet.Instance.patterns)
                {
                    bool asRGB = false;
                    if (animations.Any(anim => anim.DependsOnPattern(pattern, out asRGB)))
                    {
                        if (asRGB)
                        {
                            editSet.rgbPatterns.Add(pattern);
                        }
                        else
                        {
                            editSet.patterns.Add(pattern);
                        }
                    }
                }

                // Set the behavior
                var dataSet = editSet.ToDataSet();

                // Check the dataset against the one stored in the die
                var hash = dataSet.ComputeHash();

                // Get the hash directly from the die
                editDie.die.GetDieInfo((info_res) =>
                {
                    if (info_res)
                    {
                        if (hash != editDie.die.dataSetHash)
                        {
                            // We need to upload the dataset first
                            Debug.Log("Uploading dataset to die " + editDie.name);
                            var dataSetDataSize = dataSet.ComputeDataSetDataSize();
                            Debug.Log("Dataset data size " + dataSetDataSize);
                            UpdateProgrammingBox(0.0f, "Uploading data to " + editDie.name + "...");
                            editDie.die.UploadDataSet(dataSet,
                                                      (pct) =>
                            {
                                UpdateProgrammingBox(pct, "Uploading data to " + editDie.name + "...");
                            },
                                                      (res2, errorMsg) =>
                            {
                                if (res2)
                                {
                                    editDie.die.GetDieInfo(res3 =>
                                    {
                                        if (res3)
                                        {
                                            HideProgrammingBox();
                                            if (hash != editDie.die.dataSetHash)
                                            {
                                                ShowDialogBox("Error verifying data sent to " + editDie.name, message, "Ok", null, null);
                                                callback?.Invoke(false);
                                            }
                                            else
                                            {
                                                die.currentBehavior = behavior;
                                                AppDataSet.Instance.SaveData();
                                                onDieBehaviorUpdatedEvent?.Invoke(die, die.currentBehavior);
                                                callback?.Invoke(true);
                                            }
                                            DiceManager.Instance.DisconnectDie(editDie, null);
                                        }
                                        else
                                        {
                                            HideProgrammingBox();
                                            ShowDialogBox("Error fetching profile hash value from " + editDie.name, message, "Ok", null, null);
                                            DiceManager.Instance.DisconnectDie(editDie, null);
                                            callback?.Invoke(false);
                                        }
                                    });
                                }
                                else
                                {
                                    HideProgrammingBox();
                                    ShowDialogBox("Error uploading data to " + editDie.name, errorMsg, "Ok", null, null);
                                    DiceManager.Instance.DisconnectDie(editDie, null);
                                    callback?.Invoke(false);
                                }
                            });
                        }
                        else
                        {
                            Debug.Log("Die " + editDie.name + " already has preset with hash 0x" + hash.ToString("X8") + " programmed.");
                            HideProgrammingBox();
                            ShowDialogBox("Profile already Programmed", "Die " + editDie.name + " already has profile \"" + behavior.name + "\" programmed.", "Ok", null, null);
                            DiceManager.Instance.DisconnectDie(editDie, null);
                            callback?.Invoke(true);
                        }
                    }
                    else
                    {
                        HideProgrammingBox();
                        ShowDialogBox("Error verifying profile hash on " + editDie.name, message, "Ok", null, null);
                        DiceManager.Instance.DisconnectDie(editDie, null);
                        callback?.Invoke(false);
                    }
                });
            }
            else
            {
                HideProgrammingBox();
                ShowDialogBox("Error connecting to " + editDie.name, message, "Ok", null, null);
                callback(false);
            }
        });
    }