Exemple #1
0
        public static StateSave GetStateThatVariableBelongsTo(CustomVariable variable, IElement element)
        {
            // We only loop through categories, not uncategorized States because a variable can't belong to an uncategorized state.
            // See update below for-loop
            foreach (StateSaveCategory category in element.StateCategoryList)
            {
                if (!category.SharesVariablesWithOtherCategories)
                {
                    // This doesn't share variables, so it may own the variable
                    foreach (StateSave stateSave in category.States)
                    {
                        if (stateSave.AssignsVariable(variable))
                        {
                            return(stateSave);
                        }
                    }
                }
            }

            // Update November 16, 2011
            // Yes variables can actually
            // belong to the no-category category
            foreach (StateSave stateSave in element.States)
            {
                if (stateSave.AssignsVariable(variable))
                {
                    return(stateSave);
                }
            }

            return(null);
        }
Exemple #2
0
        private void CreateContainerEntitySave()
        {
            mEntitySaveInstance = new NamedObjectSave();
            mEntitySaveInstance.InstanceName    = "StateEntityInstance";
            mEntitySaveInstance.SourceType      = SourceType.Entity;
            mEntitySaveInstance.SourceClassType = mEntitySave.Name;

            mDerivedSaveInstance = new NamedObjectSave();
            mDerivedSaveInstance.InstanceName    = "StateDerivedEntityInstance";
            mDerivedSaveInstance.SourceType      = SourceType.Entity;
            mDerivedSaveInstance.SourceClassType = mDerivedEntitySave.Name;

            mContainerEntitySave      = new EntitySave();
            mContainerEntitySave.Name = "StateEntityContainer";

            mContainerEntitySave.NamedObjects.Add(mEntitySaveInstance);
            mContainerEntitySave.NamedObjects.Add(mDerivedSaveInstance);


            mTunneledUncategorizedStateInContainer                      = new CustomVariable();
            mTunneledUncategorizedStateInContainer.Name                 = "TunneledUncategorizedStateVariable";
            mTunneledUncategorizedStateInContainer.SourceObject         = mEntitySaveInstance.InstanceName;
            mTunneledUncategorizedStateInContainer.SourceObjectProperty = mRenamedExposedUncategorizedStateVariable.Name;
            mContainerEntitySave.CustomVariables.Add(mTunneledUncategorizedStateInContainer);


            ObjectFinder.Self.GlueProject.Entities.Add(mContainerEntitySave);
        }
        void OnPropertyValueChanged(object s, PropertyValueChangedEventArgs e)
        {
            string propertyName = e.ChangedItem.Label;

            CustomVariable customVariable = null;



            if (mCurrentNos.SourceType == SourceType.Entity && !string.IsNullOrEmpty(mCurrentNos.SourceClassType))
            {
                IElement entitySave = ObjectFinder.Self.GetIElement(mCurrentNos.SourceClassType);
                customVariable = entitySave.GetCustomVariable(propertyName).Clone();
            }
            else
            {
                customVariable      = new CustomVariable();
                customVariable.Name = propertyName;
            }
            customVariable.DefaultValue = e.ChangedItem.Value;

            customVariable.Type = mCurrentNos.GetCustomVariable(propertyName).Type;
            mCurrentElementRuntime.SetCustomVariable(customVariable);

            if (mRuntimeOptions.ShouldSave)
            {
                GlueViewCommands.Self.GlueProjectSaveCommands.SaveGlux();
            }
        }
Exemple #4
0
        public static bool ShouldGenerateEventsForVariable(CustomVariable customVariable, IElement container)
        {
            // Victor Chelaru
            // August 17, 2013
            // I debated whether
            // static variables should
            // create events or not.  They
            // technically could, but that means
            // that the custom code events would have
            // to be modified when switching between static
            // and instance.  This could have some impacts on
            // GlueView code parsing, and it currently seems to
            // be something that is either rare or something which
            // has some pretty simple workarounds.  Therefore, I'm going
            // to say that only instance variables can create events.
            bool shouldGenerate = customVariable.CreatesEvent && !customVariable.IsShared;

            if (shouldGenerate && customVariable.DefinedByBase)
            {
                var baseContainers = ObjectFinder.Self.GetAllBaseElementsRecursively(container);

                foreach (var baseContainer in baseContainers)
                {
                    if (baseContainer.CustomVariables.Any(item => item.DefinedByBase == false && item.Name == customVariable.Name && item.CreatesEvent))
                    {
                        shouldGenerate = false;
                        break;
                    }
                }
            }

            return(shouldGenerate);
        }
        public void CustomVariable_Constructor_Sets_Properties()
        {
            var customVariable = new CustomVariable("name", "value");

            Assert.AreEqual("name", customVariable.Name);
            Assert.AreEqual("value", customVariable.Value);
        }
