isaacscript-common 21.0.0 → 21.1.1

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.
package/dist/index.d.ts CHANGED
@@ -5928,6 +5928,31 @@ export declare function getRedHearts(): EntityPickupHeart[];
5928
5928
  */
5929
5929
  export declare function getRepentanceDoor(): GridEntityDoor | undefined;
5930
5930
 
5931
+ /**
5932
+ * Helper function to get a copy of a map with the keys and the values reversed.
5933
+ *
5934
+ * For example:
5935
+ *
5936
+ * ```ts
5937
+ * new Map<string, number>([
5938
+ * ["foo", 1],
5939
+ * ["bar", 2],
5940
+ * ]);
5941
+ * ```
5942
+ *
5943
+ * Would be reversed to:
5944
+ *
5945
+ * ```ts
5946
+ * new Map<number, string>([
5947
+ * [1, "foo"],
5948
+ * [2, "bar"],
5949
+ * ]);
5950
+ * ```
5951
+ */
5952
+ export declare function getReversedMap<K, V>(map: Map<K, V>): Map<V, K>;
5953
+
5954
+ export declare function getReversedMap<K, V>(map: ReadonlyMap<K, V>): ReadonlyMap<V, K>;
5955
+
5931
5956
  /**
5932
5957
  * Helper function to get the alternate rock type (i.e. urn, mushroom, etc.) that the current room
5933
5958
  * will have.
@@ -12516,7 +12541,7 @@ export { ReadonlyMap_2 as ReadonlyMap }
12516
12541
 
12517
12542
  declare interface ReadonlyMapConstructor {
12518
12543
  new (): ReadonlyMap<any, any>;
12519
- new <K, V>(entries?: ReadonlyArray<readonly [K, V]> | null): ReadonlyMap<K, V>;
12544
+ new <K, V>(entries?: ReadonlyArray<readonly [K, V]> | Iterable<readonly [K, V]> | null): ReadonlyMap<K, V>;
12520
12545
  readonly prototype: ReadonlyMap<any, any>;
12521
12546
  }
12522
12547
 
@@ -12525,7 +12550,7 @@ declare const ReadonlySet_2: ReadonlySetConstructor;
12525
12550
  export { ReadonlySet_2 as ReadonlySet }
12526
12551
 
12527
12552
  declare interface ReadonlySetConstructor {
12528
- new <T = any>(values?: readonly T[] | null): ReadonlySet<T>;
12553
+ new <T = any>(values?: readonly T[] | Iterable<T> | null): ReadonlySet<T>;
12529
12554
  readonly prototype: ReadonlySet<any>;
12530
12555
  }
12531
12556
 
@@ -1,6 +1,6 @@
1
1
  --[[
2
2
 
3
- isaacscript-common 21.0.0
3
+ isaacscript-common 21.1.1
4
4
 
5
5
  This is the "isaacscript-common" library, which was created with the IsaacScript tool.
6
6
 
@@ -37788,6 +37788,15 @@ function ____exports.getMapPartialMatch(self, searchText, map)
37788
37788
  end
37789
37789
  return {matchingKey, value}
37790
37790
  end
37791
+ function ____exports.getReversedMap(self, map)
37792
+ local reverseMap = __TS__New(Map)
37793
+ for ____, ____value in __TS__Iterator(map) do
37794
+ local key = ____value[1]
37795
+ local value = ____value[2]
37796
+ reverseMap:set(value, key)
37797
+ end
37798
+ return reverseMap
37799
+ end
37791
37800
  function ____exports.sumMap(self, map)
37792
37801
  local values = {__TS__Spread(map:values())}
37793
37802
  return sumArray(nil, values)
@@ -36,6 +36,29 @@ export declare function defaultMapSetHash<V>(map: Map<PtrHash, V>, entity: Entit
36
36
  * found, returns undefined.
37
37
  */
38
38
  export declare function getMapPartialMatch<T>(searchText: string, map: ReadonlyMap<string, T>): [string, T] | undefined;
