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"); } }
// Made public for testing public static bool GetIfIsCsv(NamedObjectSave instance, string memberName) { bool isCsv = false; // Wait! Is this thing a CSV? If so, we just want to use the string value and not try to translate: if (instance.SourceType == SaveClasses.SourceType.Entity && !string.IsNullOrEmpty(instance.SourceClassType)) { EntitySave entity = ObjectFinder.Self.GetEntitySave(instance.SourceClassType); if (entity != null) { CustomVariable customVariable = entity.GetCustomVariableRecursively(memberName); // This may not actually be a CustomVariable, but instead could be an Object that is SetByContainer. // Therefore we should tolerate a null: if (customVariable != null) { isCsv = customVariable.GetIsCsv(); } } } return(isCsv); }
private static void GetObjectFromContainerAndNameEvaluate(object container, string memberName, CodeContext codeContext, ref object foundValue, ref bool wasFound) { if (container is CsvEntry) { foundValue = (container as CsvEntry).GetValue(memberName); } if (codeContext.VariableStack.Count == 0) { throw new Exception("codeContext doesn't have any entries. It needs to have at least one"); } int index = -1; codeContext.GetVariableInformation(memberName, out index); if (index != -1) { foundValue = codeContext.VariableStack[index][memberName]; wasFound = true; } if (wasFound == false && foundValue == null && container != null) { object instance = container; Type type = container.GetType(); if (container is Type) { instance = null; type = container as Type; } // First let's do reflection if (container is ElementRuntime && (container as ElementRuntime).DirectObjectReference != null) { ElementRuntime containerElementRuntime = container as ElementRuntime; if (LateBinder.GetInstance(containerElementRuntime.DirectObjectReference.GetType()).TryGetValue(containerElementRuntime.DirectObjectReference, memberName, out foundValue)) { // do nothing. wasFound = true; } } else { if (LateBinder.GetInstance(type).TryGetValue(instance, memberName, out foundValue)) { // do nothing. wasFound = true; } } if (foundValue == null && container is ElementRuntime) { ElementRuntime containerElementRuntime = container as ElementRuntime; IElement containerElement = (container as ElementRuntime).AssociatedIElement; foundValue = TryToGetStateCategoryFromElement(memberName, containerElement); if (foundValue == null) { foundValue = containerElementRuntime.GetContainedElementRuntime(memberName); } if (foundValue == null) { foundValue = containerElementRuntime.GetReferencedFileSaveRuntime(memberName); } if (foundValue == null && containerElement != null) { // Some values like X or Y are stored inside the element runtime // (because it actually stores those values locally). However, if // a value doesn't have an underlying value, CustomVariable variable = containerElementRuntime.GetCustomVariable(memberName, VariableGetType.AsExistsAtRuntime); //CustomVariable variable = containerElement.GetCustomVariableRecursively(memberName); if (variable != null) { if (variable.GetIsCsv()) { string rfsToLookFor = FileManager.RemoveExtension(variable.Type); foundValue = containerElementRuntime.GetReferencedFileSaveRuntime(rfsToLookFor); // if it's null, maybe it's a global file if (foundValue == null) { ReferencedFileSave rfs = ObjectFinder.Self.GetReferencedFileSaveFromFile(variable.Type); if (rfs != null) { foundValue = GluxManager.GlobalContentFilesRuntime.LoadReferencedFileSave(rfs, true, containerElement); } } if (foundValue != null) { foundValue = GetCsvEntryByRequiredKey(variable.DefaultValue as string, foundValue as RuntimeCsvRepresentation); // We have a RFS, so let's get values out of it } } else { foundValue = variable.DefaultValue; wasFound = true; } } } wasFound = foundValue != null; } else if (container is StateSaveCategory) { foundValue = (container as StateSaveCategory).States.FirstOrDefault(state => state.Name == memberName); wasFound = foundValue != null; } else if (container is IElement) { foundValue = TryToGetStateCategoryFromElement(memberName, container as IElement); } } if (wasFound == false && foundValue == null) { foundValue = ObjectFinder.Self.GetElementUnqualified(memberName); wasFound = foundValue != null; } if (wasFound == false && foundValue == null) { foundValue = TypeManager.GetTypeFromString(memberName); wasFound = foundValue != null; } }
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); } }
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; }
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; } }