Exemple #6
0
        private static void MoveStateCategory(TreeNode nodeMoving, TreeNode targetNode)
        {
            if (targetNode.IsRootCustomVariablesNode() || targetNode.IsCustomVariable())
            {
                // The user drag+dropped a state category into the variables
                // Let's make sure that it's all in the same Element though:
                if (targetNode.GetContainingElementTreeNode() == nodeMoving.GetContainingElementTreeNode())
                {
                    StateSaveCategory category = nodeMoving.Tag as StateSaveCategory;

                    // expose a variable that exposes the category
                    CustomVariable customVariable = new CustomVariable();

                    if (category.SharesVariablesWithOtherCategories)
                    {
                        customVariable.Type = "VariableState";
                        customVariable.Name = "CurrentState";
                    }
                    else
                    {
                        customVariable.Type = category.Name;
                        customVariable.Name = "Current" + category.Name + "State";
                    }

                    IElement element = targetNode.GetContainingElementTreeNode().Tag as IElement;

                    element.CustomVariables.Add(customVariable);
                    GlueCommands.Self.GenerateCodeCommands.GenerateCurrentElementCode();

                    EditorLogic.CurrentElementTreeNode.UpdateReferencedTreeNodes();
                }
            }
        }
Exemple #7
0
        internal bool ApplyTo(EntitySave entity)
        {
            bool createdNewVariable = false;

            entity.Properties.SetValue(nameof(IsNetworkEntity), IsNetworkEntity);

            foreach (var variableVm in this.VariableList)
            {
                var matchingVariable = entity.GetCustomVariable(variableVm.Name);

                var isNetworkEntity = variableVm.IsChecked;

                // The network screen will show additional variables that may not be exposed as
                // variables in Glue, like velocity. In this case the user may enable these without
                // actually having variables. We'll add them...hopefully that doesn't cause problems...
                if (isNetworkEntity && matchingVariable == null)
                {
                    matchingVariable = new CustomVariable
                    {
                        Name = variableVm.Name,
                        Type = "float", // do we always assume this? It is the case for all PositionedObject values
                    };
                    createdNewVariable = true;
                    entity.CustomVariables.Add(matchingVariable);
                }

                if (matchingVariable != null)
                {
                    matchingVariable.Properties.SetValue(IsNetworkVariableProperty, isNetworkEntity);
                }
            }

            return(createdNewVariable);
        }
        public void UrchinUriBuilder_GetFinalCustomVariables_Selects_Correct_Final_Variables()
        {
            var analyticsClient = new UrchinAnalyticsClient();

            analyticsClient.SessionCustomVariables[0] = new CustomVariable("session-one-name", "session-one-value");
            analyticsClient.SessionCustomVariables[2] = new CustomVariable("session-three-name", "session-three-value");
            analyticsClient.VisitorCustomVariables[0] = new CustomVariable("Visitor-one-name", "Visitor-one-value");
            analyticsClient.VisitorCustomVariables[1] = new CustomVariable("Visitor-two-name", "Visitor-two-value");

            var activityScopedVariables = new CustomVariableSlots();

            activityScopedVariables[0] = new CustomVariable("activity-one-name", "activity-one-value");
            activityScopedVariables[1] = new CustomVariable("activity-two-name", "activity-two-value");
            activityScopedVariables[3] = new CustomVariable("activity-four-name", "activity-four-value");

            var final = analyticsClient.GetFinalCustomVariables(activityScopedVariables).ToDictionary(s => s.Slot);

            Assert.AreEqual(CustomVariableScope.Visitor, final[0].Scope);
            Assert.AreEqual(CustomVariableScope.Visitor, final[1].Scope);
            Assert.AreEqual(CustomVariableScope.Session, final[2].Scope);
            Assert.AreEqual(CustomVariableScope.Activity, final[3].Scope);

            Assert.AreEqual("Visitor-one-name", final[0].Variable.Name);
            Assert.AreEqual("Visitor-two-name", final[1].Variable.Name);
            Assert.AreEqual("session-three-name", final[2].Variable.Name);
            Assert.AreEqual("activity-four-name", final[3].Variable.Name);
        }
        private void CreateContainerEntitySave()
        {
            mContainerEntitySave      = new EntitySave();
            mContainerEntitySave.Name = "ContainerCustomVariableEntity";

            mBaseNosInContainer = new NamedObjectSave();
            mBaseNosInContainer.InstanceName    = mEntitySave.Name + "Instance";
            mBaseNosInContainer.SourceType      = SourceType.Entity;
            mBaseNosInContainer.SourceClassType = mEntitySave.Name;
            mContainerEntitySave.NamedObjects.Add(mBaseNosInContainer);

            CustomVariable customVariable = new CustomVariable();

            customVariable.Name                 = "TunneledCategorizedStateVariable";
            customVariable.SourceObject         = mBaseNosInContainer.InstanceName;
            customVariable.SourceObjectProperty = "CurrentStateCategoryState";
            customVariable.Type                 = "StateCategory";
            mContainerEntitySave.CustomVariables.Add(customVariable);

            mDerivedNosInContainer = new NamedObjectSave();
            mDerivedNosInContainer.InstanceName    = "DerivedNosInContainer";
            mDerivedNosInContainer.SourceType      = SourceType.Entity;
            mDerivedNosInContainer.SourceClassType = mDerivedEntitySave.Name;
            mDerivedNosInContainer.UpdateCustomProperties();
            mContainerEntitySave.NamedObjects.Add(mDerivedNosInContainer);


            ObjectFinder.Self.GlueProject.Entities.Add(mContainerEntitySave);
        }
