isaacscript-common 4.0.1-dev.0 → 4.0.2

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.
@@ -30,10 +30,11 @@ function hasSubscriptions(self)
30
30
  end
31
31
  function entityTakeDmgPlayer(self, tookDamage, _damageAmount, damageFlags, _damageSource, _damageCountdownFrames)
32
32
  if not hasSubscriptions(nil) then
33
- return
33
+ return nil
34
34
  end
35
35
  incrementNumSacrifices(nil, damageFlags)
36
36
  setDamageFrame(nil, tookDamage, damageFlags)
37
+ return nil
37
38
  end
38
39
  function setDamageFrame(self, tookDamage, damageFlags)
39
40
  local gameFrameCount = game:GetFrameCount()
@@ -60,13 +60,15 @@ function entityTakeDmgPlayer(
60
60
  damageFlags: BitFlags<DamageFlag>,
61
61
  _damageSource: EntityRef,
62
62
  _damageCountdownFrames: int,
63
- ) {
63
+ ): boolean | undefined {
64
64
  if (!hasSubscriptions()) {
65
- return;
65
+ return undefined;
66
66
  }
67
67
 
68
68
  incrementNumSacrifices(damageFlags); // Has to be before setting the damage frame
69
69
  setDamageFrame(tookDamage, damageFlags);
70
+
71
+ return undefined;
70
72
  }
71
73
 
