isaacscript-common 1.2.122 → 1.2.123

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.
@@ -22,7 +22,7 @@ import { JSONRoom } from "../types/JSONRoom";
22
22
  * function returns the final iterated seed after spawning everything, which can be used in
23
23
  * subsequent room deployments.
24
24
  */
25
- export declare function deployJSONRoom(jsonRoom: JSONRoom, seed?: number, verbose?: boolean): int;
25
+ export declare function deployJSONRoom(jsonRoom: JSONRoom, seed?: Seed, verbose?: boolean): Seed;
26
26
  /**
27
27
  * Helper function to deconstruct a vanilla room and set up a custom room in its place.
28
28
  * Specifically, this will clear the current room of all entities and grid entities, and then spawn
@@ -50,7 +50,7 @@ export declare function deployJSONRoom(jsonRoom: JSONRoom, seed?: number, verbos
50
50
  * function returns the final iterated seed after spawning everything, which can be used in
51
51
  * subsequent room deployments.
52
52
  */
53
- export declare function deployRandomJSONRoom(jsonRooms: JSONRoom[], seed?: number, verbose?: boolean): int;
53
+ export declare function deployRandomJSONRoom(jsonRooms: JSONRoom[], seed?: Seed, verbose?: boolean): Seed;
54
54
  /**
55
55
  * Helper function to remove all naturally spawning entities and grid entities from a room. Notably,
56
56
  * this will not remove players (1), tears (2), familiars (3), lasers (7), knives (8),
@@ -38,13 +38,13 @@ export declare function isArrayInArray<T>(arrayToMatch: T[] | readonly T[], pare
38
38
  *
39
39
  * From: https://stackoverflow.com/questions/2450954/how-to-randomize-shuffle-a-javascript-array
40
40
  */
41
- export declare function shuffleArray<T>(originalArray: T[] | readonly T[], seed?: number): T[];
41
+ export declare function shuffleArray<T>(originalArray: T[] | readonly T[], seed?: Seed): T[];
42
42
  /**
43
43
  * Shuffles the provided array in-place using the Fisher-Yates algorithm.
44
44
  *
45
45
  * From: https://stackoverflow.com/questions/2450954/how-to-randomize-shuffle-a-javascript-array
46
46
  */
47
- export declare function shuffleArrayInPlace<T>(array: T[], seed?: number): void;
47
+ export declare function shuffleArrayInPlace<T>(array: T[], seed?: Seed): void;
48
48
  export declare function sumArray(array: number[] | readonly number[]): number;
49
49
  export declare function arrayToString<T>(array: T[]): string;
50
50
  /**
@@ -69,7 +69,7 @@ export declare function arrayRemoveInPlace<T>(array: T[], ...elementsToRemove: T
69
69
  * @param seed Optional. The seed used to select the random element. Default is `Random()`.
70
70
  * @param exceptions Optional. An array of elements to skip over if selected.
71
71
  */
72
- export declare function getRandomArrayElement<T>(array: T[] | readonly T[], seed?: number, exceptions?: T[] | readonly T[]): T;
72
+ export declare function getRandomArrayElement<T>(array: T[] | readonly T[], seed?: Seed, exceptions?: T[] | readonly T[]): T;
73
73
  /**
74
74
  * Helper function to get a random element from the provided array. Once the random element is
75
75
  * decided, it is then removed from the array (in-place).
@@ -78,8 +78,8 @@ export declare function getRandomArrayElement<T>(array: T[] | readonly T[], seed
78
78
  * @param seed Optional. The seed used to select the random element. Default is `Random()`.
79
79
  * @param exceptions Optional. An array of elements to skip over if selected.
80
80
  */
81
- export declare function getRandomArrayElementAndRemove<T>(array: T[], seed?: number, exceptions?: T[] | readonly T[]): T;
82
- export declare function getRandomArrayIndex<T>(array: T[] | readonly T[], seed?: number): int;
81
+ export declare function getRandomArrayElementAndRemove<T>(array: T[], seed?: Seed, exceptions?: T[] | readonly T[]): T;
82
+ export declare function getRandomArrayIndex<T>(array: T[] | readonly T[], seed?: Seed): int;
83
83
  /**
84
84
  * Since Lua uses tables for every non-primitive data structure, it is non-trivial to determine if a
85
85
  * particular table is being used as an array. isArray returns true if:
@@ -40,13 +40,13 @@ export declare function getMaxCards(): int;
40
40
  * @param seed Optional. The seed with which to select the random card. Default is `Random()`.
41
41
  * @param exceptions Optional. An array of cards to not select.
42
42
  */
43
- export declare function getRandomCard(seed?: number, exceptions?: Card[]): Card;
43
+ export declare function getRandomCard(seed?: Seed, exceptions?: Card[]): Card;
44
44
  /**
45
45
  * @param cardType The card type that represents the pool of cards to select from.
46
46
  * @param seed Optional. The seed with which to select the random card. Default is `Random()`.
47
47
  * @param exceptions Optional. An array of cards to not select.
48
48
  */