Exemple #10
0
        private void CreateEntitySaves()
        {
            mEntitySave      = new EntitySave();
            mEntitySave.Name = "StateTestEntity";

            ObjectFinder.Self.GlueProject.Entities.Add(mEntitySave);

            CreateNamedObjectWithSetVariable();

            CreateEntityVariables();

            CreateEntitySaveState();

            mContainer      = new EntitySave();
            mContainer.Name = "StateTestContainerEntity";


            NamedObjectSave nos = new NamedObjectSave();

            nos.InstanceName    = mEntitySave.Name + "Instance";
            nos.SourceType      = SourceType.Entity;
            nos.SourceClassType = mEntitySave.Name;
            mContainer.NamedObjects.Add(nos);


            CustomVariable stateTunnel = new CustomVariable();

            stateTunnel.SourceObject         = nos.InstanceName;
            stateTunnel.SourceObjectProperty = "CurrentState";
            stateTunnel.Type = "VariableState";
            stateTunnel.Name = "StateTunnelVariable";
            mContainer.CustomVariables.Add(stateTunnel);

            CreateContainerEntityState();
        }
        public static IElement GetElementIfCustomVariableIsVariableState(CustomVariable customVariable, IElement saveObject)
        {
            if (customVariable.GetIsVariableState() && string.IsNullOrEmpty(customVariable.SourceObject))
            {
                return(saveObject);
            }
            else
            {
                NamedObjectSave sourceNamedObjectSave = saveObject.GetNamedObjectRecursively(customVariable.SourceObject);

                if (sourceNamedObjectSave != null)
                {
                    EntitySave sourceEntitySave = ObjectFinder.Self.GetEntitySave(sourceNamedObjectSave.SourceClassType);

                    if (sourceEntitySave != null &&
                        ((sourceEntitySave.States.Count != 0 && customVariable.SourceObjectProperty == "CurrentState") ||
                         sourceEntitySave.StateCategoryList.ContainsCategoryName(customVariable.Type))
                        )
                    {
                        return(sourceEntitySave);
                    }
                    else if (sourceEntitySave == null)
                    {
                        ScreenSave sourceScreenSave = ObjectFinder.Self.GetScreenSave(sourceNamedObjectSave.SourceClassType);

                        if (sourceScreenSave != null && sourceScreenSave.States.Count != 0 && customVariable.SourceObjectProperty == "CurrentState")
                        {
                            return(sourceScreenSave);
                        }
                    }
                }
                return(null);
            }
        }
        private void CreateEntitySave()
        {
            mEntitySave = ExposedVariableTests.CreateEntitySaveWithStates("CustomVariableEntity");
            mExposedStateInCategoryVariable              = new CustomVariable();
            mExposedStateInCategoryVariable.Name         = "CurrentStateCategoryState";
            mExposedStateInCategoryVariable.Type         = "StateCategory";
            mExposedStateInCategoryVariable.SetByDerived = true;
            mEntitySave.CustomVariables.Add(mExposedStateInCategoryVariable);

            mSetByDerivedVariable              = new CustomVariable();
            mSetByDerivedVariable.Type         = "float";
            mSetByDerivedVariable.Name         = "SomeVariable";
            mSetByDerivedVariable.SetByDerived = true;
            mEntitySave.CustomVariables.Add(mSetByDerivedVariable);

            mTextInBase = new NamedObjectSave();
            mTextInBase.InstanceName    = "TextObject";
            mTextInBase.SourceType      = SourceType.FlatRedBallType;
            mTextInBase.SourceClassType = "Text";
            mEntitySave.NamedObjects.Add(mTextInBase);


            CustomVariable customVariable = new CustomVariable();

            customVariable.Name                   = "TunneledDisplayText";
            customVariable.SourceObject           = mTextInBase.InstanceName;
            customVariable.SourceObjectProperty   = "DisplayText";
            customVariable.Type                   = "string";
            customVariable.OverridingPropertyType = "int";
            mEntitySave.CustomVariables.Add(customVariable);


            ObjectFinder.Self.GlueProject.Entities.Add(mEntitySave);
        }