72
74
  function setDamageFrame(tookDamage: Entity, damageFlags: BitFlags<DamageFlag>) {
@@ -52,11 +52,12 @@ function getPlayerWithControllerIndex(self, controllerIndex)
52
52
  end
53
53
  function useItemEsauJr(self, _collectibleType, _rng, player, _useFlags, _activeSlot, _customVarData)
54
54
  if not hasSubscriptions(nil) then
55
- return
55
+ return nil
56
56
  end
57
57
  local gameFrameCount = game:GetFrameCount()
58
58
  v.run.usedEsauJrFrame = gameFrameCount + 1
59
59
  v.run.usedEsauJrControllerIndex = player.ControllerIndex
60
+ return nil
60
61
  end
61
62
  v = {run = {usedEsauJrFrame = nil, usedEsauJrControllerIndex = nil, usedEsauJrAtLeastOnce = false}}
62
63
  ---
@@ -85,7 +85,7 @@ function getPlayerWithControllerIndex(controllerIndex: ControllerIndex) {
85
85
  return players.find((player) => player.ControllerIndex === controllerIndex);
86
86
  }
87
87
 
88
- // ModCallback.USE_ITEM (3)
88
+ // ModCallback.POST_USE_ITEM (3)
89
89
  // CollectibleType.ESAU_JR (703)
90
90
  function useItemEsauJr(
91
91
  _collectibleType: CollectibleType,
@@ -94,9 +94,9 @@ function useItemEsauJr(
94
94
  _useFlags: BitFlags<UseFlag>,
95
95
  _activeSlot: int,
96
96
  _customVarData: int,
97
- ) {
97
+ ): boolean | undefined {
98
98
  if (!hasSubscriptions()) {
99
- return;
99
+ return undefined;
100
100
  }
101
101
 
102
102
  const gameFrameCount = game.GetFrameCount();
@@ -104,4 +104,6 @@ function useItemEsauJr(
104
104
  // The player only changes to Esau Jr. on the frame after the item is used.
105
105
  v.run.usedEsauJrFrame = gameFrameCount + 1;
106
106
  v.run.usedEsauJrControllerIndex = player.ControllerIndex;
107
+
108
+ return undefined;
107
109
  }
@@ -22,20 +22,21 @@ function hasSubscriptions(self)
22
22
  end
23
23
  function useItemFlip(self, _collectibleType, _rng, player, _useFlags, _activeSlot, _customVarData)
24
24
  if not hasSubscriptions(nil) then
25
- return
25
+ return nil
26
26
  end
27
27
  if not isTaintedLazarus(nil, player) then
28
- return
28
+ return nil
29
29
  end
30
30
  local newLazarus = getNewLazarus(nil, player)
31
31
  if newLazarus == nil then
32
- return
32
+ return nil
33
33
  end
34
34
  if not v.run.usedFlipAtLeastOnce then
35
35
  v.run.usedFlipAtLeastOnce = true
36
36
  postFirstFlipFire(nil, newLazarus)
37
37
  end
38
38
  postFlipFire(nil, newLazarus)
39
+ return nil
39
40
  end
40
41
  function getNewLazarus(self, oldLazarus)
41
42
  local oldCharacter = oldLazarus:GetPlayerType()
@@ -36,7 +36,7 @@ function hasSubscriptions() {
36
36
  return postFlipHasSubscriptions() || postFirstFlipHasSubscriptions();
37
37
  }
38
38
 
39
- // ModCallback.USE_ITEM (3)
39
+ // ModCallback.POST_USE_ITEM (3)
40
40
  // CollectibleType.FLIP (711)
41
41
  function useItemFlip(
42
42
  _collectibleType: CollectibleType,
@@ -45,20 +45,20 @@ function useItemFlip(
45
45
  _useFlags: BitFlags<UseFlag>,
46
46
  _activeSlot: int,
47
47
  _customVarData: int,
48
- ) {
48
+ ): boolean | undefined {
49
49
  if (!hasSubscriptions()) {
50
- return;
50
+ return undefined;
51
51
  }
52
52
 
53
53
  if (!isTaintedLazarus(player)) {
54
- return;
54
+ return undefined;
55
55
  }
56
56
 
57
57
  // The player passed as part of the callback will be the old Lazarus that used the Flip item. We
58
58
  // pass the new Lazarus to the callback subscribers.
59
59
  const newLazarus = getNewLazarus(player);
60
60
  if (newLazarus === undefined) {
61
- return;
61
+ return undefined;
62
62
  }
63
63
 
64
64
  if (!v.run.usedFlipAtLeastOnce) {
@@ -67,6 +67,8 @@ function useItemFlip(
67
67
  }
68
68
 
69
69
  postFlipFire(newLazarus);
70
+
71
+ return undefined;
70
72
  }
71
73
 
72
74
  function getNewLazarus(oldLazarus: EntityPlayer) {
@@ -65,17 +65,18 @@ function playerRecentlyCollidedWithBulb(self, player)
65
65
  end
66
66
  function preNPCCollisionSucker(self, npc, collider)
67
67
  if not hasSubscriptions(nil) then
68
- return
68
+ return nil
69
69
  end
70
70
  if npc.Variant ~= SuckerVariant.BULB then
71
- return
71
+ return nil
72
72
  end
73
73
  local player = collider:ToPlayer()
74
74
  if player == nil then
75
- return
75
+ return nil
76
76
  end
77
77
  local gameFrameCount = game:GetFrameCount()
78
78
  mapSetPlayer(nil, v.room.playersBulbLastCollisionFrame, player, gameFrameCount)
79
+ return nil
79
80
  end
80
81
  v = {
81
82
  run = {
@@ -130,20 +130,25 @@ function playerRecentlyCollidedWithBulb(player: EntityPlayer) {
130
130
  * Instead, we track the frames that Bulbs collide with players and assume that a collision means a
131
131
  * zap has occurred.
132
132
  */
133
- function preNPCCollisionSucker(npc: EntityNPC, collider: Entity) {
133
+ function preNPCCollisionSucker(
134
+ npc: EntityNPC,
135
+ collider: Entity,
136
+ ): boolean | undefined {
134
137
  if (!hasSubscriptions()) {
135
- return;
138
+ return undefined;
136
139
  }
137
140
 
138
141
  if (npc.Variant !== (SuckerVariant.BULB as int)) {
139
- return;
142
+ return undefined;
140
143
  }
141
144
 
142
145
  const player = collider.ToPlayer();
143
146
  if (player === undefined) {
144
- return;
147
+ return undefined;
145
148
  }
146
149
 
147
150
  const gameFrameCount = game.GetFrameCount();
148
151
  mapSetPlayer(v.room.playersBulbLastCollisionFrame, player, gameFrameCount);
152
+
153
+ return undefined;
149
154
  }
@@ -24,9 +24,10 @@ function postNewRoom(self)
24
24
  end
25
25
  function preEntitySpawn(self)
26
26
  if not hasSubscriptions(nil) then
27
- return
27
+ return nil
28
28
  end
29
29
  checkRoomChanged(nil)
30
+ return nil
30
31
  end
31
32
  function checkRoomChanged(self)
32
33
  local room = game:GetRoom()
@@ -1,4 +1,8 @@
1
- import { GridEntityType, ModCallback } from "isaac-typescript-definitions";
1
+ import {
2
+ EntityType,
3
+ GridEntityType,
4
+ ModCallback,
5
+ } from "isaac-typescript-definitions";
2
6
  import { game } from "../cachedClasses";
3
7
  import { getTopLeftWallGridIndex, spawnGrid } from "../functions/gridEntity";
4
8
  import { logError } from "../functions/log";
@@ -35,12 +39,14 @@ function postNewRoom() {
35
39
  }
36
40
 
37
41
  // ModCallback.PRE_ENTITY_SPAWN (24)
38
- function preEntitySpawn() {
42
+ function preEntitySpawn(): [EntityType, int, int, int] | undefined {
39
43
  if (!hasSubscriptions()) {
40
- return;
44
+ return undefined;
41
45
  }
42
46
 
43
47
  checkRoomChanged();
48
+
49
+ return undefined;
44
50
  }
45
51
 
46
52
  function checkRoomChanged() {
@@ -19,11 +19,11 @@ function hasSubscriptions(self)
19
19
  end
20
20
  function entityTakeDmgPlayer(self, tookDamage, _damageAmount, damageFlags, _damageSource, _damageCountdownFrames)
21
21
  if not hasSubscriptions(nil) then
22
- return
22
+ return nil
23
23
  end
24
24
  local player = tookDamage:ToPlayer()
25
25
  if player == nil then
26
- return
26
+ return nil
27
27
  end
28
28
  local room = game:GetRoom()
29
29
  local roomType = room:GetType()
@@ -33,6 +33,7 @@ function entityTakeDmgPlayer(self, tookDamage, _damageAmount, damageFlags, _dama
33
33
  ____v_level_0[____numSacrifices_1] = ____v_level_0[____numSacrifices_1] + 1
34
34
  postSacrificeFire(nil, player, v.level.numSacrifices)
35
35
  end
36
+ return nil
36
37
  end
37
38
  v = {level = {numSacrifices = 0}}
38
39
  ---
@@ -41,14 +41,14 @@ function entityTakeDmgPlayer(
41
41
  damageFlags: BitFlags<DamageFlag>,
42
42
  _damageSource: EntityRef,
43
43
  _damageCountdownFrames: int,
44
- ) {
44
+ ): boolean | undefined {
45
45
  if (!hasSubscriptions()) {
46
- return;
46
+ return undefined;
47
47
  }
48
48
 
49
49
  const player = tookDamage.ToPlayer();
50
50
  if (player === undefined) {
51
- return;
51
+ return undefined;
52
52
  }
53
53
 
54
54
  const room = game.GetRoom();
@@ -59,4 +59,6 @@ function entityTakeDmgPlayer(
59
59
  v.level.numSacrifices += 1;
60
60
  postSacrificeFire(player, v.level.numSacrifices);
61
61
  }
62
+
63
+ return undefined;
62
64
  }
@@ -23,11 +23,11 @@ function hasSubscriptions(self)
23
23
  end
24
24
  function entityTakeDmgPlayer(self, tookDamage, _damageAmount, _damageFlags, _damageSource, _damageCountdownFrames)
25
25
  if not hasSubscriptions(nil) then
26
- return
26
+ return nil
27
27
  end
28
28
  local player = tookDamage:ToPlayer()
29
29
  if player == nil then
30
- return
30
+ return nil
31
31
  end
32
32
  local trinketMap = defaultMapGetPlayer(nil, v.run.playersTrinketMap, player)
33
33
  for ____, trinketType in ipairs(TRINKETS_THAT_CAN_BREAK) do
@@ -46,6 +46,7 @@ function entityTakeDmgPlayer(self, tookDamage, _damageAmount, _damageFlags, _dam
46
46
  end
47
47
  ::__continue8::
48
48
  end
49
+ return nil
49
50
  end
50
51
  function postPEffectUpdateReordered(self, player)
51
52
  if not hasSubscriptions(nil) then
@@ -58,14 +58,14 @@ function entityTakeDmgPlayer(
58
58
  _damageFlags: BitFlags<DamageFlag>,
59
59
  _damageSource: EntityRef,
60
60
  _damageCountdownFrames: int,
61
- ) {
61
+ ): boolean | undefined {
62
62
  if (!hasSubscriptions()) {
63
- return;
63
+ return undefined;
64
64
  }
65
65
 
66
66
  const player = tookDamage.ToPlayer();
67
67
  if (player === undefined) {
68
- return;
68
+ return undefined;
69
69
  }
70
70
 
71
71
  const trinketMap = defaultMapGetPlayer(v.run.playersTrinketMap, player);
@@ -92,6 +92,8 @@ function entityTakeDmgPlayer(
92
92
 
93
93
  postTrinketBreakFire(player, trinketType);
94
94
  }
95
+
96
+ return undefined;
95
97
  }
96
98
 
97
99
  // ModCallbackCustom.POST_PEFFECT_UPDATE_REORDERED
@@ -19,6 +19,7 @@ function hasSubscriptions(self)
19
19
  end
20
20
  function useItemGlowingHourGlass(self)
21
21
  usedGlowingHourGlass = true
22
+ return nil
22
23
  end
23
24
  function postGameStartedVanilla(self, isContinued)
24
25
  if not hasSubscriptions(nil) then
@@ -56,10 +56,12 @@ function hasSubscriptions() {
56
56
 
57
57
  // ModCallback.POST_USE_ITEM (3)
58
58
  // CollectibleType.GLOWING_HOUR_GLASS (422)
59
- function useItemGlowingHourGlass() {
59
+ function useItemGlowingHourGlass(): boolean | undefined {
60
60
  // If Glowing Hour Glass is used on the first room of a floor, it will send the player to the
61
61
  // previous floor without triggering the PostNewLevel callback. Manually check for this.
62
62
  usedGlowingHourGlass = true;
63
+
64
+ return undefined;
63
65
  }
64
66
 
65
67
  // ModCallback.POST_GAME_STARTED (15)
@@ -16,7 +16,11 @@ export declare class ModUpgraded implements Mod {
16
16
  AddCallback<T extends ModCallback>(modCallback: T, ...args: AddCallbackParameter[T]): void;
17
17
  HasData(): boolean;
18
18
  LoadData(): string;
19
- RemoveCallback(callbackID: ModCallback, callback: () => void): void;
19
+ /**
20
+ * This method does not care about the tertiary argument. Regardless of the conditions of how you
21
+ * registered the callback, it will be removed.
22
+ */
23
+ RemoveCallback<T extends ModCallback>(modCallback: T, callback: AddCallbackParameter[T][0]): void;
20
24
  RemoveData(): void;
21
25
  SaveData(data: string): void;
22
26
  AddCallbackCustom<T extends ModCallbackCustom>(modCallbackCustom: T, ...args: AddCallbackParameterCustom[T]): void;
@@ -24,8 +24,8 @@ end
24
24
  function ModUpgraded.prototype.LoadData(self)
25
25
  return self.Mod:LoadData()
26
26
  end
27
- function ModUpgraded.prototype.RemoveCallback(self, callbackID, callback)
28
- self.Mod:RemoveCallback(callbackID, callback)
27
+ function ModUpgraded.prototype.RemoveCallback(self, modCallback, callback)
28
+ self.Mod:RemoveCallback(modCallback, callback)
29
29
  end
30
30
  function ModUpgraded.prototype.RemoveData(self)
31
31
  self.Mod:RemoveData()
@@ -49,8 +49,15 @@ export class ModUpgraded implements Mod {
49
49
  return this.Mod.LoadData();
50
50
  }
51
51
 
52
- RemoveCallback(callbackID: ModCallback, callback: () => void): void {
53
- this.Mod.RemoveCallback(callbackID, callback);
52
+ /**
53
+ * This method does not care about the tertiary argument. Regardless of the conditions of how you
54
+ * registered the callback, it will be removed.
55
+ */
56
+ RemoveCallback<T extends ModCallback>(
57
+ modCallback: T,
58
+ callback: AddCallbackParameter[T][0],
59
+ ): void {
60
+ this.Mod.RemoveCallback(modCallback, callback);
54
61
  }
55
62
 
56
63
  RemoveData(): void {
@@ -51,6 +51,7 @@ function resetInventory(self, player)
51
51
  end
52
52
  function useItemD4(self, _collectibleType, _rng, player)
53
53
  resetInventory(nil, player)
54
+ return nil
54
55
  end
55
56
  function postGameStarted(self)
56
57
  for ____, player in ipairs(getAllPlayers(nil)) do
@@ -68,8 +68,10 @@ function useItemD4(
68
68
  _collectibleType: CollectibleType,
69
69
  _rng: RNG,
70
70
  player: EntityPlayer,
71
- ) {
71
+ ): boolean | undefined {
72
72
  resetInventory(player);
73
+
74
+ return undefined;
73
75
  }
74
76
 
75
77
  // ModCallback.POST_GAME_STARTED (15)
@@ -203,11 +203,6 @@ function ____exports.addStat(self, player, cacheFlag, amount)
203
203
  break
204
204
  end
205
205
  end
206
- do
207
- do
208
- break
209
- end
210
- end
211
206
  until true
212
207
  end
213
208
  function ____exports.addTrinketCostume(self, player, trinketType)
@@ -749,9 +744,9 @@ function ____exports.setActiveItem(self, player, collectibleType, activeSlot, ch
749
744
  itemPool:RemoveCollectible(collectibleType)
750
745
  end
751
746
  repeat
752
- local ____switch124 = activeSlot
753
- local ____cond124 = ____switch124 == ActiveSlot.PRIMARY
754
- if ____cond124 then
747
+ local ____switch123 = activeSlot
748
+ local ____cond123 = ____switch123 == ActiveSlot.PRIMARY
749
+ if ____cond123 then
755
750
  do
756
751
  if primaryCollectibleType ~= CollectibleType.NULL then
757
752
  player:RemoveCollectible(primaryCollectibleType)
@@ -760,8 +755,8 @@ function ____exports.setActiveItem(self, player, collectibleType, activeSlot, ch
760
755
  break
761
756
  end
762
757
  end
763
- ____cond124 = ____cond124 or ____switch124 == ActiveSlot.SECONDARY
764
- if ____cond124 then
758
+ ____cond123 = ____cond123 or ____switch123 == ActiveSlot.SECONDARY
759
+ if ____cond123 then
765
760
  do
766
761
  if primaryCollectibleType ~= CollectibleType.NULL then
767
762
  player:RemoveCollectible(primaryCollectibleType)
@@ -776,16 +771,16 @@ function ____exports.setActiveItem(self, player, collectibleType, activeSlot, ch
776
771
  break
777
772
  end
778
773
  end
779
- ____cond124 = ____cond124 or ____switch124 == ActiveSlot.POCKET
780
- if ____cond124 then
774
+ ____cond123 = ____cond123 or ____switch123 == ActiveSlot.POCKET
775
+ if ____cond123 then
781
776
  do
782
777
  player:SetPocketActiveItem(collectibleType, activeSlot, keepInPools)
783
778
  player:SetActiveCharge(charge, activeSlot)
784
779
  break
785
780
  end
786
781
  end
787
- ____cond124 = ____cond124 or ____switch124 == ActiveSlot.POCKET_SINGLE_USE
788
- if ____cond124 then
782
+ ____cond123 = ____cond123 or ____switch123 == ActiveSlot.POCKET_SINGLE_USE
783
+ if ____cond123 then
789
784
  do
790
785
  player:SetPocketActiveItem(collectibleType, activeSlot, keepInPools)
791
786
  break
@@ -108,10 +108,6 @@ export function addStat(
108
108
  player.Luck += amount;
109
109
  break;
110
110
  }
111
-
112
- default: {
113
- break;
114
- }
115
111
  }
116
112
  }
117
113
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "isaacscript-common",
3
- "version": "4.0.1-dev.0",
3
+ "version": "4.0.2",
4
4
  "description": "Helper functions and features for IsaacScript mods.",
5
5
  "keywords": [
6
6
  "isaac",
@@ -22,6 +22,6 @@
22
22
  "main": "index",
23
23
  "types": "index.d.ts",
24
24
  "dependencies": {
25
- "isaac-typescript-definitions": "^3.0.3"
25
+ "isaac-typescript-definitions": "^3.0.5"
26
26
  }
27
27
  }