2 using System.Collections.Generic;
3 using System.Collections.ObjectModel;
8 namespace Loot.Api.Content
18 internal Dictionary<string, List<(string name, T content)>> Map;
19 internal Dictionary<uint, T> Content;
21 internal bool SkipModChecks;
23 public uint IdCount {
get;
private set; }
27 uint @
return = IdCount;
32 internal void _Initialize()
34 Map =
new Dictionary<string, List<(string, T)>>();
35 Content =
new Dictionary<uint, T>();
40 internal virtual void Initialize()
49 internal virtual void Load()
53 internal void _Unload()
62 internal virtual void Unload()
66 internal void AddMod(
Mod mod)
68 Map.Add(mod.Name,
new List<(
string, T)>());
71 internal virtual bool CheckContentPiece(T contentPiece) =>
true;
73 internal void AddContent(Type type,
Mod mod)
75 T contentPiece = (T) Activator.CreateInstance(type);
76 AddContent(contentPiece, mod);
79 internal void AddContent(T contentPiece,
Mod mod)
81 if (!typeof(ILoadableContentSetter).IsAssignableFrom(typeof(T)))
83 throw new Exception(
"Invalid type passed to AddContent");
86 string s = $
"[{nameof(T)}]{nameof(contentPiece)}";
92 if (!Map.TryGetValue(mod.Name, out var lrm))
94 throw new Exception($
"Map for {mod.Name} not found (trying to add {s}");
97 if (!CheckContentPiece(contentPiece))
99 throw new Exception($
"A problem occurred trying to add {s}");
102 if (lrm.Exists(x => x.name.Equals(contentPiece.Name)))
104 throw new Exception($
"You have already added {s}");
107 ((ILoadableContentSetter) contentPiece).Mod = mod;
108 ((ILoadableContentSetter) contentPiece).Type = GetNextId();
109 Content[contentPiece.Type] = contentPiece;
110 Map[mod.Name].Add((contentPiece.Name, contentPiece));
115 T contentPiece = Content.Values.FirstOrDefault(x => x.GetType().FullName == type.FullName);
116 return (T) contentPiece?.Clone();
121 T contentPiece = _GetContent(modName, contentKey);
122 return (T) contentPiece?.Clone();
127 return Map[modName].FirstOrDefault(x => x.name.Equals(key)).content;
132 return type < IdCount ? (T) Content[type].Clone() :
default;
135 public ReadOnlyCollection<T> GetContent()
136 => Content.Select(e => (T) e.Value?.Clone()).ToList().AsReadOnly();
This class is used for Content holders in the Content namespace As a modder you should not use this c...
T GetContent(string modName, string contentKey)
Defines a piece of loadable content The interface is used in classes where the deriving class already...
T _GetContent(string modName, string key)
This class is responsible for loading mods into Even More Modifiers Mods can be registered and trigge...