Exemple #13
0
        private TreeNode FindCustomVariableInEntities(CustomVariable variable, TreeNodeCollection nodeCollection)
        {
            TreeNode foundNode = null;

            foreach (TreeNode treeNode in nodeCollection)
            {
                if (treeNode is EntityTreeNode)
                {
                    foundNode = ((EntityTreeNode)treeNode).GetTreeNodeFor(variable);
                    if (foundNode != null)
                    {
                        break;
                    }
                }
                else
                {
                    foundNode = FindCustomVariableInEntities(variable, treeNode.Nodes);
                    if (foundNode != null)
                    {
                        break;
                    }
                }
            }
            return(foundNode);
        }
Exemple #14
0
        private object Convert(object whatToConvert, CustomVariable variable)
        {
            // early out:
            if (whatToConvert == null)
            {
                return(null);
            }

            switch (variable.Type)
            {
            case "float":
                return(System.Convert.ToSingle(whatToConvert.ToString(), CultureInfo.InvariantCulture));

            case "int":
                return(System.Convert.ToInt32(whatToConvert.ToString()));

            case "bool":
                return(System.Convert.ToBoolean(whatToConvert.ToString()));

            case "long":
                return(System.Convert.ToInt64(whatToConvert.ToString()));

            case "double":
                return(System.Convert.ToDouble(whatToConvert.ToString(), CultureInfo.InvariantCulture));

            case "byte":
                return(System.Convert.ToByte(whatToConvert.ToString()));

            default:
                return(whatToConvert);
            }
        }
        internal void PopulateWithReferencesTo(CustomVariable customVariable, IElement container)
        {
            foreach (var state in container.AllStates)
            {
                if (state.InstructionSaves.Any(instruction => instruction.Member == customVariable.Name))
                {
                    listBox1.Items.Add(state);
                }
            }

            var derivedElements = ObjectFinder.Self.GetAllElementsThatInheritFrom(container);

            foreach (var element in derivedElements)
            {
                foreach (var variable in element.CustomVariables.Where(item => item.DefinedByBase && item.Name == customVariable.Name))
                {
                    listBox1.Items.Add(variable);
                }
            }

            foreach (var ers in container.GetEventsOnVariable(customVariable.Name))
            {
                listBox1.Items.Add(ers);
            }
        }
        public void TestRegularVisibility()
        {
            CustomVariable visibleVariable = mEntitySave.GetCustomVariable("Visible");

            mElementRuntime.SetCustomVariable(visibleVariable, mElementRuntime.AssociatedIElement, false, false);


            ElementRuntime containedElementRuntime = mElementRuntime.ContainedElements[0] as ElementRuntime;

            Sprite sprite = containedElementRuntime.DirectObjectReference as Sprite;

            if (sprite.AbsoluteVisible)
            {
                throw new Exception("Sprite is visible, but it is part of an element runtime that isn't, so it shouldn't be");
            }


            sprite.Visible = false;
            mElementRuntime.SetCustomVariable(visibleVariable, mElementRuntime.AssociatedIElement, true, false);

            if (sprite.Visible)
            {
                throw new Exception("The Sprite should still have a relative Visibility of true, even though the parent is false");
            }

            sprite.Visible = true;
            if (!sprite.AbsoluteVisible)
            {
                throw new Exception("The Sprite should be visible now!");
            }
        }