39
+ /**
40
+ * Helper function to get a copy of a map with the keys and the values reversed.
41
+ *
42
+ * For example:
43
+ *
44
+ * ```ts
45
+ * new Map<string, number>([
46
+ * ["foo", 1],
47
+ * ["bar", 2],
48
+ * ]);
49
+ * ```
50
+ *
51
+ * Would be reversed to:
52
+ *
53
+ * ```ts
54
+ * new Map<number, string>([
55
+ * [1, "foo"],
56
+ * [2, "bar"],
57
+ * ]);
58
+ * ```
59
+ */
60
+ export declare function getReversedMap<K, V>(map: Map<K, V>): Map<V, K>;
61
+ export declare function getReversedMap<K, V>(map: ReadonlyMap<K, V>): ReadonlyMap<V, K>;
39
62
  /**
40
63
  * Helper function to set a value for a `DefaultMap` that corresponds to an entity, assuming that
41
64
  * the map uses `PtrHash` as an index.
@@ -1 +1 @@
1
-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ahF;;;GAGG;AACH,wBAAgB,UAAU,CAAC,CAAC,EAC1B,GAAG,EAAE,GAAG,CAAC,OAAO,EAAE,CAAC,CAAC,EACpB,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,CAAC,GACP,IAAI,CAGN;AAED,4DAA4D;AAC5D,wBAAgB,MAAM,CACpB,GAAG,EAAE,GAAG,CAAC,OAAO,EAAE,MAAM,CAAC,GAAG,WAAW,CAAC,OAAO,EAAE,MAAM,CAAC,GACvD,MAAM,CAGR"}
@@ -67,6 +67,34 @@ function ____exports.getMapPartialMatch(self, searchText, map)
67
67
  end
68
68
  return {matchingKey, value}
69
69
  end
70
+ --- Helper function to get a copy of a map with the keys and the values reversed.
71
+ --
72
+ -- For example:
73
+ --
74
+ -- ```ts
75
+ -- new Map<string, number>([
76
+ -- ["foo", 1],
77
+ -- ["bar", 2],
78
+ -- ]);
79
+ -- ```
80
+ --
81
+ -- Would be reversed to:
82
+ --
83
+ -- ```ts
84
+ -- new Map<number, string>([
85
+ -- [1, "foo"],
86
+ -- [2, "bar"],
87
+ -- ]);
88
+ -- ```
89
+ function ____exports.getReversedMap(self, map)
90
+ local reverseMap = __TS__New(Map)
91
+ for ____, ____value in __TS__Iterator(map) do
92
+ local key = ____value[1]
93
+ local value = ____value[2]
94
+ reverseMap:set(value, key)
95
+ end
96
+ return reverseMap
97
+ end
70
98
  --- Helper function to sum every value in a map together.
71
99
  function ____exports.sumMap(self, map)
72
100
  local values = {__TS__Spread(map:values())}
@@ -1 +1 @@
1
- {"version":3,"file":"roomGrid.d.ts","sourceRoot":"","sources":["../../../src/functions/roomGrid.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AAUzD;;;;GAIG;AACH,wBAAgB,8BAA8B,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,GAAG,MAAM,CAGrE;AAED;;;;;GAKG;AACH,wBAAgB,uBAAuB,CACrC,SAAS,EAAE,GAAG,EACd,SAAS,EAAE,SAAS,GACnB,MAAM,CAMR;AAED;;;;GAIG;AACH,wBAAgB,2BAA2B,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM,CAIxE;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CACjC,YAAY,EAAE,MAAM,EACpB,SAAS,EAAE,SAAS,GACnB,OAAO,CAIT;AA0BD;;;;GAIG;AACH,wBAAgB,2BAA2B,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAIpE;AAED;;;;;;GAMG;AACH,wBAAgB,+BAA+B,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAIxE"}
1
+ {"version":3,"file":"roomGrid.d.ts","sourceRoot":"","sources":["../../../src/functions/roomGrid.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AAUzD;;;;GAIG;AACH,wBAAgB,8BAA8B,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,GAAG,MAAM,CAGrE;AAED;;;;;GAKG;AACH,wBAAgB,uBAAuB,CACrC,SAAS,EAAE,GAAG,EACd,SAAS,EAAE,SAAS,GACnB,MAAM,CAMR;AAED;;;;GAIG;AACH,wBAAgB,2BAA2B,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM,CAKxE;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CACjC,YAAY,EAAE,MAAM,EACpB,SAAS,EAAE,SAAS,GACnB,OAAO,CAIT;AA0BD;;;;GAIG;AACH,wBAAgB,2BAA2B,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAIpE;AAED;;;;;;GAMG;AACH,wBAAgB,+BAA+B,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAIxE"}
@@ -1,6 +1,6 @@
1
1
  interface ReadonlyMapConstructor {
2
2
  new (): ReadonlyMap<any, any>;
3
- new <K, V>(entries?: ReadonlyArray<readonly [K, V]> | null): ReadonlyMap<K, V>;
3
+ new <K, V>(entries?: ReadonlyArray<readonly [K, V]> | Iterable<readonly [K, V]> | null): ReadonlyMap<K, V>;
4
4
  readonly prototype: ReadonlyMap<any, any>;
5
5
  }
6
6
  /** An alias for the `Map` constructor that returns a read-only map. */
