2 using System.Collections.Generic;
6 using Microsoft.Xna.Framework.Graphics;
9 namespace Loot.Api.Loaders
25 if (!
RegistryLoader.CheckModRegistered(mod,
"RegisterAssets",
false))
27 throw new NullReferenceException($
"Mod {mod.Name} must be registered before calling RegisterAssets");
30 if (
Loot.ModContentManager == null)
32 throw new NullReferenceException(
"Loot.ContentManager is null in RegisterAssets");
36 if (graphicsContent == null)
38 throw new NullReferenceException(
"ModGraphicsContent is null in RegisterAssets");
41 if (folder.StartsWith($
"{mod.Name}/"))
43 folder = folder.Replace($
"{mod.Name}/",
"");
46 string keyPass = $
"{mod.Name}/{folder}";
47 graphicsContent.AddKeyPass(mod.Name, keyPass);
49 FieldInfo texturesField = typeof(
Mod).GetField(
"textures", BindingFlags.Instance | BindingFlags.NonPublic);
50 Dictionary<string, Texture2D> dictionary = ((Dictionary<string, Texture2D>) texturesField?.GetValue(mod));
51 if (dictionary == null)
53 throw new NullReferenceException($
"textures dictionary for mod {mod.Name} was null");
56 var textures = dictionary.Where(x => x.Key.StartsWith(folder)).ToList();
57 var glowmasks = textures.Where(x => x.Key.EndsWith(
"_Glowmask") || x.Key.EndsWith(
"_Glow")).ToList();
58 var shaders = textures.Where(x => x.Key.EndsWith(
"_Shader") || x.Key.EndsWith(
"_Shad")).ToList();
60 foreach (var kvp
in glowmasks)
62 string assetKey = graphicsContent.GetAssetKey(kvp.Value.Name, mod);
68 if (graphicsContent.AnyGlowmaskAssetExists(assetKey, mod))
70 throw new Exception($
"{mod.Name} attempted to add a glowmask asset already present: {assetKey}");
73 graphicsContent.AddGlowmaskTexture(assetKey, kvp.Value);
76 dictionary.Remove(kvp.Key);
80 foreach (var kvp
in shaders)
82 string assetKey = graphicsContent.GetAssetKey(kvp.Value.Name, mod);
88 if (graphicsContent.AnyShaderAssetExists(assetKey, mod))
90 throw new Exception($
"{mod.Name} attempted to add a shader asset already present: {assetKey}");
93 graphicsContent.AddShaderTexture(assetKey, kvp.Value);
96 dictionary.Remove(kvp.Key);
102 graphicsContent.Prepare(mod);
103 graphicsContent.ClearPreparation();
static void RegisterAssets(Mod mod, string folder, bool clearOwnTextures=true)
Registers the assets folder for the given mod
This class stores glowmask and shader textures that can be looked up during drawing ...
This Loader is responsible for loading graphics assets for a mod These include shader and glowmask te...
This class is responsible for loading mods into Even More Modifiers Mods can be registered and trigge...