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.

Tweakable.cs 4.1KB

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