Exemple #1
0
        public static bool GetIsAnimationChain(this CustomVariable variable)
        {
            Type runtimeType = variable.GetRuntimeType();

            return(runtimeType != null &&
                   runtimeType == typeof(string) && variable.SourceObjectProperty == "CurrentChainName");
        }
Exemple #2
0
        public static void FixEnumerationTypes(this CustomVariable customVariable)
        {
            if (customVariable.GetIsEnumeration() && customVariable.DefaultValue != null && customVariable.DefaultValue.GetType() == typeof(int))
            {
                Type  runtimeType = customVariable.GetRuntimeType();
                Array array       = Enum.GetValues(runtimeType);
                int   valueAsInt  = (int)customVariable.DefaultValue;


                try
                {
                    string name = Enum.GetName(runtimeType, valueAsInt);

                    foreach (object enumValue in array)
                    {
                        if (name == enumValue.ToString())
                        {
                            customVariable.DefaultValue = enumValue;
                            break;
                        }
                    }
                }
                catch (Exception e)
                {
                    throw new Exception("Could not set the integer value" + valueAsInt + "to an enumeration of type " + runtimeType.FullName);
                }
            }
        }
        public static bool GetShouldCustomVariableBeConvertedToType(MemberChangeArgs args, CustomVariable variable)
        {
            var runtimeType = variable.GetRuntimeType();

            return runtimeType != null && args.Value is string && !variable.GetIsFile() && variable.Type != "Color";
        }
        private void DefaultValueIncludeActivity(CustomVariable instance)
        {

            bool handled = false;

            if (instance.GetIsCsv())
            {
                if (instance.GetIsListCsv())
                {
                    handled = true;
                    var member = IncludeMember("Set CreatesDictionary to true to assign value", typeof(string),
                        (object sender, MemberChangeArgs args) => { },
                        () => { return null; },


                        null,
                        // Let's put this in the variables list
                        new Attribute[] { new CategoryAttribute("\t") });
                    member.IsReadOnly = true;
                }
            }


            if (!handled)
            {
                Type typeToPass = instance.GetRuntimeType();
                if (typeToPass == null)
                {
                    typeToPass = typeof(string);
                }

                var typeConverter =
                    instance.GetTypeConverter(CurrentElement);

                IncludeMember(
                    "DefaultValue",
                    typeToPass,
                    OnMemberChanged,
                    instance.GetValue,
                    typeConverter,
                    new Attribute[] { new CategoryAttribute("\t") });
            }
            else
            {
                ExcludeMember("DefaultValue");
            }
        }
Exemple #5
0
        public static TypeConverter GetTypeConverter(this CustomVariable customVariable, IElement containingElement, StateSave stateSave, FlatRedBall.Glue.Plugins.ExportedInterfaces.IGlueState glueState)
        {
            TypeConverter typeConverter = null;

            if (customVariable.GetIsVariableState())
            {
                typeConverter = new AvailableStates(
                    FacadeContainer.Self.GlueState.CurrentNamedObjectSave,
                    FacadeContainer.Self.GlueState.CurrentElement,
                    FacadeContainer.Self.GlueState.CurrentCustomVariable,
                    FacadeContainer.Self.GlueState.CurrentStateSave
                    );
            }
            else
            {
                Type runtimeType = customVariable.GetRuntimeType();

                if (runtimeType != null)
                {
                    if (runtimeType.IsEnum)
                    {
                        typeConverter = new EnumConverter(runtimeType);
                    }
                    else if (runtimeType == typeof(Color))
                    {
                        return(new AvailableColorTypeConverter());
                    }

                    else if ((runtimeType == typeof(string) || runtimeType == typeof(AnimationChainList)) &&
                             customVariable.SourceObjectProperty == "CurrentChainName")
                    {
                        typeConverter = new AvailableAnimationChainsStringConverter(customVariable, stateSave);
                    }
                    else if (customVariable.GetIsFile())
                    {
                        AvailableFileStringConverter converter = new AvailableFileStringConverter(containingElement);
                        converter.QualifiedRuntimeTypeName = runtimeType.FullName;
                        converter.ShowNewFileOption        = false;
                        converter.RemovePathAndExtension   = true;
                        typeConverter = converter;
                    }
                }
                else if (customVariable.GetIsCsv())
                {
                    if (FacadeContainer.Self.ProjectValues == null)
                    {
                        throw new NullReferenceException("The ProjectValues property in FAcadeContainer.Self.ProjectValues must be set before trying to get the CSV type converter for the variable " + customVariable.ToString());
                    }

                    ReferencedFileSave rfs = ObjectFinder.Self.GetAllReferencedFiles().FirstOrDefault(item =>
                                                                                                      item.IsCsvOrTreatedAsCsv && item.GetTypeForCsvFile() == customVariable.Type);

                    AvailableSpreadsheetValueTypeConverter converter = null;
                    if (rfs != null)
                    {
                        converter = new AvailableSpreadsheetValueTypeConverter(
                            FacadeContainer.Self.ProjectValues.ContentDirectory + rfs.Name, containingElement);
                    }
                    else
                    {
                        converter = new AvailableSpreadsheetValueTypeConverter(
                            FacadeContainer.Self.ProjectValues.ContentDirectory + customVariable.Type, containingElement);
                    }
                    converter.ShouldAppendFileName = true;

                    typeConverter = converter;
                }
                else if (customVariable.GetIsFile())
                {
                    // If we got here, that means that the
                    // CustomVariable is a file, but it doesn't
                    // have a System.Type, so it only knows its runtime
                    // type;
                    AvailableFileStringConverter converter = new AvailableFileStringConverter(containingElement);
                    converter.UnqualifiedRuntimeTypeName = customVariable.Type;
                    converter.ShowNewFileOption          = false;
                    converter.RemovePathAndExtension     = true;
                    typeConverter = converter;
                }
            }


            return(typeConverter);
        }
 internal static bool IsTypeFromCsv(CustomVariable customVariable)
 {
     return customVariable != null && customVariable.Type != null && customVariable.Type.Contains(".") &&
         customVariable.GetRuntimeType() == null
         ;
 }