Exemple #17
0
 public AvailableStates(NamedObjectSave currentNamedObject, IElement currentElement, CustomVariable currentCustomVariable, StateSave currentStateSave) : base()
 {
     CurrentNamedObject    = currentNamedObject;
     CurrentElement        = currentElement;
     CurrentCustomVariable = currentCustomVariable;
     CurrentStateSave      = currentStateSave;
 }
Exemple #18
0
        public static void RemoveCustomVariable(CustomVariable customVariable, List <string> additionalFilesToRemove)
        {
            // additionalFilesToRemove is added to keep this consistent with other remove methods

            IElement element = ObjectFinder.Self.GetElementContaining(customVariable);

            if (element == null || !element.CustomVariables.Contains(customVariable))
            {
                throw new ArgumentException();
            }
            else
            {
                element.CustomVariables.Remove(customVariable);
                element.RefreshStatesToCustomVariables();

                List <EventResponseSave> eventsReferencedByVariable = element.GetEventsOnVariable(customVariable.Name);

                foreach (EventResponseSave ers in eventsReferencedByVariable)
                {
                    element.Events.Remove(ers);
                }
            }
            UpdateCurrentTreeNodeAndCodeAndSave();

            UpdateAllDerivedElementFromBaseValues(true);

            PluginManager.ReactToVariableRemoved(customVariable);
        }
Exemple #19
0
        private void HandleScopeSet(CustomVariable customVariable, object oldValue)
        {
            var owner = GlueState.Self.CurrentElement;

            var newScope = customVariable.Scope;

            SetDerivedElementVariables(owner, customVariable.Name, newScope);
        }
 public static void SetDefaultValueFor(CustomVariable customVariable, IElement element)
 {
     object defaultValue = GetDefaultValueFor(customVariable, element);
     if(defaultValue != null)
     {
         customVariable.DefaultValue = defaultValue;
     }
 }
        public AvailableAnimationChainsStringConverter(CustomVariable customVariable, StateSave stateSave = null)
        {
            IElement element = ObjectFinder.Self.GetVariableContainer(customVariable);

            NamedObjectSave referencedNos = element.GetNamedObjectRecursively(customVariable.SourceObject);

            Initialize(element, referencedNos, stateSave);
        }
Exemple #22
0
        public void TestRelativeAbsoluteConversion()
        {
            NamedObjectSave nos = new NamedObjectSave();

            nos.SourceType      = SourceType.FlatRedBallType;
            nos.SourceClassType = "Sprite";
            nos.UpdateCustomProperties();
            nos.InstanceName = "SpriteObject";
            nos.SetPropertyValue("ScaleX", 2.0f);
            nos.SetPropertyValue("X", 4.0f);
            nos.SetPropertyValue("RotationZ", 4.0f);
            nos.SetPropertyValue("RotationZVelocity", 4.0f);

            mEntitySave.NamedObjects.Add(nos);

            CustomVariable customVariable = new CustomVariable();

            customVariable.SourceObject         = nos.InstanceName;
            customVariable.SourceObjectProperty = "ScaleY";
            customVariable.DefaultValue         = 8.0f;

            mEntitySave.CustomVariables.Add(customVariable);

            ElementRuntime elementRuntime = new ElementRuntime();

            elementRuntime.Initialize(mEntitySave, null, null, null, null);

            Sprite sprite = elementRuntime.ContainedElements[0].DirectObjectReference as Sprite;

            sprite.ForceUpdateDependencies();

            if (elementRuntime.X != 0)
            {
                throw new Exception("NOS variables are being applied to the container instead of just to the NOS");
            }

            if (sprite.X != 4.0f)
            {
                throw new Exception("Absolute values should get set when setting X on objects even though they're attached");
            }

            if (sprite.RotationZ != 4.0f)
            {
                throw new Exception("Absolute values should get set when setting RotationZ on objects even though they're attached");
            }
            if (sprite.RelativeRotationZVelocity != 4.0f)
            {
                throw new Exception("Setting RotationZVelocity should set RelativeRotationZVelocity");
            }
            if (sprite.ScaleX != 2.0f)
            {
                throw new Exception("Scale values aren't properly showing up on Sprites");
            }
            if (sprite.ScaleY != 8.0f)
            {
                throw new Exception("Scale values aren't properly showing up on Sprites");
            }
        }