@@ -1 +1 @@
1
- {"version":3,"file":"ReadonlyMap.d.ts","sourceRoot":"","sources":["../../../src/types/ReadonlyMap.ts"],"names":[],"mappings":"AAEA,UAAU,sBAAsB;IAC9B,QAAQ,WAAW,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;IAC9B,KAAK,CAAC,EAAE,CAAC,EAAE,OAAO,CAAC,EAAE,aAAa,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,IAAI,GAAG,WAAW,CACtE,CAAC,EACD,CAAC,CACF,CAAC;IACF,QAAQ,CAAC,SAAS,EAAE,WAAW,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;CAC3C;AAED,uEAAuE;AACvE,eAAO,MAAM,WAAW,wBAAgC,CAAC"}
1
+ {"version":3,"file":"ReadonlyMap.d.ts","sourceRoot":"","sources":["../../../src/types/ReadonlyMap.ts"],"names":[],"mappings":"AAEA,UAAU,sBAAsB;IAC9B,QAAQ,WAAW,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;IAC9B,KAAK,CAAC,EAAE,CAAC,EACP,OAAO,CAAC,EAAE,aAAa,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,QAAQ,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,IAAI,GAC1E,WAAW,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IACrB,QAAQ,CAAC,SAAS,EAAE,WAAW,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;CAC3C;AAED,uEAAuE;AACvE,eAAO,MAAM,WAAW,wBAAgC,CAAC"}
@@ -1,5 +1,5 @@
1
1
  interface ReadonlySetConstructor {
2
- new <T = any>(values?: readonly T[] | null): ReadonlySet<T>;
2
+ new <T = any>(values?: readonly T[] | Iterable<T> | null): ReadonlySet<T>;
3
3
  readonly prototype: ReadonlySet<any>;
4
4
  }
5
5
  /** An alias for the `Set` constructor that returns a read-only set. */
