Exemplo n.º 1
0
        public virtual List <IIntentState> Combine(List <IIntentState> states)
        {
            StateCombinatorValue.Clear();
            //TODO consider layers and may not need to iterate all of them. Need them in a sorted order by layer
            foreach (var intentState in states)
            {
                intentState.Dispatch(this);
            }

            return(StateCombinatorValue);
        }
Exemplo n.º 2
0
 public virtual void Handle(IIntentState <CommandValue> obj)
 {
     StateCombinatorValue.Add(obj);
 }
Exemplo n.º 3
0
 public virtual void Handle(IIntentState <PositionValue> obj)
 {
     StateCombinatorValue.Add(obj);
 }
Exemplo n.º 4
0
        public override List <IIntentState> Combine(List <IIntentState> states)
        {
            //Reset our return type and check to see if we really have anything to combine.
            //If we have one or none we can skip all the complex stuff
            if (states.Count <= 1)
            {
                if (states.Count == 1 && states[0].Layer.RequiresMixingPartner)
                {
                    return(EmptyState);
                }
                return(states);
            }

            if (states.All(x => x.Layer.RequiresMixingPartner))
            {
                return(EmptyState);
            }

            //Reset all our temp variables
            StateCombinatorValue.Clear();
            _tempMixingColor     = null;
            _combinedMixingColor = null;

            //Order all states in decending order by layer
            //We are going to do this without Linq because it is way more memory efficient
            states.Sort(LayerComparer);

            //Establish the top level layer
            var currentLayer          = states[0].Layer;
            ILayerMixingFilter filter = null;

            //Walk through the groups of layers and process them
            foreach (var state in states)
            {
                //Iterate the states in the layer
                if (state.Layer.LayerLevel == currentLayer.LayerLevel)
                {
                    //Dispatch each state to the Handle method for its type to combine down to one state
                    //per layer in a mixing fashion
                    state.Dispatch(this);
                    continue;
                }

                //We have a new layer so we need to wrap up the previous one
                MixLayers(filter);
                filter = currentLayer.LayerMixingFilter;
                state.Dispatch(this);
                currentLayer = state.Layer;
            }

            //Mix the final layer

            MixLayers(filter);

            //Now we should be down to one mixing type and we can put that in our return obejct as a RGBValue.
            //This will convert all mxing types to the simpler more efficient RGBValue
            if (_combinedMixingColor != null)
            {
                _mixedIntentState.SetValue(new RGBValue(_combinedMixingColor.Value));
                StateCombinatorValue.Add(_mixedIntentState);
            }

            //Do the same for the discrete types. Here we should be down to one per color and we return these as Discrete values
            //so we can maintatin the source color and an intensity
            if (_combinedDiscreteColors?.Count > 0)
            {
                foreach (var combinedDiscreteColor in _combinedDiscreteColors)
                {
                    StateCombinatorValue.Add(new StaticIntentState <DiscreteValue>(combinedDiscreteColor.Value));
                }
                _combinedDiscreteColors.Clear();
            }

            return(StateCombinatorValue);
        }