isaacscript-common 1.2.5 → 1.2.6

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.
@@ -61,6 +61,15 @@ export declare function arrayRemoveInPlace<T>(array: T[], ...elements: T[]): boo
61
61
  * @param exceptions Optional. An array of elements to skip over if selected.
62
62
  */
63
63
  export declare function getRandomArrayElement<T>(array: T[], seed?: number, exceptions?: T[]): T;
64
+ /**
65
+ * Helper function to get a random element from the provided array. Once the random element is
66
+ * decided, it is then removed from the array (in-place).
67
+ *
68
+ * @param array The array to get an element from.
69
+ * @param seed Optional. The seed used to select the random element. `Random()` by default.
70
+ * @param exceptions Optional. An array of elements to skip over if selected.
71
+ */
72
+ export declare function getRandomArrayElementAndRemove<T>(array: T[], seed?: number, exceptions?: T[]): T;
64
73
  export declare function getRandomArrayIndex<T>(array: T[], seed?: number): int;
65
74
  /**
66
75
  * Since Lua uses tables for every non-primitive data structure, it is non-trivial to determine if a
@@ -145,6 +145,17 @@ function ____exports.getRandomArrayElement(self, array, seed, exceptions)
145
145
  local randomIndex = ____exports.getRandomArrayIndex(nil, arrayWithoutExceptions, seed)
146
146
  return arrayWithoutExceptions[randomIndex + 1]
147
147
  end
148
+ function ____exports.getRandomArrayElementAndRemove(self, array, seed, exceptions)
149
+ if seed == nil then
150
+ seed = Random()
151
+ end
152
+ if exceptions == nil then
153
+ exceptions = {}
154
+ end
155
+ local randomArrayElement = ____exports.getRandomArrayElement(nil, array, seed, exceptions)
156
+ ____exports.arrayRemoveInPlace(nil, array, randomArrayElement)
157
+ return randomArrayElement
158
+ end
148
159
  function ____exports.isArray(self, ____table)
149
160
  local metatable = getmetatable(____table)
150
161
  if metatable ~= nil then
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "isaacscript-common",
3
- "version": "1.2.5",
3
+ "version": "1.2.6",
4
4
  "description": "Helper functions for IsaacScript mods",
5
5
  "keywords": [
6
6
  "isaac",