isaacscript-common 8.7.0 → 8.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,3 +1,12 @@
1
1
  import { LevelCurse } from "isaac-typescript-definitions";
2
+ /**
3
+ * Helper function to get the actual bit flag for modded curses.
4
+ *
5
+ * Will throw a runtime error if the provided curse does not exist.
6
+ *
7
+ * Use this over the `Isaac.GetCurseIdByName` method because that will return an integer instead of
8
+ * a bit flag.
9
+ */
10
+ export declare function getCurseIDByName(name: string): LevelCurse;
2
11
  export declare function hasCurse(curse: LevelCurse): boolean;
3
12
  //# sourceMappingURL=curses.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"curses.d.ts","sourceRoot":"","sources":["../../src/functions/curses.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,8BAA8B,CAAC;AAI1D,wBAAgB,QAAQ,CAAC,KAAK,EAAE,UAAU,GAAG,OAAO,CAInD"}
1
+ {"version":3,"file":"curses.d.ts","sourceRoot":"","sources":["../../src/functions/curses.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,8BAA8B,CAAC;AAI1D;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,UAAU,CAWzD;AAED,wBAAgB,QAAQ,CAAC,KAAK,EAAE,UAAU,GAAG,OAAO,CAInD"}
@@ -3,6 +3,19 @@ local ____cachedClasses = require("core.cachedClasses")
3
3
  local game = ____cachedClasses.game
4
4
  local ____flag = require("functions.flag")
5
5
  local hasFlag = ____flag.hasFlag
6
+ --- Helper function to get the actual bit flag for modded curses.
7
+ --
8
+ -- Will throw a runtime error if the provided curse does not exist.
9
+ --
10
+ -- Use this over the `Isaac.GetCurseIdByName` method because that will return an integer instead of
11
+ -- a bit flag.
12
+ function ____exports.getCurseIDByName(self, name)
13
+ local curseID = Isaac.GetCurseIdByName(name)
14
+ if curseID == -1 then
15
+ error(("Failed to get the curse ID corresponding to the curse name of \"" .. tostring(curseID)) .. "\". Does this name match what you put in the \"content/curses.xml\" file?")
16
+ end
17
+ return 1 << curseID - 1
18
+ end
6
19
  function ____exports.hasCurse(self, curse)
7
20
  local level = game:GetLevel()
8
21
  local curses = level:GetCurses()
package/dist/index.d.ts CHANGED
@@ -2805,6 +2805,16 @@ export declare function getCombinedBossSet(stage: int): ReadonlySet<string> | un
2805
2805
  */
2806
2806
  export declare function getCrawlSpaces(crawlSpaceVariant?: CrawlSpaceVariant): GridEntity[];
2807
2807
 
2808
+ /**
2809
+ * Helper function to get the actual bit flag for modded curses.
2810
+ *
2811
+ * Will throw a runtime error if the provided curse does not exist.
2812
+ *
2813
+ * Use this over the `Isaac.GetCurseIdByName` method because that will return an integer instead of
2814
+ * a bit flag.
2815
+ */
2816
+ export declare function getCurseIDByName(name: string): LevelCurse;
2817
+
2808
2818
  /**
2809
2819
  * Helper function to get the custom grid entities in the current room. Returns an array of tuples
2810
2820
  * containing the raw decoration grid entity and the associated entity data.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "isaacscript-common",
3
- "version": "8.7.0",
3
+ "version": "8.8.0",
4
4
  "description": "Helper functions and features for IsaacScript mods.",
5
5
  "keywords": [
6
6
  "isaac",
@@ -2,6 +2,27 @@ import { LevelCurse } from "isaac-typescript-definitions";
2
2
  import { game } from "../core/cachedClasses";
3
3
  import { hasFlag } from "./flag";
4
4
 
5
+ /**
6
+ * Helper function to get the actual bit flag for modded curses.
7
+ *
8
+ * Will throw a runtime error if the provided curse does not exist.
9
+ *
10
+ * Use this over the `Isaac.GetCurseIdByName` method because that will return an integer instead of
11
+ * a bit flag.
12
+ */
13
+ export function getCurseIDByName(name: string): LevelCurse {
14
+ const curseID = Isaac.GetCurseIdByName(name);
15
+ if (curseID === -1) {
16
+ error(
17
+ `Failed to get the curse ID corresponding to the curse name of "${curseID}". Does this name match what you put in the "content/curses.xml" file?`,
18
+ );
19
+ }
20
+
21
+ // For example, the final vanilla curse is "Curse of the Giant", which has an ID of 8. This
22
+ // corresponds to `LevelCurse.GIANT`, which has a value of `1 << 7`.
23
+ return (1 << (curseID - 1)) as LevelCurse;
24
+ }
25
+
5
26
  export function hasCurse(curse: LevelCurse): boolean {
6
27
  const level = game.GetLevel();
7
28
  const curses = level.GetCurses();