A stable modding interface between Techblox and mods https://mod.exmods.org/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

99 lines
4.1KB

  1. namespace GamecraftModdingAPI.Blocks
  2. {
  3. /// <summary>
  4. /// Common tweakable stats operations.
  5. /// The functionality of this class works best in build mode.
  6. /// </summary>
  7. public static class Tweakable
  8. {
  9. private static TweakableEngine tweakableEngine = new TweakableEngine();
  10. /// <summary>
  11. /// Get the tweakable stat's value using a dynamic variable type.
  12. /// This is similar to GetStat<T> but without strong type enforcement.
  13. /// This should be used in dynamically-typed languages like Python.
  14. /// </summary>
  15. /// <returns>The stat's value.</returns>
  16. /// <param name="blockID">The block's id.</param>
  17. /// <param name="stat">The stat's enumerated id.</param>
  18. public static dynamic GetStatD(uint blockID, TweakableStat stat)
  19. {
  20. return tweakableEngine.GetStatDynamic(blockID, stat);
  21. }
  22. /// <summary>
  23. /// Get the tweakable stat's value.
  24. /// If T is not the same type as the stat, an InvalidCastException will be thrown.
  25. /// </summary>
  26. /// <returns>The stat's value.</returns>
  27. /// <param name="blockID">The block's id.</param>
  28. /// <param name="stat">The stat's enumerated id.</param>
  29. /// <typeparam name="T">The stat's type.</typeparam>
  30. public static T GetStat<T>(uint blockID, TweakableStat stat)
  31. {
  32. return tweakableEngine.GetStatAny<T>(blockID, stat);
  33. }
  34. /// <summary>
  35. /// Set the tweakable stat's value using dynamically-typed variables.
  36. /// This is similar to SetStat<T> but without strong type enforcement.
  37. /// This should be used in dynamically-typed languages like Python.
  38. /// </summary>
  39. /// <returns>The stat's new value.</returns>
  40. /// <param name="blockID">The block's id.</param>
  41. /// <param name="stat">The stat's enumerated id.</param>
  42. /// <param name="value">The stat's new value.</param>
  43. public static dynamic SetStatD(uint blockID, TweakableStat stat, dynamic value)
  44. {
  45. return tweakableEngine.SetStatDynamic(blockID, stat, value);
  46. }
  47. /// <summary>
  48. /// Set the tweakable stat's value.
  49. /// If T is not the stat's actual type, an InvalidCastException will be thrown.
  50. /// </summary>
  51. /// <returns>The stat's new value.</returns>
  52. /// <param name="blockID">The block's id.</param>
  53. /// <param name="stat">The stat's enumerated id.</param>
  54. /// <param name="value">The stat's new value.</param>
  55. /// <typeparam name="T">The stat's type.</typeparam>
  56. public static T SetStat<T>(uint blockID, TweakableStat stat, T value)
  57. {
  58. return tweakableEngine.SetStatAny<T>(blockID, stat, value);
  59. }
  60. /// <summary>
  61. /// Add another value to the tweakable stat's value using dynamically-typed variables.
  62. /// This is similar to AddStat<T> but without strong type enforcement.
  63. /// This should be used in dynamically-typed languages like Python.
  64. /// </summary>
  65. /// <returns>The stat's new value.</returns>
  66. /// <param name="blockID">The block's id.</param>
  67. /// <param name="stat">The stat's enumerated id.</param>
  68. /// <param name="value">The value to be added to the stat.</param>
  69. public static dynamic AddStatD(uint blockID, TweakableStat stat, dynamic value)
  70. {
  71. return tweakableEngine.AddStatDynamic(blockID, stat, value);
  72. }
  73. /// <summary>
  74. /// Add another value to the tweakable stat's value.
  75. /// If T is not the stat's actual type, an InvalidCastException will be thrown.
  76. /// </summary>
  77. /// <returns>The stat's new value.</returns>
  78. /// <param name="blockID">The block's id.</param>
  79. /// <param name="stat">The stat's enumerated id.</param>
  80. /// <param name="value">The value to be added to the stat.</param>
  81. /// <typeparam name="T">The stat's type.</typeparam>
  82. public static T AddStat<T>(uint blockID, TweakableStat stat, T value)
  83. {
  84. return tweakableEngine.AddStatAny<T>(blockID, stat, value);
  85. }
  86. public static void Init()
  87. {
  88. GamecraftModdingAPI.Utility.GameEngineManager.AddGameEngine(tweakableEngine);
  89. }
  90. }
  91. }