isaacscript-common 1.0.513 → 1.0.517

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/debug.d.ts CHANGED
@@ -1 +1,2 @@
1
+ /** Set this to true to enable more verbosity in the save data manger. */
1
2
  export declare const DEBUG = false;
@@ -1,5 +1,15 @@
1
+ /**
2
+ * Helper function to get a stack trace.
3
+ *
4
+ * This will only work if the `--luadebug` launch option is enabled or the Racing+ sandbox is
5
+ * enabled.
6
+ */
7
+ export declare function getTraceback(): string;
1
8
  /**
2
9
  * Helper function to print a stack trace to the "log.txt" file, similar to JavaScript's
3
- * `console.trace()` function. This will only work if the `--luadebug` launch option is enabled.
10
+ * `console.trace()` function.
11
+ *
12
+ * This will only work if the `--luadebug` launch option is enabled or the Racing+ sandbox is
13
+ * enabled.
4
14
  */
5
15
  export declare function traceback(): void;
@@ -1,15 +1,16 @@
1
1
  --[[ Generated with https://github.com/TypeScriptToLua/TypeScriptToLua ]]
2
2
  local ____exports = {}
3
- function ____exports.traceback(self)
3
+ function ____exports.getTraceback(self)
4
4
  if debug ~= nil then
5
- local tracebackMsg = debug.traceback()
6
- Isaac.DebugString(tracebackMsg)
7
- return
5
+ return debug.traceback()
8
6
  end
9
- if sandboxTraceback ~= nil then
10
- sandboxTraceback()
11
- return
7
+ if sandboxGetTraceback ~= nil then
8
+ return sandboxGetTraceback()
12
9
  end
13
- Isaac.DebugString("Error: Cannot perform a traceback since --luadebug is not enabled.")
10
+ return "stack traceback:\n(the \"--luadebug\" flag is not enabled)"
11
+ end
12
+ function ____exports.traceback(self)
13
+ local tracebackOutput = ____exports.getTraceback(nil)
14
+ Isaac.DebugString(tracebackOutput)
14
15
  end
15
16
  return ____exports
@@ -1,14 +1,11 @@
1
1
  --[[ Generated with https://github.com/TypeScriptToLua/TypeScriptToLua ]]
2
2
  local ____exports = {}
3
3
  local RECOMMENDED_SHIFT_IDX
4
- local ____debug = require("functions.debug")
5
- local traceback = ____debug.traceback
6
4
  function ____exports.initRNG(self, seed)
7
5
  if seed == nil then
8
6
  seed = Random()
9
7
  end
10
8
  if seed == 0 then
11
- traceback(nil)
12
9
  error("You cannot initialize an RNG object with a seed of 0, or the game will crash.")
13
10
  end
14
11
  local rng = RNG()
@@ -5,6 +5,7 @@
5
5
  * do not forget to set the LeaveDoor property.
6
6
  */
7
7
  export declare function changeRoom(roomGridIndex: int): void;
8
+ export declare function getAllRoomGridIndexes(): int[];
8
9
  export declare function getCurrentDimension(): Dimension;
9
10
  export declare function getRoomData(): RoomConfig | undefined;
10
11
  /**
@@ -132,6 +133,14 @@ export declare function inMinibossRoomOf(minibossID: MinibossID): boolean;
132
133
  * starting room of the mirror world does not count).
133
134
  */
134
135
  export declare function inStartingRoom(): boolean;
136
+ /**
137
+ * Helper function to loop through every room on the floor and see if it has been cleared.
138
+ *
139
+ * @param onlyCheckRoomTypes Optional. A whitelist of room types. If specified, room types not in
140
+ * the array will be ignored. If not specified, then all rooms will be checked. Undefined by
141
+ * default.
142
+ */
143
+ export declare function isAllRoomsClear(onlyCheckRoomTypes?: RoomType[]): boolean;
135
144
  /**
136
145
  * Helper function to determine whether or not the current room is part of the floor layout. For
137
146
  * example, Devil Rooms and the Mega Satan room are not considered to be inside the map.
@@ -55,6 +55,23 @@ function ____exports.changeRoom(self, roomGridIndex)
55
55
  level.LeaveDoor = -1
56
56
  game:ChangeRoom(roomGridIndex)
57
57
  end
58
+ function ____exports.getAllRoomGridIndexes(self)
59
+ local game = Game()
60
+ local level = game:GetLevel()
61
+ local rooms = level:GetRooms()
62
+ local allRoomGridIndexes = {}
63
+ do
64
+ local i = 0
65
+ while i < rooms.Size do
66
+ local roomDesc = rooms:Get(i)
67
+ if roomDesc ~= nil then
68
+ __TS__ArrayPush(allRoomGridIndexes, roomDesc.SafeGridIndex)
69
+ end
70
+ i = i + 1
71
+ end
72
+ end
73
+ return allRoomGridIndexes
74
+ end
58
75
  function ____exports.getCurrentDimension(self)
59
76
  local game = Game()
60
77
  local level = game:GetLevel()
@@ -214,6 +231,37 @@ function ____exports.inStartingRoom(self)
214
231
  local roomSafeGridIndex = ____exports.getRoomSafeGridIndex(nil)
215
232
  return (roomSafeGridIndex == startingRoomGridIndex) and ____exports.inDimension(nil, 0)
216
233
  end
234
+ function ____exports.isAllRoomsClear(self, onlyCheckRoomTypes)
235
+ local game = Game()
236
+ local level = game:GetLevel()
237
+ local rooms = level:GetRooms()
238
+ local roomTypeWhitelist = (((onlyCheckRoomTypes == nil) and (function() return nil end)) or (function() return __TS__New(Set, onlyCheckRoomTypes) end))()
239
+ do
240
+ local i = 0
241
+ while i < rooms.Size do
242
+ do
243
+ local roomDesc = rooms:Get(i)
244
+ if roomDesc == nil then
245
+ goto __continue42
246
+ end
247
+ local roomData = roomDesc.Data
248
+ if roomData == nil then
249
+ goto __continue42
250
+ end
251
+ local roomType = roomData.Type
252
+ if (roomTypeWhitelist ~= nil) and (not roomTypeWhitelist:has(roomType)) then
253
+ goto __continue42
254
+ end
255
+ if not roomDesc.Clear then
256
+ return false
257
+ end
258
+ end
259
+ ::__continue42::
260
+ i = i + 1
261
+ end
262
+ end
263
+ return true
264
+ end
217
265
  function ____exports.isRoomInsideMap(self)
218
266
  local roomSafeGridIndex = ____exports.getRoomSafeGridIndex(nil)
219
267
  return roomSafeGridIndex >= 0
@@ -242,14 +290,14 @@ function ____exports.setRoomCleared(self)
242
290
  ) do
243
291
  do
244
292
  if isHiddenSecretRoomDoor(nil, door) then
245
- goto __continue42
293
+ goto __continue51
246
294
  end
247
295
  door.State = DoorState.STATE_OPEN
248
296
  local sprite = door:GetSprite()
249
297
  sprite:Play("Opened", true)
250
298
  door.ExtraVisible = false
251
299
  end
252
- ::__continue42::
300
+ ::__continue51::
253
301
  end
254
302
  sfx:Stop(SoundEffect.SOUND_DOOR_HEAVY_OPEN)
255
303
  game:ShakeScreen(0)
@@ -57,6 +57,18 @@ export declare function getEnumValues(transpiledEnum: unknown): int[];
57
57
  */
58
58
  export declare function hexToKColor(hexString: string, alpha: float): KColor;
59
59
  export declare function isGreedMode(): boolean;
60
+ /**
61
+ * Players can boot the game with an launch option called "--luadebug", which will enable additional
62
+ * functionality that is considered to be unsafe. For more information about this flag, see the
63
+ * wiki: https://bindingofisaacrebirth.fandom.com/wiki/Launch_Options
64
+ *
65
+ * When this flag is enabled, the global environment will be slightly different. The differences are
66
+ * documented here: https://wofsauge.github.io/IsaacDocs/rep/Globals.html
67
+ *
68
+ * This function uses the `package` global variable as a proxy to determine if the "--luadebug" flag
69
+ * is enabled or not.
70
+ */
71
+ export declare function isLuaDebugEnabled(): boolean;
60
72
  /**
61
73
  * Whether or not the player is playing on a set seed (i.e. that they entered in a specific seed by
62
74
  * pressing tab on the character selection screen). When the player resets the game on a set seed,
@@ -51,6 +51,9 @@ function ____exports.isGreedMode(self)
51
51
  local game = Game()
52
52
  return (game.Difficulty == Difficulty.DIFFICULTY_GREED) or (game.Difficulty == Difficulty.DIFFICULTY_GREEDIER)
53
53
  end
54
+ function ____exports.isLuaDebugEnabled(self)
55
+ return package ~= nil
56
+ end
54
57
  function ____exports.onSetSeed(self)
55
58
  local game = Game()
56
59
  local seeds = game:GetSeeds()
@@ -0,0 +1,9 @@
1
+ /**
2
+ * In Lua, the `error` function will tell you the line number of the error, but not give you a full
3
+ * traceback of the parent functions, which is unlike how JavaScript works. This function monkey
4
+ * patches the `error` function to add this functionality.
5
+ *
6
+ * Traceback functionality can only be added if the "--luadebug" flag is turned on, so this function
7
+ * does nothing if the "--luadebug" flag is disabled.
8
+ */
9
+ export declare function patchErrorFunction(): void;
@@ -0,0 +1,44 @@
1
+ --[[ Generated with https://github.com/TypeScriptToLua/TypeScriptToLua ]]
2
+ require("lualib_bundle");
3
+ local ____exports = {}
4
+ local errorWithTraceback, slimTracebackOutput, vanillaError
5
+ local ____debug = require("functions.debug")
6
+ local getTraceback = ____debug.getTraceback
7
+ local ____util = require("functions.util")
8
+ local isLuaDebugEnabled = ____util.isLuaDebugEnabled
9
+ function errorWithTraceback(message, level)
10
+ if vanillaError == nil then
11
+ error(message, level)
12
+ end
13
+ if level == nil then
14
+ level = 1
15
+ end
16
+ local tracebackOutput = getTraceback(nil)
17
+ local slimmedTracebackOutput = slimTracebackOutput(nil, tracebackOutput)
18
+ Isaac.DebugString(slimmedTracebackOutput)
19
+ vanillaError(message, level + 1)
20
+ end
21
+ function slimTracebackOutput(self, tracebackOutput)
22
+ local lineSeparator = "\n"
23
+ local lines = __TS__StringSplit(tracebackOutput, lineSeparator)
24
+ if __TS__StringIncludes(lines[2], "in upvalue 'getTraceback'") then
25
+ __TS__ArraySplice(lines, 1, 1)
26
+ end
27
+ if __TS__StringIncludes(lines[2], "in function 'error'") then
28
+ __TS__ArraySplice(lines, 1, 1)
29
+ end
30
+ local slimmedTracebackOutput = table.concat(lines, lineSeparator or ",")
31
+ return slimmedTracebackOutput
32
+ end
33
+ function ____exports.patchErrorFunction(self)
34
+ if not isLuaDebugEnabled(nil) then
35
+ return
36
+ end
37
+ if __PATCHED_ERROR ~= nil then
38
+ return
39
+ end
40
+ __PATCHED_ERROR = true
41
+ vanillaError = error
42
+ error = errorWithTraceback
43
+ end
44
+ return ____exports
@@ -0,0 +1,8 @@
1
+ /**
2
+ * When the "--luadebug" flag is enabled, the `print` function will no longer print messages to the
3
+ * "log.txt" file or the in-game console. This function monkey patches the `print` function to
4
+ * restore this functionality.
5
+ *
6
+ * If the "--luadebug" flag is disabled, this function will do nothing.
7
+ */
8
+ export declare function patchPrintFunction(): void;
@@ -0,0 +1,45 @@
1
+ --[[ Generated with https://github.com/TypeScriptToLua/TypeScriptToLua ]]
2
+ local ____exports = {}
3
+ local printForLuaDebug, getPrintMsg, getValueToPrint
4
+ local ____util = require("functions.util")
5
+ local isLuaDebugEnabled = ____util.isLuaDebugEnabled
6
+ local ____vector = require("functions.vector")
7
+ local isVector = ____vector.isVector
8
+ function printForLuaDebug(...)
9
+ local args = {...}
10
+ local msg = getPrintMsg(nil, args)
11
+ Isaac.DebugString(msg)
12
+ local msgWithNewline = msg .. "\n"
13
+ Isaac.ConsoleOutput(msgWithNewline)
14
+ end
15
+ function getPrintMsg(self, args)
16
+ if #args == 0 then
17
+ return tostring(nil)
18
+ end
19
+ local msg = ""
20
+ for ____, arg in ipairs(args) do
21
+ if msg ~= "" then
22
+ msg = msg .. " "
23
+ end
24
+ msg = msg .. getValueToPrint(nil, arg)
25
+ end
26
+ return msg
27
+ end
28
+ function getValueToPrint(self, arg)
29
+ if isVector(nil, arg) then
30
+ local vector = arg
31
+ return ((("Vector(" .. tostring(vector.X)) .. ", ") .. tostring(vector.Y)) .. ")"
32
+ end
33
+ return tostring(arg)
34
+ end
35
+ function ____exports.patchPrintFunction(self)
36
+ if not isLuaDebugEnabled(nil) then
37
+ return
38
+ end
39
+ if __PATCHED_PRINT ~= nil then
40
+ return
41
+ end
42
+ __PATCHED_PRINT = true
43
+ print = printForLuaDebug
44
+ end
45
+ return ____exports
@@ -77,6 +77,10 @@ local sirenHelpersInit = ____sirenHelpers.sirenHelpersInit
77
77
  local ____initialized = require("initialized")
78
78
  local areFeaturesInitialized = ____initialized.areFeaturesInitialized
79
79
  local setFeaturesInitialized = ____initialized.setFeaturesInitialized
80
+ local ____patchErrorFunctions = require("patchErrorFunctions")
81
+ local patchErrorFunction = ____patchErrorFunctions.patchErrorFunction
82
+ local ____patchPrintFunction = require("patchPrintFunction")
83
+ local patchPrintFunction = ____patchPrintFunction.patchPrintFunction
80
84
  local ____ModUpgraded = require("types.ModUpgraded")
81
85
  local ModUpgraded = ____ModUpgraded.ModUpgraded
82
86
  function initCustomCallbacks(self, mod)
@@ -121,6 +125,8 @@ function ____exports.upgradeMod(self, modVanilla, verbose)
121
125
  if verbose == nil then
122
126
  verbose = false
123
127
  end
128
+ patchErrorFunction(nil)
129
+ patchPrintFunction(nil)
124
130
  local mod = __TS__New(ModUpgraded, modVanilla, verbose)
125
131
  if not areFeaturesInitialized(nil) then
126
132
  setFeaturesInitialized(nil)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "isaacscript-common",
3
- "version": "1.0.513",
3
+ "version": "1.0.517",
4
4
  "description": "Helper functions for IsaacScript mods",
5
5
  "keywords": [
6
6
  "isaac",
@@ -25,7 +25,7 @@
25
25
  "dist/**/*.d.ts"
26
26
  ],
27
27
  "devDependencies": {
28
- "isaac-typescript-definitions": "^1.0.294",
28
+ "isaac-typescript-definitions": "^1.0.295",
29
29
  "isaacscript-lint": "^1.0.71",
30
30
  "typedoc": "^0.22.10",
31
31
  "typescript": "4.4.4",