isaacscript-common 1.2.280 → 1.2.283

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.
@@ -0,0 +1,10 @@
1
+ /// <reference types="isaac-typescript-definitions" />
2
+ declare type ConversionHeartSubType = HeartSubType.HEART_SOUL | HeartSubType.HEART_BLACK;
3
+ /**
4
+ * Helper function to make a character that has the same health mechanic as Blue Baby (red heart
5
+ * containers --> soul hearts) or Dark Judas (red heart containers --> black hearts).
6
+ *
7
+ * Call this function once at the beginning of your mod to declare the health conversion type.
8
+ */
9
+ export declare function registerCharacterHealthConversion(playerType: PlayerType | int, conversionHeartSubType: ConversionHeartSubType): void;
10
+ export {};
@@ -0,0 +1,81 @@
1
+ local ____lualib = require("lualib_bundle")
2
+ local Map = ____lualib.Map
3
+ local __TS__New = ____lualib.__TS__New
4
+ local ____exports = {}
5
+ local postPEffectUpdate, convertRedHeartContainers, removeRedHearts, prePickupCollisionHeart, characterHealthReplacementMap
6
+ local ____featuresInitialized = require("featuresInitialized")
7
+ local errorIfFeaturesNotInitialized = ____featuresInitialized.errorIfFeaturesNotInitialized
8
+ local ____pickups = require("functions.pickups")
9
+ local isRedHeart = ____pickups.isRedHeart
10
+ local ____utils = require("functions.utils")
11
+ local ensureAllCases = ____utils.ensureAllCases
12
+ function postPEffectUpdate(self, player)
13
+ local character = player:GetPlayerType()
14
+ local conversionHeartSubType = characterHealthReplacementMap:get(character)
15
+ if conversionHeartSubType == nil then
16
+ return
17
+ end
18
+ convertRedHeartContainers(nil, player, conversionHeartSubType)
19
+ removeRedHearts(nil, player)
20
+ end
21
+ function convertRedHeartContainers(self, player, heartSubType)
22
+ local maxHearts = player:GetMaxHearts()
23
+ if maxHearts == 0 then
24
+ return
25
+ end
26
+ player:AddMaxHearts(maxHearts * -1, false)
27
+ repeat
28
+ local ____switch7 = heartSubType
29
+ local ____cond7 = ____switch7 == HeartSubType.HEART_SOUL
30
+ if ____cond7 then
31
+ do
32
+ player:AddSoulHearts(maxHearts)
33
+ return
34
+ end
35
+ end
36
+ ____cond7 = ____cond7 or ____switch7 == HeartSubType.HEART_BLACK
37
+ if ____cond7 then
38
+ do
39
+ player:AddBlackHearts(maxHearts)
40
+ return
41
+ end
42
+ end
43
+ do
44
+ do
45
+ ensureAllCases(nil, heartSubType)
46
+ end
47
+ end
48
+ until true
49
+ end
50
+ function removeRedHearts(self, player)
51
+ local hearts = player:GetHearts()
52
+ if hearts > 0 then
53
+ player:AddHearts(hearts * -1)
54
+ end
55
+ end
56
+ function prePickupCollisionHeart(self, pickup, collider)
57
+ if not isRedHeart(nil, pickup) then
58
+ return nil
59
+ end
60
+ local player = collider:ToPlayer()
61
+ if player == nil then
62
+ return nil
63
+ end
64
+ local character = player:GetPlayerType()
65
+ local conversionHeartSubType = characterHealthReplacementMap:get(character)
66
+ if conversionHeartSubType == nil then
67
+ return nil
68
+ end
69
+ return false
70
+ end
71
+ local FEATURE_NAME = "character health manager"
72
+ characterHealthReplacementMap = __TS__New(Map)
73
+ function ____exports.characterHealthConversionInit(self, mod)
74
+ mod:AddCallback(ModCallbacks.MC_POST_PEFFECT_UPDATE, postPEffectUpdate)
75
+ mod:AddCallback(ModCallbacks.MC_PRE_PICKUP_COLLISION, prePickupCollisionHeart, 10)
76
+ end
77
+ function ____exports.registerCharacterHealthConversion(self, playerType, conversionHeartSubType)
78
+ errorIfFeaturesNotInitialized(nil, FEATURE_NAME)
79
+ characterHealthReplacementMap:set(playerType, conversionHeartSubType)
80
+ end
81
+ return ____exports
@@ -44,6 +44,8 @@ export declare function getRooms(includeExtraDimensionalRooms?: boolean): RoomDe
44
44
  * Helper function to get the room descriptor for every room on the level in a specific dimension.
45
45
  * Uses the `Level.GetRooms` method to accomplish this. Rooms without data are assumed to be
46
46
  * non-existent and are not added to the list.
47
+ *
48
+ * @returns A map of room ListIndex to RoomDescriptor.
47
49
  */
48
50
  export declare function getRoomsOfDimension(dimension: Dimension): RoomDescriptor[];
