/// <summary> /// Returns whether or not a texture with the specified name exists. texture will be populated with null if not found, and the texture if found. /// </summary> /// <param name="name">The texture name that is requested</param> /// <param name="texture">The texture itself will be output to this</param> /// <returns>True if the texture is found, false otherwise.</returns> internal static bool TryGetTexture(string name, out Asset <Texture2D> texture) { texture = null; if (Main.dedServ || !TextureExists(name)) { return(false); } SplitName(name, out string modName, out string subName); if (modName == "Terraria") { if ((Main.instance.Content as TMLContentManager).ImageExists(subName)) { texture = Main.Assets.Request <Texture2D>(Path.Combine("Images", subName)); return(true); } return(false); } Mod mod = ModLoader.GetMod(modName); if (mod != null && mod.TextureExists(subName)) { texture = mod.GetTexture(subName); return(true); } return(false); }
/// <summary> /// Gets the texture with the specified name. The name is in the format of "ModFolder/OtherFolders/FileNameWithoutExtension". Throws an ArgumentException if the texture does not exist. If a vanilla texture is desired, the format "Terraria/FileNameWithoutExtension" will reference an image from the "terraria/Content/Images" folder. Note: Texture2D is in the Microsoft.Xna.Framework.Graphics namespace. /// </summary> /// <exception cref="MissingResourceException">Missing mod: " + name</exception> public static Asset <Texture2D> GetTexture(string name) { if (Main.dedServ) { return(null); } SplitName(name, out string modName, out string subName); if (modName == "Terraria") { return(Main.Assets.Request <Texture2D>(Path.Combine("Images", subName))); } Mod mod = ModLoader.GetMod(modName); if (mod == null) { throw new MissingResourceException($"Missing mod: {name}"); } return(mod.GetTexture(subName)); }
/// <summary> /// Gets the texture with the specified name. The name is in the format of "ModFolder/OtherFolders/FileNameWithoutExtension". Throws an ArgumentException if the texture does not exist. If a vanilla texture is desired, the format "Terraria/FileNameWithoutExtension" will reference an image from the "terraria/Content/Images" folder. Note: Texture2D is in the Microsoft.Xna.Framework.Graphics namespace. /// </summary> /// <exception cref="MissingResourceException">Missing mod: " + name</exception> public static Texture2D GetTexture(string name) { if (Main.dedServ) { return(null); } string modName, subName; SplitName(name, out modName, out subName); if (modName == "Terraria") { return(Main.instance.Content.Load <Texture2D>("Images" + Path.DirectorySeparatorChar + subName)); } Mod mod = GetMod(modName); if (mod == null) { throw new MissingResourceException("Missing mod: " + name); } return(mod.GetTexture(subName)); }