internal string GetAddToManagersFunc(IElement glueElement, NamedObjectSave namedObjectSave, ReferencedFileSave referencedFileSave, string layerName) { var stringBuilder = new StringBuilder(); var namedObjectName = namedObjectSave?.FieldName ?? referencedFileSave.GetInstanceName(); string layerCode = "null"; if (!string.IsNullOrEmpty(layerName)) { layerCode = $"System.Linq.Enumerable.FirstOrDefault(FlatRedBall.Gum.GumIdb.AllGumLayersOnFrbLayer({layerName}))"; } if (glueElement is EntitySave) { stringBuilder.AppendLine("{"); stringBuilder.AppendLine($"{namedObjectName}.AddToManagers(RenderingLibrary.SystemManagers.Default, {layerCode});"); var shouldGenerateWrapper = namedObjectSave?.AttachToContainer == true; if (shouldGenerateWrapper) { stringBuilder.AppendLine($"var wrapperForAttachment = new GumCoreShared.FlatRedBall.Embedded.PositionedObjectGueWrapper(this, {namedObjectName});"); stringBuilder.AppendLine("FlatRedBall.SpriteManager.AddPositionedObject(wrapperForAttachment);"); stringBuilder.AppendLine("gumAttachmentWrappers.Add(wrapperForAttachment);"); } stringBuilder.AppendLine("}"); } else { stringBuilder.AppendLine($"{namedObjectName}.AddToManagers(RenderingLibrary.SystemManagers.Default, {layerCode});"); } return(stringBuilder.ToString()); }
public static void GenerateTimedEmit(ICodeBlock codeBlock, ReferencedFileSave rfs, IElement element) { if (rfs.LoadedAtRuntime && !rfs.LoadedOnlyWhenReferenced && (element is ScreenSave || rfs.IsSharedStatic == false) && !string.IsNullOrEmpty(rfs.Name) && FileManager.GetExtension(rfs.Name) == "emix") { codeBlock.Line(rfs.GetInstanceName() + ".TimedEmit();"); } }
private void GenerateAddToManagers(ICodeBlock codeBlock, ReferencedFileSave file) { if (file.GetProperty <bool>(EntityCreationManager.CreateEntitiesInGeneratedCodePropertyName)) { var instanceName = file.GetInstanceName(); codeBlock.Line( $"FlatRedBall.TileEntities.TileEntityInstantiator.CreateEntitiesFrom({instanceName});"); } }
private string GetObjectFromFileFunc(IElement element, NamedObjectSave namedObjectSave, ReferencedFileSave referencedFileSave, string overridingContainerName) { // CollisionLayer1 = TmxWithTileShapeCollectionLayers.Collisions.First(item => item.Name == "CollisionLayer1"); T Get <T>(string name) { return(namedObjectSave.Properties.GetValue <T>(name)); } var creationOptions = Get <CollisionCreationOptions>( nameof(TileShapeCollectionPropertiesViewModel.CollisionCreationOptions)); if (creationOptions == CollisionCreationOptions.FromLayer) { //var tileType = namedObjectSave.Properties.GetValue<string>( // nameof(ViewModels.TileShapeCollectionPropertiesViewModel.CollisionTileType)); var toReturn = $"{namedObjectSave.FieldName} = new FlatRedBall.TileCollisions.TileShapeCollection();\n"; toReturn += "FlatRedBall.TileCollisions.TileShapeCollectionLayeredTileMapExtensions.AddCollisionFrom(\n" + $"{namedObjectSave.FieldName},\n" + $"{referencedFileSave.GetInstanceName()}.MapLayers.FindByName(\"{namedObjectSave.FieldName}\"),\n" + $"{referencedFileSave.GetInstanceName()},\n" + $"list => list.Any(" + //$"item => item.Name == \"Type\" " + //$" && item.Value as string == \"{tileType}\")" + $"));\n"; //if (namedObjectSave.Properties.GetValue<bool>(nameof(ViewModels.TileShapeCollectionPropertiesViewModel.IsCollisionVisible))) //{ // toReturn += $"{namedObjectSave.FieldName}.Visible = true;\n"; //} return(toReturn); } //else //{ // return $"{namedObjectSave.FieldName} = {referencedFileSave.GetInstanceName()}.Collisions.First(item => item.Name == \"{sourceName}\");"; //} return(""); }
private NamedObjectSave CreateSpriteNamedObject(ReferencedFileSave rfs) { SpriteSave spriteSave = new SpriteSave(); int imageHeight = AppState.Self.CurrentTileset.Images[0].height; int imageWidth = AppState.Self.CurrentTileset.Images[0].width; var currentTileset = AppState.Self.CurrentTileset; var id = (uint)(AppState.Self.CurrentMapTilesetTile.id + currentTileset.Firstgid); TMXGlueLib.TiledMapSave.SetSpriteTextureCoordinates( id, spriteSave, currentTileset, AppState.Self.CurrentTiledMapSave.orientation); NamedObjectSave nos = new NamedObjectSave(); nos.SourceType = SourceType.FlatRedBallType; nos.SourceClassType = "Sprite"; nos.InstanceName = "Sprite"; nos.InstructionSaves.Add(new CustomVariableInNamedObject() { Member = "Texture", Type = "Texture2D", Value = rfs.GetInstanceName() }); nos.InstructionSaves.Add(new CustomVariableInNamedObject() { Member = "TextureScale", Value = 1.0f }); nos.InstructionSaves.Add(new CustomVariableInNamedObject() { Member = "TopTexturePixel", Value = spriteSave.TopTextureCoordinate * (float)imageHeight }); nos.InstructionSaves.Add(new CustomVariableInNamedObject() { Member = "BottomTexturePixel", Value = spriteSave.BottomTextureCoordinate * (float)imageHeight }); nos.InstructionSaves.Add(new CustomVariableInNamedObject() { Member = "LeftTexturePixel", Value = spriteSave.LeftTextureCoordinate * (float)imageWidth }); nos.InstructionSaves.Add(new CustomVariableInNamedObject() { Member = "RightTexturePixel", Value = spriteSave.RightTextureCoordinate * (float)imageWidth }); return(nos); }
private string GetObjectFromFileFunc(IElement element, NamedObjectSave namedObjectSave, ReferencedFileSave referencedFileSave, string overridingContainerName) { // CollisionLayer1 = TmxWithTileShapeCollectionLayers.Collisions.First(item => item.Name == "CollisionLayer1"); var sourceName = namedObjectSave.SourceNameWithoutParenthesis; var valueAsString = namedObjectSave.Properties.GetValue <string>( nameof(ViewModels.TileShapeCollectionPropertiesViewModel.CollisionInclusion)); var hasSpecificType = valueAsString == ViewModels.CollisionInclusion.ByType.ToString(); if (hasSpecificType) { var tileType = namedObjectSave.Properties.GetValue <string>( nameof(ViewModels.TileShapeCollectionPropertiesViewModel.CollisionTileType)); var toReturn = $"{namedObjectSave.FieldName} = new FlatRedBall.TileCollisions.TileShapeCollection();\n"; toReturn += "FlatRedBall.TileCollisions.TileShapeCollectionLayeredTileMapExtensions.AddCollisionFrom(\n" + $"{namedObjectSave.FieldName},\n" + $"{referencedFileSave.GetInstanceName()}.MapLayers.FindByName(\"{namedObjectSave.FieldName}\"),\n" + $"{referencedFileSave.GetInstanceName()},\n" + $"list => list.Any(item => item.Name == \"Type\" && item.Value as string == \"{tileType}\"));\n"; if (namedObjectSave.Properties.GetValue <bool>(nameof(ViewModels.TileShapeCollectionPropertiesViewModel.IsCollisionVisible))) { toReturn += $"{namedObjectSave.FieldName}.Visible = true;\n"; } return(toReturn); } else { return($"{namedObjectSave.FieldName} = {referencedFileSave.GetInstanceName()}.Collisions.First(item => item.Name == \"{sourceName}\");"); } }
private static ICodeBlock GetGlobalContentFilesMethods() { ICodeBlock codeBlock = new CodeDocument(); var currentBlock = codeBlock; var classLevelBlock = currentBlock; codeBlock._(); // Don't use foreach to make this tolerate changes to the collection while it generates //foreach (ReferencedFileSave rfs in ProjectManager.GlueProjectSave.GlobalFiles) for (int i = 0; i < ProjectManager.GlueProjectSave.GlobalFiles.Count; i++) { ReferencedFileSave rfs = ProjectManager.GlueProjectSave.GlobalFiles[i]; ReferencedFileSaveCodeGenerator.AppendFieldOrPropertyForReferencedFile(currentBlock, rfs, null); } const bool inheritsFromElement = false; ReferencedFileSaveCodeGenerator.GenerateGetStaticMemberMethod(ProjectManager.GlueProjectSave.GlobalFiles, currentBlock, true, inheritsFromElement); ReferencedFileSaveCodeGenerator.GenerateGetFileMethodByName( ProjectManager.GlueProjectSave.GlobalFiles, currentBlock, false, "GetFile", false); if (ProjectManager.GlueProjectSave.GlobalContentSettingsSave.RecordLockContention) { currentBlock.Line("public static List<string> LockRecord = new List<string>();"); } currentBlock .AutoProperty("public static bool", "IsInitialized", "", "private"); currentBlock .AutoProperty("public static bool", "ShouldStopLoading"); currentBlock.Line("const string ContentManagerName = \"Global\";"); var initializeFunction = currentBlock.Function("public static void", "Initialize", ""); currentBlock = initializeFunction ._(); foreach (var generator in CodeWriter.GlobalContentCodeGenerators) { generator.GenerateInitializeStart(initializeFunction); } //stringBuilder.AppendLine("\t\t\tstring ContentManagerName = \"Global\";"); // Do the high-proprity loads first // Update May 10, 2011 // If loading asynchronously // the first Screen may load before // we even get to the high-priority RFS's // (which are localization). This could cause // the first Screen to have unlocalized text. That's // why we want to load it before we even start our async loading. foreach (ReferencedFileSave rfs in ProjectManager.GlueProjectSave.GlobalFiles) { if (ReferencedFileSaveCodeGenerator.IsRfsHighPriority(rfs)) { ReferencedFileSaveCodeGenerator.GetInitializationForReferencedFile(rfs, null, initializeFunction, LoadType.CompleteLoad); } } bool loadAsync = GenerateLoadAsyncCode(classLevelBlock, initializeFunction); if (GlobalContentCodeGenerator.SuppressGlobalContentDictionaryRefresh == false) { ReferencedFileSaveCodeGenerator.RefreshGlobalContentDictionary(); } if (loadAsync) { currentBlock.Line("#if !REQUIRES_PRIMARY_THREAD_LOADING"); } foreach (ReferencedFileSave rfs in ProjectManager.GlueProjectSave.GlobalFiles) { if (!ReferencedFileSaveCodeGenerator.IsRfsHighPriority(rfs) && rfs.LoadedAtRuntime) { var blockToUse = initializeFunction; if (loadAsync) { blockToUse = classLevelBlock .Function("static void", "Load" + rfs.Name.Replace("/", "_").Replace(".", "_"), ""); } ReferencedFileSaveCodeGenerator.GetInitializationForReferencedFile(rfs, null, blockToUse, LoadType.CompleteLoad); if (loadAsync) { blockToUse.Line("#if !REQUIRES_PRIMARY_THREAD_LOADING"); blockToUse.Line("m" + rfs.GetInstanceName() + "Mre.Set();"); blockToUse.Line("#endif"); blockToUse.End(); } } } if (loadAsync) { currentBlock.Line("#endif"); } if (!loadAsync) { currentBlock = currentBlock .Line("\t\t\tIsInitialized = true;") .End(); } GenerateReloadFileMethod(classLevelBlock); foreach (var generator in CodeWriter.GlobalContentCodeGenerators) { generator.GenerateInitializeEnd(initializeFunction); generator.GenerateAdditionalMethods(classLevelBlock); } return(codeBlock); }
private static void MoveReferencedFile(TreeNode treeNodeMoving, TreeNode targetNode) { var response = GeneralResponse.SuccessfulResponse; while (targetNode != null && targetNode.IsReferencedFile()) { targetNode = targetNode.Parent; } // If the user drops a file on a Screen or Entity, let's allow them to // complete the operation on the Files node if (targetNode is BaseElementTreeNode) { targetNode = ((BaseElementTreeNode)targetNode).FilesTreeNode; } ReferencedFileSave referencedFileSave = treeNodeMoving.Tag as ReferencedFileSave; if (!targetNode.IsFilesContainerNode() && !targetNode.IsFolderInFilesContainerNode() && !targetNode.IsFolderForGlobalContentFiles() && !targetNode.IsNamedObjectNode() && !targetNode.IsRootNamedObjectNode()) { response.Fail(@"Can't drop this file here"); } else if (!string.IsNullOrEmpty(referencedFileSave.SourceFile) || referencedFileSave.SourceFileCache.Count != 0) { response.Fail("Can't move the file\n\n" + referencedFileSave.Name + "\n\nbecause it has source-referencing files. These sources will be broken " + "if the file is moved. You will need to manually move the file, modify the source references, remove this file, then add the newly-created file."); } if (response.Succeeded) { if (targetNode.IsGlobalContentContainerNode()) { if (targetNode.GetContainingElementTreeNode() == null) { string targetDirectory = ProjectManager.MakeAbsolute(targetNode.GetRelativePath(), true); MoveReferencedFileToDirectory(referencedFileSave, targetDirectory); } else { DragAddFileToGlobalContent(treeNodeMoving, referencedFileSave); // This means the user wants to add the file // to global content. } } else if (targetNode.IsFolderForGlobalContentFiles()) { string targetDirectory = ProjectManager.MakeAbsolute(targetNode.GetRelativePath(), true); MoveReferencedFileToDirectory(referencedFileSave, targetDirectory); } else if (targetNode.IsRootNamedObjectNode()) { AddObjectViewModel viewModel = new AddObjectViewModel(); viewModel.SourceType = SourceType.File; viewModel.SourceFile = (treeNodeMoving.Tag as ReferencedFileSave).Name; GlueCommands.Self.DialogCommands.ShowAddNewObjectDialog(viewModel); } else if (targetNode.IsNamedObjectNode() && // dropping on an object in the same element targetNode.GetContainingElementTreeNode() == treeNodeMoving.GetContainingElementTreeNode()) { response = HandleDroppingFileOnObjectInSameElement(targetNode, referencedFileSave); } //if (targetNode.IsFolderInFilesContainerNode() || targetNode.IsFilesContainerNode()) else { // See if we're moving the RFS from one Element to another IElement container = ObjectFinder.Self.GetElementContaining(referencedFileSave); TreeNode elementTreeNodeDroppingIn = targetNode.GetContainingElementTreeNode(); IElement elementDroppingIn = null; if (elementTreeNodeDroppingIn != null) { // User didn't drop on an entity, but instead on a node within the entity. // Let's check if it's a subfolder. If so, we need to tell the user that we // can't add the file in a subfolder. if (targetNode.IsFolderInFilesContainerNode()) { response.Message = "Shared files cannot be added to subfolders, so it will be added directly to \"Files\""; } elementDroppingIn = elementTreeNodeDroppingIn.Tag as IElement; } if (container != elementDroppingIn) { // Make sure the target element is not named the same as the file itself. // For example, dropping a file called Level1.tmx in a screen called Level1. // This will not compile so we shouldn't allow it. var areNamedTheSame = elementDroppingIn.GetStrippedName() == referencedFileSave.GetInstanceName(); if (areNamedTheSame) { response.Fail($"The file {referencedFileSave.GetInstanceName()} has the same name as the target screen. it will not be added since this is not allowed."); } if (response.Succeeded) { ElementViewWindow.SelectedNode = targetNode; string absoluteFileName = ProjectManager.MakeAbsolute(referencedFileSave.Name, true); string creationReport; string errorMessage; var newlyCreatedFile = ElementCommands.Self.CreateReferencedFileSaveForExistingFile(elementDroppingIn, null, absoluteFileName, PromptHandleEnum.Prompt, referencedFileSave.GetAssetTypeInfo(), out creationReport, out errorMessage); ElementViewWindow.UpdateChangedElements(); if (!String.IsNullOrEmpty(errorMessage)) { MessageBox.Show(errorMessage); } else if (newlyCreatedFile != null) { GlueCommands.Self.TreeNodeCommands.SelectTreeNode(newlyCreatedFile); } } } else { // Not moving into or out of an element string targetDirectory = ProjectManager.MakeAbsolute(targetNode.GetRelativePath(), true); MoveReferencedFileToDirectory(referencedFileSave, targetDirectory); } } } if (!string.IsNullOrEmpty(response.Message)) { MessageBox.Show(response.Message); } }
private string GetRawDialogTreeLoadCode(IElement element, NamedObjectSave namedObject, ReferencedFileSave referencedFile, string contentManager) { var fileName = ReferencedFileSaveCodeGenerator.GetFileToLoadForRfs(referencedFile, referencedFile.GetAssetTypeInfo()); return($"{referencedFile.GetInstanceName()} = DialogTreePlugin.SaveClasses.DialogTreeRaw.RootObject.FromJson(\"{fileName}\");"); }