Terraria ModLoader  0.11.7.5
A mod to make and play Terraria mods
BackgroundTextureLoader.cs
Go to the documentation of this file.
1 using System;
2 using System.Collections.Generic;
3 
4 namespace Terraria.ModLoader
5 {
6  //todo: further documentation
10  public static class BackgroundTextureLoader
11  {
12  public const int vanillaBackgroundTextureCount = Main.maxBackgrounds;
13  private static int nextBackground = vanillaBackgroundTextureCount;
14  internal static IDictionary<string, int> backgrounds = new Dictionary<string, int>();
15 
16  internal static int ReserveBackgroundSlot() {
17  int reserve = nextBackground;
18  nextBackground++;
19  return reserve;
20  }
21 
25  public static int GetBackgroundSlot(string texture) => backgrounds.TryGetValue(texture, out int slot) ? slot : -1;
26 
27  internal static void ResizeAndFillArrays() {
28  Array.Resize(ref Main.backgroundTexture, nextBackground);
29  Array.Resize(ref Main.backgroundHeight, nextBackground);
30  Array.Resize(ref Main.backgroundWidth, nextBackground);
31  Array.Resize(ref Main.backgroundLoaded, nextBackground);
32  foreach (string texture in backgrounds.Keys) {
33  int slot = backgrounds[texture];
34  Main.backgroundTexture[slot] = ModContent.GetTexture(texture);
35  Main.backgroundWidth[slot] = Main.backgroundTexture[slot].Width;
36  Main.backgroundHeight[slot] = Main.backgroundTexture[slot].Height;
37  Main.backgroundLoaded[slot] = true;
38  }
39  }
40 
41  internal static void Unload() {
42  nextBackground = vanillaBackgroundTextureCount;
43  backgrounds.Clear();
44  }
45  }
46 }
This is the class that keeps track of all modded background textures and their slots/IDs.
static Texture2D GetTexture(string name)
Gets the texture with the specified name. The name is in the format of "ModFolder/OtherFolders/FileNa...
Definition: ModContent.cs:72
Manages content added by mods. Liasons between mod content and Terraria&#39;s arrays and oversees the Loa...
Definition: ModContent.cs:26