void CreateContainerElementRuntime() { EntitySave containerEntitySave = new EntitySave { Name = "ContainerVariableSetting" }; ObjectFinder.Self.GlueProject.Entities.Add(containerEntitySave); NamedObjectSave nos = new NamedObjectSave(); nos.SourceType = SourceType.Entity; nos.InstanceName = mEntitySave.Name + "Instance"; nos.SourceClassType = mEntitySave.Name; containerEntitySave.NamedObjects.Add(nos); nos.UpdateCustomProperties(); nos.SetPropertyValue("CurrentStateSaveCategoryState", "SecondState"); mContainedElementRuntime = new ElementRuntime(); mContainedElementRuntime.Initialize(containerEntitySave, null, null, null, null); // This thing is attached - we need to check its relativeX //if (mContainedElementRuntime.ContainedElements[0].X != -10.0f) if (mContainedElementRuntime.ContainedElements[0].RelativeX != -10.0f) { throw new Exception("Categorized states on contained NamedObjectSave Elements aren't setting values properly"); } }
public EntityTreeNode EntityTreeNode(EntitySave entitySave) { // Vic says: I don't know why I had code duplication here, but let's fix it: //return GetEntityTreeNode(entitySave.Name); // Vic says: Update on Sept. 13 2010 - Turns out that the GetEntityTreeNode call above uses the name. But this one // does an actual comparison between the EntitySave referenced by the tree node so it doesn't depend // on the Entity's name. Very important when doing renaming! string containingDirectory = FileManager.MakeRelative(FileManager.GetDirectory(entitySave.Name)); TreeNode treeNodeToAddTo = GlueState.Self.Find.TreeNodeForDirectoryOrEntityNode(containingDirectory.Substring("Entities/".Length), ElementViewWindow.EntitiesTreeNode); for (int i = 0; i < treeNodeToAddTo.Nodes.Count; i++) { if (treeNodeToAddTo.Nodes[i] is EntityTreeNode) { EntityTreeNode asEntityTreeNode = treeNodeToAddTo.Nodes[i] as EntityTreeNode; if (asEntityTreeNode.EntitySave == entitySave) { return(asEntityTreeNode); } } } return(null); }
private void GenerateIgnoresParentVisibility(ICodeBlock codeBlock, EntitySave entitySave) { if (!entitySave.GetInheritsFromIVisible()) { codeBlock.AutoProperty("public bool", "IgnoresParentVisibility"); } }
private TreeNode MoveEntityOntoElement(EntityTreeNode treeNodeMoving, TreeNode targetNode, TreeNode newTreeNode) { EntitySave entitySaveMoved = treeNodeMoving.EntitySave; #region Get the IElement elementToCreateIn IElement elementToCreateIn = null; if (targetNode.IsRootNamedObjectNode()) { BaseElementTreeNode baseElementTreeNode = targetNode.Parent as BaseElementTreeNode; elementToCreateIn = baseElementTreeNode.SaveObject; } else { elementToCreateIn = ((BaseElementTreeNode)targetNode).SaveObject; } #endregion // We used to ask the user if they're sure, but this isn't a destructive action so just do it: //DialogResult result = // MessageBox.Show("Create a new Object in\n\n" + elementToCreateIn.Name + "\n\nusing\n\n\t" + entitySaveMoved.Name + "?", "Create new Object?", MessageBoxButtons.YesNo); NamedObjectSave newNamedObject = CreateNewNamedObjectInElement(elementToCreateIn, entitySaveMoved); newTreeNode = GlueState.Self.Find.NamedObjectTreeNode(newNamedObject); return(newTreeNode); }
private static void GenerateCsv(EntitySave entity, TopDownEntityViewModel viewModel) { TaskManager.Self.Add( () => CsvGenerator.Self.GenerateFor(entity, viewModel), "Generating Top Down CSV for " + entity.Name); TaskManager.Self.Add( () => { string rfsName = entity.Name.Replace("\\", "/") + "/" + CsvGenerator.RelativeCsvFile; bool isAlreadyAdded = entity.ReferencedFiles.FirstOrDefault(item => item.Name == rfsName) != null; if (!isAlreadyAdded) { GlueCommands.Self.GluxCommands.AddSingleFileTo( CsvGenerator.Self.CsvFileFor(entity).FullPath, CsvGenerator.RelativeCsvFile, "", null, false, null, entity, null ); } var rfs = entity.ReferencedFiles.FirstOrDefault(item => item.Name == rfsName); if (rfs != null && rfs.CreatesDictionary == false) { rfs.CreatesDictionary = true; GlueCommands.Self.GluxCommands.SaveGlux(); GlueCommands.Self.GenerateCodeCommands.GenerateElementCode(entity); } const string customClassName = "TopDownValues"; if (GlueState.Self.CurrentGlueProject.CustomClasses.Any(item => item.Name == customClassName) == false) { CustomClassSave throwaway; GlueCommands.Self.GluxCommands.AddNewCustomClass(customClassName, out throwaway); } var customClass = GlueState.Self.CurrentGlueProject.CustomClasses .FirstOrDefault(item => item.Name == customClassName); if (rfs != null) { if (customClass != null && customClass.CsvFilesUsingThis.Contains(rfs.Name) == false) { FlatRedBall.Glue.CreatedClass.CustomClassController.Self.SetCsvRfsToUseCustomClass(rfs, customClass, force: true); GlueCommands.Self.GluxCommands.SaveGlux(); } } }, "Adding csv to top down entity" ); }
public void SetProperty <T>(EntitySave entitySave, string name, T value) { string newValue; FileManager.XmlSerialize(value, out newValue); entitySave.Properties.SetValue(name, newValue); }
private void GenerateAbsoluteVisible(ICodeBlock codeBlock, EntitySave entitySave) { if (!entitySave.GetInheritsFromIVisible()) { var prop = codeBlock.Property("AbsoluteVisible", Public: true, Override: false, Type: "bool"); prop.Get().Line("return Visible && (Parent == null || IgnoresParentVisibility || Parent is FlatRedBall.Graphics.IVisible == false || (Parent as FlatRedBall.Graphics.IVisible).AbsoluteVisible);"); } }
public void TestLayerOrthoValues() { EntitySave entitySave = new EntitySave(); entitySave.Name = "LayerTestTestLayerOrthoValuesEntity"; NamedObjectSave nos = new NamedObjectSave(); nos.SourceType = SourceType.FlatRedBallType; nos.SourceClassType = "Layer"; nos.InstanceName = "Layer1"; nos.IndependentOfCamera = true; nos.Is2D = true; nos.LayerCoordinateUnit = LayerCoordinateUnit.Pixel; nos.LayerCoordinateType = LayerCoordinateType.MatchCamera; entitySave.NamedObjects.Add(nos); nos = new NamedObjectSave(); nos.SourceType = SourceType.FlatRedBallType; nos.SourceClassType = "Layer"; nos.InstanceName = "Layer2"; nos.IndependentOfCamera = true; nos.Is2D = true; nos.LayerCoordinateUnit = LayerCoordinateUnit.Pixel; nos.LayerCoordinateType = LayerCoordinateType.MatchCamera; nos.DestinationRectangle = new FloatRectangle(0, 0, 80, 64); entitySave.NamedObjects.Add(nos); SpriteManager.Camera.Orthogonal = true; SpriteManager.Camera.OrthogonalWidth = 800; SpriteManager.Camera.OrthogonalHeight = 640; ElementRuntime elementRuntime = new ElementRuntime(); elementRuntime.Initialize(entitySave, null, null, null, null); Layer layer = (elementRuntime.ContainedElements[0].DirectObjectReference as Layer); if (layer.LayerCameraSettings.OrthogonalWidth != 800 || layer.LayerCameraSettings.OrthogonalHeight != 640) { throw new Exception("A Layer using MatchCamera coordinate types is not matching the Camera's ortho values"); } layer = (elementRuntime.ContainedElements[1].DirectObjectReference as Layer); if (layer.LayerCameraSettings.OrthogonalWidth != 80 || layer.LayerCameraSettings.OrthogonalHeight != 64) { throw new Exception("A Layer using MatchCamera with a destination rectangle does not have proper coordinates"); } }
internal void UpdateTo(EntitySave currentEntitySave) { ignoresPropertyChanges = true; viewModel.GlueObject = currentEntitySave; viewModel.UpdateFromGlueObject(); ignoresPropertyChanges = false; }
private void CreateDerivedEntitySave() { mDerivedEntitySave = new EntitySave(); mDerivedEntitySave.Name = "DerivedCustomVariableTestsEntity"; ObjectFinder.Self.GlueProject.Entities.Add(mDerivedEntitySave); mDerivedEntitySave.BaseEntity = mEntitySave.Name; mDerivedEntitySave.UpdateFromBaseType(); }
public void AddResetVariablesForPooling_Click() { // Search: pool, pooling, variable reset, variablereset, add reset variables for pooling mResetVariablesToAdd.Clear(); EntitySave entitySave = EditorLogic.CurrentEntitySave; SetResetVariablesForEntitySave(entitySave); }
private void AddTopDownGlueVariables(EntitySave entity) { // We don't make any variables because currently there's no concept of // different movement types that the plugin can switch between, the way // the platformer switches between ground/air/double-jump // Actually even though there's not air, ground, double jump, there is a CurrentMovementValues // property. But we'll just codegen that for now. }
public static IEnumerable <FilePath> GetAllNetworkFilesFor(EntitySave entitySave) { yield return(CodeGeneratorCommonLogic.GetGeneratedElementNetworkFilePathFor(entitySave)); yield return(CodeGeneratorCommonLogic.GetCustomElementNetworkFilePathFor(entitySave)); yield return(CodeGeneratorCommonLogic.GetGeneratedNetStateFilePathFor(entitySave)); yield return(CodeGeneratorCommonLogic.GetCustomNetStateFilePathFor(entitySave)); }
private void CreateEntityTreeNodes() { for (int i = 0; i < ProjectManager.GlueProjectSave.Entities.Count; i++) { EntitySave entitySave = ProjectManager.GlueProjectSave.Entities[i]; EntityTreeNode entityTreeNode = GlueState.Self.Find.EntityTreeNode(entitySave.Name); entityTreeNode.UpdateReferencedTreeNodes(); } }
public static List<EntitySave> GetAllEntitiesThatThisInherits(string derivedEntity) { List<EntitySave> listToReturn = new List<EntitySave>(); EntitySave entity = ObjectFinder.Self.GetEntitySave(derivedEntity); entity.GetAllBaseEntities(listToReturn); return listToReturn; }
static bool CanHaveSubCollisions(NamedObjectSave nos) { EntitySave entity = null; if (nos != null) { return(GetEntitySaveReferencedBy(nos)?.ImplementsICollidable == true); } return(false); }
private ElementReference ToComponentReference(EntitySave entitySave) { var elementReference = new ElementReference(); elementReference.ElementType = ElementType.Component; elementReference.Name = entitySave.Name.Substring( "Entities\\".Length); return(elementReference); }
private void CreateButtonList() { mButtonList = new EntitySave(); mButtonList.Name = "ButtonListInCodeGenerationTests"; ObjectFinder.Self.GlueProject.Entities.Add(mButtonList); mButtonInButtonList = new NamedObjectSave(); mButtonInButtonList.SourceType = SourceType.Entity; mButtonInButtonList.SourceClassType = mButton.Name; mButtonList.NamedObjects.Add(mButtonInButtonList); }
internal void GenerateFor(EntitySave entity, RacingEntityViewModel viewModel) { string contents = GetCsvContents(entity, viewModel); string fileName = CsvFileFor(entity).FullPath; GlueCommands.Self.TryMultipleTimes(() => { FileManager.SaveText(contents, fileName); }); }
public void Initialize() { OverallInitializer.Initialize(); ExposedVariableManager.Initialize(); mEntitySave = CreateEntitySaveWithStates("ExposedVariableEntity"); mEntitySave.ImplementsIVisible = true; ObjectFinder.Self.GlueProject.Entities.Add(mEntitySave); mDerivedEntitySave = new EntitySave(); mDerivedEntitySave.BaseEntity = mEntitySave.Name; mDerivedEntitySave.Name = "DerivedExposedVariableEntity"; ObjectFinder.Self.GlueProject.Entities.Add(mDerivedEntitySave); mEntityWithCategorizedThatShareVariables = new EntitySave(); mEntityWithCategorizedThatShareVariables.Name = "ExposedVariableTestEntityWithCategorizedThatShareVariables"; ObjectFinder.Self.GlueProject.Entities.Add(mEntityWithCategorizedThatShareVariables); StateSaveCategory category = new StateSaveCategory(); category.SharesVariablesWithOtherCategories = true; // this is important - it means that it won't make a new enum or property, so it is just the "CurrentState" variable category.Name = "Category1"; mEntityWithCategorizedThatShareVariables.StateCategoryList.Add(category); StateSave stateSave = new StateSave(); stateSave.Name = "CategorizedState1"; category.States.Add(stateSave); mContainerBaseEntity = new EntitySave(); mContainerBaseEntity.Name = "ExposedVariableTestContainerBaseEntity"; ObjectFinder.Self.GlueProject.Entities.Add(mContainerBaseEntity); NamedObjectSave namedObjectSave = new NamedObjectSave(); namedObjectSave.InstanceName = mEntitySave.Name + "Instance"; namedObjectSave.SourceType = SourceType.Entity; namedObjectSave.SourceClassType = mEntitySave.Name; mContainerBaseEntity.NamedObjects.Add(namedObjectSave); CustomVariable tunneledVariable = new CustomVariable(); tunneledVariable.Name = "TunneledStateVariable"; tunneledVariable.SourceObject = namedObjectSave.InstanceName; tunneledVariable.SourceObjectProperty = "Current" + mEntitySave.StateCategoryList[0].Name + "State"; tunneledVariable.Type = mEntitySave.StateCategoryList[0].Name; tunneledVariable.SetByDerived = true; mContainerBaseEntity.CustomVariables.Add(tunneledVariable); mContainerDerivedEntity = new EntitySave(); mContainerDerivedEntity.Name = "ExposedVariableTestContainerDerivedEntity"; ObjectFinder.Self.GlueProject.Entities.Add(mContainerDerivedEntity); mContainerDerivedEntity.BaseEntity = mContainerBaseEntity.Name; mContainerDerivedEntity.UpdateFromBaseType(); mContainerDerivedEntity.GetCustomVariable(tunneledVariable.Name).DefaultValue = mEntitySave.StateCategoryList[0].States[0].Name; CreateCsvContainerEntitySave(); }
internal void SetFrom(EntitySave entity) { VariableList = new ObservableCollection <NetworkVariableViewModel>(); IsNetworkEntity = entity.Properties.GetValue <bool>(nameof(IsNetworkEntity)); var variables = entity .CustomVariables .ToArray(); string[] variablesToAlwaysInclude = new string[] { // Don't include Name because this isn't something Glue understands as a variable //nameof(PositionedObject.Name), nameof(PositionedObject.X), nameof(PositionedObject.Y), nameof(PositionedObject.XVelocity), nameof(PositionedObject.YVelocity), nameof(PositionedObject.XAcceleration), nameof(PositionedObject.YAcceleration), nameof(PositionedObject.Drag), nameof(PositionedObject.RotationZ), nameof(PositionedObject.RotationZVelocity), }; List <NetworkVariableViewModel> temporaryList = new List <NetworkVariableViewModel>(); foreach (var variable in variables) { var variableVm = new NetworkVariableViewModel(); variableVm.Name = variable.Name; variableVm.IsChecked = IsNetworked(variable); variableVm.PropertyChanged += HandleVariableVmPropertyChanged; temporaryList.Add(variableVm); } foreach (var variableName in variablesToAlwaysInclude) { var alreadyIncluded = temporaryList.Any(item => item.Name == variableName); if (!alreadyIncluded) { var variableVm = new NetworkVariableViewModel(); variableVm.Name = variableName; variableVm.IsChecked = false; variableVm.PropertyChanged += HandleVariableVmPropertyChanged; temporaryList.Add(variableVm); } } foreach (var vm in temporaryList.OrderBy(item => item.Name)) { VariableList.Add(vm); } }
private void CreateDerivedElementRuntime() { mDerivedEntitySave = new EntitySave(); mDerivedEntitySave.Name = "DerivedVariableSettingEntity"; mDerivedEntitySave.BaseEntity = mEntitySave.Name; ObjectFinder.Self.GlueProject.Entities.Add(mDerivedEntitySave); mDerivedEntitySave.UpdateFromBaseType(); mDerivedEntitySave.GetCustomVariable("CurrentState").DefaultValue = "Uncategorized"; mDerivedElementRuntime = new ElementRuntime(mDerivedEntitySave, null, null, null, null); }
private static bool IsEntityNamedObject2D(NamedObjectSave nos) { bool is2D = false; EntitySave entitySave = ObjectFinder.Self.GetEntitySave(nos.SourceClassType); if (entitySave != null) { is2D |= DoesNamedObjectSaveListContain2DObjects(entitySave.NamedObjects); } return(is2D); }
private static string GenerateEmptyCustomNetStateCode(EntitySave entitySave) { ICodeBlock topBlock = new CodeBlockBaseNoIndent(null); string netStateNamespace = CodeGeneratorCommonLogic.GetNetStateNamespace(entitySave); ICodeBlock codeBlock = topBlock.Namespace(netStateNamespace); codeBlock = codeBlock.Class("public partial", entitySave.GetStrippedName() + "NetState"); return(topBlock.ToString()); }
private void AddTreeNodeFor(EntitySave entitySave) { string fullName = entitySave.Name; string directory = FileManager.GetDirectory(fullName, RelativeType.Relative); TreeNode directoryNode = GetOrCreateDirectoryNode(directory, AllElementsTreeView.Nodes); TreeNode elementNode = new TreeNode(FileManager.RemovePath(entitySave.Name)); elementNode.Tag = entitySave; directoryNode.Nodes.Add(elementNode); }
private void GenerateIVisibleParent(ICodeBlock codeBlock, EntitySave entitySave) { if (!entitySave.GetInheritsFromIVisible()) { var prop = codeBlock.Property("FlatRedBall.Graphics.IVisible.Parent", Override: false, Type: "FlatRedBall.Graphics.IVisible"); var get = prop.Get(); get.If("this.Parent != null && this.Parent is FlatRedBall.Graphics.IVisible") .Line("return this.Parent as FlatRedBall.Graphics.IVisible;").End() .Else() .Line("return null;"); } }
private static NamedObjectSave GetEntireFileNos(EntitySave entitySave, string sourceFileName) { foreach (NamedObjectSave nos in entitySave.NamedObjects) { if (nos.IsEntireFile && nos.SourceType == SourceType.File && nos.SourceFile == sourceFileName) { return(nos); } } return(null); }
private void CreateCsvContainerEntitySave() { mCsvContainerEntitySave = new EntitySave(); mCsvContainerEntitySave.Name = "CsvContainerEntityInExposedVariableTests"; ObjectFinder.Self.GlueProject.Entities.Add(mCsvContainerEntitySave); ReferencedFileSave rfs = new ReferencedFileSave(); rfs.SourceFile = "Whatever.csv"; rfs.Name = "Whatever.csv"; mCsvContainerEntitySave.ReferencedFiles.Add(rfs); }
public void TestRecursion() { EntitySave container = new EntitySave(); container.Name = "TestRecursionContainer"; ObjectFinder.Self.GlueProject.Entities.Add(container); if (RecursionManager.Self.CanContainInstanceOf(container, container.Name) == true) { throw new Exception("A type cannot contain itself"); } }
/// <summary> /// Assigns the instance type onto the instance view models ocntained in the main view model. /// This is needed so that the Glue data is the authority on the type of an instance, rather than /// relying on stored values on a model or view model. /// </summary> /// <param name="viewModel"></param> /// <param name="entitySave"></param> private void AssignInstancetypesOn(MainViewModel viewModel, EntitySave entitySave) { var allNamedObjects = entitySave.AllNamedObjects; foreach (var instanceViewModel in viewModel.Instances) { var namedObject = allNamedObjects .FirstOrDefault(item => item.InstanceName == instanceViewModel.Name); instanceViewModel.Type = namedObject?.InstanceType; } }