public ValidationResponse AddNewCustomClass(string className, out CustomClassSave customClassSave) { ValidationResponse validationResponse = new ValidationResponse(); customClassSave = null; string whyIsntValid; if (!NameVerifier.IsCustomClassNameValid(className, out whyIsntValid)) { validationResponse.OperationResult = OperationResult.Failure; validationResponse.Message = whyIsntValid; } else if (ProjectManager.GlueProjectSave.GetCustomClass(className) != null) { validationResponse.OperationResult = OperationResult.Failure; validationResponse.Message = $"The custom class {className} already exists"; } else { validationResponse.OperationResult = OperationResult.Success; customClassSave = new CustomClassSave(); customClassSave.Name = className; ProjectManager.GlueProjectSave.CustomClasses.Add(customClassSave); GlueCommands.Self.GluxCommands.SaveGlux(); GlueCommands.Self.GenerateCodeCommands.GenerateCustomClassesCode(); } return(validationResponse); }
private static NamedObjectSave HandleAddShape(string message, string sourceClassType) { NamedObjectSave toReturn = null; var tiw = new TextInputWindow(); tiw.Message = message; var dialogResult = tiw.ShowDialog(); if (dialogResult == DialogResult.OK) { string whyItIsntValid; NameVerifier.IsNamedObjectNameValid(tiw.Result, out whyItIsntValid); if (!string.IsNullOrEmpty(whyItIsntValid)) { GlueCommands.Self.DialogCommands.ShowMessageBox(whyItIsntValid); } else { var viewModel = new AddObjectViewModel(); viewModel.ObjectName = tiw.Result; viewModel.SourceType = SaveClasses.SourceType.FlatRedBallType; viewModel.SourceClassType = sourceClassType; toReturn = GlueCommands.Self.GluxCommands.AddNewNamedObjectToSelectedElement(viewModel); GlueState.Self.CurrentNamedObjectSave = toReturn; } } return(toReturn); }
public static bool IsVariableInvalid(AddVariableWindow addVariableWindow, string resultName, IElement currentElement, out string failureMessage) { bool didFailureOccur = false; string whyItIsntValid = ""; didFailureOccur = NameVerifier.IsCustomVariableNameValid(resultName, null, currentElement, ref whyItIsntValid) == false; failureMessage = null; if (didFailureOccur) { failureMessage = whyItIsntValid; } else if (addVariableWindow != null && NameVerifier.DoesTunneledVariableAlreadyExist(addVariableWindow.TunnelingObject, addVariableWindow.TunnelingVariable, currentElement)) { didFailureOccur = true; failureMessage = "There is already a variable that is modifying " + addVariableWindow.TunnelingVariable + " on " + addVariableWindow.TunnelingObject; } else if (addVariableWindow != null && IsUserTryingToCreateNewWithExposableName(addVariableWindow.ResultName, addVariableWindow.DesiredVariableType == CustomVariableType.Exposed)) { didFailureOccur = true; failureMessage = "The variable\n\n" + resultName + "\n\nis an expoable variable. Please use a different variable name or select the variable through the Expose tab"; } else if (ExposedVariableManager.IsReservedPositionedPositionedObjectMember(resultName) && currentElement is EntitySave) { didFailureOccur = true; failureMessage = "The variable\n\n" + resultName + "\n\nis reserved by FlatRedBall."; } return(didFailureOccur); }
public NamedObjectSave ShowAddNewObjectDialog(AddObjectViewModel addObjectViewModel = null) { NamedObjectSave newNamedObject = null; // add named object, add object, addnamedobject, add new object, addnewobject, createobject, addobject addObjectViewModel = CreateAndShowAddNamedObjectWindow(addObjectViewModel); if (addObjectViewModel.DialogResult == DialogResult.OK) { string whyItIsntValid = null; bool isValid = NameVerifier.IsNamedObjectNameValid(addObjectViewModel.ObjectName, out whyItIsntValid); if (isValid) { if (addObjectViewModel.SourceType == SourceType.Entity && !RecursionManager.Self.CanContainInstanceOf(GlueState.Self.CurrentElement, addObjectViewModel.SourceClassType)) { isValid = false; whyItIsntValid = "This type would result in infinite recursion"; } } if (isValid) { newNamedObject = GlueCommands.Self.GluxCommands.AddNewNamedObjectToSelectedElement(addObjectViewModel); GlueState.Self.CurrentNamedObjectSave = newNamedObject; } else { GlueGui.ShowMessageBox(whyItIsntValid); } } return(newNamedObject); }
public void ShowAddNewScreenDialog() { // AddScreen, add screen, addnewscreen, add new screen if (ProjectManager.GlueProjectSave == null) { System.Windows.Forms.MessageBox.Show("You need to create or load a project first."); } else { if (ProjectManager.StatusCheck() == ProjectManager.CheckResult.Passed) { var tiw = new CustomizableTextInputWindow(); tiw.Message = "Enter a name for the new Screen"; string name = "NewScreen"; if (GlueState.Self.CurrentGlueProject.Screens.Count == 0) { name = "GameScreen"; } var allScreenNames = GlueState.Self.CurrentGlueProject.Screens .Select(item => item.GetStrippedName()) .ToList(); name = StringFunctions.MakeStringUnique(name, allScreenNames, 2); tiw.Result = name; tiw.HighlghtText(); var result = tiw.ShowDialog(); if (result == true) { string whyItIsntValid; if (!NameVerifier.IsScreenNameValid(tiw.Result, null, out whyItIsntValid)) { MessageBox.Show(whyItIsntValid); } else { var screen = GlueCommands.Self.GluxCommands.ScreenCommands.AddScreen(tiw.Result); GlueState.Self.CurrentElement = screen; var treeNode = EditorLogic.CurrentScreenTreeNode; if (treeNode != null) { treeNode.Expand(); } } } } } }
public void ShowAddNewEntityDialog() { // search: addentity, add entity if (ProjectManager.GlueProjectSave == null) { System.Windows.Forms.MessageBox.Show("You need to create or load a project first."); } else { if (ProjectManager.StatusCheck() == ProjectManager.CheckResult.Passed) { AddEntityWindow window = new Controls.AddEntityWindow(); window.WindowStartupLocation = System.Windows.WindowStartupLocation.Manual; double width = window.Width; if (double.IsNaN(width)) { width = 0; } double height = window.Height; if (double.IsNaN(height)) { height = 0; } window.Left = MainGlueWindow.MousePosition.X - width / 2; window.Top = MainGlueWindow.MousePosition.Y - height / 2; PluginManager.ModifyAddEntityWindow(window); var result = window.ShowDialog(); if (result == true) { string entityName = window.EnteredText; string whyIsntValid; if (!NameVerifier.IsEntityNameValid(entityName, null, out whyIsntValid)) { MessageBox.Show(whyIsntValid); } else { string directory = ""; if (EditorLogic.CurrentTreeNode.IsDirectoryNode()) { directory = EditorLogic.CurrentTreeNode.GetRelativePath(); directory = directory.Replace('/', '\\'); } var entity = CreateEntityAndObjects(window, entityName, directory); PluginManager.ReactToNewEntityCreated(entity, window); } } } } }
public void HandleCreateEntityClick(object sender, EventArgs e) { if (AppState.Self.CurrentMapTilesetTile == null) { MessageBox.Show("You must first select a tile"); return; } TextInputWindow tiw; ControlForAddingCollision collisionControl; DialogResult result; AskToCreateEntity(out tiw, out collisionControl, out result); if (result == DialogResult.OK) { string entityName = tiw.Result; string whyItIsntValid; if (NameVerifier.IsEntityNameValid(entityName, null, out whyItIsntValid) == false) { MessageBox.Show(whyItIsntValid); } else { var newEntity = GlueCommands.Self.GluxCommands.EntityCommands.AddEntity( entityName, is2D: true); // Give it a factory so that instances can automatically be added newEntity.CreatedByOtherEntities = true; ReferencedFileSave rfs = CreateReferencedFileSave(); newEntity.ReferencedFiles.Add(rfs); NamedObjectSave nos = CreateSpriteNamedObject(rfs); newEntity.NamedObjects.Add(nos); if (collisionControl.HasCollision) { NamedObjectSave collisionNos = CreateCollisionNamedObject( collisionControl.CircleSelected, collisionControl.RectangleSelected); newEntity.NamedObjects.Add(collisionNos); } AddNamePropertyToTile(entityName); GlueCommands.Self.GluxCommands.SaveGlux(); GlueCommands.Self.UpdateCommands.Update(newEntity); TileGraphicsPluginClass.Self.SaveTiledMapSave(changeType: TmxEditor.Events.ChangeType.Tileset); TileGraphicsPluginClass.Self.UpdateTilesetDisplay(); } } }
public static void RenameReferencedFile(string oldName, string newName, ReferencedFileSave rfs, IElement container) { string oldDirectory = FileManager.GetDirectory(oldName); string newDirectory = FileManager.GetDirectory(newName); string newFileNameAbsolute = ProjectManager.MakeAbsolute(newName); string instanceName = FileManager.RemovePath(FileManager.RemoveExtension(newName)); string whyIsntValid; if (oldDirectory != newDirectory) { MessageBox.Show("The old file was located in \n" + oldDirectory + "\n" + "The new file is located in \n" + newDirectory + "\n" + "Currently Glue does not support changing directories.", "Warning"); rfs.SetNameNoCall(oldName); } else if (NameVerifier.IsReferencedFileNameValid(instanceName, rfs.GetAssetTypeInfo(), rfs, container, out whyIsntValid) == false) { MessageBox.Show(whyIsntValid); rfs.SetNameNoCall(oldName); } else { bool shouldMove = true; bool shouldContinue = true; CheckForExistingFileOfSameName(oldName, rfs, newFileNameAbsolute, ref shouldMove, ref shouldContinue); if (shouldContinue) { MoveFileIfNecessary(oldName, newName, shouldMove); string rfsType = rfs.RuntimeType; if (rfsType != null && rfsType.Contains(".")) { // We dont want the fully qualified type. rfsType = FileManager.GetExtension(rfsType); } UpdateObjectsUsingFile(container, oldName, rfs, rfsType); RegenerateCodeAndUpdateUiAccordingToRfsRename(oldName, newName, rfs); UpdateBuildItemsForRenamedRfs(oldName, newName); AdjustDataFilesIfIsCsv(oldName, rfs); GluxCommands.Self.SaveGlux(); ProjectManager.SaveProjects(); } } }
public static void Main(string[] args) { IRepository <Client> clientRepository = new Repository <Client>(); IRepository <Employee> employeeRepository = new Repository <Employee>(); IRepository <Bike> bikeRepository = new Repository <Bike>(); INameVerifier bikeNameVerifier = new NameVerifier(bikeRepository); IBikeService bikeService = new BikeService(bikeRepository, bikeNameVerifier); App app = new App(clientRepository, employeeRepository, bikeRepository, bikeService); app.AddBike("Кама", 50); app.AddBike("Кама", 100); }
public void ReactToStateSaveChangedValue(StateSave stateSave, StateSaveCategory category, string changedMember, object oldValue, IElement parentObject, ref bool updateTreeView) { if (changedMember != "Name") { updateTreeView = false; } // See if this is an Unmodified object // We don't support NamedObjectPropertyOverrides anymore //NamedObjectPropertyOverride propertyOverride = parentObject as NamedObjectPropertyOverride; //if (propertyOverride != null) //{ // if (stateSave.NamedObjectPropertyOverrides.Contains(propertyOverride)) // { // if (changedMember == "SourceFile" && propertyOverride.SourceFile == AvailableFileStringConverter.UseDefaultString) // { // propertyOverride.SourceFile = null; // } // if (propertyOverride.IsNulledOut) // { // stateSave.NamedObjectPropertyOverrides.Remove(propertyOverride); // } // } // else // { // switch (changedMember) // { // case "SourceFile": // propertyOverride.SourceFile = NamedObjectPropertyOverride.SourceFileBuffer; // break; // } // stateSave.NamedObjectPropertyOverrides.Add(propertyOverride); // } //} if (changedMember == "Name") { string whyItIsntValid; if (!NameVerifier.IsStateNameValid(stateSave.Name, EditorLogic.CurrentElement, EditorLogic.CurrentStateSaveCategory, EditorLogic.CurrentStateSave, out whyItIsntValid)) { stateSave.Name = (string)oldValue; updateTreeView = false; AutomatedGlue.GlueGui.ShowMessageBox(whyItIsntValid); } else { ReactToStateNameChange(oldValue, stateSave, category, parentObject); } } }
public void TestStateSave() { EntitySave baseEntity = new EntitySave(); baseEntity.Name = "BaseForStateSaveNameTest"; ObjectFinder.Self.GlueProject.Entities.Add(baseEntity); EntitySave derivedEntity = new EntitySave(); derivedEntity.Name = "DerivedForStateSaveNameTest"; ObjectFinder.Self.GlueProject.Entities.Add(derivedEntity); derivedEntity.BaseEntity = baseEntity.Name; StateSave stateSave = new StateSave(); stateSave.Name = "NameOfState"; baseEntity.States.Add(stateSave); string whyItIsntValid; NameVerifier.IsStateNameValid("NameOfState", baseEntity, null, null, out whyItIsntValid); if (string.IsNullOrEmpty(whyItIsntValid)) { throw new Exception("Name verifier should not allow duplicate names"); } NameVerifier.IsStateNameValid("NameOfState", derivedEntity, null, null, out whyItIsntValid); if (string.IsNullOrEmpty(whyItIsntValid)) { throw new Exception("Name verifier should not allow derived to duplicate state names"); } baseEntity.StateCategoryList.Add(new StateSaveCategory() { Name = "Category1", SharesVariablesWithOtherCategories = false }); baseEntity.StateCategoryList[0].States.Add(new StateSave() { Name = "StateInCategory" }); NameVerifier.IsStateNameValid("StateInCategory", baseEntity, baseEntity.StateCategoryList[0], null, out whyItIsntValid); if (string.IsNullOrEmpty(whyItIsntValid)) { throw new Exception("Categories should not allow multiple states with the same name in them"); } }
public void TestNamedObjectSave() { EntitySave entitySave = new EntitySave(); NamedObjectSave nos = new NamedObjectSave(); string whyNot; NameVerifier.IsNamedObjectNameValid("Parent", nos, out whyNot); if (string.IsNullOrEmpty(whyNot)) { throw new Exception("Parent should not be avalid name for a PositionedObject, but Glue allows it"); } }
public void TestStateCategorySave() { string whyNot; NameVerifier.IsStateCategoryNameValid("Color", out whyNot); if (string.IsNullOrEmpty(whyNot)) { throw new Exception("Glue shouldn't allow naming a state category reserved names like Color"); } NameVerifier.IsStateCategoryNameValid("Camera", out whyNot); if (string.IsNullOrEmpty(whyNot)) { throw new Exception("Glue shouldn't allow naming a state category reserved names like Camera"); } }
private void TextBox_TextChanged(object sender, TextChangedEventArgs e) { string whyIsntValid; var isValid = NameVerifier.IsEntityNameValid(TextBox.Text, null, out whyIsntValid); if (isValid) { FailureTextBlock.Visibility = Visibility.Collapsed; } else { FailureTextBlock.Visibility = Visibility.Visible; FailureTextBlock.Text = whyIsntValid; } }
public void ShowAddNewEntityDialog() { // search: addentity, add entity if (ProjectManager.GlueProjectSave == null) { System.Windows.Forms.MessageBox.Show("You need to create or load a project first."); } else { if (ProjectManager.StatusCheck() == ProjectManager.CheckResult.Passed) { AddEntityWindow window = new Controls.AddEntityWindow(); PluginManager.ModifyAddEntityWindow(window); var result = window.ShowDialog(); if (result == true) { string entityName = window.EnteredText; string whyIsntValid; if (!NameVerifier.IsEntityNameValid(entityName, null, out whyIsntValid)) { MessageBox.Show(whyIsntValid); } else { string directory = ""; if (EditorLogic.CurrentTreeNode.IsDirectoryNode()) { directory = EditorLogic.CurrentTreeNode.GetRelativePath(); directory = directory.Replace('/', '\\'); } var entity = CreateEntityAndObjects(window, entityName, directory); PluginManager.ReactToNewEntityCreated(entity, window); } } } } }
public void TestReferencedFileSave() { EntitySave entitySave = new EntitySave(); ReferencedFileSave rfs = new ReferencedFileSave(); rfs.DestroyOnUnload = false; rfs.Name = "File.png"; entitySave.ReferencedFiles.Add(rfs); string whyNot; NameVerifier.IsReferencedFileNameValid("File", null, null, entitySave, out whyNot); if (string.IsNullOrEmpty(whyNot)) { throw new Exception("Same-named files shouldn't be allowed, but the NameVerifier allows it."); } NameVerifier.IsReferencedFileNameValid("File.wav", null, null, entitySave, out whyNot); if (string.IsNullOrEmpty(whyNot)) { throw new Exception("Same-named files shouldn't be allowed, but the NameVerifier allows it."); } NameVerifier.IsReferencedFileNameValid("Folder/File.wav", null, null, entitySave, out whyNot); if (string.IsNullOrEmpty(whyNot)) { throw new Exception("Same-named files shouldn't be allowed, but the NameVerifier allows it."); } NameVerifier.IsReferencedFileNameValid("Folder/File", null, null, entitySave, out whyNot); if (string.IsNullOrEmpty(whyNot)) { throw new Exception("Same-named files shouldn't be allowed, but the NameVerifier allows it."); } NameVerifier.IsReferencedFileNameValid("if", null, null, entitySave, out whyNot); if (string.IsNullOrEmpty(whyNot)) { throw new Exception("'if' is a reserved keyword and should not be allowed as a file name"); } }
public void ReactToStateSaveChangedValue(StateSave stateSave, StateSaveCategory category, string changedMember, object oldValue, IElement parentObject, ref bool updateTreeView) { if (changedMember != "Name") { updateTreeView = false; } if (changedMember == "Name") { string whyItIsntValid; if (!NameVerifier.IsStateNameValid(stateSave.Name, EditorLogic.CurrentElement, EditorLogic.CurrentStateSaveCategory, EditorLogic.CurrentStateSave, out whyItIsntValid)) { stateSave.Name = (string)oldValue; updateTreeView = false; AutomatedGlue.GlueGui.ShowMessageBox(whyItIsntValid); } else { ReactToStateNameChange(oldValue, stateSave, category, parentObject); } } }
private static string HandleObjectInFileSelected(NewObjectTypeSelectionControl typeSelectControl) { string newName; var spaceParen = typeSelectControl.SourceName.IndexOf(" ("); if (spaceParen != -1) { newName = typeSelectControl.SourceName.Substring(0, spaceParen); } else { newName = typeSelectControl.SourceName; } // If the user selected "Entire File" we want to make sure the space doesn't show up: newName = newName.Replace(" ", ""); string throwaway; bool isInvalid = NameVerifier.IsNamedObjectNameValid(newName, out throwaway); if (!isInvalid) { // let's get the type: var split = typeSelectControl.SourceName.Split('(', ')'); var last = split.LastOrDefault(item => !string.IsNullOrEmpty(item)); if (last != null) { var lastDot = last.LastIndexOf('.'); newName = last.Substring(lastDot + 1, last.Length - (lastDot + 1)); } } return(newName); }
public ReferencedFileSave CreateReferencedFileSaveForExistingFile(IElement containerForFile, string directoryInsideContainer, string absoluteFileName, PromptHandleEnum unknownTypeHandle, AssetTypeInfo ati, out string creationReport, out string errorMessage) { creationReport = ""; errorMessage = null; ReferencedFileSave referencedFileSaveToReturn = null; string whyItIsntValid; // Let's see if there is already an Entity with the same name string fileWithoutPath = FileManager.RemovePath(FileManager.RemoveExtension(absoluteFileName)); bool isValid = NameVerifier.IsReferencedFileNameValid(fileWithoutPath, ati, referencedFileSaveToReturn, containerForFile, out whyItIsntValid); if (!isValid) { errorMessage = "Invalid file name:\n" + fileWithoutPath + "\n" + whyItIsntValid; } else { Zipper.UnzipAndModifyFileIfZip(ref absoluteFileName); string extension = FileManager.GetExtension(absoluteFileName); bool isValidExtensionOrIsConfirmedByUser; bool isUnknownType; CheckAndWarnAboutUnknownFileTypes(unknownTypeHandle, extension, out isValidExtensionOrIsConfirmedByUser, out isUnknownType); if (isValidExtensionOrIsConfirmedByUser) { string directoryThatFileShouldBeRelativeTo = GetFullPathContentDirectory(containerForFile, directoryInsideContainer); string projectDirectory = ProjectManager.ContentProject.GetAbsoluteContentFolder(); string fileToAdd = GetNameOfFileRelativeToContentFolder(absoluteFileName, directoryThatFileShouldBeRelativeTo, projectDirectory); BuildToolAssociation bta = null; if (ati != null && !string.IsNullOrEmpty(ati.CustomBuildToolName)) { bta = BuildToolAssociationManager.Self.GetBuilderToolAssociationByName(ati.CustomBuildToolName); } if (containerForFile != null) { referencedFileSaveToReturn = containerForFile.AddReferencedFile(fileToAdd, ati, bta); } else { bool useFullPathAsName = false; // todo - support built files here referencedFileSaveToReturn = AddReferencedFileToGlobalContent(fileToAdd, useFullPathAsName); } // This will be null if there was an error above in creating this file if (referencedFileSaveToReturn != null) { if (containerForFile != null) { containerForFile.HasChanged = true; } if (fileToAdd.EndsWith(".csv")) { string fileToAddAbsolute = ProjectManager.MakeAbsolute(fileToAdd); CsvCodeGenerator.GenerateAndSaveDataClass(referencedFileSaveToReturn, referencedFileSaveToReturn.CsvDelimiter); } if (isUnknownType) { referencedFileSaveToReturn.LoadedAtRuntime = false; } ProjectManager.UpdateFileMembershipInProject(referencedFileSaveToReturn); PluginManager.ReactToNewFile(referencedFileSaveToReturn); GluxCommands.Self.SaveGlux(); ProjectManager.SaveProjects(); UnreferencedFilesManager.Self.RefreshUnreferencedFiles(false); string error; referencedFileSaveToReturn.RefreshSourceFileCache(false, out error); if (!string.IsNullOrEmpty(error)) { ErrorReporter.ReportError(referencedFileSaveToReturn.Name, error, false); } } } } return(referencedFileSaveToReturn); }
private static void ReactToChangedCustomVariableName(string oldName, CustomVariable customVariable) { string whyItIsntValid = ""; bool isNameValid = NameVerifier.IsCustomVariableNameValid(customVariable.Name, customVariable, GlueState.Self.CurrentElement, ref whyItIsntValid); string newName = EditorLogic.CurrentCustomVariable.Name; if (customVariable.GetIsVariableState() && oldName != newName) { whyItIsntValid += "\nState variables cannot be renamed - they require specific names to function properly."; } if (!string.IsNullOrEmpty(whyItIsntValid)) { MessageBox.Show(whyItIsntValid); customVariable.Name = oldName; // handle invalid names here } else { IElement element = EditorLogic.CurrentElement; List <IElement> elementsToGenerate = new List <IElement>(); List <IElement> elementsToSearchForTunneledVariablesIn = new List <IElement>(); #region Change any states that use this variable foreach (StateSave stateSave in element.AllStates) { foreach (InstructionSave instructionSave in stateSave.InstructionSaves) { if (instructionSave.Member == oldName) { instructionSave.Member = newName; } } } #endregion #region Change any NOS that uses this as its source List <NamedObjectSave> nosList = ObjectFinder.Self.GetAllNamedObjectsThatUseElement(element); foreach (NamedObjectSave nos in nosList) { IElement container = ObjectFinder.Self.GetElementContaining(nos); if (!elementsToSearchForTunneledVariablesIn.Contains(container)) { elementsToSearchForTunneledVariablesIn.Add(container); } if (nos.RenameVariable(oldName, newName)) { if (!elementsToGenerate.Contains(container)) { elementsToGenerate.Add(container); } } } #endregion #region Change any CustomVaribles that tunnel in to this variable foreach (IElement elementToCheck in elementsToSearchForTunneledVariablesIn) { foreach (CustomVariable variableToCheck in elementToCheck.CustomVariables) { if (!string.IsNullOrEmpty(variableToCheck.SourceObject) && !string.IsNullOrEmpty(variableToCheck.SourceObjectProperty) && variableToCheck.SourceObjectProperty == oldName) { NamedObjectSave nos = elementToCheck.GetNamedObjectRecursively(variableToCheck.SourceObject); // just to be safe if (nos != null && nosList.Contains(nos)) { variableToCheck.SourceObjectProperty = newName; if (!elementsToGenerate.Contains(elementToCheck)) { elementsToGenerate.Add(elementToCheck); } } } } } #endregion #region Change all events that reference this variable foreach (var eventResponse in element.Events) { if (eventResponse.SourceVariable == oldName) { eventResponse.SourceVariable = newName; Plugins.PluginManager.ReceiveOutput("Changing event " + eventResponse.EventName + " to use variable " + newName); } } #endregion foreach (IElement toRegenerate in elementsToGenerate) { CodeWriter.GenerateCode(toRegenerate); } } }
private void ReactToNamedObjectChangedInstanceName(NamedObjectSave namedObjectSave, object oldValueAsObject) { string oldValue = (string)oldValueAsObject; #region Fail checks string whyItIsntValid; NameVerifier.IsNamedObjectNameValid(namedObjectSave.InstanceName, out whyItIsntValid); if (!string.IsNullOrEmpty(whyItIsntValid)) { GlueGui.ShowMessageBox(whyItIsntValid); namedObjectSave.InstanceName = oldValue; } #endregion else { IElement currentElement = EditorLogic.CurrentElement; string baseObject = ((IElement)EditorLogic.CurrentElement).BaseObject; // See if the entity has a base and if the base contains this name if (!string.IsNullOrEmpty(baseObject)) { INamedObjectContainer baseNamedObjectContainer = ObjectFinder.Self.GetNamedObjectContainer(baseObject); NamedObjectSave baseNamedObject = baseNamedObjectContainer.GetNamedObjectRecursively(namedObjectSave.InstanceName); if (baseNamedObject != null) { if (baseNamedObject.SetByDerived) { // There is a base element that has an object with the same // name as the derived element. The derived doesn't have a same-named // object already, and the base is SetByDerived, so let's setup the derived // to use the base and notify the user. namedObjectSave.DefinedByBase = true; MessageBox.Show("This object has the same name as\n\n" + baseNamedObject.ToString() + "\n\nIt is SetByDerived, " + "so Glue will use this as the base object for the object " + namedObjectSave.InstanceName); } else { System.Windows.Forms.MessageBox.Show("A base object already has an object with this name"); namedObjectSave.InstanceName = oldValue; } } } if (currentElement != null) { // See if any named objects in this instance use this for tunneling foreach (CustomVariable customVariable in currentElement.CustomVariables) { if (!string.IsNullOrEmpty(customVariable.SourceObject) && customVariable.SourceObject == oldValue) { MessageBox.Show("Changing the variable " + customVariable.Name + " so it uses " + namedObjectSave.InstanceName + " instead of " + (string)oldValue); customVariable.SourceObject = namedObjectSave.InstanceName; } } // See if any events tunnel to this NOS foreach (EventResponseSave eventResponseSave in currentElement.Events) { if (!string.IsNullOrEmpty(eventResponseSave.SourceObject) && eventResponseSave.SourceObject == oldValue) { MessageBox.Show("Chaing the Event " + eventResponseSave.EventName + " so it uses " + namedObjectSave.InstanceName + " instead of " + oldValue); eventResponseSave.SourceObject = namedObjectSave.InstanceName; } } } // If this is a layer, see if any other NOS's use this as their Layer if (namedObjectSave.IsLayer) { List <NamedObjectSave> namedObjectList = EditorLogic.CurrentElement.NamedObjects; string oldLayerName = (string)oldValue; foreach (NamedObjectSave nos in namedObjectList) { nos.ReplaceLayerRecursively(oldLayerName, namedObjectSave.InstanceName); } } } }
public ReferencedFileSave CreateReferencedFileSaveForExistingFile(IElement containerForFile, string directoryInsideContainer, string absoluteFileName, PromptHandleEnum unknownTypeHandle, AssetTypeInfo ati, out string creationReport, out string errorMessage) { creationReport = ""; errorMessage = null; ReferencedFileSave referencedFileSaveToReturn = null; string whyItIsntValid; // Let's see if there is already an Entity with the same name string fileWithoutPath = FileManager.RemovePath(FileManager.RemoveExtension(absoluteFileName)); bool isValid = NameVerifier.IsReferencedFileNameValid(fileWithoutPath, ati, referencedFileSaveToReturn, containerForFile, out whyItIsntValid); if (!isValid) { errorMessage = "Invalid file name:\n" + fileWithoutPath + "\n" + whyItIsntValid; } else { Zipper.UnzipAndModifyFileIfZip(ref absoluteFileName); string extension = FileManager.GetExtension(absoluteFileName); bool isValidExtensionOrIsConfirmedByUser; bool isUnknownType; FlatRedBall.Glue.Plugins.ExportedImplementations.CommandInterfaces.ElementCommands.CheckAndWarnAboutUnknownFileTypes(unknownTypeHandle, extension, out isValidExtensionOrIsConfirmedByUser, out isUnknownType); string fileToAdd = null; if (isValidExtensionOrIsConfirmedByUser) { string directoryThatFileShouldBeRelativeTo = FlatRedBall.Glue.Plugins.ExportedImplementations.CommandInterfaces.ElementCommands.GetFullPathContentDirectory(containerForFile, directoryInsideContainer); string projectDirectory = ProjectManager.ContentProject.GetAbsoluteContentFolder(); bool needsToCopy = !FileManager.IsRelativeTo(absoluteFileName, projectDirectory); if (needsToCopy) { fileToAdd = directoryThatFileShouldBeRelativeTo + FileManager.RemovePath(absoluteFileName); fileToAdd = FileManager.MakeRelative(fileToAdd, ProjectManager.ContentProject.GetAbsoluteContentFolder()); try { FileHelper.RecursivelyCopyContentTo(absoluteFileName, FileManager.GetDirectory(absoluteFileName), directoryThatFileShouldBeRelativeTo); } catch (System.IO.FileNotFoundException fnfe) { errorMessage = "Could not copy the files because of a missing file: " + fnfe.Message; } } else { fileToAdd = FlatRedBall.Glue.Plugins.ExportedImplementations.CommandInterfaces.ElementCommands.GetNameOfFileRelativeToContentFolder(absoluteFileName, directoryThatFileShouldBeRelativeTo, projectDirectory); } } if (string.IsNullOrEmpty(errorMessage)) { BuildToolAssociation bta = null; if (ati != null && !string.IsNullOrEmpty(ati.CustomBuildToolName)) { bta = BuildToolAssociationManager.Self.GetBuilderToolAssociationByName(ati.CustomBuildToolName); } if (containerForFile != null) { referencedFileSaveToReturn = containerForFile.AddReferencedFile(fileToAdd, ati, bta); } else { bool useFullPathAsName = false; // todo - support built files here referencedFileSaveToReturn = AddReferencedFileToGlobalContent(fileToAdd, useFullPathAsName); } // This will be null if there was an error above in creating this file if (referencedFileSaveToReturn != null) { if (containerForFile != null) { containerForFile.HasChanged = true; } if (fileToAdd.EndsWith(".csv")) { string fileToAddAbsolute = ProjectManager.MakeAbsolute(fileToAdd); CsvCodeGenerator.GenerateAndSaveDataClass(referencedFileSaveToReturn, referencedFileSaveToReturn.CsvDelimiter); } if (isUnknownType) { referencedFileSaveToReturn.LoadedAtRuntime = false; } string error; referencedFileSaveToReturn.RefreshSourceFileCache(false, out error); if (!string.IsNullOrEmpty(error)) { ErrorReporter.ReportError(referencedFileSaveToReturn.Name, error, false); } } } } return(referencedFileSaveToReturn); }
public void Test() { AvailableStates availableStates = new AvailableStates( null, mEntitySave, mExposedStateInCategoryVariable, null); List <string> listToFill = new List <string>(); availableStates.CurrentCustomVariable = mExposedStateVariable; listToFill.Clear(); availableStates.GetListOfStates(listToFill, null); if (listToFill.Count != NumberOfUncategorizedAndSharedStates(mEntitySave) + 1 || listToFill[1] != "Uncategorized") { throw new Exception("GetListOfStates isn't properly filtering out categorized states"); } listToFill.Clear(); availableStates.CurrentCustomVariable = mExposedStateInCategoryVariable; availableStates.GetListOfStates(listToFill, null); if (listToFill.Count != 2 || listToFill[1] != "StateInCategory1") { throw new Exception("GetListOfStates isn't properly filtering out uncategorized states"); } // Test getting states for variables that don't use the "CurrentWhatever" naming in categories listToFill.Clear(); availableStates.CurrentElement = mContainerEntitySave; availableStates.CurrentNamedObject = mEntitySaveInstance; availableStates.CurrentCustomVariable = null; availableStates.GetListOfStates(listToFill, mRenamedExposedCategorizedStateVariable.Name); if (listToFill.Contains("StateInCategory1") == false) { throw new Exception("GetListOfStates doesn't work properly on states that are categorized and have variables that don't follow the typical CurrentWhatever naming."); } // Test getting states for variables that don't use the "CurrentWhatever" naming in categories, and are accessed through inheritance listToFill.Clear(); availableStates.CurrentElement = mContainerEntitySave; availableStates.CurrentNamedObject = mDerivedSaveInstance; availableStates.CurrentCustomVariable = null; availableStates.GetListOfStates(listToFill, mRenamedExposedUncategorizedStateVariable.Name); if (listToFill.Count != mEntitySave.States.Count + 1) { throw new Exception("GetListOfStates on NOS's that are derived doesn't seem to work properly"); } listToFill.Clear(); availableStates.CurrentElement = mContainerEntitySave; availableStates.CurrentCustomVariable = null; availableStates.CurrentNamedObject = mEntitySaveInstance; availableStates.GetListOfStates(listToFill, "CurrentState"); if (listToFill.Count != NumberOfUncategorizedAndSharedStates(mEntitySave) + 1 || listToFill[1] != "Uncategorized") // will include "<NONE>" { throw new Exception("GetListOfStates isn't properly filtering out categorized states"); } // Test getting states for a variable that doesn't use the typical "CurrentWhatever" naming on uncategorized listToFill.Clear(); availableStates.CurrentElement = mContainerEntitySave; availableStates.CurrentCustomVariable = null; availableStates.CurrentNamedObject = mEntitySaveInstance; availableStates.GetListOfStates(listToFill, mRenamedExposedUncategorizedStateVariable.Name); if (listToFill.Count != NumberOfUncategorizedAndSharedStates(mEntitySave) + 1 || listToFill[1] != "Uncategorized") // will include "<NONE>" { throw new Exception("GetListOfStates isn't properly filtering out categorized states"); } // Test getting states for a tunneled variable that doesn't use the typical "CurrentWhatever" naming on uncategorized listToFill.Clear(); availableStates.CurrentElement = mContainerEntitySave; availableStates.CurrentCustomVariable = mTunneledUncategorizedStateInContainer; availableStates.CurrentNamedObject = null; availableStates.GetListOfStates(listToFill, mRenamedExposedUncategorizedStateVariable.Name); if (listToFill.Count != NumberOfUncategorizedAndSharedStates(mEntitySave) + 1 || listToFill[1] != "Uncategorized") // will include "<NONE>" { throw new Exception("GetListOfStates isn't properly filtering out categorized states"); } listToFill.Clear(); availableStates.CurrentElement = mContainerEntitySave; availableStates.CurrentNamedObject = mEntitySaveInstance; availableStates.CurrentCustomVariable = null; availableStates.GetListOfStates(listToFill, "CurrentStateCategoryState"); if (listToFill.Count != 2 || listToFill[1] != "StateInCategory1") { throw new Exception("GetListOfStates isn't properly filtering out uncategorized states"); } string whyItIsntValid; if (NameVerifier.IsStateNameValid("Color", null, null, null, out whyItIsntValid)) { throw new Exception("The state name Color should not be a valid name, but Glue allows it"); } listToFill.Clear(); availableStates.CurrentElement = mDerivedEntitySave; availableStates.CurrentCustomVariable = mDerivedEntitySave.CustomVariables[0]; availableStates.CurrentNamedObject = null; availableStates.GetListOfStates(listToFill, mDerivedEntitySave.CustomVariables[0].Name); if (listToFill.Count == 0 || listToFill[1] != "Uncategorized") { throw new Exception("GetListOfStates is not properly finding uncategorized states defined in a base type"); } listToFill.Clear(); availableStates.CurrentElement = mDerivedEntitySave; availableStates.CurrentCustomVariable = mDerivedEntitySave.CustomVariables[1]; availableStates.CurrentNamedObject = null; availableStates.GetListOfStates(listToFill, mDerivedEntitySave.CustomVariables[1].Name); if (listToFill.Count == 0 || listToFill[1] != "StateInCategory1") { throw new Exception("GetListOfStates is not properly finding categorized states defined in a base type"); } // Test CurrentState variable tate in the Container listToFill.Clear(); availableStates.CurrentElement = mContainerEntitySave; availableStates.CurrentCustomVariable = null; availableStates.CurrentStateSave = null; availableStates.CurrentNamedObject = mDerivedSaveInstance; availableStates.GetListOfStates(listToFill, "CurrentState"); if (listToFill.Count != mEntitySave.States.Count + 1) { throw new Exception("Getting state on NamedObject that is of a derived type that gets its state from the base type is not working properly"); } ////Test adding same name with shared category //Test shared vs shared var sharedCategoryElement = new EntitySave(); string outString; sharedCategoryElement.StateCategoryList.Add(new StateSaveCategory { Name = "First", SharesVariablesWithOtherCategories = true }); sharedCategoryElement.StateCategoryList[0].States.Add(new StateSave { Name = "State1" }); sharedCategoryElement.StateCategoryList.Add(new StateSaveCategory { Name = "Second", SharesVariablesWithOtherCategories = true }); if (NameVerifier.IsStateNameValid("State1", sharedCategoryElement, sharedCategoryElement.StateCategoryList[1], null, out outString)) { throw new Exception("Should not allow adding same state name between shared categories."); } //Test shared vs main sharedCategoryElement = new EntitySave(); sharedCategoryElement.StateCategoryList.Add(new StateSaveCategory { Name = "First", SharesVariablesWithOtherCategories = true }); sharedCategoryElement.StateCategoryList[0].States.Add(new StateSave { Name = "State1" }); if (NameVerifier.IsStateNameValid("State1", sharedCategoryElement, null, null, out outString)) { throw new Exception("Should not allow adding same state name in main when exists in shared categories."); } //Test main vs shared sharedCategoryElement = new EntitySave(); sharedCategoryElement.States.Add(new StateSave { Name = "State1" }); sharedCategoryElement.StateCategoryList.Add(new StateSaveCategory { Name = "First", SharesVariablesWithOtherCategories = true }); if (NameVerifier.IsStateNameValid("State1", sharedCategoryElement, sharedCategoryElement.StateCategoryList[0], null, out outString)) { throw new Exception("Should not allow adding same state name in shared category when exists in main states."); } }