private static VariableSave TryGetVariableFromStateOnInstance(InstanceSave instance, string variable, IEnumerable <StateSave> statesToPullFrom, string stateVariableName, StateSave fallbackState, List <StateSave> statesToLoopThrough)
        {
            VariableSave foundVariableSave = null;

            // Let's see if this is in a non-default state
            string thisState = null;

            foreach (var stateToPullFrom in statesToPullFrom)
            {
                var foundStateVariable = stateToPullFrom.GetVariableSave(instance.Name + "." + stateVariableName);
                if (foundStateVariable != null && foundStateVariable.SetsValue)
                {
                    thisState = foundStateVariable.Value as string;
                }
            }
            StateSave instanceStateToPullFrom = fallbackState;

            // if thisState is not null, then the state is being explicitly set, so let's try to get that state
            if (!string.IsNullOrEmpty(thisState) && statesToLoopThrough.Any(item => item.Name == thisState))
            {
                instanceStateToPullFrom = statesToLoopThrough.First(item => item.Name == thisState);
            }

            if (instanceStateToPullFrom != null)
            {
                // Eventually use the instanceBase's current state value
                foundVariableSave = instanceStateToPullFrom.GetVariableRecursive(variable);
            }
            return(foundVariableSave);
        }
        public static VariableSave GetVariableFromThisOrBase(this ElementSave element, string variable, bool forceDefault = false)
        {
            StateSave stateToPullFrom = element.DefaultState;

#if GUM
            if (element == SelectedState.Self.SelectedElement &&
                SelectedState.Self.SelectedStateSave != null &&
                !forceDefault)
            {
                stateToPullFrom = SelectedState.Self.SelectedStateSave;
            }
#endif
            return(stateToPullFrom.GetVariableRecursive(variable));
        }
        public VariableSave GetVariable(string variableName)
        {
            switch (ContainerType)
            {
            case VariableContainerType.InstanceSave:

                string instanceName = null;
                if (ElementStack.Count != 0)
                {
                    instanceName = ElementStack.Last().InstanceName;
                }

                bool onlyIfSetsValue = false;

#if DEBUG
                if (ElementStack.Count != 0)
                {
                    if (ElementStack.Last().Element == null)
                    {
                        throw new InvalidOperationException("The ElementStack contains an ElementWithState with no Element");
                    }
                }
#endif

                var found = mInstanceSave.GetVariableFromThisOrBase(ElementStack, this, variableName, false, onlyIfSetsValue);
                if (found != null && !string.IsNullOrEmpty(found.ExposedAsName))
                {
                    var allExposed = GetExposedVariablesForThisInstance(mInstanceSave, instanceName, ElementStack, variableName);
                    var exposed    = allExposed.FirstOrDefault();

                    if (exposed != null && exposed.Value != null)
                    {
                        found = exposed;
                    }
                }

                if (found == null || found.SetsValue == false || found.Value == null)
                {
                    onlyIfSetsValue = true;
                    found           = mInstanceSave.GetVariableFromThisOrBase(ElementStack, this, variableName, false, true);
                }

                return(found);

            case VariableContainerType.StateSave:
                return(mStateSave.GetVariableRecursive(variableName));
                //break;
            }
            throw new NotImplementedException();
        }
Esempio n. 4
0
        public void Test()
        {
            StateSave defaultState = mElementSaveCollection.Screen.DefaultState;

            object value = defaultState.GetValueRecursive("ButtonInstance.X");

            if (value == null)
            {
                throw new Exception("StateSave.GetValueRecursive is not properly returning values");
            }

            VariableSave variableSave = defaultState.GetVariableRecursive("ButtonInstance.X");

            if (variableSave == null)
            {
                throw new Exception("StateSave.GetVariableSaveRecursively is not finding values");
            }
        }
        public static object GetValueFromThisOrBase(this ElementSave element, string variable, bool forceDefault = false)
        {
            StateSave stateToPullFrom = element.DefaultState;

#if GUM
            if (element == SelectedState.Self.SelectedElement &&
                SelectedState.Self.SelectedStateSave != null &&
                !forceDefault)
            {
                stateToPullFrom = SelectedState.Self.SelectedStateSave;
            }
#endif
            VariableSave variableSave = stateToPullFrom.GetVariableRecursive(variable);
            if (variableSave != null)
            {
                return(variableSave.Value);
            }
            else
            {
                return(null);
            }
        }