isaacscript-common 3.1.1 → 3.2.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.
- package/classes/DefaultMap.d.ts +1 -2
- package/classes/DefaultMap.lua +1 -4
- package/functions/saveFile.d.ts +15 -0
- package/functions/saveFile.lua +106 -0
- package/index.d.ts +1 -0
- package/index.lua +8 -0
- package/package.json +1 -1
package/classes/DefaultMap.d.ts
CHANGED
|
@@ -46,7 +46,7 @@ export declare type FactoryFunction<V, Args extends unknown[]> = (...extraArgs:
|
|
|
46
46
|
*
|
|
47
47
|
* ```ts
|
|
48
48
|
* // Initializes a new empty DefaultMap with a default value of a new empty array.
|
|
49
|
-
* const factoryFunction = () => []
|
|
49
|
+
* const factoryFunction = () => [];
|
|
50
50
|
* const defaultMapWithArray = new DefaultMap<string, string[]>(factoryFunction);
|
|
51
51
|
* ```
|
|
52
52
|
*
|
|
@@ -96,7 +96,6 @@ export declare class DefaultMap<Key, Value, Args extends unknown[] = []> extends
|
|
|
96
96
|
* it will set a default value for the provided key, and then return the default value.
|
|
97
97
|
*/
|
|
98
98
|
getAndSetDefault(key: Key, ...extraArgs: Args): Value;
|
|
99
|
-
getWithoutDefault(key: Key): Value | undefined;
|
|
100
99
|
/**
|
|
101
100
|
* Returns the default value to be used for a new key. (If a factory function was provided during
|
|
102
101
|
* instantiation, this will execute the factory function.)
|
package/classes/DefaultMap.lua
CHANGED
|
@@ -46,7 +46,7 @@ local ____exports = {}
|
|
|
46
46
|
--
|
|
47
47
|
-- ```ts
|
|
48
48
|
-- // Initializes a new empty DefaultMap with a default value of a new empty array.
|
|
49
|
-
-- const factoryFunction = () => []
|
|
49
|
+
-- const factoryFunction = () => [];
|
|
50
50
|
-- const defaultMapWithArray = new DefaultMap<string, string[]>(factoryFunction);
|
|
51
51
|
-- ```
|
|
52
52
|
--
|
|
@@ -111,9 +111,6 @@ function DefaultMap.prototype.getAndSetDefault(self, key, ...)
|
|
|
111
111
|
self:set(key, defaultValue)
|
|
112
112
|
return defaultValue
|
|
113
113
|
end
|
|
114
|
-
function DefaultMap.prototype.getWithoutDefault(self, key)
|
|
115
|
-
return Map.prototype.get(self, key)
|
|
116
|
-
end
|
|
117
114
|
function DefaultMap.prototype.getDefaultValue(self, ...)
|
|
118
115
|
if self.defaultValue ~= nil then
|
|
119
116
|
return self.defaultValue
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { CollectibleType, ItemPoolType } from "isaac-typescript-definitions";
|
|
2
|
+
/**
|
|
3
|
+
* Helper function to see if the given collectible is unlocked on the player's save file. This
|
|
4
|
+
* requires providing the corresponding item pool that the collectible is located in.
|
|
5
|
+
*
|
|
6
|
+
* - If any player currently has the item, then it is assumed to be unlocked. (This is because Eden
|
|
7
|
+
* may have randomly started with the provided collectible, and it will be subsequently removed
|
|
8
|
+
* from all pools.)
|
|
9
|
+
* - If the collectible is located in more than one item pool, then any item pool can be provided.
|
|
10
|
+
* - If the collectible is not located in any item pools, then this function will always return
|
|
11
|
+
* false.
|
|
12
|
+
* - If any player is Tainted Lost, they will be temporarily changed to Isaac and then temporarily
|
|
13
|
+
* changed back (because Tainted Lost is not able to retrieve some collectibles from item pools).
|
|
14
|
+
*/
|
|
15
|
+
export declare function isCollectibleUnlocked(collectibleTypeToCheckFor: CollectibleType, itemPoolToCheckFor: ItemPoolType): boolean;
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
local ____lualib = require("lualib_bundle")
|
|
2
|
+
local Map = ____lualib.Map
|
|
3
|
+
local __TS__New = ____lualib.__TS__New
|
|
4
|
+
local Set = ____lualib.Set
|
|
5
|
+
local __TS__Iterator = ____lualib.__TS__Iterator
|
|
6
|
+
local ____exports = {}
|
|
7
|
+
local ____isaac_2Dtypescript_2Ddefinitions = require("isaac-typescript-definitions")
|
|
8
|
+
local CollectibleType = ____isaac_2Dtypescript_2Ddefinitions.CollectibleType
|
|
9
|
+
local PlayerType = ____isaac_2Dtypescript_2Ddefinitions.PlayerType
|
|
10
|
+
local TrinketType = ____isaac_2Dtypescript_2Ddefinitions.TrinketType
|
|
11
|
+
local ____cachedClasses = require("cachedClasses")
|
|
12
|
+
local game = ____cachedClasses.game
|
|
13
|
+
local ____collectibleSet = require("functions.collectibleSet")
|
|
14
|
+
local getCollectibleSet = ____collectibleSet.getCollectibleSet
|
|
15
|
+
local ____player = require("functions.player")
|
|
16
|
+
local anyPlayerHasCollectible = ____player.anyPlayerHasCollectible
|
|
17
|
+
local getPlayersOfType = ____player.getPlayersOfType
|
|
18
|
+
local ____playerDataStructures = require("functions.playerDataStructures")
|
|
19
|
+
local mapGetPlayer = ____playerDataStructures.mapGetPlayer
|
|
20
|
+
local mapSetPlayer = ____playerDataStructures.mapSetPlayer
|
|
21
|
+
local ____playerIndex = require("functions.playerIndex")
|
|
22
|
+
local getPlayers = ____playerIndex.getPlayers
|
|
23
|
+
local ____utils = require("functions.utils")
|
|
24
|
+
local ____repeat = ____utils["repeat"]
|
|
25
|
+
local COLLECTIBLES_THAT_AFFECT_ITEM_POOLS = {CollectibleType.CHAOS, CollectibleType.SACRED_ORB, CollectibleType.TMTRAINER}
|
|
26
|
+
local TRINKETS_THAT_AFFECT_ITEM_POOLS = {TrinketType.NO}
|
|
27
|
+
--- Helper function to see if the given collectible is unlocked on the player's save file. This
|
|
28
|
+
-- requires providing the corresponding item pool that the collectible is located in.
|
|
29
|
+
--
|
|
30
|
+
-- - If any player currently has the item, then it is assumed to be unlocked. (This is because Eden
|
|
31
|
+
-- may have randomly started with the provided collectible, and it will be subsequently removed
|
|
32
|
+
-- from all pools.)
|
|
33
|
+
-- - If the collectible is located in more than one item pool, then any item pool can be provided.
|
|
34
|
+
-- - If the collectible is not located in any item pools, then this function will always return
|
|
35
|
+
-- false.
|
|
36
|
+
-- - If any player is Tainted Lost, they will be temporarily changed to Isaac and then temporarily
|
|
37
|
+
-- changed back (because Tainted Lost is not able to retrieve some collectibles from item pools).
|
|
38
|
+
function ____exports.isCollectibleUnlocked(self, collectibleTypeToCheckFor, itemPoolToCheckFor)
|
|
39
|
+
if anyPlayerHasCollectible(nil, collectibleTypeToCheckFor) then
|
|
40
|
+
return true
|
|
41
|
+
end
|
|
42
|
+
local taintedLosts = getPlayersOfType(nil, PlayerType.THE_LOST_B)
|
|
43
|
+
for ____, player in ipairs(taintedLosts) do
|
|
44
|
+
player:ChangePlayerType(PlayerType.ISAAC)
|
|
45
|
+
end
|
|
46
|
+
local removedItemsMap = __TS__New(Map)
|
|
47
|
+
local removedTrinketsMap = __TS__New(Map)
|
|
48
|
+
for ____, player in ipairs(getPlayers(nil)) do
|
|
49
|
+
local removedItems = {}
|
|
50
|
+
for ____, itemToRemove in ipairs(COLLECTIBLES_THAT_AFFECT_ITEM_POOLS) do
|
|
51
|
+
if player:HasCollectible(itemToRemove) then
|
|
52
|
+
local numCollectibles = player:GetCollectibleNum(itemToRemove)
|
|
53
|
+
____repeat(
|
|
54
|
+
nil,
|
|
55
|
+
numCollectibles,
|
|
56
|
+
function()
|
|
57
|
+
player:RemoveCollectible(itemToRemove)
|
|
58
|
+
removedItems[#removedItems + 1] = itemToRemove
|
|
59
|
+
end
|
|
60
|
+
)
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
mapSetPlayer(nil, removedItemsMap, player, removedItems)
|
|
64
|
+
local removedTrinkets = {}
|
|
65
|
+
for ____, trinketToRemove in ipairs(TRINKETS_THAT_AFFECT_ITEM_POOLS) do
|
|
66
|
+
if player:HasTrinket(trinketToRemove) then
|
|
67
|
+
local numTrinkets = player:GetTrinketMultiplier(trinketToRemove)
|
|
68
|
+
____repeat(
|
|
69
|
+
nil,
|
|
70
|
+
numTrinkets,
|
|
71
|
+
function()
|
|
72
|
+
player:TryRemoveTrinket(trinketToRemove)
|
|
73
|
+
removedTrinkets[#removedTrinkets + 1] = trinketToRemove
|
|
74
|
+
end
|
|
75
|
+
)
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
mapSetPlayer(nil, removedTrinketsMap, player, removedTrinkets)
|
|
79
|
+
end
|
|
80
|
+
local itemPool = game:GetItemPool()
|
|
81
|
+
local collectibleSet = getCollectibleSet(nil)
|
|
82
|
+
for ____, collectibleType in __TS__Iterator(collectibleSet:values()) do
|
|
83
|
+
if collectibleType ~= collectibleTypeToCheckFor then
|
|
84
|
+
itemPool:AddRoomBlacklist(collectibleType)
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
local retrievedCollectibleType = itemPool:GetCollectible(itemPoolToCheckFor, false, 1)
|
|
88
|
+
local collectibleUnlocked = retrievedCollectibleType == collectibleTypeToCheckFor
|
|
89
|
+
itemPool:ResetRoomBlacklist()
|
|
90
|
+
for ____, player in ipairs(getPlayers(nil)) do
|
|
91
|
+
local removedItems = mapGetPlayer(nil, removedItemsMap, player)
|
|
92
|
+
if removedItems ~= nil then
|
|
93
|
+
for ____, collectibleType in ipairs(removedItems) do
|
|
94
|
+
player:AddCollectible(collectibleType, 0, false)
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
local removedTrinkets = mapGetPlayer(nil, removedTrinketsMap, player)
|
|
98
|
+
if removedTrinkets ~= nil then
|
|
99
|
+
for ____, trinketType in ipairs(removedTrinkets) do
|
|
100
|
+
player:AddTrinket(trinketType, false)
|
|
101
|
+
end
|
|
102
|
+
end
|
|
103
|
+
end
|
|
104
|
+
return collectibleUnlocked
|
|
105
|
+
end
|
|
106
|
+
return ____exports
|
package/index.d.ts
CHANGED
|
@@ -89,6 +89,7 @@ export * from "./functions/roomGrid";
|
|
|
89
89
|
export * from "./functions/rooms";
|
|
90
90
|
export * from "./functions/roomShape";
|
|
91
91
|
export * from "./functions/run";
|
|
92
|
+
export * from "./functions/saveFile";
|
|
92
93
|
export * from "./functions/seeds";
|
|
93
94
|
export * from "./functions/serialization";
|
|
94
95
|
export * from "./functions/set";
|
package/index.lua
CHANGED
|
@@ -705,6 +705,14 @@ do
|
|
|
705
705
|
end
|
|
706
706
|
end
|
|
707
707
|
end
|
|
708
|
+
do
|
|
709
|
+
local ____export = require("functions.saveFile")
|
|
710
|
+
for ____exportKey, ____exportValue in pairs(____export) do
|
|
711
|
+
if ____exportKey ~= "default" then
|
|
712
|
+
____exports[____exportKey] = ____exportValue
|
|
713
|
+
end
|
|
714
|
+
end
|
|
715
|
+
end
|
|
708
716
|
do
|
|
709
717
|
local ____export = require("functions.seeds")
|
|
710
718
|
for ____exportKey, ____exportValue in pairs(____export) do
|