isaacscript-common 1.0.515 → 1.0.516

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.
@@ -1,5 +1,9 @@
1
1
  /**
2
2
  * 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.
3
+ * `console.trace()` function. This will only work if the `--luadebug` launch option is enabled or
4
+ * the Racing+ sandbox is enabled.
5
+ *
6
+ * @param silent Optional. Whether or not to print an error message if the `--luadebug` launch
7
+ * option is not turned on. False by default.
4
8
  */
5
- export declare function traceback(): void;
9
+ export declare function traceback(silent?: boolean): void;
@@ -1,6 +1,9 @@
1
1
  --[[ Generated with https://github.com/TypeScriptToLua/TypeScriptToLua ]]
2
2
  local ____exports = {}
3
- function ____exports.traceback(self)
3
+ function ____exports.traceback(self, silent)
4
+ if silent == nil then
5
+ silent = false
6
+ end
4
7
  if debug ~= nil then
5
8
  local tracebackMsg = debug.traceback()
6
9
  Isaac.DebugString(tracebackMsg)
@@ -10,6 +13,8 @@ function ____exports.traceback(self)
10
13
  sandboxTraceback()
11
14
  return
12
15
  end
13
- Isaac.DebugString("Error: Cannot perform a traceback since --luadebug is not enabled.")
16
+ if not silent then
17
+ Isaac.DebugString("Error: Cannot perform a traceback since --luadebug is not enabled.")
18
+ end
14
19
  end
15
20
  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()
@@ -136,8 +136,9 @@ export declare function inStartingRoom(): boolean;
136
136
  /**
137
137
  * Helper function to loop through every room on the floor and see if it has been cleared.
138
138
  *
139
- * @param onlyCheckRoomTypes Optional. A whitelist of room types. Room types not in the provided
140
- * array will be ignored. If not specified, then all rooms will be checked. Undefined by default.
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.
141
142
  */
142
143
  export declare function isAllRoomsClear(onlyCheckRoomTypes?: RoomType[]): boolean;
143
144
  /**
@@ -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,26 @@
1
+ --[[ Generated with https://github.com/TypeScriptToLua/TypeScriptToLua ]]
2
+ local ____exports = {}
3
+ local errorWithTraceback, vanillaError
4
+ local ____debug = require("functions.debug")
5
+ local traceback = ____debug.traceback
6
+ local ____util = require("functions.util")
7
+ local isLuaDebugEnabled = ____util.isLuaDebugEnabled
8
+ function errorWithTraceback(message, level)
9
+ if vanillaError == nil then
10
+ error(message, level)
11
+ end
12
+ traceback(nil)
13
+ vanillaError(message, level)
14
+ end
15
+ function ____exports.patchErrorFunction(self)
16
+ if not isLuaDebugEnabled(nil) then
17
+ return
18
+ end
19
+ if __PATCHED_ERROR ~= nil then
20
+ return
21
+ end
22
+ __PATCHED_ERROR = true
23
+ vanillaError = error
24
+ error = errorWithTraceback
25
+ end
26
+ 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.515",
3
+ "version": "1.0.516",
4
4
  "description": "Helper functions for IsaacScript mods",
5
5
  "keywords": [
6
6
  "isaac",