Esempio n. 1
0
        public override string ToString()
        {
            var sources = string.Join(", ", SourceNodes.Select(x => x.GetType().Name));
            var targets = string.Join(", ", TargetNodes.Select(x => x.GetType().Name));

            return($"{ThisNode.GetType().Name}, Builder='{Builder.Name}', Sources=[{sources}], Targets=[{targets}]");
        }
Esempio n. 2
0
        //Validate that the we are using valid colors and set appropriate defaults if not.
        private void CheckForInvalidColorData()
        {
            // check for sane default colors when first rendering it
            HashSet <Color> validColors = new HashSet <Color>();

            validColors.AddRange(TargetNodes.SelectMany(x => ColorModule.getValidColorsForElementNode(x, true)));

            //Validate Color 1
            if (validColors.Any() &&
                (!validColors.Contains(_data.Color1.ToArgb()) || !_data.ColorGradient1.GetColorsInGradient().IsSubsetOf(validColors)))
            {
                Color1         = validColors.First();
                ColorGradient1 = new ColorGradient(validColors.First());
            }

            //Validate color 2
            if (validColors.Any() &&
                (!validColors.Contains(_data.Color2.ToArgb()) || !_data.ColorGradient2.GetColorsInGradient().IsSubsetOf(validColors)))
            {
                if (validColors.Count > 1)
                {
                    Color2         = validColors.ElementAt(1);
                    ColorGradient2 = new ColorGradient(validColors.ElementAt(1));
                }
                else
                {
                    Color2         = validColors.First();
                    ColorGradient2 = new ColorGradient(validColors.First());
                }
            }
        }
Esempio n. 3
0
        public IEffectNode CreateEffectNode(Dictionary <Guid, ElementNode> elementNodes)
        {
            // Create a element node lookup of elements that are currently valid.

            //Currently we only have one TargetNode per effect, so removing all the extra junk that sorts though
            //Multiples. If it changes in the future, we can change this around.

            //IEnumerable<Guid> targetNodeIds = TargetNodes.Select(x => x.NodeId);
            //IEnumerable<Guid> validElementIds = targetNodeIds.Intersect(elementNodes.Keys);

            IEffectModuleInstance effect = Modules.ModuleManagement.GetEffect(TypeId);

            effect.InstanceId = InstanceId;
            effect.TimeSpan   = TimeSpan;
            effect.StartTime  = StartTime;
            //effect.TargetNodes = validElementIds.Select(x => elementNodes[x]).ToArray();

            if (elementNodes.TryGetValue(TargetNodes.First().NodeId, out var node))
            {
                effect.TargetNodes = new IElementNode[] { node };
            }
            else
            {
                effect.TargetNodes = new IElementNode[] { new ProxyElementNode(TargetNodes.First().NodeId, TargetNodes.First().Name) };
            }
            return(new EffectNode(effect, StartTime));
        }
Esempio n. 4
0
 protected override void TargetNodesChanged()
 {
     if (TargetNodes.Any())
     {
         CheckForInvalidColorData();
     }
 }
Esempio n. 5
0
        private List <ElementNode> GetNodesToRenderOn()
        {
            IEnumerable <ElementNode> renderNodes = null;

            if (DepthOfEffect == 0)
            {
                renderNodes = TargetNodes.SelectMany(x => x.GetLeafEnumerator()).ToList();
            }
            else
            {
                renderNodes = TargetNodes;
                for (int i = 0; i < DepthOfEffect; i++)
                {
                    renderNodes = renderNodes.SelectMany(x => x.Children);
                }
            }

            // If the given DepthOfEffect results in no nodes (because it goes "too deep" and misses all nodes),
            // then we'll default to the LeafElements, which will at least return 1 element (the TargetNode)
            if (!renderNodes.Any())
            {
                renderNodes = TargetNodes.SelectMany(x => x.GetLeafEnumerator());
            }

            return(renderNodes.ToList());
        }
