public static bool GetCanUseContentPipeline(this ReferencedFileSave instance) { return // CSVs can use content pipeline (instance.IsCsvOrTreatedAsCsv || (instance.GetAssetTypeInfo() != null && !string.IsNullOrEmpty(instance.GetAssetTypeInfo().ContentProcessor))); }
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 AssetTypeInfo GetAssetTypeInfoForProjectSpecificFile(this ReferencedFileSave instance, ProjectSpecificFile psf) { string extension = FileManager.GetExtension(psf.FilePath); AssetTypeInfo thisAssetTypeInfo = instance.GetAssetTypeInfo(); foreach (AssetTypeInfo assetTypeInfo in AvailableAssetTypes.Self.AllAssetTypes) { if (assetTypeInfo.Extension == extension && assetTypeInfo.RuntimeTypeName == thisAssetTypeInfo.RuntimeTypeName) { return(assetTypeInfo); } } return(null); }
public static bool GetGeneratesMember(this ReferencedFileSave instance) { bool toReturn = instance.LoadedAtRuntime && !instance.IsDatabaseForLocalizing; if (!instance.IsCsvOrTreatedAsCsv) { var ati = instance.GetAssetTypeInfo(); if (ati != null && string.IsNullOrEmpty(ati.QualifiedRuntimeTypeName.QualifiedType)) { return(false); } } return(toReturn); }
public static void AppendFieldOrPropertyForReferencedFile(ICodeBlock codeBlock, ReferencedFileSave referencedFile, string containerName, IElement element, string contentManagerName) { /////////////////////////////////////EARLY OUT////////////////////////////////////////////// // If the referenced file is a database for localizing, it will just be stuffed right into the localization manager if (!referencedFile.LoadedAtRuntime || referencedFile.IsDatabaseForLocalizing) return; ///////////////////////////////////END EARLY OUT///////////////////////////////////////////// string fileName = referencedFile.Name; string extension = FileManager.GetExtension(fileName); AssetTypeInfo ati = referencedFile.GetAssetTypeInfo(); string variableName = referencedFile.GetInstanceName(); #region Get the typeName string typeName = null; if (ati != null && !referencedFile.TreatAsCsv && ati.QualifiedRuntimeTypeName.QualifiedType != null) { typeName = ati.QualifiedRuntimeTypeName.QualifiedType; } else if (extension == "csv" || referencedFile.TreatAsCsv) { typeName = CsvCodeGenerator.GetEntireGenericTypeForCsvFile(referencedFile); } #endregion //////////////////////////////EARLY OUT/////////////////////////////////////// if (typeName == null) return; ///////////////////////////END EARLY OUT////////////////////////////////////// AddIfConditionalSymbolIfNecesssary(codeBlock, referencedFile); if (NeedsFullProperty(referencedFile, containerName)) { AppendPropertyForReferencedFileSave(codeBlock, referencedFile, containerName, element, contentManagerName, ati, variableName, typeName); } else { if (containerName == ContentLoadWriter.GlobalContentContainerName) { // Global Content will always have the content as properties. This is so that you can switch between // async and sync loading and not have to change reflection code codeBlock.AutoProperty(variableName, Public: referencedFile.HasPublicProperty, // Should be protected so derived classes can access this Protected: !referencedFile.HasPublicProperty, Static: referencedFile.IsSharedStatic, Type: typeName); } else { codeBlock.Line(StringHelper.Modifiers( Public: referencedFile.HasPublicProperty, // Should be protected so derived classes can access this Protected: !referencedFile.HasPublicProperty, Static: referencedFile.IsSharedStatic, Type: typeName, Name: variableName) + ";"); } } AddEndIfIfNecessary(codeBlock, referencedFile); }
public static void GenerateConvertToManuallyUpdated(ICodeBlock currentBlock, ReferencedFileSave rfs) { if (rfs.LoadedAtRuntime && !rfs.LoadedOnlyWhenReferenced) { AssetTypeInfo ati = rfs.GetAssetTypeInfo(); if (!rfs.IsSharedStatic && ati != null && !string.IsNullOrEmpty(ati.MakeManuallyUpdatedMethod)) { AddIfConditionalSymbolIfNecesssary(currentBlock, rfs); currentBlock.Line(ati.MakeManuallyUpdatedMethod.Replace("this", rfs.GetInstanceName()) + ";"); AddEndIfIfNecessary(currentBlock, rfs); } } }
public static bool GetIfShouldAddToManagers(IElement saveObject, ReferencedFileSave referencedFile) { bool shouldAddToManagers = referencedFile.LoadedAtRuntime && !referencedFile.LoadedOnlyWhenReferenced; if (shouldAddToManagers) { AssetTypeInfo ati = referencedFile.GetAssetTypeInfo(); // We don't want to add shared static stuff to the manager - it's just used to pull and clone objects out of. // Update September 12, 2012 // We actually do want to add // static objects if they are part // of a Screen. shouldAddToManagers = ati != null && (!referencedFile.IsSharedStatic || saveObject is ScreenSave) && ati.AddToManagersMethod.Count != 0 && !string.IsNullOrEmpty(ati.AddToManagersMethod[0]) && referencedFile.AddToManagers; } return shouldAddToManagers; }
public static ICodeBlock GetAddToManagersForReferencedFile(IElement mSaveObject, ReferencedFileSave referencedFile) { bool shouldAddToManagers = GetIfShouldAddToManagers(mSaveObject, referencedFile); ICodeBlock codeBlock = new CodeDocument(3); // We don't want to add shared static stuff to the manager - it's just used to pull and clone objects out of. // Update September 12, 2012 // We actually do want to add // static objects if they are part // of a Screen. if (shouldAddToManagers) { ICodeBlock currentBlock = codeBlock; AssetTypeInfo ati = referencedFile.GetAssetTypeInfo(); string fileName = referencedFile.Name; AddIfConditionalSymbolIfNecesssary(codeBlock, referencedFile); string typeName = ati.RuntimeTypeName; string variableName = referencedFile.GetInstanceName(); if (BaseElementTreeNode.IsOnOwnLayer(mSaveObject) && ati.LayeredAddToManagersMethod.Count != 0 && !string.IsNullOrEmpty(ati.LayeredAddToManagersMethod[0])) { string layerAddToManagersMethod = ati.LayeredAddToManagersMethod[0]; if (mSaveObject is EntitySave) { layerAddToManagersMethod = layerAddToManagersMethod.Replace("mLayer", "layerToAddTo"); } currentBlock.Line(layerAddToManagersMethod.Replace("this", variableName) + ";"); } else if (ati.LayeredAddToManagersMethod.Count != 0 && !string.IsNullOrEmpty(ati.LayeredAddToManagersMethod[0]) && mSaveObject is ScreenSave) { string layerAddToManagersMethod = ati.LayeredAddToManagersMethod[0]; // The Screen has an mLayer //layerAddToManagersMethod = layerAddToManagersMethod.Replace("mLayer", "layerToAddTo"); currentBlock.Line(layerAddToManagersMethod.Replace("this", variableName) + ";"); } else { currentBlock.Line(ati.AddToManagersMethod[0].Replace("this", variableName) + ";"); } if (referencedFile.IsManuallyUpdated && !string.IsNullOrEmpty(ati.MakeManuallyUpdatedMethod)) { currentBlock.Line(ati.MakeManuallyUpdatedMethod.Replace("this", variableName) + ";"); } AddEndIfIfNecessary(codeBlock, referencedFile); } return codeBlock; }
protected ICodeBlock GetDestroyForReferencedFile(IElement element, ReferencedFileSave referencedFile) { ICodeBlock codeBlock = new CodeDocument(3); ///////////////////////////////EARLY OUT/////////////////////// if (!referencedFile.LoadedAtRuntime || !referencedFile.DestroyOnUnload) { return codeBlock; } if (referencedFile.GetGeneratesMember() == false) { return codeBlock; } /////////////////////////////END EARLY OUT///////////////////// AddIfConditionalSymbolIfNecesssary(codeBlock, referencedFile); string fileName = referencedFile.Name; AssetTypeInfo ati = referencedFile.GetAssetTypeInfo(); string variableName = referencedFile.GetInstanceName(); bool isScreenSave = element is ScreenSave; if (referencedFile.LoadedOnlyWhenReferenced) { variableName = "m" + variableName; codeBlock = codeBlock.If(variableName + " != null"); } if (ati != null && (!referencedFile.IsSharedStatic || isScreenSave)) { string typeName = ati.RuntimeTypeName; string destroyMethod = ati.DestroyMethod; string recycleMethod = ati.RecycledDestroyMethod; if (string.IsNullOrEmpty(recycleMethod)) { recycleMethod = destroyMethod; } if (!string.IsNullOrEmpty(ati.DestroyMethod)) { if (isScreenSave && recycleMethod != destroyMethod) { codeBlock = codeBlock.If("this.UnloadsContentManagerWhenDestroyed && ContentManagerName != \"Global\""); codeBlock.Line(destroyMethod.Replace("this", variableName) + ";"); if (referencedFile.LoadedOnlyWhenReferenced) { codeBlock = codeBlock.End().ElseIf(variableName + " != null"); } else { codeBlock = codeBlock.End().Else(); } codeBlock.Line(recycleMethod.Replace("this", variableName) + ";"); codeBlock = codeBlock.End(); } else { codeBlock.Line(destroyMethod.Replace("this", variableName) + ";"); } } if (ati.ShouldBeDisposed && element.UseGlobalContent == false) { codeBlock = codeBlock.If("this.UnloadsContentManagerWhenDestroyed && ContentManagerName != \"Global\""); codeBlock.Line(string.Format("{0}.Dispose();", variableName)); codeBlock = codeBlock.End(); } } if (element is ScreenSave && referencedFile.IsSharedStatic) { if (referencedFile.LoadedOnlyWhenReferenced) { variableName = "m" + referencedFile.GetInstanceName(); } // We used to do this here, but we want to do it after all Objects have been destroyed // because we may need to make the file one way before the destruction of the objects. if (ati != null && ati.SupportsMakeOneWay) { codeBlock = codeBlock.If("this.UnloadsContentManagerWhenDestroyed && ContentManagerName != \"Global\""); codeBlock.Line(string.Format("{0} = null;", variableName)); codeBlock = codeBlock.End().Else(); codeBlock.Line(string.Format("{0}.MakeOneWay();", variableName)); codeBlock = codeBlock.End(); } else { codeBlock.Line(string.Format("{0} = null;", variableName)); } } if (referencedFile.LoadedOnlyWhenReferenced) { codeBlock = codeBlock.End(); } AddEndIfIfNecessary(codeBlock, referencedFile); return codeBlock; }
public static ICodeBlock GetPostCustomActivityForReferencedFile(ReferencedFileSave referencedFile) { ICodeBlock codeBlock = new CodeDocument(); if (!referencedFile.LoadedAtRuntime) { return codeBlock; } AssetTypeInfo ati = referencedFile.GetAssetTypeInfo(); // January 8, 2012 // This used to not // check LoadedOnlyWhenReferenced // but I think it should otherwise // this code will always load Scenes // that are LoadedOnlyWhenReferenced by // calling their ManageAll method - so I // added a check for LoadedOnlyWhenReferenced. if (ati != null && !referencedFile.IsSharedStatic && !referencedFile.LoadedOnlyWhenReferenced && ati.AfterCustomActivityMethod != null) { AddIfConditionalSymbolIfNecesssary(codeBlock, referencedFile); string variableName = referencedFile.GetInstanceName(); codeBlock.Line(ati.AfterCustomActivityMethod.Replace("this", variableName) + ";"); AddEndIfIfNecessary(codeBlock, referencedFile); return codeBlock; } else { return codeBlock; } }
private static string GetTextureFormatTag(ReferencedFileSave rfs) { if (rfs.GetAssetTypeInfo() != null && rfs.GetAssetTypeInfo().RuntimeTypeName == "Texture2D") { return "ProcessorParameters_TextureFormat"; } else { return "ProcessorParameters_TextureProcessorOutputFormat"; } }
bool IsRfsOfUnqualifiedRuntimeType(ReferencedFileSave rfs, string unqualifiedRuntimeType) { AssetTypeInfo ati = rfs.GetAssetTypeInfo(); if (ati != null) { return ati.RuntimeTypeName == unqualifiedRuntimeType; } else { return false; } }
bool IsRfsOfType(ReferencedFileSave rfs, Type type) { AssetTypeInfo ati = rfs.GetAssetTypeInfo(); if (ati != null) { return ati.QualifiedRuntimeTypeName.QualifiedType == type.FullName; } else { return false; } }
private void UpdateIncludedAndExcluded(ReferencedFileSave instance) { ResetToDefault(); AssetTypeInfo ati = instance.GetAssetTypeInfo(); ExcludeMember("InvalidFileNameCharacters"); ExcludeMember("ToStringDelegate"); ExcludeMember("Properties"); ContainerType containerType = instance.GetContainerType(); if (containerType == ContainerType.Entity) { // We do this because this is set automatically if the Entity is unique ExcludeMember("IsSharedStatic"); // We do this because whether the objects from a file are manually updated or not // should be up to the entity, not the source file. ExcludeMember("IsManuallyUpdated"); } if (containerType == ContainerType.Entity || ati == null || ati.QualifiedRuntimeTypeName.QualifiedType != "Microsoft.Xna.Framework.Media.Song") { ExcludeMember("DestroyOnUnload"); } #region Extension-based additions/removals string extension = FileManager.GetExtension(instance.Name); if (extension != "csv" && !instance.TreatAsCsv) { ExcludeMember("CreatesDictionary"); ExcludeMember("IsDatabaseForLocalizing"); ExcludeMember("UniformRowType"); } else { IncludeMember("UniformRowType", typeof(ReferencedFileSave), new AvailablePrimitiveTypeArraysStringConverter()); } if ((extension != "txt" && extension != "csv") || (extension == "txt" && instance.TreatAsCsv == false) ) { ExcludeMember("CsvDelimiter"); } if (extension != "txt") { ExcludeMember("TreatAsCsv"); } if (extension == "png") { Attribute[] fileDetailsCategoryAttribute = new Attribute[]{ new CategoryAttribute("File Details")}; IncludeMember("ImageWidth", typeof(int), null, GetImageWidth, null, fileDetailsCategoryAttribute); IncludeMember("ImageHeight", typeof(int), null, GetImageHeight, null, fileDetailsCategoryAttribute); } if (extension == "emix") { Attribute[] fileDetailsCategoryAttribute = new Attribute[]{ new CategoryAttribute("File Details")}; IncludeMember("EquilibriumParticleCount", typeof(float), null, GetEquilibriumParticleCount, null, fileDetailsCategoryAttribute); IncludeMember("BurstParticleCount", typeof(float), null, GetBurstParticleCount, null, fileDetailsCategoryAttribute); } #endregion AddProjectSpecificFileMember(); if (!instance.LoadedAtRuntime) { ExcludeMember("IsSharedStatic"); ExcludeMember("IsManuallyUpdated"); ExcludeMember("LoadedOnlyWhenReferenced"); ExcludeMember("HasPublicProperty"); ExcludeMember("InstanceName"); ExcludeMember("IncludeDirectoryRelativeToContainer"); } if (ati == null || string.IsNullOrEmpty(ati.MakeManuallyUpdatedMethod)) { ExcludeMember("IsManuallyUpdated"); } if (!instance.GetCanUseContentPipeline()) { ExcludeMember("UseContentPipeline"); } if (!instance.UseContentPipeline || ati.QualifiedRuntimeTypeName.QualifiedType != "Microsoft.Xna.Framework.Graphics.Texture2D") { ExcludeMember("TextureFormat"); } IncludeMember("OpensWith", typeof(ReferencedFileSave), new AvailableApplicationsStringConverters()); bool shouldShowRuntimeType = instance.LoadedAtRuntime; if (shouldShowRuntimeType) { IncludeMember("RuntimeType", typeof(ReferencedFileSave), new AvailableRuntimeTypeForExtensionConverter() { Extension = extension }); } else { ExcludeMember("RuntimeType"); } if (string.IsNullOrEmpty(instance.SourceFile)) { ExcludeMember("SourceFile"); ExcludeMember("BuildTool"); ExcludeMember("AdditionalArguments"); ExcludeMember("ConditionalCompilationSymbols"); } else { } }
public static void WriteTextSpecificInitialization(ReferencedFileSave rfs, ICodeBlock codeBlock) { AssetTypeInfo ati = rfs.GetAssetTypeInfo(); if (ati != null) { if (ati.QualifiedRuntimeTypeName.QualifiedType == "FlatRedBall.Scene" && !rfs.IsSharedStatic && ObjectFinder.Self.GlueProject.UsesTranslation) { WriteTextInitializationLoopForScene(codeBlock, FileManager.RemovePath(FileManager.RemoveExtension(rfs.Name))); } } }
private static string WriteMethodForClone(NamedObjectSave namedObject, ICodeBlock codeBlock, List<string[]> referencedFilesAlreadyUsingFullFile, AssetTypeInfo nosAti, string objectName, ReferencedFileSave rfs, IElement container, string containerName, string overridingName) { int lastParen = namedObject.SourceName.LastIndexOf(" ("); string nameOfSourceInContainer = namedObject.SourceName.Substring(0, lastParen); // This could have a quote in the name. If so we want to escape it since this will be put in code: nameOfSourceInContainer = nameOfSourceInContainer.Replace("\"", "\\\""); string cloneString = ".Clone()"; string namedObjectToPullFrom = null; foreach (string[] stringPair in referencedFilesAlreadyUsingFullFile) { if (rfs != null && stringPair[0] == rfs.Name && !namedObject.SourceName.StartsWith("Entire File (")) { namedObjectToPullFrom = stringPair[1]; break; } } // September 30, 2012 // Now all files - whether // they are part of an Entity // or part of a Screen, are static. // This means that the rfs.IsSharedStatic // check will usually fail. However, Screens // will still add to managers even for static // object, so we want to make sure that we don't // clone an object already added to managers, so we // need the last check to see if the container is a ScreenSave. if (nosAti == null || !nosAti.CanBeCloned || namedObjectToPullFrom != null || (rfs != null && rfs.IsSharedStatic == false) || container is ScreenSave) { cloneString = ""; } if (nosAti != null && !string.IsNullOrEmpty(nosAti.CustomCloneMethod)) { cloneString = nosAti.CustomCloneMethod; } AssetTypeInfo rfsAti = null; if (rfs != null) { rfsAti = rfs.GetAssetTypeInfo(); } bool usesFullConversion = false; if (rfsAti != null && rfsAti.Conversion.Count != 0) { var foundConversion = rfsAti.Conversion.FirstOrDefault(item => item.ToType == namedObject.InstanceType); if (foundConversion != null) { cloneString = foundConversion.ConversionPattern.Replace("{NEW}", objectName); cloneString = cloneString.Replace("{THIS}", rfs.GetInstanceName()); usesFullConversion = true; } } if (namedObjectToPullFrom != null) { containerName = namedObjectToPullFrom; } if (!string.IsNullOrEmpty(overridingName)) { containerName = overridingName; } string listMemberName = ContentParser.GetMemberNameForList(FileManager.GetExtension(namedObject.SourceFile), namedObject.InstanceType); if (!string.IsNullOrEmpty(listMemberName)) { listMemberName += "."; } if (nameOfSourceInContainer == "Entire File" && string.IsNullOrEmpty(listMemberName)) { if (usesFullConversion) { codeBlock.Line(cloneString + ";"); } else if (cloneString.Contains("{THIS}")) { string entireString = cloneString.Replace("{THIS}", objectName); entireString = entireString.Replace("{SOURCE_FILE}", containerName); codeBlock.Line(entireString); } else { codeBlock.Line(string.Format("{0} = {1}{2};", objectName, containerName, cloneString)); } } else { string findByNameLine = ""; if (nosAti != null) { findByNameLine = nosAti.FindByNameSyntax; if (string.IsNullOrEmpty(findByNameLine)) { string message = "The object " + namedObject.ToString() + " is part of a file. To be properly generated " + "the AssetTypeInfo (or CSV value) for " + nosAti.ToString() + " must contain a FindByNameSyntax property"; throw new Exception(message); } } findByNameLine = findByNameLine.Replace("OBJECTNAME", nameOfSourceInContainer); string possibleDot = "."; if (findByNameLine.StartsWith("[")) { possibleDot = ""; } //if (namedObject.AddToManagers) { // Not sure why we don't clone on a non add to manager. This post right here suggests we should // and I tend to believe Scott so...I'm following his advice: // http://www.flatredball.com/frb/forum/viewtopic.php?f=26&t=4741 codeBlock.Line(string.Format("{0} = {1}{2}{3}{4}{5};", objectName, containerName, possibleDot, listMemberName, findByNameLine, cloneString)); } //else //{ // stringBuilder.AppendLine( // string.Format("\t\t\t{0} = {1}{2}{3}{4};", // objectName, // containerName, // possibleDot, // listMemberName, // findByNameLine)); //} } return containerName; }
private static void AddCodeforFileLoad(ReferencedFileSave referencedFile, ref ICodeBlock codeBlock, bool loadsUsingGlobalContentManager, ref bool directives, bool isProjectSpecific, ref string fileName, ProjectBase project, LoadType loadType, string containerName) { if (project != null) { if (ProjectManager.IsContent(fileName)) { fileName = (ProjectManager.ContentProject.ContainedFilePrefix + fileName).ToLower(); } if (isProjectSpecific) { if (directives == true) { codeBlock = codeBlock.End() .Line("#elif " + project.PrecompilerDirective) .CodeBlockIndented(); } else { directives = true; codeBlock = codeBlock .Line("#if " + project.PrecompilerDirective) .CodeBlockIndented(); } } else { if (directives == true) { codeBlock = codeBlock.End() .Line("#else") .CodeBlockIndented(); } } if (referencedFile.IsDatabaseForLocalizing) { GenerateCodeForLocalizationDatabase(referencedFile, codeBlock, fileName, loadType); } else { AssetTypeInfo ati = referencedFile.GetAssetTypeInfo(); // I think we can set the field rather than the property, and then Set() the MRE if necessary afterwards: //string variableName = referencedFile.GetInstanceName(); string variableName = null; if (NeedsFullProperty(referencedFile, containerName)) { variableName = "m" + referencedFile.GetInstanceName(); } else { variableName = referencedFile.GetInstanceName(); } if (!referencedFile.IsCsvOrTreatedAsCsv && ati != null) { // If it's not a CSV, then we only support loading if the load type is complete // I don't know if I'll want to change this (or if I can) in the future. if (loadType == LoadType.CompleteLoad) { GenerateInitializationForAssetTypeInfoRfs(referencedFile, codeBlock, loadsUsingGlobalContentManager, variableName, fileName, ati, project); } } else if(referencedFile.IsCsvOrTreatedAsCsv) { GenerateInitializationForCsvRfs(referencedFile, codeBlock, variableName, fileName, loadType); } } NamedObjectSaveCodeGenerator.WriteTextSpecificInitialization(referencedFile, codeBlock); } }
private static bool AddOrRemoveIndividualRfs(ReferencedFileSave rfs, List<string> filesInModifiedRfs, ref bool shouldRemoveAndAdd, ProjectBase projectBase) { List<ProjectBase> projectsAlreadyModified = new List<ProjectBase>(); bool usesContentPipeline = rfs.UseContentPipeline || rfs.GetAssetTypeInfo() != null && rfs.GetAssetTypeInfo().MustBeAddedToContentPipeline; if (rfs.GetAssetTypeInfo() != null && rfs.GetAssetTypeInfo().MustBeAddedToContentPipeline && rfs.UseContentPipeline == false) { rfs.UseContentPipeline = true; MessageBox.Show("The file " + rfs.Name + " must use the content pipeline"); } else { string absoluteName = ProjectManager.MakeAbsolute(rfs.Name, true); shouldRemoveAndAdd = usesContentPipeline && !projectBase.IsFilePartOfProject(absoluteName, BuildItemMembershipType.CompileOrContentPipeline) || !usesContentPipeline && !projectBase.IsFilePartOfProject(absoluteName, BuildItemMembershipType.CopyIfNewer); if (shouldRemoveAndAdd) { projectBase.RemoveItem(absoluteName); projectBase.AddContentBuildItem(absoluteName, SyncedProjectRelativeType.Contained, usesContentPipeline); projectsAlreadyModified.Add(projectBase); #region Loop through all synced projects and add or remove the file referenced by the RFS foreach (ProjectBase syncedProject in ProjectManager.SyncedProjects) { ProjectBase syncedContentProjectBase = syncedProject; if (syncedProject.ContentProject != null) { syncedContentProjectBase = syncedProject.ContentProject; } if (!projectsAlreadyModified.Contains(syncedContentProjectBase)) { projectsAlreadyModified.Add(syncedContentProjectBase); syncedContentProjectBase.RemoveItem(absoluteName); if (syncedContentProjectBase.SaveAsAbsoluteSyncedProject) { syncedContentProjectBase.AddContentBuildItem(absoluteName, SyncedProjectRelativeType.Contained, usesContentPipeline); } else { syncedContentProjectBase.AddContentBuildItem(absoluteName, SyncedProjectRelativeType.Linked, usesContentPipeline); } } } #endregion List<string> filesReferencedByAsset = FileReferenceManager.Self.GetFilesReferencedBy(absoluteName, EditorObjects.Parsing.TopLevelOrRecursive.Recursive); for (int i = 0; i < filesReferencedByAsset.Count; i++) { if (!filesInModifiedRfs.Contains(filesReferencedByAsset[i])) { filesInModifiedRfs.Add(filesReferencedByAsset[i]); } } } } return usesContentPipeline; }
static ICodeBlock GetActivityForReferencedFile(ReferencedFileSave referencedFile, IElement element) { ICodeBlock codeBlock = new CodeDocument(); /////////////////////EARLY OUT///////////////////////// if (!referencedFile.LoadedAtRuntime) { return codeBlock; } //////////////////END EARLY OUT////////////////////// AssetTypeInfo ati = referencedFile.GetAssetTypeInfo(); // If it's an emitter, call TimedEmit: ParticleCodeGenerator.GenerateTimedEmit(codeBlock, referencedFile, element); if (ati != null && (!referencedFile.IsSharedStatic || element is ScreenSave )&& !referencedFile.LoadedOnlyWhenReferenced && ati.ActivityMethod != null) { AddIfConditionalSymbolIfNecesssary(codeBlock, referencedFile); string variableName = referencedFile.GetInstanceName(); codeBlock.Line(ati.ActivityMethod.Replace("this", variableName) + ";"); AddEndIfIfNecessary(codeBlock, referencedFile); return codeBlock; } else { return codeBlock; } }
public static void UpdateTextureFormatFor(ReferencedFileSave rfs) { string absoluteName = ProjectManager.MakeAbsolute(rfs.Name, true); bool usesContentPipeline = rfs.UseContentPipeline || rfs.GetAssetTypeInfo() != null && rfs.GetAssetTypeInfo().MustBeAddedToContentPipeline; string parameterTag = GetTextureFormatTag(rfs); string valueToSet = rfs.TextureFormat.ToString(); SetParameterOnBuildItems(absoluteName, parameterTag, valueToSet); }
public static ICodeBlock GetPostInitializeForReferencedFile(ReferencedFileSave referencedFile) { AssetTypeInfo ati = referencedFile.GetAssetTypeInfo(); ICodeBlock codeBlock = new CodeDocument(); if (ati != null && !referencedFile.IsSharedStatic) { string variableName = referencedFile.GetInstanceName(); if (!string.IsNullOrEmpty(ati.PostInitializeCode)) { codeBlock.Line(ati.PostInitializeCode.Replace("this", variableName) + ";"); } } return codeBlock; }
/// <summary> /// Updates the presence of the RFS in the main project. If the RFS has project specific files, then those /// files are updated in the appropriate synced project. /// </summary> /// <remarks> /// This method does not update synced projects if the synced projects use the same file. The reason is because /// this is taken care of when the projects are saved later on. /// </remarks> /// <param name="referencedFileSave">The RFS representing the file to update membership on.</param> /// <returns>Whether anything was added to any projects.</returns> public static bool UpdateFileMembershipInProject(ReferencedFileSave referencedFileSave) { var assetTypeInfo = referencedFileSave.GetAssetTypeInfo(); bool shouldSkip = assetTypeInfo != null && assetTypeInfo.ExcludeFromContentProject; bool wasAnythingAdded = false; if (!shouldSkip) { bool useContentPipeline = referencedFileSave.UseContentPipeline || (assetTypeInfo != null && assetTypeInfo.MustBeAddedToContentPipeline); wasAnythingAdded = UpdateFileMembershipInProject(ProjectBase, referencedFileSave.GetRelativePath(), useContentPipeline, false); foreach (ProjectSpecificFile projectSpecificFile in referencedFileSave.ProjectSpecificFiles) { wasAnythingAdded |= UpdateFileMembershipInProject(GetProjectByTypeId(projectSpecificFile.ProjectId), projectSpecificFile.FilePath, useContentPipeline, true); } if (wasAnythingAdded) { int m = 3; } } return wasAnythingAdded; }