Exemple #23
0
        public void ScopedCustomVariable_Constructor_Sets_Properties()
        {
            var customVariable           = new CustomVariable("name3", "value3");
            var scopedCustomVariableSlot = new ScopedCustomVariableSlot(CustomVariableScope.Session, customVariable, 3);

            Assert.AreEqual(CustomVariableScope.Session, scopedCustomVariableSlot.Scope);
            Assert.AreEqual(3, scopedCustomVariableSlot.Slot);
            Assert.AreEqual(customVariable, scopedCustomVariableSlot.Variable);
        }
        public static void SetDefaultValueFor(CustomVariable customVariable, IElement element)
        {
            object defaultValue = GetDefaultValueFor(customVariable, element);

            if (defaultValue != null)
            {
                customVariable.DefaultValue = defaultValue;
            }
        }
Exemple #25
0
        public void CustomVariableSlots_Indexer_Sets_Slot()
        {
            var slots   = new CustomVariableSlots();
            var slotOne = new CustomVariable("one", "1");

            slots[1] = slotOne;

            Assert.AreEqual(slotOne, slots[1]);
        }
        public void TestMethodCallParser()
        {
            CustomVariable variable = MethodCallParser.GetCustomVariableFromNosOrElement(mParentElementRuntime.ContainedElements[0], "CsvTypeVariable");

            if (variable == null || variable.DefaultValue == null)
            {
                throw new Exception("The MethodCallParser is not properly finding values on NamedObjects");
            }
        }
        public void Update(string containerName, CustomVariable customVariable)
        {
            var container  = ObjectFinder.Self.GetIElement(containerName);
            var currentNos = container.GetCustomVariableRecursively(customVariable.Name);

            CopyObject(customVariable, currentNos);
            RefreshElement(container);
            //GlueCommand.GluxCommands.SaveGlux();
        }
Exemple #28
0
        private static ICodeBlock AssignValuesUsingStartingValues(IElement element, ICodeBlock curBlock, Dictionary <InstructionSave, InterpolationCharacteristic> mInterpolationCharacteristics)
        {
            foreach (KeyValuePair <InstructionSave, InterpolationCharacteristic> kvp in mInterpolationCharacteristics)
            {
                if (kvp.Value != InterpolationCharacteristic.CantInterpolate)
                {
                    curBlock = curBlock.If("set" + kvp.Key.Member);

                    CustomVariable variable = element.GetCustomVariable(kvp.Key.Member);
                    var            nos      = element.GetNamedObjectRecursively(variable.SourceObject);

                    if (nos != null)
                    {
                        NamedObjectSaveCodeGenerator.AddIfConditionalSymbolIfNecesssary(curBlock, nos);
                    }

                    string relativeValue = InstructionManager.GetRelativeForAbsolute(kvp.Key.Member);

                    string variableToAssign = kvp.Key.Member;


                    string leftSideOfEqualsWithRelative = GetLeftSideOfEquals(element, variable, kvp.Key, true);

                    if (!string.IsNullOrEmpty(leftSideOfEqualsWithRelative) && leftSideOfEqualsWithRelative != kvp.Key.Member)
                    {
                        string beforeDotParent = variable.SourceObject;

                        if (string.IsNullOrEmpty(variable.SourceObject))
                        {
                            beforeDotParent = "this";
                        }

                        curBlock = curBlock.If(beforeDotParent + ".Parent != null");



                        AddAssignmentForInterpolationForVariable(curBlock, variable, variableToAssign, leftSideOfEqualsWithRelative);
                        curBlock = curBlock.End().Else();
                    }

                    AddAssignmentForInterpolationForVariable(curBlock, variable, variableToAssign, variableToAssign);

                    if (!string.IsNullOrEmpty(relativeValue))
                    {
                        curBlock = curBlock.End(); // end the else
                    }

                    curBlock = curBlock.End();
                    if (nos != null)
                    {
                        NamedObjectSaveCodeGenerator.AddEndIfIfNecessary(curBlock, nos);
                    }
                }
            }
            return(curBlock);
        }