Esempio n. 6
0
        public EffectIntents Render()
        {
            if (IsDirty && !IsRendering)
            {
                IsRendering = true;
                try
                {
                    PreRender();
                }
                catch (Exception e)
                {
                    //Trap any errors to prevent the effect from staying in a state of rendering.
                    Logging.Error(e, $"Error rendering {EffectName} on element {TargetNodes?.FirstOrDefault()?.Name}");
                    Logging.Error($"Error rendering Effect Property settings: {PropertyInfo()}");
                }
                finally
                {
                    IsRendering = false;
                }
            }
            else
            {
                //To prevent the effect from being rendered multiple times if multiple threads
                //try to access it all at the same time. I.E the editor pre rendering process.
                while (IsRendering)
                {
                    Thread.Sleep(1);
                }
            }

            return(_Render());
        }
Esempio n. 7
0
        private IEnumerable <IElementNode> GetNodesToRenderOn()
        {
            IEnumerable <IElementNode> renderNodes = TargetNodes;

            renderNodes = TargetNodes.SelectMany(x => x.GetLeafEnumerator());

            return(renderNodes);
        }
Esempio n. 8
0
 private void CalculateAffectedElements()
 {
     if (TargetNodes == null || TargetNodes.Length == 0)
     {
         EffectedElementIds = Enumerable.Empty <Guid>();
     }
     EffectedElementIds =
         TargetNodes.SelectMany(y => y.GetElementEnumerator()).Select(z => z.Id);
 }
Esempio n. 9
0
        protected override void _PreRender()
        {
            _effectIntents = new EffectIntents();
            _r             = new Random();

            foreach (Element element in TargetNodes.SelectMany(x => x))
            {
                _RenderCandleOnElement(element);
            }
        }
Esempio n. 10
0
        protected override void TargetNodesChanged()
        {
            CheckForInvalidColorData();
            var firstNode = TargetNodes.FirstOrDefault();

            if (firstNode != null && DepthOfEffect > firstNode.GetMaxChildDepth() - 1)
            {
                DepthOfEffect = 0;
            }
        }
Esempio n. 11
0
        /// <summary>
        /// Performs encoding transformation for each <c>XmlElement</c> of <c>App.config</c> where <c>Encode</c> transform is applied for.
        /// </summary>
        protected override void Apply()
        {
            //If target node has no attributes - skip the transform:
            if (TargetNode.Attributes == null)
            {
                return;
            }

            //Getting list of passed XPath arguments to this Encode instance:
            var encodeXPathArguments = new List <string>();

            if (Arguments != null)
            {
                encodeXPathArguments.AddRange(Arguments);
            }

            //Adding DefaultAttributeName to XPath arguments if it's not present:
            if (!encodeXPathArguments.Contains(DefaultAttributeName))
            {
                encodeXPathArguments.Add(DefaultAttributeName);
            }

            //Looping thru TargetNodes
            foreach (var targetNode in TargetNodes.OfType <XmlElement>())
            {
                //For each TargetNode looping thru encodeXPathArguments
                foreach (var arg in encodeXPathArguments)
                {
                    //Getting TargetNode.XmlNode by XPath arg:
                    var destinationNode = targetNode.SelectSingleNode(arg);

                    if (destinationNode == null)
                    {
                        continue;
                    }

                    //TransformNode.XmlNode by XPath arg:
                    var applyTransformNode = TransformNode.SelectSingleNode(arg);

                    //Determine which XmlNode.InnerText to encode:
                    string valueToEncode =
                        applyTransformNode == null || string.IsNullOrEmpty(applyTransformNode.InnerText)
                            ? destinationNode.InnerText     //Getting default destination XmlNode.InnerText
                            : applyTransformNode.InnerText; //Getting XmlNode.InnerText specified in App.config transformer

                    if (string.IsNullOrEmpty(valueToEncode))
                    {
                        continue;
                    }

                    //If valueToEncode is OK - then encrypt it and assign to destination XmlNode.InnerText:
                    destinationNode.InnerText = _encryptorDecryptor.Encrypt(valueToEncode);
                }
            }
        }
