public void ApplyUndo() { var lateBinder = LateBinder.GetInstance(Owner.GetType()); if (X.HasValue) { lateBinder.SetValue(Owner, "X", X.Value); } if (Y.HasValue) { lateBinder.SetValue(Owner, "Y", Y.Value); } if (Z.HasValue) { lateBinder.SetValue(Owner, "Z", Z.Value); } if (ScaleX.HasValue) { lateBinder.SetValue(Owner, "ScaleX", ScaleX.Value); } if (ScaleY.HasValue) { lateBinder.SetValue(Owner, "ScaleY", ScaleY.Value); } }
public object InstanceForElementRuntime(ElementRuntime elementRuntime) { if (elementRuntime == null) { return(null); } if (elementRuntime.AssociatedNamedObjectSave == null) { throw new Exception("The ElementRuntime does not have an associated NamedObject and it should"); } string nameToFind = elementRuntime.AssociatedNamedObjectSave.InstanceName; IElement containerIElement = ObjectFinder.Self.GetElementContaining(elementRuntime.AssociatedNamedObjectSave); string containerNameStripped = null; if (containerIElement is EntitySave) { containerNameStripped = containerIElement.Name.Substring("Entities/".Length); } else //Implied: if (containerIElement is ScreenSave) { containerNameStripped = containerIElement.Name.Substring("Screens/".Length); } ArrowElementSave container = ArrowState.Self.CurrentArrowProject.Elements.FirstOrDefault( item => item.Name == containerNameStripped); return(container.AllInstances.FirstOrDefault(item => LateBinder.GetInstance(item.GetType()).GetValue(item, "Name") as string == nameToFind)); }
public static UndoState FromObject(object recordFrom) { UndoState toReturn = new UndoState(); toReturn.Owner = recordFrom; var lateBinder = LateBinder.GetInstance(recordFrom.GetType()); object result; if (lateBinder.TryGetValue(recordFrom, "X", out result)) { toReturn.X = (float)result; } if (lateBinder.TryGetValue(recordFrom, "Y", out result)) { toReturn.Y = (float)result; } if (lateBinder.TryGetValue(recordFrom, "Z", out result)) { toReturn.Z = (float)result; } if (lateBinder.TryGetValue(recordFrom, "ScaleX", out result)) { toReturn.ScaleX = (float)result; } if (lateBinder.TryGetValue(recordFrom, "ScaleY", out result)) { toReturn.ScaleY = (float)result; } return(toReturn); }
private void MakeAllInvisible() { foreach (object visibleObject in mVisibleRepresentations.Values) { LateBinder.GetInstance(visibleObject.GetType()).SetValue(visibleObject, "Visible", false); } }
public ElementRuntime ElementRuntimeForArrowInstance(object instance, ElementRuntime container) { // todo: Add verification because we assume the current IElement contains a NOS for the instance string name = (string)LateBinder.GetInstance(instance.GetType()).GetValue(instance, "Name"); ElementRuntime contained = container.GetContainedElementRuntime(name); return(contained); }
private static void SetSavePositionsFromRelativeValues(PositionedObject whatToPullFromAsPo, object saveObject) { if (whatToPullFromAsPo.Parent != null) { var lateBinderInstance = LateBinder.GetInstance(saveObject.GetType()); lateBinderInstance.SetValue(saveObject, "X", whatToPullFromAsPo.RelativeX); lateBinderInstance.SetValue(saveObject, "Y", whatToPullFromAsPo.RelativeY); lateBinderInstance.SetValue(saveObject, "Z", whatToPullFromAsPo.RelativeZ); } }
public override void SetValue(object component, object value) { if (MemberChangeEvent != null) { MemberChangeEvent(null, new MemberChangeArgs { Owner = Instance, Member = this.Name, Value = value }); } else if (Instance != null) { LateBinder.GetInstance(Instance.GetType()).SetValue(Instance, this.Name, value); } }
public void ReactToMemberChange(object sender, MemberChangeArgs args) { if (MemberChange != null) { MemberChange(sender, args); } else { LateBinder.GetInstance(args.Owner.GetType()).SetValue(args.Owner, args.Member, args.Value); } if (AfterMemberChange != null) { AfterMemberChange(sender, args); } }
public UndoState GetDiff(object compareTo) { UndoState toReturn = new UndoState(); var lateBinder = LateBinder.GetInstance(compareTo.GetType()); object result = null; bool foundSomething = false; if (X.HasValue && lateBinder.TryGetValue(compareTo, "X", out result) && (float)result != X.Value) { toReturn.X = this.X; foundSomething = true; } if (Y.HasValue && lateBinder.TryGetValue(compareTo, "Y", out result) && (float)result != Y.Value) { toReturn.Y = this.Y; foundSomething = true; } if (Z.HasValue && lateBinder.TryGetValue(compareTo, "Z", out result) && (float)result != Z) { toReturn.Z = this.Z; foundSomething = true; } if (ScaleX.HasValue && lateBinder.TryGetValue(compareTo, "ScaleX", out result) && (float)result != ScaleX) { toReturn.ScaleX = this.ScaleX; foundSomething = true; } if (ScaleY.HasValue && lateBinder.TryGetValue(compareTo, "ScaleY", out result) && (float)result != ScaleY) { toReturn.ScaleY = this.ScaleY; foundSomething = true; } if (foundSomething) { toReturn.Owner = compareTo; return(toReturn); } else { return(null); } }
public override object GetValue(object component) { try { if (CustomGetMember != null) { return(CustomGetMember()); } else if (Instance != null) { return(LateBinder.GetInstance(Instance.GetType()).GetValue(Instance, this.Name)); } else { return(null); } } catch (Exception e) { int m = 3; return(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; } }
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 void UpdateToEmitter(Emitter currentEmitter) { #region Update All Visibility if (currentEmitter == null) { if (mCurrentVisibleRepresentation != null) { MakeAllInvisible(); mCurrentVisibleRepresentation = null; } } else { object shapeThatShouldBeVisible = mVisibleRepresentations[currentEmitter.AreaEmission]; if (shapeThatShouldBeVisible != ((object)mCurrentVisibleRepresentation)) { MakeAllInvisible(); object visibleRepresentation = mVisibleRepresentations[currentEmitter.AreaEmission]; LateBinder.GetInstance(visibleRepresentation.GetType()).SetValue(visibleRepresentation, "Visible", true); mCurrentVisibleRepresentation = mVisibleRepresentations[currentEmitter.AreaEmission] as PositionedObject; } } #endregion #region Update the current Shape's properties if (mCurrentVisibleRepresentation != null) { switch (currentEmitter.AreaEmission) { case Emitter.AreaEmissionType.Point: // We do nothing here since we're not showing anything break; case Emitter.AreaEmissionType.Cube: AxisAlignedCube asAxisAlignedCube = mCurrentVisibleRepresentation as AxisAlignedCube; asAxisAlignedCube.ScaleX = currentEmitter.ScaleX; asAxisAlignedCube.ScaleY = currentEmitter.ScaleY; asAxisAlignedCube.ScaleZ = currentEmitter.ScaleZ; asAxisAlignedCube.Position = currentEmitter.Position; break; case Emitter.AreaEmissionType.Rectangle: AxisAlignedRectangle asAxisAlignedRectangle = mCurrentVisibleRepresentation as AxisAlignedRectangle; asAxisAlignedRectangle.ScaleX = currentEmitter.ScaleX; asAxisAlignedRectangle.ScaleY = currentEmitter.ScaleY; asAxisAlignedRectangle.Position = currentEmitter.Position; break; } } #endregion }