49
- export declare function getRandomCardOfType(cardType: CardType, seed?: number, exceptions?: Card[]): Card;
49
+ export declare function getRandomCardOfType(cardType: CardType, seed?: Seed, exceptions?: Card[]): Card;
50
50
  /**
51
51
  * Has an equal chance of returning any rune (e.g. Rune of Hagalaz, Blank Rune, Black Rune, Soul of
52
52
  * Isaac, etc.). This will never return a Rune Shard.
@@ -54,7 +54,7 @@ export declare function getRandomCardOfType(cardType: CardType, seed?: number, e
54
54
  * @param seed Optional. The seed with which to select the random rune. Default is `Random()`.
55
55
  * @param exceptions Optional. An array of runes to not select.
56
56
  */
57
- export declare function getRandomRune(seed?: number, exceptions?: Card[]): Card;
57
+ export declare function getRandomRune(seed?: Seed, exceptions?: Card[]): Card;
58
58
  /**
59
59
  * Returns true for cards that have the following card type:
60
60
  * - CardType.TAROT
@@ -9,4 +9,4 @@ export declare function getJSONRoomsOfSubType(jsonRooms: JSONRoom[], subType: in
9
9
  * properly account for each room weight using the algorithm from:
10
10
  * https://stackoverflow.com/questions/1761626/weighted-random-numbers
11
11
  */
12
- export declare function getRandomJSONRoom(jsonRooms: JSONRoom[], seed?: number, verbose?: boolean): JSONRoom;
12
+ export declare function getRandomJSONRoom(jsonRooms: JSONRoom[], seed?: Seed, verbose?: boolean): JSONRoom;
@@ -1,2 +1,20 @@
1
+ /// <reference types="isaac-typescript-definitions" />
2
+ import { DefaultMap } from "../types/DefaultMap";
3
+ import { PlayerIndex } from "../types/PlayerIndex";
1
4
  /** Helper function to copy a map. (You can also use a Map constructor to accomplish this task.) */
2
5
  export declare function copyMap<K, V>(oldMap: Map<K, V>): Map<K, V>;
6
+ /**
7
+ * Helper function to make using default maps with an index of `PlayerIndex` easier. Use this
8
+ * instead of the `DefaultMap.getAndSetDefault` method.
9
+ */
10
+ export declare function defaultMapGetPlayer<V>(map: DefaultMap<PlayerIndex, V>, player: EntityPlayer): V | undefined;
11
+ /**
12
+ * Helper function to make using maps with an index of `PlayerIndex` easier. Use this instead of the
13
+ * `Map.get` method.
14
+ */
15
+ export declare function mapGetPlayer<V>(map: Map<PlayerIndex, V>, player: EntityPlayer): V | undefined;
16
+ /**
17
+ * Helper function to make using maps with an index of `PlayerIndex` easier. Use this instead of the
18
+ * `Map.set` method.
19
+ */
20
+ export declare function mapSetPlayer<V>(map: Map<PlayerIndex, V>, player: EntityPlayer, value: V): void;
@@ -4,6 +4,8 @@ local Map = ____lualib.Map
4
4
  local __TS__New = ____lualib.__TS__New
5
5
  local __TS__Iterator = ____lualib.__TS__Iterator
6
6
  local ____exports = {}
7
+ local ____player = require("functions.player")
8
+ local getPlayerIndex = ____player.getPlayerIndex
7
9
  function ____exports.copyMap(self, oldMap)
8
10
  local newMap = __TS__New(Map)
9
11
  for ____, ____value in __TS__Iterator(oldMap:entries()) do
@@ -13,4 +15,16 @@ function ____exports.copyMap(self, oldMap)
13
15
  end
14
16
  return newMap
15
17
  end
18
+ function ____exports.defaultMapGetPlayer(self, map, player)
19
+ local playerIndex = getPlayerIndex(nil, player)
20
+ return map:getAndSetDefault(playerIndex)
21
+ end
22
+ function ____exports.mapGetPlayer(self, map, player)
23
+ local playerIndex = getPlayerIndex(nil, player)
24
+ return map:get(playerIndex)
25
+ end
26
+ function ____exports.mapSetPlayer(self, map, player, value)
27
+ local playerIndex = getPlayerIndex(nil, player)
28
+ map:set(playerIndex, value)
29
+ end
16
30
  return ____exports
@@ -4,7 +4,7 @@
4
4
  * the high end. (This is because `RNG.RandomFloat()` can return a value of 0.999, but it will never
5
5
  * return a value of exactly 1.)
6
6
  */
