private void ReactToAnimationChainSet(NamedObjectSave namedObjectSave, object oldValue) { AvailableAnimationChainsStringConverter aacsc = new AvailableAnimationChainsStringConverter( GlueState.Self.CurrentElement, namedObjectSave); var customVariable = namedObjectSave.GetCustomVariable("CurrentChainName"); string currentChain = null; if (customVariable != null) { currentChain = customVariable.Value as string; } if (!aacsc.AvailableChains.Contains(currentChain)) { if (aacsc.AvailableChains.Length == 0) { namedObjectSave.SetPropertyValue("CurrentChainName", null); } else { namedObjectSave.SetPropertyValue("CurrentChainName", aacsc.AvailableChains[0]); } } }
private TypeConverter HandleGetTypeConverter(IElement container, NamedObjectSave instance, TypedMemberBase typedMember) { Type memberType = typedMember.MemberType; string memberName = typedMember.MemberName; TypeConverter typeConverter = null; // If the NOS references a FRB type, we need to adjust the type appropriately bool wasTypeModified = false; Type oldType = memberType; bool handled = false; if (instance.SourceType == SourceType.FlatRedBallType) { Type type = TypeManager.GetTypeFromString(instance.SourceClassType); if (type == typeof(Sprite) && memberName == "CurrentChainName") { // special case handling for CurrentChainName typeConverter = new AvailableAnimationChainsStringConverter(container, instance); handled = true; } // Victor Chelaru // October 26, 2015: // I don't think we need this anymore - we should just let the CSVs do their job // defining variables and not rely on reflection. That way plugins will be able to // handle everything without relying on reflection //if (!handled && type != null) //{ // FieldInfo fieldInfo = type.GetField(memberName); // if (fieldInfo != null) // { // memberType = fieldInfo.FieldType; // wasTypeModified = true; // } // if (wasTypeModified == false) // { // PropertyInfo propertyInfo = type.GetProperty(memberName); // if (propertyInfo != null) // { // memberType = propertyInfo.PropertyType; // wasTypeModified = true; // } // } //} } else if (instance.SourceType == SourceType.File) { if (instance.ClassType == "Sprite" && memberName == "CurrentChainName") { // special case handling for CurrentChainName typeConverter = new AvailableAnimationChainsStringConverter(container, instance); handled = true; } } if (!handled) { if (instance.DoesMemberNeedToBeSetByContainer(memberName)) { typeConverter = new AvailableNamedObjectsAndFiles(container); } else if (memberType.IsEnum) { typeConverter = new EnumConverter(memberType); } else if (memberType == typeof(Microsoft.Xna.Framework.Color)) { typeConverter = new AvailableColorTypeConverter(); memberType = typeof(string); } else if (IsTypeFile(typedMember)) { AvailableFileStringConverter availableFileStringConverter = new AvailableFileStringConverter(container); availableFileStringConverter.QualifiedRuntimeTypeName = memberType.FullName; if(!string.IsNullOrEmpty( typedMember.CustomTypeName )) { availableFileStringConverter.QualifiedRuntimeTypeName = typedMember.CustomTypeName; } availableFileStringConverter.RemovePathAndExtension = true; typeConverter = availableFileStringConverter; memberType = typeof(string); } else if (instance.SourceType == SourceType.Entity && !string.IsNullOrEmpty(instance.SourceClassType)) { EntitySave entity = ObjectFinder.Self.GetEntitySave(instance.SourceClassType); if (entity != null) { CustomVariable customVariable = entity.GetCustomVariable(memberName); if (customVariable != null) { typeConverter = customVariable.GetTypeConverter(entity); } } } } //else if (this.SourceType == SaveClasses.SourceType.FlatRedBallType && // typedMember != null && typedMember.MemberType != null) //{ //} if (wasTypeModified) { memberType = oldType; } return typeConverter; }
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; }