Even More Modifiers  1.0.0.0
A mod for rolling various bonus stats on items
TextureModContent.cs
Go to the documentation of this file.
1 using System;
2 using System.Collections.Generic;
3 using Microsoft.Xna.Framework.Graphics;
4 
5 namespace Loot.Api.ModContent
6 {
10  public abstract class TextureModContent
11  {
12  protected IDictionary<string, Texture2D> _textures;
13 
14  protected Texture2D GetFrom(IDictionary<string, Texture2D> dictionary, string key)
15  {
16  return dictionary.TryGetValue(key, out var texture) ? texture : null;
17  }
18 
19  public Texture2D GetTexture(string key)
20  {
21  return GetFrom(_textures, key);
22  }
23 
24  protected void AddTo(IDictionary<string, Texture2D> dictionary, string key, Texture2D texture)
25  {
26  if (dictionary.ContainsKey(key))
27  {
28  throw new Exception($"Key '{key}' already present in ModContent");
29  }
30 
31  ProcessTexture2D(ref texture);
32  dictionary.Add(key, texture);
33  }
34 
35  public void AddTexture(string key, Texture2D texture)
36  {
37  AddTo(_textures, key, texture);
38  }
39 
40  public void _Initialize()
41  {
42  _textures = new Dictionary<string, Texture2D>();
43  Initialize();
44  }
45 
46  public void _Load()
47  {
48  Load();
49  }
50 
51  public void _Unload()
52  {
53  _textures = null;
54  Unload();
55  }
56 
57  protected virtual void ProcessTexture2D(ref Texture2D texture)
58  {
59  }
60 
61  protected virtual void Initialize()
62  {
63  }
64 
65  protected virtual void Load()
66  {
67  }
68 
69  protected virtual void Unload()
70  {
71  }
72 
73  public abstract string GetRegistryKey();
74  }
75 }
IDictionary< string, Texture2D > _textures
Texture2D GetFrom(IDictionary< string, Texture2D > dictionary, string key)
virtual void ProcessTexture2D(ref Texture2D texture)
void AddTexture(string key, Texture2D texture)
An abstract class that contains a mapping of strings to texture instances
void AddTo(IDictionary< string, Texture2D > dictionary, string key, Texture2D texture)