Exemple #29
0
        internal static void TryGenerateEventsForVariable(ICodeBlock codeBlock, CustomVariable customVariable, IElement container)
        {
            var shouldGenerate = ShouldGenerateEventsForVariable(customVariable, container);

            // Currently we don't support events on static variables
            if (shouldGenerate)
            {
                EventCodeGenerator.GenerateEventsForVariable(codeBlock, customVariable.Name);
            }
        }
        private bool GetIfCanBeRenamed(CustomVariable customVariable)
        {
            if (customVariable.GetIsVariableState())
            {
                return(false);
            }


            return(true);
        }
Exemple #31
0
        private TiledObjectTypePropertySave CreatePropertySaveFrom(CustomVariable variable)
        {
            var toReturn = new TiledObjectTypePropertySave();

            toReturn.name            = variable.Name;
            toReturn.Type            = GetTmxFriendlyType(variable.Type);
            toReturn.DefaultAsString = GetTmxFriendlyValue(variable.DefaultValue?.ToString(), variable.Type);

            return(toReturn);
        }
        public static InterpolationCharacteristic GetInterpolationCharacteristic(CustomVariable customVariable, IElement container)
        {
            string variableType = null;
            if (customVariable != null)
            {
                if (!string.IsNullOrEmpty(customVariable.OverridingPropertyType))
                {
                    variableType = customVariable.OverridingPropertyType;
                }
                else
                {
                    variableType = customVariable.Type;
                }
            }


            if (customVariable != null && customVariable.GetIsVariableState(container))
            {
                return InterpolationCharacteristic.CanInterpolate;
            }

            if (customVariable == null ||
                variableType == null ||
                variableType == "string" ||
                variableType == "bool" ||
                variableType == "Color" ||
                customVariable.GetIsFile() ||
                customVariable.GetIsCsv() ||
                (customVariable.GetRuntimeType() != null && customVariable.GetRuntimeType().IsEnum)
                )
            {
                return InterpolationCharacteristic.CantInterpolate;
            }

            string velocityMember = null;

            if(!string.IsNullOrEmpty(customVariable.SourceObject))
            {
                velocityMember = FlatRedBall.Instructions.InstructionManager.GetVelocityForState(customVariable.SourceObjectProperty);
            }
            else
            {
                velocityMember = FlatRedBall.Instructions.InstructionManager.GetVelocityForState(customVariable.Name);

            }
            if (!string.IsNullOrEmpty(velocityMember))
            {
                // There's a velocity variable for this, but we need to make sure
                // it's actually available
                var exposableMembers = ExposedVariableManager.GetExposableMembersFor(container, false);

                if (exposableMembers.Any(item=>item.Member ==velocityMember))
                {
                    return InterpolationCharacteristic.CanInterpolate;
                }
            }            
            
            // December 26, 2013
            // This used to not pass
            // a value for maxDepth which
            // means a maxDepth of 0.  Not
            // sure why, but we do want to look
            // at tunneling at any depth.
            int maxDepth = int.MaxValue;
            if(customVariable.HasAccompanyingVelocityConsideringTunneling(container, maxDepth) )
            {
                return InterpolationCharacteristic.CanInterpolate;
            }

            else
            {
                return InterpolationCharacteristic.NeedsVelocityVariable;
            }


        }
        public static bool IsStateMissingFor(CustomVariable customVariable, IElement container)
        {
            // We can't use the CustomVariable's check because
            // the state may not exist.  Therefore we have to look
            // at the properties and determine if it should be associated
            // with a state.
            bool isState = IsCustomVariableReferencingState(customVariable);
            if (isState)
            {
                // This variable is an exposed state, so let's make sure the state exists for it
                StateSaveCategory existingCategory = null;
                if (customVariable.Type == "VariableState")
                {
                    if (container.States.Count != 0)
                    {
                        return false;
                    }
                    else if (container.StateCategoryList.FirstOrDefault(category => category.SharesVariablesWithOtherCategories == true) != null)
                    {
                        return false;
                    }
                    else
                    {
                        return true;
                    }
                }
                else
                {
                    bool returnValue = container.StateCategoryList.FirstOrDefault(
                        category => 
                            category.SharesVariablesWithOtherCategories == false && 
                            category.Name == customVariable.Type) == null;

                    return returnValue;
                }
            }
            else
            {
                return false;
            }

        }
        private static object GetDefaultValueFor(CustomVariable customVariable, IElement element)
        {
            object valueToReturn = null;

            // Lets handle all file types here:
            //if (customVariable.Type == "Texture2D")
            if(customVariable.GetIsFile())
            {
                // If we don't return 
                // null then this will
                // return the name of the
                // file (like "redball.bmp").
                // This will screw up code generation
                // because texture variables can only be
                // set to Texture2D instances, not to the
                // name of the image.
                valueToReturn = null;
            }
            else
            {



                try
                {
                    if (!string.IsNullOrEmpty(customVariable.SourceObject) && !string.IsNullOrEmpty(customVariable.SourceObjectProperty))
                    {
                        NamedObjectSave nos = element.GetNamedObjectRecursively(customVariable.SourceObject);

                        if (nos != null)
                        {
                            object defaultValue = GetDefaultValueFor(nos, customVariable.SourceObjectProperty, customVariable.OverridingPropertyType);

                            valueToReturn = defaultValue;
                        }
                    }
                    else if (customVariable.Name == "Visible" && element is EntitySave && ((EntitySave)element).ImplementsIVisible)
                    {
                        // This shouldn't be true, we don't want to set the value
                        // because we don't want to kick off events
                        //valueToReturn = true;
                        valueToReturn = null;
                    }
                    else if (customVariable.Name == "Enabled" && element is EntitySave && ((EntitySave)element).ImplementsIWindow)
                    {
                        // This shouldn't be true, we don't want to set the value
                        // because we don't want to kick off events
                        //valueToReturn = true;
                        valueToReturn = null;
                    }
                    else
                    {

                        valueToReturn = GetDefaultValueForPropertyInType(customVariable.Name, "PositionedObject");
                    }
                }
                catch
                {
                    // do nothing.
                }

                if (valueToReturn is Microsoft.Xna.Framework.Color)
                {
                    string standardName =
                        AvailableColorTypeConverter.GetStandardColorNameFrom((Color)valueToReturn);

                    if (string.IsNullOrEmpty(standardName))
                    {
                        return "Red";
                    }
                    else
                    {
                        return standardName;
                    }
                }
            }
            return valueToReturn;
        }
        private static bool IsCustomVariableReferencingState(CustomVariable customVariable)
        {
            bool toReturn = string.IsNullOrEmpty(customVariable.SourceObject) &&
                TypeManager.GetTypeFromString(customVariable.Type) == null &&
                !customVariable.GetIsCsv() &&
                customVariable.Name.StartsWith("Current") &&
                customVariable.Name.EndsWith("State");

            return toReturn;
        }
Exemple #36
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="customVariable"></param>
 public static void Delete( CustomVariable customVariable )
 {
     Data.DeleteObject<CustomVariable>( customVariable );
 }
Exemple #37
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="customVariable"></param>
 public static void Save( CustomVariable customVariable )
 {
     Data.SaveObject<CustomVariable>( customVariable );
 }
        public void SaveCustomVariable( CustomVariable customVariable )
        {
            customVariable.TaskGroupId = this.TaskGroupId;

            CustomVariableLogic.Save( customVariable );

            // Refresh the list
            this.CustomVariables = new ObservableCollection<CustomVariable>( CustomVariableLogic.GetCustomVariablesByGroupId( this.TaskGroupId ) );

            ObservableCollection<CustomVariable> customVariables = new ObservableCollection<CustomVariable>();
            customVariables.Add( customVariable );
            SelectedCustomVariables = customVariables;
        }