Esempio n. 12
0
 protected override void TargetNodesChanged()
 {
     if (TargetNodes.Any())
     {
         CheckForInvalidColorData();
         if (DepthOfEffect > TargetNodes.FirstOrDefault().GetMaxChildDepth() - 1)
         {
             DepthOfEffect = 0;
         }
     }
 }
Esempio n. 13
0
        /// <summary>
        /// Gets the list of valid colors this effect can use and sets the hasDiscreteColors flag if any of it's targeted elements are discrete and have a restricted list.
        /// </summary>
        /// <returns></returns>
        protected HashSet <Color> GetValidColors()
        {
            HashSet <Color> validColors = new HashSet <Color>();

            validColors.AddRange(TargetNodes.SelectMany(x => ColorModule.getValidColorsForElementNode(x, true)));
            if (validColors.Any())
            {
                HasDiscreteColors = true;
            }
            return(validColors);
        }
Esempio n. 14
0
        private void CheckForInvalidColorData()
        {
            HashSet <Color> validColors = new HashSet <Color>();

            validColors.AddRange(TargetNodes.SelectMany(x => ColorModule.getValidColorsForElementNode(x, true)));
            if (validColors.Any() && !_data.ColorGradient.GetColorsInGradient().IsSubsetOf(validColors))
            {
                //Our color is not valid for any elements we have.
                //Try to set a default color gradient from our available colors
                _data.ColorGradient = new ColorGradient(validColors.First());
            }
        }
Esempio n. 15
0
        //Validate that the we are using valid colors and set appropriate defaults if not.
        private void CheckForInvalidColorData()
        {
            HashSet <Color> validColors = new HashSet <Color>();

            validColors.AddRange(TargetNodes.SelectMany(x => ColorModule.getValidColorsForElementNode(x, true)));
            if (validColors.Any() && !validColors.Contains(_data.color.ToArgb()))
            {
                //Our color is not valid for any elements we have.
                //Set a default color
                Color = validColors.First();
            }
        }
Esempio n. 16
0
        //Validate that the we are using valid colors and set appropriate defaults if not.
        private void CheckForInvalidColorData()
        {
            HashSet <Color> validColors = new HashSet <Color>();

            validColors.AddRange(TargetNodes.SelectMany(x => ColorModule.getValidColorsForElementNode(x, true)));

            if (validColors.Any() &&
                (!validColors.Contains(_data.StaticColor) || !_data.ColorGradient.GetColorsInGradient().IsSubsetOf(validColors)))                 //Discrete colors specified
            {
                _data.ColorGradient = new ColorGradient(validColors.DefaultIfEmpty(Color.White).First());
                _data.StaticColor   = validColors.First();
            }
        }
Esempio n. 17
0
        private void ConfigureVirtualBuffer()
        {
            ElementLocations = TargetNodes.SelectMany(x => x.GetLeafEnumerator()).Select(x => new ElementLocation(x)).ToList();
            var xMax = ElementLocations.Max(p => p.X);
            var xMin = ElementLocations.Min(p => p.X);
            var yMax = ElementLocations.Max(p => p.Y);
            var yMin = ElementLocations.Min(p => p.Y);

            _bufferWi       = (yMax - yMin) + 1;
            _bufferHt       = (xMax - xMin) + 1;
            _bufferWiOffset = yMin;
            _bufferHtOffset = xMin;
        }
Esempio n. 18
0
        protected override void _PreRender(CancellationTokenSource cancellationToken = null)
        {
            _effectIntents = new EffectIntents();
            _r             = new Random();

            var nodes = TargetNodes.SelectMany(x => x.GetLeafEnumerator());

            var elementGroup = nodes.Select((x, index) => new { x, index })
                               .GroupBy(x => x.index / GroupLevel, y => y.x);

            foreach (IGrouping <int, ElementNode> block in elementGroup)
            {
                _RenderCandleOnElements(block.GetElements().ToList());
            }
        }
