isaacscript-common 67.0.0 → 67.1.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.
@@ -1862,7 +1862,7 @@ export declare function countEntities(entityType?: EntityType | -1, variant?: nu
1862
1862
  * Helper function to count the number of bits that are set to 1 in a binary representation of a
1863
1863
  * number.
1864
1864
  */
1865
- export declare function countSetBits(n: int): int;
1865
+ export declare function countSetBits(num: int): int;
1866
1866
 
1867
1867
  /**
1868
1868
  * The base class for a custom callback. Individual custom callbacks (and validation callbacks) will
@@ -16091,7 +16091,7 @@ export declare function renderTextOnEntity(entity: Entity | GridEntity, text: st
16091
16091
  * });
16092
16092
  * ```
16093
16093
  */
16094
- export declare function repeat(n: int, func: (i: int) => void): void;
16094
+ export declare function repeat(num: int, func: (i: int) => void): void;
16095
16095
 
16096
16096
  /**
16097
16097
  * Helper function to reroll an enemy. Use this instead of the vanilla "Game.RerollEnemy" function
@@ -17947,6 +17947,22 @@ export declare function spawnVoidPortal(gridIndex: int): GridEntity | undefined;
17947
17947
  */
17948
17948
  export declare function spawnWithSeed(entityType: EntityType, variant: int, subType: int, positionOrGridIndex: Vector | int, seedOrRNG: Seed | RNG, velocity?: Vector, spawner?: Entity | undefined): Entity;
17949
17949
 
17950
+ /**
17951
+ * Breaks a number into chunks of a given size. This is similar to the `String.split` method, but
17952
+ * for a number instead of a string.
17953
+ *
17954
+ * For example, `splitNumber(90, 25)` would return an array with four elements:
17955
+ *
17956
+ * - [1, 25]
17957
+ * - [26, 50]
17958
+ * - [51, 75]
17959
+ * - [76, 90]
17960
+ *
17961
+ * @param num The number to split into chunks. This must be a positive integer.
17962
+ * @param size The size of each chunk. This must be a positive integer.
17963
+ */
17964
+ export declare function splitNumber(num: int, size: int): Array<[min: int, max: int]>;
17965
+
17950
17966
  /**
17951
17967
  * Helper function to check if two sprite layers have the same sprite sheet by using the
17952
17968
  * `Sprite.GetTexel` method.
@@ -1,6 +1,6 @@
1
1
  --[[
2
2
 
3
- isaacscript-common 67.0.0
3
+ isaacscript-common 67.1.0
4
4
 
5
5
  This is the "isaacscript-common" library, which was created with the IsaacScript tool.
6
6
 
@@ -16336,10 +16336,10 @@ function ____exports.isRepentance(self)
16336
16336
  local getAnimation = classTable.GetAnimation
16337
16337
  return isFunction(nil, getAnimation)
16338
16338
  end
16339
- ____exports["repeat"] = function(self, n, func)
16339
+ ____exports["repeat"] = function(self, num, func)
16340
16340
  do
16341
16341
  local i = 0
16342
- while i < n do
16342
+ while i < num do
16343
16343
  func(nil, i)
16344
16344
  i = i + 1
16345
16345
  end
@@ -20285,6 +20285,22 @@ function ____exports.sign(self, n)
20285
20285
  end
20286
20286
  return 0
20287
20287
  end
20288
+ function ____exports.splitNumber(self, num, size)
20289
+ if num <= 0 then
20290
+ error("The number to split needs to be a positive number and is instead: " .. tostring(num))
20291
+ end
20292
+ if size <= 0 then
20293
+ error("The size to split needs to be a positive number and is instead: " .. tostring(num))
20294
+ end
20295
+ local chunks = {}
20296
+ local min = 1
20297
+ while min <= num do
20298
+ local max = math.min(min + size - 1, num)
20299
+ chunks[#chunks + 1] = {min, max}
20300
+ min = max + 1
20301
+ end
20302
+ return chunks
20303
+ end
20288
20304
  function ____exports.tanh(self, x)
20289
20305
  return (math.exp(x) - math.exp(-x)) / (math.exp(x) + math.exp(-x))
20290
20306
  end
@@ -20642,10 +20658,10 @@ function ____exports.convertDecimalToBinary(self, num, minLength)
20642
20658
  end
20643
20659
  return bits
20644
20660
  end
20645
- function ____exports.countSetBits(self, n)
20661
+ function ____exports.countSetBits(self, num)
20646
20662
  local count = 0
20647
- while n > 0 do
20648
- n = n & n - 1
20663
+ while num > 0 do
20664
+ num = num & num - 1
20649
20665
  count = count + 1
20650
20666
  end
20651
20667
  return count
@@ -20,7 +20,7 @@ export declare function convertDecimalToBinary(num: number, minLength?: int): in
20
20
  * Helper function to count the number of bits that are set to 1 in a binary representation of a
21
21
  * number.
22
22
  */
23
- export declare function countSetBits(n: int): int;
23
+ export declare function countSetBits(num: int): int;
24
24
  /** Helper function to get the value of a specific but in a binary representation of a number. */
25
25
  export declare function getKBitOfN(k: int, n: int): int;
26
26
  /** Helper function to get the number of bits in a binary representation of a number. */
@@ -1 +1 @@
1
- {"version":3,"file":"bitwise.d.ts","sourceRoot":"","sources":["../../../src/functions/bitwise.ts"],"names":[],"mappings":";;;;AAGA,+EAA+E;AAC/E,wBAAgB,eAAe,CAAC,CAAC,SAAS,OAAO,GAAG,UAAU,EAC5D,KAAK,EAAE,CAAC,EAAE,GAAG,SAAS,CAAC,EAAE,GACxB,QAAQ,CAAC,CAAC,CAAC,CAOb;AAED,mFAAmF;AACnF,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,GAAG,EAAE,GAAG,MAAM,CAG1D;AAED;;;;;;;;GAQG;AACH,wBAAgB,sBAAsB,CAAC,GAAG,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,GAAG,GAAG,GAAG,EAAE,CAqB1E;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAAC,CAAC,EAAE,GAAG,GAAG,GAAG,CASxC;AAED,iGAAiG;AACjG,wBAAgB,UAAU,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,GAAG,GAAG,CAE9C;AAED,wFAAwF;AACxF,wBAAgB,aAAa,CAAC,CAAC,EAAE,GAAG,GAAG,GAAG,CAQzC;AAED,+EAA+E;AAC/E,wBAAgB,aAAa,CAAC,CAAC,SAAS,OAAO,GAAG,UAAU,EAC1D,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC,GAAG,WAAW,CAAC,CAAC,CAAC,GAC3B,QAAQ,CAAC,CAAC,CAAC,CAOb"}
1
+ {"version":3,"file":"bitwise.d.ts","sourceRoot":"","sources":["../../../src/functions/bitwise.ts"],"names":[],"mappings":";;;;AAGA,+EAA+E;AAC/E,wBAAgB,eAAe,CAAC,CAAC,SAAS,OAAO,GAAG,UAAU,EAC5D,KAAK,EAAE,CAAC,EAAE,GAAG,SAAS,CAAC,EAAE,GACxB,QAAQ,CAAC,CAAC,CAAC,CAOb;AAED,mFAAmF;AACnF,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,GAAG,EAAE,GAAG,MAAM,CAG1D;AAED;;;;;;;;GAQG;AACH,wBAAgB,sBAAsB,CAAC,GAAG,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,GAAG,GAAG,GAAG,EAAE,CAqB1E;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,GAAG,GAAG,GAAG,CAS1C;AAED,iGAAiG;AACjG,wBAAgB,UAAU,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,GAAG,GAAG,CAE9C;AAED,wFAAwF;AACxF,wBAAgB,aAAa,CAAC,CAAC,EAAE,GAAG,GAAG,GAAG,CAQzC;AAED,+EAA+E;AAC/E,wBAAgB,aAAa,CAAC,CAAC,SAAS,OAAO,GAAG,UAAU,EAC1D,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC,GAAG,WAAW,CAAC,CAAC,CAAC,GAC3B,QAAQ,CAAC,CAAC,CAAC,CAOb"}
@@ -49,10 +49,10 @@ function ____exports.convertDecimalToBinary(self, num, minLength)
49
49
  end
50
50
  --- Helper function to count the number of bits that are set to 1 in a binary representation of a
51
51
  -- number.
52
- function ____exports.countSetBits(self, n)
52
+ function ____exports.countSetBits(self, num)
53
53
  local count = 0
54
- while n > 0 do
55
- n = n & n - 1
54
+ while num > 0 do
55
+ num = num & num - 1
56
56
  count = count + 1
57
57
  end
58
58
  return count
@@ -46,5 +46,20 @@ export declare function lerpAngleDegrees(aStart: number, aEnd: number, percent:
46
46
  export declare function round(num: float, numDecimalPlaces?: number): float;
47
47
  /** @returns 1 if n is positive, -1 if n is negative, or 0 if n is 0. */
48
48
  export declare function sign(n: number): int;
49
+ /**
50
+ * Breaks a number into chunks of a given size. This is similar to the `String.split` method, but
51
+ * for a number instead of a string.
52
+ *
53
+ * For example, `splitNumber(90, 25)` would return an array with four elements:
54
+ *
55
+ * - [1, 25]
56
+ * - [26, 50]
57
+ * - [51, 75]
58
+ * - [76, 90]
59
+ *
60
+ * @param num The number to split into chunks. This must be a positive integer.
61
+ * @param size The size of each chunk. This must be a positive integer.
62
+ */
63
+ export declare function splitNumber(num: int, size: int): Array<[min: int, max: int]>;
49
64
  export declare function tanh(x: number): number;
50
65
  //# sourceMappingURL=math.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"math.d.ts","sourceRoot":"","sources":["../../../src/functions/math.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AAGzD;;;;;GAKG;AACH,wBAAgB,KAAK,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,GAAG,GAAG,CAEvD;AAED,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,GAAG,KAAK,CAGtE;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,0BAA0B,CACxC,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,KAAK,EACb,SAAS,EAAE,GAAG,EACd,WAAW,SAAI,EACf,WAAW,SAAI,EACf,gBAAgB,YAAe,GAC9B,MAAM,EAAE,CAaV;AAED;;;;;GAKG;AACH,wBAAgB,WAAW,CACzB,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,MAAM,EACf,WAAW,EAAE,MAAM,GAClB,OAAO,CAOT;AAED;;GAEG;AACH,wBAAgB,6BAA6B,CAC3C,YAAY,EAAE,MAAM,EACpB,YAAY,EAAE,KAAK,EACnB,gBAAgB,EAAE,MAAM,EACxB,oBAAoB,EAAE,MAAM,GAC3B,OAAO,CAgBT;AAED,wBAAgB,MAAM,CAAC,GAAG,EAAE,GAAG,GAAG,OAAO,CAGxC;AAED,wBAAgB,KAAK,CAAC,GAAG,EAAE,GAAG,GAAG,OAAO,CAGvC;AAED,wBAAgB,IAAI,C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AAM,GAC3B,OAAO,CAgBT;AAED,wBAAgB,MAAM,CAAC,GAAG,EAAE,GAAG,GAAG,OAAO,CAGxC;AAED,wBAAgB,KAAK,CAAC,GAAG,EAAE,GAAG,GAAG,OAAO,CAGvC;AAED,wBAAgB,IAAI,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,GAAG,EAAE,KAAK,GAAG,MAAM,CAE7D;AAED,wBAAgB,gBAAgB,CAC9B,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,KAAK,GACb,MAAM,CAER;AAED;;;;;;;GAOG;AACH,wBAAgB,KAAK,CAAC,GAAG,EAAE,KAAK,EAAE,gBAAgB,SAAI,GAAG,KAAK,CAG7D;AAED,wEAAwE;AACxE,wBAAgB,IAAI,CAAC,CAAC,EAAE,MAAM,GAAG,GAAG,CAUnC;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,GAAG,KAAK,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC,CAuB5E;AAED,wBAAgB,IAAI,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAEtC"}
@@ -113,6 +113,34 @@ function ____exports.sign(self, n)
113
113
  end
114
114
  return 0
115
115
  end
116
+ --- Breaks a number into chunks of a given size. This is similar to the `String.split` method, but
117
+ -- for a number instead of a string.
118
+ --
119
+ -- For example, `splitNumber(90, 25)` would return an array with four elements:
120
+ --
121
+ -- - [1, 25]
122
+ -- - [26, 50]
123
+ -- - [51, 75]
124
+ -- - [76, 90]
125
+ --
126
+ -- @param num The number to split into chunks. This must be a positive integer.
127
+ -- @param size The size of each chunk. This must be a positive integer.
128
+ function ____exports.splitNumber(self, num, size)
129
+ if num <= 0 then
130
+ error("The number to split needs to be a positive number and is instead: " .. tostring(num))
131
+ end
132
+ if size <= 0 then
133
+ error("The size to split needs to be a positive number and is instead: " .. tostring(num))
134
+ end
135
+ local chunks = {}
136
+ local min = 1
137
+ while min <= num do
138
+ local max = math.min(min + size - 1, num)
139
+ chunks[#chunks + 1] = {min, max}
140
+ min = max + 1
141
+ end
142
+ return chunks
143
+ end
116
144
  function ____exports.tanh(self, x)
117
145
  return (math.exp(x) - math.exp(-x)) / (math.exp(x) + math.exp(-x))
118
146
  end
@@ -115,7 +115,7 @@ export declare function isRepentance(): boolean;
115
115
  * });
116
116
  * ```
117
117
  */
118
- export declare function repeat(n: int, func: (i: int) => void): void;
118
+ export declare function repeat(num: int, func: (i: int) => void): void;
119
119
  /**
120
120
  * Helper function to signify that the enclosing code block is not yet complete. Using this function
121
121
  * is similar to writing a "TODO" comment, but it has the benefit of preventing ESLint errors due to
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/functions/utils.ts"],"names":[],"mappings":";AAIA;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,CAAC,EAC7B,KAAK,EAAE,CAAC,EACR,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC,CAAC,GAC7B,CAAC,MAAM,CAAC,GACR;IACE,iFAAiF;CAClF,GACJ,OAAO,CAAC,KAAK,IAAI,OAAO,CAAC,CAAC,EAAE,SAAS,CAAC,CAIxC;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,CAAC,EAC7B,KAAK,EAAE,CAAC,EACR,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,GACxB,CAAC,MAAM,CAAC,GACR;IACE,4EAA4E;CAC7E,GACJ,OAAO,CAAC,KAAK,IAAI,OAAO,CAAC,CAAC,EAAE,IAAI,CAAC,CAInC;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,MAAM,CAAC,KAAK,EAAE,GAAG,EAAE,GAAG,CAAC,EAAE,GAAG,EAAE,SAA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AAC,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,GACxB,CAAC,MAAM,CAAC,GACR;IACE,4EAA4E;CAC7E,GACJ,OAAO,CAAC,KAAK,IAAI,OAAO,CAAC,CAAC,EAAE,IAAI,CAAC,CAInC;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,MAAM,CAAC,KAAK,EAAE,GAAG,EAAE,GAAG,CAAC,EAAE,GAAG,EAAE,SAAS,SAAI,GAAG,GAAG,EAAE,CAkBlE;AAED;;;GAGG;AACH,wBAAgB,uBAAuB,CACrC,GAAG,EAAE,OAAO,EACZ,oBAAoB,EAAE,MAAM,GAC3B,MAAM,CAQR;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,MAAM,CAAC,KAAK,EAAE,GAAG,EAAE,GAAG,CAAC,EAAE,GAAG,EAAE,SAAS,SAAI,GAAG,GAAG,EAAE,CAQlE;AAED;;;;;;;;;GASG;AACH,wBAAgB,OAAO,CAAC,GAAG,EAAE,GAAG,EAAE,KAAK,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,GAAG,OAAO,CAE/D;AAED;;;;;;;;GAQG;AACH,wBAAgB,aAAa,IAAI,OAAO,CAMvC;AAED;;;;;;;GAOG;AACH,wBAAgB,YAAY,IAAI,OAAO,CAiBtC;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,MAAM,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,GAAG,KAAK,IAAI,GAAG,IAAI,CAI7D;AAED;;;;;;;;;;;;;;GAcG;AAEH,wBAAgB,IAAI,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAAG"}
@@ -175,10 +175,10 @@ end
175
175
  -- print(i); // Prints "0", "1", "2"
176
176
  -- });
177
177
  -- ```
178
- ____exports["repeat"] = function(self, n, func)
178
+ ____exports["repeat"] = function(self, num, func)
179
179
  do
180
180
  local i = 0
181
- while i < n do
181
+ while i < num do
182
182
  func(nil, i)
183
183
  i = i + 1
184
184
  end
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "isaacscript-common",
3
- "version": "67.0.0",
3
+ "version": "67.1.0",
4
4
  "description": "Helper functions and features for IsaacScript mods.",
5
5
  "keywords": [
6
6
  "isaac",
@@ -55,11 +55,11 @@ export function convertDecimalToBinary(num: number, minLength?: int): int[] {
55
55
  * Helper function to count the number of bits that are set to 1 in a binary representation of a
56
56
  * number.
57
57
  */
58
- export function countSetBits(n: int): int {
58
+ export function countSetBits(num: int): int {
59
59
  let count = 0;
60
60
 
61
- while (n > 0) {
62
- n &= n - 1;
61
+ while (num > 0) {
62
+ num &= num - 1;
63
63
  count++;
64
64
  }
65
65
 
@@ -143,6 +143,45 @@ export function sign(n: number): int {
143
143
  return 0;
144
144
  }
145
145
 
146
+ /**
147
+ * Breaks a number into chunks of a given size. This is similar to the `String.split` method, but
148
+ * for a number instead of a string.
149
+ *
150
+ * For example, `splitNumber(90, 25)` would return an array with four elements:
151
+ *
152
+ * - [1, 25]
153
+ * - [26, 50]
154
+ * - [51, 75]
155
+ * - [76, 90]
156
+ *
157
+ * @param num The number to split into chunks. This must be a positive integer.
158
+ * @param size The size of each chunk. This must be a positive integer.
159
+ */
160
+ export function splitNumber(num: int, size: int): Array<[min: int, max: int]> {
161
+ if (num <= 0) {
162
+ error(
163
+ `The number to split needs to be a positive number and is instead: ${num}`,
164
+ );
165
+ }
166
+
167
+ if (size <= 0) {
168
+ error(
169
+ `The size to split needs to be a positive number and is instead: ${num}`,
170
+ );
171
+ }
172
+
173
+ const chunks: Array<[number, number]> = [];
174
+ let min = 1;
175
+
176
+ while (min <= num) {
177
+ const max = Math.min(min + size - 1, num);
178
+ chunks.push([min, max]);
179
+ min = max + 1;
180
+ }
181
+
182
+ return chunks;
183
+ }
184
+
146
185
  export function tanh(x: number): number {
147
186
  return (Math.exp(x) - Math.exp(-x)) / (Math.exp(x) + Math.exp(-x));
148
187
  }
@@ -206,8 +206,8 @@ export function isRepentance(): boolean {
206
206
  * });
207
207
  * ```
208
208
  */
209
- export function repeat(n: int, func: (i: int) => void): void {
210
- for (let i = 0; i < n; i++) {
209
+ export function repeat(num: int, func: (i: int) => void): void {
210
+ for (let i = 0; i < num; i++) {
211
211
  func(i);
212
212
  }
213
213
  }