isaacscript-common 1.2.125 → 1.2.126
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/functions/map.d.ts +6 -0
- package/dist/functions/map.lua +14 -0
- package/package.json +1 -1
package/dist/functions/map.d.ts
CHANGED
|
@@ -1,2 +1,8 @@
|
|
|
1
|
+
/// <reference types="isaac-typescript-definitions" />
|
|
1
2
|
/** Helper function to copy a map. (You can also use a Map constructor to accomplish this task.) */
|
|
2
3
|
export declare function copyMap<K, V>(oldMap: Map<K, V>): Map<K, V>;
|
|
4
|
+
/**
|
|
5
|
+
* Helper function to make using map with `Seed` values easier. Use this instead of manually getting
|
|
6
|
+
* the current value, incrementing it, and then re-setting it.
|
|
7
|
+
*/
|
|
8
|
+
export declare function mapGetNextSeed<K>(map: Map<K, Seed>, key: K): Seed | undefined;
|
package/dist/functions/map.lua
CHANGED
|
@@ -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 ____random = require("functions.random")
|
|
8
|
+
local nextSeed = ____random.nextSeed
|
|
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.mapGetNextSeed(self, map, key)
|
|
19
|
+
local seed = map:get(key)
|
|
20
|
+
if seed == nil then
|
|
21
|
+
return nil
|
|
22
|
+
end
|
|
23
|
+
if seed == 0 then
|
|
24
|
+
error("The seed map had a value of 0 for the key of: " .. tostring(key))
|
|
25
|
+
end
|
|
26
|
+
local newSeed = nextSeed(nil, seed)
|
|
27
|
+
map:set(key, newSeed)
|
|
28
|
+
return newSeed
|
|
29
|
+
end
|
|
16
30
|
return ____exports
|