49
51
  /**
@@ -3,9 +3,10 @@ local __TS__ArrayMap = ____lualib.__TS__ArrayMap
3
3
  local Set = ____lualib.Set
4
4
  local __TS__New = ____lualib.__TS__New
5
5
  local __TS__ArrayFilter = ____lualib.__TS__ArrayFilter
6
+ local Map = ____lualib.Map
7
+ local __TS__Spread = ____lualib.__TS__Spread
6
8
  local __TS__StringIncludes = ____lualib.__TS__StringIncludes
7
9
  local __TS__ArrayEvery = ____lualib.__TS__ArrayEvery
8
- local Map = ____lualib.Map
9
10
  local ____exports = {}
10
11
  local ____cachedClasses = require("cachedClasses")
11
12
  local game = ____cachedClasses.game
@@ -47,14 +48,14 @@ function ____exports.getRooms(self, includeExtraDimensionalRooms)
47
48
  end
48
49
  local level = game:GetLevel()
49
50
  local roomList = level:GetRooms()
50
- local rooms = {}
51
+ local roomsMap = __TS__New(Map)
51
52
  if includeExtraDimensionalRooms then
52
53
  do
53
54
  local i = 0
54
55
  while i < roomList.Size do
55
56
  local roomDescriptor = roomList:Get(i)
56
57
  if roomDescriptor ~= nil and roomDescriptor.Data ~= nil then
57
- rooms[#rooms + 1] = roomDescriptor
58
+ roomsMap:set(roomDescriptor.ListIndex, roomDescriptor)
58
59
  end
59
60
  i = i + 1
60
61
  end
@@ -65,13 +66,13 @@ function ____exports.getRooms(self, includeExtraDimensionalRooms)
65
66
  while i <= MAX_ROOM_INDEX do
66
67
  local roomDescriptor = level:GetRoomByIdx(i)
67
68
  if roomDescriptor.Data ~= nil then
68
- rooms[#rooms + 1] = roomDescriptor
69
+ roomsMap:set(roomDescriptor.ListIndex, roomDescriptor)
69
70
  end
70
71
  i = i + 1
71
72
  end
72
73
  end
73
74
  end
74
- return rooms
75
+ return {__TS__Spread(roomsMap:values())}
75
76
  end
76
77
  function ____exports.inDeathCertificateArea(self)
77
78
  local roomStageID = getRoomStageID(nil)
@@ -136,18 +137,18 @@ function ____exports.getRoomItemPoolType(self)
136
137
  end
137
138
  function ____exports.getRoomsOfDimension(self, dimension)
138
139
  local level = game:GetLevel()
139
- local rooms = {}
140
+ local roomsMap = __TS__New(Map)
140
141
  do
141
142
  local i = 0
142
143
  while i <= MAX_ROOM_INDEX do
143
144
  local roomDescriptor = level:GetRoomByIdx(i, dimension)
144
145
  if roomDescriptor.Data ~= nil then
145
- rooms[#rooms + 1] = roomDescriptor
146
+ roomsMap:set(roomDescriptor.ListIndex, roomDescriptor)
146
147
  end
147
148
  i = i + 1
148
149
  end
149
150
  end
150
- return rooms
151
+ return {__TS__Spread(roomsMap:values())}
151
152
  end
152
153
  function ____exports.in2x1Room(self)
153
154
  local room = game:GetRoom()
package/dist/index.d.ts CHANGED
@@ -12,7 +12,8 @@ export * from "./enums/PillEffectClass";
12
12
  export * from "./enums/PillEffectType";
13
13
  export * from "./enums/PocketItemType";
14
14
  export * from "./enums/SerializationType";
15
- export * from "./features/characterStats";
15
+ export { registerCharacterHealthConversion } from "./features/characterHealthConversion";
16
+ export { registerCharacterStats } from "./features/characterStats";
16
17
  export { deployJSONRoom, deployRandomJSONRoom, emptyRoom, } from "./features/deployJSONRoom";
17
18
  export { disableAllInputs, disableAllInputsExceptFor, disableMovementInputs, disableShootingInputs, enableAllInputs, enableAllInputsExceptFor, } from "./features/disableInputs";
18
19
  export { disableAllSound, enableAllSound } from "./features/disableSound";
package/dist/index.lua CHANGED
@@ -111,12 +111,14 @@ do
111
111
  end
112
112
  end
113
113
  do
114
- local ____export = require("features.characterStats")
115
- for ____exportKey, ____exportValue in pairs(____export) do
116
- if ____exportKey ~= "default" then
117
- ____exports[____exportKey] = ____exportValue
118
- end
119
- end
114
+ local ____characterHealthConversion = require("features.characterHealthConversion")
115
+ local registerCharacterHealthConversion = ____characterHealthConversion.registerCharacterHealthConversion
116
+ ____exports.registerCharacterHealthConversion = registerCharacterHealthConversion
117
+ end
118
+ do
119
+ local ____characterStats = require("features.characterStats")
120
+ local registerCharacterStats = ____characterStats.registerCharacterStats
121
+ ____exports.registerCharacterStats = registerCharacterStats
120
122
  end
121
123
  do
122
124
  local ____deployJSONRoom = require("features.deployJSONRoom")
@@ -78,6 +78,8 @@ local ____roomClearChange = require("callbacks.roomClearChange")
78
78
  local roomClearChangeCallbackInit = ____roomClearChange.roomClearChangeCallbackInit
79
79
  local ____ModUpgraded = require("classes.ModUpgraded")
80
80
  local ModUpgraded = ____ModUpgraded.ModUpgraded
81
+ local ____characterHealthConversion = require("features.characterHealthConversion")
82
+ local characterHealthConversionInit = ____characterHealthConversion.characterHealthConversionInit
81
83
  local ____characterStats = require("features.characterStats")
82
84
  local characterStatsInit = ____characterStats.characterStatsInit
83
85
  local ____deployJSONRoom = require("features.deployJSONRoom")
@@ -166,6 +168,7 @@ function initFeatures(self, mod)
166
168
  fastResetInit(nil, mod)
167
169
  fadeInRemoverInit(nil, mod)
168
170
  characterStatsInit(nil, mod)
171
+ characterHealthConversionInit(nil, mod)
169
172
  end
170
173
  function ____exports.upgradeMod(self, modVanilla)
171
174
  patchErrorFunction(nil)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "isaacscript-common",
3
- "version": "1.2.280",
3
+ "version": "1.2.283",
4
4
  "description": "Helper functions for IsaacScript mods",
5
5
  "keywords": [
6
6
  "isaac",