Esempio n. 19
0
        protected void SetOrientation()
        {
            var orientation = OrientationModule.GetOrientationForElement(TargetNodes.First());

            switch (orientation)
            {
            case Orientation.Horizontal:
                StringOrientation = StringOrientation.Horizontal;
                break;

            default:
                StringOrientation = StringOrientation.Vertical;
                break;
            }
        }
        public ISequenceFilterNode CreateFilterNode()
        {
            var elementNodes = VixenSystem.Nodes.Distinct().ToDictionary(x => x.Id);

            IEnumerable <Guid> targetNodeIds   = TargetNodes.Select(x => x.NodeId);
            IEnumerable <Guid> validElementIds = targetNodeIds.Intersect(elementNodes.Keys);

            ISequenceFilterModuleInstance filter = Modules.ModuleManagement.GetSequenceFilter(TypeId);

            filter.InstanceId  = InstanceId;
            filter.TimeSpan    = TimeSpan;
            filter.TargetNodes = validElementIds.Select(x => elementNodes[x]).ToArray();

            return(new SequenceFilterNode(filter, StartTime));
        }
        public IEffectNode CreateEffectNode()
        {
            // Create a element node lookup of elements that are currently valid.
            var elementNodes = VixenSystem.Nodes.Distinct().ToDictionary(x => x.Id);

            IEnumerable <Guid> targetNodeIds   = TargetNodes.Select(x => x.NodeId);
            IEnumerable <Guid> validElementIds = targetNodeIds.Intersect(elementNodes.Keys);

            IEffectModuleInstance effect = Modules.ModuleManagement.GetEffect(TypeId);

            effect.InstanceId  = InstanceId;
            effect.TimeSpan    = TimeSpan;
            effect.TargetNodes = validElementIds.Select(x => elementNodes[x]).ToArray();

            return(new EffectNode(effect, StartTime));
        }
Esempio n. 22
0
        protected override void _PreRender(CancellationTokenSource cancellationToken = null)
        {
            _effectIntents = new EffectIntents();
            _r             = new Random();

            var nodes = TargetNodes.SelectMany(x => x.GetLeafEnumerator());

            var elementGroup = nodes.Select((x, index) => new { x, index })
                               .GroupBy(x => x.index / GroupLevel, y => y.x);

            foreach (IGrouping <int, IElementNode> block in elementGroup)
            {
                _RenderCandleOnElements(block.ToList());
            }

            //_effectIntents = IntentBuilder.ConvertToStaticArrayIntents(_effectIntents, TimeSpan, IsDiscrete());
        }
Esempio n. 23
0
        protected override void _PreRender(CancellationTokenSource cancellationToken = null)
        {
            _elementData = new EffectIntents();
            var targetNodes = TargetNodes.AsParallel();

            if (cancellationToken != null)
            {
                targetNodes = targetNodes.WithCancellation(cancellationToken.Token);
            }

            targetNodes.ForAll(node =>
            {
                if (node != null)
                {
                    RenderNode(node);
                }
            });
        }
Esempio n. 24
0
        protected override void _PreRender(CancellationTokenSource cancellationToken = null)
        {
            _effectIntents = new EffectIntents();
            _r             = new Random();

            foreach (Element element in TargetNodes.SelectMany(x => x))
            {
                if (cancellationToken != null && cancellationToken.IsCancellationRequested)
                {
                    return;
                }

                if (element != null)
                {
                    _RenderCandleOnElement(element);
                }
            }
        }
Esempio n. 25
0
 /// <summary>
 /// Sets the fixed attribute values from <see cref="AbstractSolver{T}.TargetNodes"/> and
 /// from <see cref="AdvancedSolverSettings.InitialAttributes"/>.
 /// </summary>
 private void CreateFixedAttributes()
 {
     _fixedNodes = TargetNodes.Select(n => n.Id).ToList();
     // Set start stats from start and target nodes.
     AddAttributes(_fixedNodes, _fixedAttributes);
     // Add the initial stats from the settings.
     foreach (var initialStat in Settings.InitialAttributes)
     {
         var name = initialStat.Key;
         if (_attrNameLookup.ContainsKey(name))
         {
             foreach (var i in _attrNameLookup[name])
             {
                 _fixedAttributes[i] += initialStat.Value * _attrConversionMultipliers[Tuple.Create(name, i)];
             }
         }
     }
 }
