Populating the Dictionary as a non MSU depentant mod - TeamMoonstorm/MoonstormSharedUtils GitHub Wiki

This Guide goes thru the process of populating the Item Display Dictionaries from the Item Display Module Base as a non MSU Dependant Mod.

Why would i want to do this?

  • As explained in the ItemDisplayModule page, the Module itself works via a miriad of Dictionaries filled with string keys that point to their respective assets. Due to the nature of dictionaries being unable to hold duplicate keys and duplicate assets, it is usually a bad idea to have an external mod (Such as Starstorm2) try to load in the display prefabs and the key assets from a different mod (Such as Aetherium). this can cause general headache as it would be substancially easier to simply have the other mod populate the dictionaries using simple methods.

  • This guide will go thru on how to populate the MSU ItemDisplay Dictionaries using a single class.

The MSIDRSUtil Class

The MSIDRSUtil class was made specifically for the convenience of mod creators to populate the dictionaries for IDRS. using the KeyAssetDisplayPair struct found inside the KeyAssetDisplayPairHolder scriptable object.

There are 2 Main methods in this class, one of which who has 2 overrides.

public static KeyAssetDisplayPair CreateKeyAssetDisplayPair(Object keyAsset, GameObject displayPrefab)
{
	var toReturn = new KeyAssetDisplayPair();
	toReturn.keyAsset = keyAsset;
	toReturn.displayPrefabs = new List<GameObject> { displayPrefab };
	return toReturn;
}	

public static KeyAssetDisplayPair CreateKeyAssetDisplayPair(Object keyAsset, 	List<GameObject> displayPrefabs)
{
	var toReturn = new KeyAssetDisplayPair();
	toReturn.keyAsset = keyAsset;
	toReturn.displayPrefabs = displayPrefabs;
	return toReturn;
}

The CreateKeyAssetDisplayPair returns a KeyAssetDisplayPair by giving it at least the Key asset object (Either an ItemDef or an EquipmentDef) and the DisplayPrefab itself (List if there are multiple versions of a display prefab)

public static void AddIDRSStuff(List<KeyAssetDisplayPair> keyAssetDisplayPairs)
{
keyAssetDisplayPairs.ForEach(kadp => kadp.AddKeyAssetDisplayPrefabsToIDRS());
}

The AddIDRSStuff Method runs a method within the struct that adds the prefabs and key assets to the IDRS module.

Here's a quick example on how to use this system, it can be found in Aetherium's Repository. https://github.com/KomradeSpectre/AetheriumMod/blob/37a1538072315b44faca4fb69da68ca8fe755d96/Aetherium/Compatability/ModCompatability.cs#L457-L498

⚠️ **GitHub.com Fallback** ⚠️