7
- export declare function getRandom(seed?: number): float;
7
+ export declare function getRandom(seed?: Seed): float;
8
8
  /**
9
9
  * This returns a random float between min and max. It is inclusive on the low end, but exclusive on
10
10
  * the high end. (This is because `RNG.RandomFloat()` can return a value of 0.999, but it will never
@@ -15,7 +15,7 @@ export declare function getRandom(seed?: number): float;
15
15
  * const realNumberBetweenOneAndThree = getRandomFloat(1, 3, seed);
16
16
  * ```
17
17
  */
18
- export declare function getRandomFloat(min: int, max: int, seed?: number): float;
18
+ export declare function getRandomFloat(min: int, max: int, seed?: Seed): float;
19
19
  /**
20
20
  * This returns a random integer between min and max, inclusive.
21
21
  *
@@ -24,14 +24,14 @@ export declare function getRandomFloat(min: int, max: int, seed?: number): float
24
24
  * const oneTwoOrThree = getRandomInt(1, 3, seed);
25
25
  * ```
26
26
  */
27
- export declare function getRandomInt(min: int, max: int, seed?: number): int;
27
+ export declare function getRandomInt(min: int, max: int, seed?: Seed): int;
28
28
  /**
29
29
  * Helper function to get the next seed value.
30
30
  *
31
31
  * This function is useful because it is standard practice to work with seed values directly over
32
32
  * RNG objects, since the latter are not serializable.
33
33
  */
34
- export declare function nextSeed(seed: int): int;
34
+ export declare function nextSeed(seed: Seed): Seed;
35
35
  /**
36
36
  * Helper function to initialize an RNG object.
37
37
  *
@@ -46,4 +46,4 @@ export declare function nextSeed(seed: int): int;
46
46
  * (If you aren't initializing it with a seed, then don't use this function and instead simply call
47
47
  * the `RNG()` constructor.)
48
48
  */
49
- export declare function initRNG(seed?: number): RNG;
49
+ export declare function initRNG(seed?: Seed): RNG;
@@ -1,3 +1,4 @@
1
+ /// <reference types="isaac-typescript-definitions" />
1
2
  /**
2
3
  * Helper function to add all of the values in one set to another set. The first set passed will be
3
4
  * modified in place.
@@ -27,7 +28,7 @@ export declare function deleteSetsFromSet<T>(mainSet: Set<T>, ...setsToRemove: A
27
28
  * @param seed Optional. The seed used to select the random element. Default is `Random()`.
28
29
  * @param exceptions Optional. An array of elements to skip over if selected.
29
30
  */
30
- export declare function getRandomSetElement<T>(set: Set<T> | ReadonlySet<T>, seed?: number, exceptions?: T[] | readonly T[]): T;
31
+ export declare function getRandomSetElement<T>(set: Set<T> | ReadonlySet<T>, seed?: Seed, exceptions?: T[] | readonly T[]): T;
31
32
  /**
32
33
  * Helper function to get a sorted array based on the contents of a set.
33
34
  *
@@ -12,7 +12,7 @@
12
12
  * @param forceFreeItem Optional. Set to true to disable the logic that gives the item a price for
13
13
  * Tainted Keeper. Default is false.
14
14
  */
15
- export declare function spawnCollectible(collectibleType: CollectibleType | int, position: Vector, seed?: number, options?: boolean, forceFreeItem?: boolean): EntityPickup;
15
+ export declare function spawnCollectible(collectibleType: CollectibleType | int, position: Vector, seed?: Seed, options?: boolean, forceFreeItem?: boolean): EntityPickup;
16
16
  /**
17
17
  * Helper function to spawn an empty collectible. Doing this is tricky since spawning a collectible
18
18
  * with `CollectibleType.COLLECTIBLE_NULL` will result in spawning a collectible with a random type
@@ -21,4 +21,4 @@ export declare function spawnCollectible(collectibleType: CollectibleType | int,
21
21
  * Instead, this function arbitrarily spawns a collectible with
22
22
  * `CollectibleType.COLLECTIBLE_SAD_ONION`, and then converts it to an empty pedestal afterward.
23
23
  */
24
- export declare function spawnEmptyCollectible(position: Vector, seed?: number): EntityPickup;
24
+ export declare function spawnEmptyCollectible(position: Vector, seed?: Seed): EntityPickup;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "isaacscript-common",
3
- "version": "1.2.122",
3
+ "version": "1.2.123",
4
4
  "description": "Helper functions for IsaacScript mods",
5
5
  "keywords": [
6
6
  "isaac",
@@ -26,7 +26,7 @@
26
26
  ],
27
27
  "devDependencies": {
28
28
  "@zamiell/typescript-to-lua": "^1.4.2",
29
- "isaac-typescript-definitions": "^1.0.359",
29
+ "isaac-typescript-definitions": "^1.0.360",
30
30
  "isaacscript-lint": "^1.0.84",
31
31
  "isaacscript-tsconfig": "^1.1.8",
32
32
  "typedoc": "^0.22.13",