Esempio n. 26
0
        protected override void _PreRender(CancellationTokenSource cancellationToken = null)
        {
            _elementData = new EffectIntents();

            var value = new CommandValue(new StringCommand(string.Format("{0}|{1},{2}", "Launcher", _data.Executable, _data.Arguments)));

            var targetNodes = TargetNodes.AsParallel();

            if (cancellationToken != null)
            {
                targetNodes = targetNodes.WithCancellation(cancellationToken.Token);
            }

            targetNodes.ForAll(node => {
                IIntent i = new CommandIntent(value, TimeSpan);
                _elementData.AddIntentForElement(node.Element.Id, i, TimeSpan.Zero);
            });
        }
Esempio n. 27
0
        // renders the given node to the internal ElementData dictionary. If the given node is
        // not a element, will recursively descend until we render its elements.
        private void RenderNodes()
        {
            var renderNodes = TargetNodes.SelectMany(x => x.GetNodeEnumerator());

            if (LipSyncMode == LipSyncMode.MarkCollection)
            {
                SetupMarks();
            }

            PhonemeType phoneme = _data.StaticPhoneme;

            if (MappingType == MappingType.Map)
            {
                if (!_library.Library.ContainsKey(_data.PhonemeMapping))
                {
                    _data.PhonemeMapping = _library.DefaultMappingName;
                }

                LipSyncMapData mapData;
                if (_library.Library.TryGetValue(_data.PhonemeMapping, out mapData))
                {
                    if (mapData.IsMatrix)
                    {
                        RenderMapMatrix(mapData, phoneme);
                    }
                    else
                    {
                        //We should never get here becasue we no longer have string maps
                        Logging.Error("Trying to render as deprecated string maps!");
                        foreach (var element in renderNodes)
                        {
                            RenderMapElements(mapData, element, phoneme);
                        }
                    }
                }
            }
            else
            {
                foreach (var element in renderNodes)
                {
                    RenderPropertyMapElements(element, phoneme);
                }
            }
        }
Esempio n. 28
0
        private IEnumerable <ElementNode> FindLeafParents()
        {
            var nodes           = new List <ElementNode>();
            var nonLeafElements = new List <ElementNode>();

            if (TargetNodes.FirstOrDefault() != null)
            {
                nonLeafElements = TargetNodes.SelectMany(x => x.GetNonLeafEnumerator()).ToList();
                foreach (var elementNode in TargetNodes)
                {
                    foreach (var leafNode in elementNode.GetLeafEnumerator())
                    {
                        nodes.AddRange(leafNode.Parents);
                    }
                }
            }
            //Some nodes can have multiple node parents with odd groupings so this fancy linq query makes sure that the parent
            //node is part of the Target nodes lineage.
            return(nodes.Distinct().Intersect(nonLeafElements));
        }
Esempio n. 29
0
    void selectTargetNode()
    {
        selectTargetTransform();

        if (_targetTransform == null)
        {
            return;
        }

        TargetNodes targetNodes = _targetTransform.GetComponent <TargetNodes>();

        Pathfinding.GraphNode targetNode = targetNodes.GetClosestNode(_transform.position);

        if (targetNode == null)
        {
            return;
        }

        _aiPath.destination = (Vector3)targetNode.position;
    }
Esempio n. 30
0
 protected override void TargetNodesChanged()
 {
     if (TargetNodes.Any())
     {
         if (TargetNodes.Length > 1)
         {
             DepthOfEffect = 0;
         }
         else
         {
             CheckForInvalidColorData();
             var firstNode = TargetNodes.FirstOrDefault();
             if (firstNode != null && DepthOfEffect > firstNode.GetMaxChildDepth() - 1)
             {
                 DepthOfEffect = 0;
             }
         }
     }
     UpdateTargetingAttributes();
     TypeDescriptor.Refresh(this);
 }