spacechase0

SMAPI Content API

Oct 10th, 2017
256
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.92 KB | None | 0 0
  1.  
  2.             // The content API isn't technically public yet, so this is how you use it.
  3.             // It will be much cleaner once SMAPI 2.0 is released.
  4.             var editors = ((IList<IAssetEditor>)helper.Content.GetType().GetProperty("AssetEditors", BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance).GetValue(Helper.Content));
  5.             editors.Add(new ContentInjector());
  6.  
  7.  
  8.     public class ContentInjector : IAssetEditor
  9.     {
  10.         public bool CanEdit<T>(IAssetInfo asset)
  11.         {
  12.             if (asset.AssetNameEquals("Data\\ObjectInformation"))
  13.                 return true;
  14.             return false;
  15.         }
  16.  
  17.         public void Edit<T>(IAssetData asset)
  18.         {
  19.             if (asset.AssetNameEquals("Data\\ObjectInformation"))
  20.             {
  21.                 var data = asset.AsDictionary<int, string>().Data;
  22.                 // your changes here
  23.             }
  24.         }
  25.     }
Advertisement
Add Comment
Please, Sign In to add comment