Ejemplo n.º 1
0
 protected virtual void AddVariableToNos(NamedObjectSave toReturn, string memberName, object currentValue)
 {
     CustomVariableInNamedObject cvino = new CustomVariableInNamedObject();
     cvino.Member = memberName;
     cvino.Value = currentValue;
     toReturn.InstructionSaves.Add(cvino);
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Returns the value of a variable either set in the NamedObjectSave (if it is set there) or in the underlying Entity if not
        /// </summary>
        /// <param name="instance">The NamedObjectSave to get the variable from.</param>
        /// <param name="variableName">The name of the variable, such as "ScaleX"</param>
        /// <returns>The value of the variable in either the NamedObjectSave or underlying Entity.  Returns null if varible isn't found.</returns>
        public static object GetEffectiveValue(this NamedObjectSave instance, string variableName)
        {
            CustomVariableInNamedObject cvino = instance.GetCustomVariable(variableName);

            if (cvino == null || cvino.Value == null)
            {
                if (instance.SourceType == SourceType.Entity && !string.IsNullOrEmpty(instance.SourceClassType))
                {
                    EntitySave entitySave = ObjectFinder.Self.GetEntitySave(instance.SourceClassType);

                    if (entitySave != null)
                    {
                        CustomVariable variable = entitySave.GetCustomVariableRecursively(variableName);

                        if (variable != null)
                        {
                            return(variable.DefaultValue);
                        }
                    }
                }
            }
            else
            {
                return(cvino.Value);
            }
            return(null);
        }
Ejemplo n.º 3
0
        public static CustomVariableInNamedObject AddNewGenericInstructionFor(this NamedObjectSave instance, string member, Type type)
        {
            CustomVariableInNamedObject instructionSave = new CustomVariableInNamedObject();

            instructionSave.Value = null; // make it the default

            instructionSave.Type   = type.Name;
            instructionSave.Type   = TypeManager.ConvertToCommonType(instructionSave.Type);
            instructionSave.Member = member;
            // Create a new instruction

            instance.InstructionSaves.Add(instructionSave);
            return(instructionSave);
        }
Ejemplo n.º 4
0
        public CustomVariableInNamedObject SetVariableValue(string variableName, object value)
        {
            var instructionToSet = GetCustomVariable(variableName);

            if (instructionToSet == null)
            {
                instructionToSet        = new CustomVariableInNamedObject();
                instructionToSet.Member = variableName;
                this.InstructionSaves.Add(instructionToSet);
            }

            instructionToSet.Value = value;

            return(instructionToSet);
        }
Ejemplo n.º 5
0
        public static CustomVariableInNamedObject AddNewGenericInstructionFor(this NamedObjectSave instance, string member, Type type)
        {
            CustomVariableInNamedObject instructionSave = new CustomVariableInNamedObject();

            instructionSave.Value = null; // make it the default

            // April 2, 2018
            // This used to just assign type.Name, but that can cause ambiguity between
            // different systems like FRB's HorizontalAlignment and Gum's HorizontalAlignment,
            // so we need to have the values be fully qualified.
            //instructionSave.Type = type.Name;

            instructionSave.Type   = type.FullName;
            instructionSave.Type   = TypeManager.ConvertToCommonType(instructionSave.Type);
            instructionSave.Member = member;
            // Create a new instruction

            instance.InstructionSaves.Add(instructionSave);
            return(instructionSave);
        }
Ejemplo n.º 6
0
        private void HandleItemSelected(TreeNode selectedTreeNode)
        {
            NamedObjectSave namedObjectSave = null;

            if (selectedTreeNode != null)
            {
                namedObjectSave = selectedTreeNode.Tag as NamedObjectSave;
            }



            bool shouldShow = namedObjectSave != null;

            if (shouldShow)
            {
                shouldShow = namedObjectSave.SourceClassType == "Polygon";

            }

            if (shouldShow)
            {
                var instructions = namedObjectSave.GetInstructionFromMember("Points");

                if (instructions == null)
                {
                    instructions = new CustomVariableInNamedObject();
                    instructions.Member = "Points";
                    instructions.Value = new List<Vector2>();

                    namedObjectSave.InstructionSaves.Add(instructions);
                }

                mPointEditWindow.Data = instructions.Value as List<Vector2>;

                ShowTab();
            }
            else
            {
                HideTab();
            }
        }
Ejemplo n.º 7
0
        private static CustomVariableInNamedObject GetOrCreateInstruction(NamedObjectSave nos, string variableName)
        {
            foreach (var instruction in nos.InstructionSaves)
            {
                if (instruction.Member == variableName)
                {
                    return instruction;
                }
            }

            CustomVariableInNamedObject cvino = new CustomVariableInNamedObject();
            nos.InstructionSaves.Add(cvino);
            return cvino;
        }
 private bool IsVariableExposed(CustomVariableInNamedObject cvino, NamedObjectSave n)
 {
     
     return 
         // December 16, 2012 Victor Chelaru
         // I think that even if the NOS isn't
         // a Entity, the TypedMembers should still
         // have all properties shouldn't they?  It looks
         // like they do according to my tests...
         //n.SourceType != SourceType.Entity ||
         n.TypedMembers.FirstOrDefault(member => member.MemberName == cvino.Member) != null;
 }
		private void UpdateIElementVariable(ElementRuntime elementRuntime, string variableToUpdate)
		{
			IElement currentIElement = elementRuntime.AssociatedIElement;

			if (currentIElement != null)
			{
				bool exists = currentIElement.GetCustomVariable(variableToUpdate) != null;

				if (!exists)
				{

                    CustomVariable variable = new CustomVariable();
                    variable.Type = "float";
                    variable.Name = variableToUpdate;
                    currentIElement.CustomVariables.Add(variable);
					variable.DefaultValue = 0.0f;

					//Update the Save so you can see the newly added variables
					elementRuntime.AssociatedNamedObjectSave.UpdateCustomProperties();
				}
			}


            bool isFlatRedBallType = elementRuntime.AssociatedNamedObjectSave.SourceType == SourceType.FlatRedBallType;
            bool wasFound = false;
            //Update the saves to the new position

            object objectToGetValueFrom = elementRuntime;
            if(elementRuntime.DirectObjectReference != null)
            {
                objectToGetValueFrom = elementRuntime.DirectObjectReference;
            }

            try
            {
                foreach (InstructionSave instruction in elementRuntime.AssociatedNamedObjectSave.InstructionSaves)
                {
                    if (instruction.Member == variableToUpdate)
                    {
                        Type objectType = objectToGetValueFrom.GetType();
                        instruction.Value = (float)LateBinder.GetInstance(objectType).GetValue(objectToGetValueFrom, variableToUpdate);
                        wasFound = true;
                        break;
                    }
                }
            }
            catch (Exception e)
            {
                int m = 3;

            }



            if (!wasFound)
            {
                CustomVariableInNamedObject newVariable = new CustomVariableInNamedObject();
                newVariable.Member = variableToUpdate;

                Type objectType = objectToGetValueFrom.GetType();
                newVariable.Value = (float)LateBinder.GetInstance(objectType).GetValue(objectToGetValueFrom, variableToUpdate);


                newVariable.Type = "float";// assume this for now, change later if necessary
                elementRuntime.AssociatedNamedObjectSave.InstructionSaves.Add(newVariable);
                wasFound = true;
            }
		}
        public static CustomVariableInNamedObject AddNewGenericInstructionFor(this NamedObjectSave instance, string member, Type type)
        {
            CustomVariableInNamedObject instructionSave = new CustomVariableInNamedObject();
            instructionSave.Value = null; // make it the default

            instructionSave.Type = type.Name;
            instructionSave.Type = TypeManager.ConvertToCommonType(instructionSave.Type);
            instructionSave.Member = member;
            // Create a new instruction

            instance.InstructionSaves.Add(instructionSave);
            return instructionSave;
        }