@@ -1 +1 @@
1
- {"version":3,"file":"ReadonlySet.d.ts","sourceRoot":"","sources":["../../../src/types/ReadonlySet.ts"],"names":[],"mappings":"AAEA,UAAU,sBAAsB;IAC9B,KAAK,CAAC,GAAG,GAAG,EAAE,MAAM,CAAC,EAAE,SAAS,CAAC,EAAE,GAAG,IAAI,GAAG,WAAW,CAAC,CAAC,CAAC,CAAC;IAC5D,QAAQ,CAAC,SAAS,EAAE,WAAW,CAAC,GAAG,CAAC,CAAC;CACtC;AAED,uEAAuE;AACvE,eAAO,MAAM,WAAW,wBAAgC,CAAC"}
1
+ {"version":3,"file":"ReadonlySet.d.ts","sourceRoot":"","sources":["../../../src/types/ReadonlySet.ts"],"names":[],"mappings":"AAEA,UAAU,sBAAsB;IAC9B,KAAK,CAAC,GAAG,GAAG,EAAE,MAAM,CAAC,EAAE,SAAS,CAAC,EAAE,GAAG,QAAQ,CAAC,CAAC,CAAC,GAAG,IAAI,GAAG,WAAW,CAAC,CAAC,CAAC,CAAC;IAC1E,QAAQ,CAAC,SAAS,EAAE,WAAW,CAAC,GAAG,CAAC,CAAC;CACtC;AAED,uEAAuE;AACvE,eAAO,MAAM,WAAW,wBAAgC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "isaacscript-common",
3
- "version": "21.0.0",
3
+ "version": "21.1.1",
4
4
  "description": "Helper functions and features for IsaacScript mods.",
5
5
  "keywords": [
6
6
  "isaac",
@@ -82,6 +82,41 @@ export function getMapPartialMatch<T>(
82
82
  return [matchingKey, value];
83
83
  }
84
84
 
85
+ /**
86
+ * Helper function to get a copy of a map with the keys and the values reversed.
87
+ *
88
+ * For example:
89
+ *
90
+ * ```ts
91
+ * new Map<string, number>([
92
+ * ["foo", 1],
93
+ * ["bar", 2],
94
+ * ]);
95
+ * ```
96
+ *
97
+ * Would be reversed to:
98
+ *
99
+ * ```ts
100
+ * new Map<number, string>([
101
+ * [1, "foo"],
102
+ * [2, "bar"],
103
+ * ]);
104
+ * ```
105
+ */
106
+ export function getReversedMap<K, V>(map: Map<K, V>): Map<V, K>;
107
+ export function getReversedMap<K, V>(map: ReadonlyMap<K, V>): ReadonlyMap<V, K>;
108
+ export function getReversedMap<K, V>(
109
+ map: Map<K, V> | ReadonlyMap<K, V>,
110
+ ): Map<V, K> {
111
+ const reverseMap = new Map<V, K>();
112
+
113
+ for (const [key, value] of map) {
114
+ reverseMap.set(value, key);
115
+ }
116
+
117
+ return reverseMap;
118
+ }
119
+
85
120
  /**
86
121
  * Helper function to set a value for a `DefaultMap` that corresponds to an entity, assuming that
87
122
  * the map uses `PtrHash` as an index.
@@ -52,6 +52,7 @@ export function gridIndexToGridPosition(
52
52
  export function gridPositionToWorldPosition(gridPosition: Vector): Vector {
53
53
  const x = (gridPosition.X + 2) * 40;
54
54
  const y = (gridPosition.Y + 4) * 40;
55
+
55
56
  return Vector(x, y);
56
57
  }
57
58
 
@@ -2,10 +2,9 @@
2
2
 
3
3
  interface ReadonlyMapConstructor {
4
4
  new (): ReadonlyMap<any, any>;
5
- new <K, V>(entries?: ReadonlyArray<readonly [K, V]> | null): ReadonlyMap<
6
- K,
7
- V
8
- >;
5
+ new <K, V>(
6
+ entries?: ReadonlyArray<readonly [K, V]> | Iterable<readonly [K, V]> | null,
7
+ ): ReadonlyMap<K, V>;
9
8
  readonly prototype: ReadonlyMap<any, any>;
10
9
  }
11
10
 
@@ -1,7 +1,7 @@
1
1
  /* eslint-disable @typescript-eslint/no-explicit-any */
2
2
 
3
3
  interface ReadonlySetConstructor {
4
- new <T = any>(values?: readonly T[] | null): ReadonlySet<T>;
4
+ new <T = any>(values?: readonly T[] | Iterable<T> | null): ReadonlySet<T>;
5
5
  readonly prototype: ReadonlySet<any>;
6
6
  }
7
7