isaacscript-common 84.1.1 → 84.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.
Files changed (39) hide show
  1. package/dist/classes/features/callbackLogic/PlayerCollectibleDetection.d.ts.map +1 -1
  2. package/dist/classes/features/callbackLogic/PlayerCollectibleDetection.js +3 -2
  3. package/dist/classes/features/callbackLogic/PlayerCollectibleDetection.lua +4 -2
  4. package/dist/functions/array.d.ts +1 -1
  5. package/dist/functions/array.d.ts.map +1 -1
  6. package/dist/functions/array.js +2 -1
  7. package/dist/functions/array.lua +3 -1
  8. package/dist/functions/enums.d.ts.map +1 -1
  9. package/dist/functions/enums.js +7 -4
  10. package/dist/functions/enums.lua +9 -4
  11. package/dist/functions/logMisc.d.ts +2 -2
  12. package/dist/functions/logMisc.d.ts.map +1 -1
  13. package/dist/functions/logMisc.js +3 -4
  14. package/dist/functions/logMisc.lua +4 -3
  15. package/dist/functions/set.d.ts +3 -3
  16. package/dist/functions/set.d.ts.map +1 -1
  17. package/dist/functions/set.js +2 -1
  18. package/dist/functions/set.lua +3 -1
  19. package/dist/functions/sort.d.ts +2 -1
  20. package/dist/functions/sort.d.ts.map +1 -1
  21. package/dist/functions/sort.js +3 -2
  22. package/dist/functions/sort.lua +6 -6
  23. package/dist/functions/table.js +1 -1
  24. package/dist/functions/types.d.ts.map +1 -1
  25. package/dist/functions/types.js +7 -5
  26. package/dist/functions/types.lua +3 -1
  27. package/dist/index.rollup.d.ts +9 -7
  28. package/dist/isaacscript-common.lua +33 -19
  29. package/dist/lib/jsonLua.d.ts +12 -0
  30. package/dist/lib/jsonLua.js +701 -0
  31. package/package.json +1 -1
  32. package/src/classes/features/callbackLogic/PlayerCollectibleDetection.ts +3 -2
  33. package/src/functions/array.ts +3 -2
  34. package/src/functions/enums.ts +7 -6
  35. package/src/functions/logMisc.ts +5 -6
  36. package/src/functions/set.ts +7 -4
  37. package/src/functions/sort.ts +2 -2
  38. package/src/functions/table.ts +1 -1
  39. package/src/functions/types.ts +7 -5
@@ -5047,7 +5047,7 @@ export declare function getArrayCombinations<T>(array: readonly T[], includeEmpt
5047
5047
  * Helper function to get the duplicate elements in an array. Only one element for each value will
5048
5048
  * be returned. The elements will be sorted before they are returned.
5049
5049
  */
5050
- export declare function getArrayDuplicateElements<T>(array: readonly T[]): readonly T[];
5050
+ export declare function getArrayDuplicateElements<T extends number | string>(array: readonly T[]): readonly T[];
5051
5051
 
5052
5052
  /**
5053
5053
  * Helper function to get an array containing the indexes of an array.
@@ -7261,7 +7261,7 @@ export declare function getRandomSeed(): Seed;
7261
7261
  * a random seed.
7262
7262
  * @param exceptions Optional. An array of elements to skip over if selected.
7263
7263
  */
7264
- export declare function getRandomSetElement<T>(set: ReadonlySet<T>, seedOrRNG: Seed | RNG | undefined, exceptions?: readonly T[]): T;
7264
+ export declare function getRandomSetElement<T extends number | string>(set: ReadonlySet<T>, seedOrRNG: Seed | RNG | undefined, exceptions?: readonly T[]): T;
7265
7265
 
7266
7266
  /**
7267
7267
  * Helper function to get a random vector between (-1, -1) and (1, 1).
@@ -7876,7 +7876,7 @@ export declare function getSeedEffects(): readonly SeedEffect[];
7876
7876
  * @param set The set to get the combinations of.
7877
7877
  * @param includeEmptyArray Whether to include an empty array in the combinations.
7878
7878
  */
7879
- export declare function getSetCombinations<T>(set: ReadonlySet<T>, includeEmptyArray: boolean): ReadonlyArray<ReadonlySet<T>>;
7879
+ export declare function getSetCombinations<T extends number | string>(set: ReadonlySet<T>, includeEmptyArray: boolean): ReadonlyArray<ReadonlySet<T>>;
7880
7880
 
7881
7881
  /**
7882
7882
  * Helper function to get the shooting actions that the specified `ControllerIndex` is currently
@@ -7934,7 +7934,7 @@ export declare function getSlots(slotVariant?: SlotVariant | -1, subType?: numbe
7934
7934
  * Normally, set values are returned in insertion order, so use this function when the ordering of
7935
7935
  * the contents is important.
7936
7936
  */
7937
- export declare function getSortedSetValues<T>(set: ReadonlySet<T>): T[];
7937
+ export declare function getSortedSetValues<T extends number | string>(set: ReadonlySet<T>): T[];
7938
7938
 
7939
7939
  /** Helper function to get all of the `GridEntitySpikes` in the room. */
7940
7940
  export declare function getSpikes(variant?: number): readonly GridEntitySpikes[];
@@ -10860,7 +10860,7 @@ export declare function logLevelStateFlags(this: void): void;
10860
10860
  * @param map The TSTL `Map` to log.
10861
10861
  * @param name Optional. The name of the map, which will be logged before the elements.
10862
10862
  */
10863
- export declare function logMap(this: void, map: ReadonlyMap<AnyNotNil, unknown>, name?: string): void;
10863
+ export declare function logMap(this: void, map: ReadonlyMap<number | string, unknown>, name?: string): void;
10864
10864
 
10865
10865
  export declare function logMusic(this: void): void;
10866
10866
 
@@ -10901,7 +10901,7 @@ export declare function logSeedEffects(this: void): void;
10901
10901
  * @param set The TSTL `Set` to log.
10902
10902
  * @param name Optional. The name of the set, which will be logged before the elements.
10903
10903
  */
10904
- export declare function logSet(this: void, set: ReadonlySet<AnyNotNil>, name?: string): void;
10904
+ export declare function logSet(this: void, set: ReadonlySet<number | string>, name?: string): void;
10905
10905
 
10906
10906
  /** Helper function for logging every sound effect that is currently playing. */
10907
10907
  export declare function logSounds(this: void): void;
@@ -18189,6 +18189,8 @@ export declare function smeltTrinkets(player: EntityPlayer, ...trinketTypes: rea
18189
18189
  */
18190
18190
  export declare function some<T>(array: readonly T[], func: (value: T, index: number, array: readonly T[]) => boolean): boolean;
18191
18191
 
18192
+ export declare function sortNormal(a: unknown, b: unknown): -1 | 0 | 1;
18193
+
18192
18194
  /**
18193
18195
  * Helper function to sort an array of objects by one of the object keys.
18194
18196
  *
@@ -18217,7 +18219,7 @@ export declare function sortObjectArrayByKey(key: string): (a: unknown, b: unkno
18217
18219
  *
18218
18220
  * ```ts
18219
18221
  * const myArray = [[1, 2], [2, 3], [3, 4]];
18220
- * myArray.sort(twoDimensionalSort);
18222
+ * myArray.sort(sortTwoDimensionalArray);
18221
18223
  * ```
18222
18224
  *
18223
18225
  * This function also properly handles when the array elements are strings or numbers (instead of
@@ -1,6 +1,6 @@
1
1
  --[[
2
2
 
3
- isaacscript-common 84.1.0
3
+ isaacscript-common 84.1.2
4
4
 
5
5
  This is the "isaacscript-common" library, which was created with the IsaacScript tool.
6
6
 
@@ -17055,6 +17055,8 @@ end
17055
17055
  return ____exports
17056
17056
  end,
17057
17057
  ["functions.types"] = function(...)
17058
+ local ____lualib = require("lualib_bundle")
17059
+ local __TS__TypeOf = ____lualib.__TS__TypeOf
17058
17060
  local ____exports = {}
17059
17061
  function ____exports.isNumber(self, variable)
17060
17062
  return type(variable) == "number"
@@ -17164,7 +17166,7 @@ function ____exports.isInteger(self, variable)
17164
17166
  end
17165
17167
  --- Helper function to detect if a variable is a boolean, number, or string.
17166
17168
  function ____exports.isPrimitive(self, variable)
17167
- local variableType = type(variable)
17169
+ local variableType = __TS__TypeOf(variable)
17168
17170
  return variableType == "boolean" or variableType == "number" or variableType == "string"
17169
17171
  end
17170
17172
  function ____exports.isString(self, variable)
@@ -17203,7 +17205,7 @@ local ____types = require("functions.types")
17203
17205
  local isNumber = ____types.isNumber
17204
17206
  local isString = ____types.isString
17205
17207
  local isTable = ____types.isTable
17206
- local function sortNormal(self, a, b)
17208
+ function ____exports.sortNormal(self, a, b)
17207
17209
  if not isNumber(nil, a) and not isString(nil, a) then
17208
17210
  error("Failed to normal sort since the first value was not a number or string and was instead: " .. type(a))
17209
17211
  end
@@ -17245,7 +17247,7 @@ function ____exports.sortObjectArrayByKey(self, key)
17245
17247
  end
17246
17248
  local aValue = a[key]
17247
17249
  local bValue = b[key]
17248
- return sortNormal(nil, aValue, bValue)
17250
+ return ____exports.sortNormal(nil, aValue, bValue)
17249
17251
  end
17250
17252
  end
17251
17253
  --- Helper function to sort a two-dimensional array by the first element.
@@ -17254,7 +17256,7 @@ end
17254
17256
  --
17255
17257
  -- ```ts
17256
17258
  -- const myArray = [[1, 2], [2, 3], [3, 4]];
17257
- -- myArray.sort(twoDimensionalSort);
17259
+ -- myArray.sort(sortTwoDimensionalArray);
17258
17260
  -- ```
17259
17261
  --
17260
17262
  -- This function also properly handles when the array elements are strings or numbers (instead of
@@ -17269,7 +17271,7 @@ function ____exports.sortTwoDimensionalArray(self, a, b)
17269
17271
  error(((((((("Failed to two-dimensional sort since the two elements were disparate types: " .. tostring(a)) .. " & ") .. tostring(b)) .. " (") .. aType) .. " & ") .. bType) .. ")")
17270
17272
  end
17271
17273
  if aType == "string" or aType == "number" then
17272
- return sortNormal(nil, a, b)
17274
+ return ____exports.sortNormal(nil, a, b)
17273
17275
  end
17274
17276
  if aType ~= "table" then
17275
17277
  error("Failed to two-dimensional sort since the first element was not a string, number, or table.")
@@ -17290,7 +17292,7 @@ function ____exports.sortTwoDimensionalArray(self, a, b)
17290
17292
  if elementType1 ~= elementType2 then
17291
17293
  error(((((((("Failed to two-dimensional sort since the first element of each array were disparate types: " .. tostring(firstElement1)) .. " & ") .. tostring(firstElement2)) .. " (") .. elementType1) .. " & ") .. elementType2) .. ")")
17292
17294
  end
17293
- return sortNormal(nil, firstElement1, firstElement2)
17295
+ return ____exports.sortNormal(nil, firstElement1, firstElement2)
17294
17296
  end
17295
17297
  --- Helper function to sort an array in a stable way.
17296
17298
  --
@@ -17299,7 +17301,7 @@ end
17299
17301
  -- Under the hood, this uses the merge sort algorithm.
17300
17302
  function ____exports.stableSort(self, array, sortFunc)
17301
17303
  if sortFunc == nil then
17302
- sortFunc = sortNormal
17304
+ sortFunc = ____exports.sortNormal
17303
17305
  end
17304
17306
  if #array <= 1 then
17305
17307
  return array
@@ -18702,6 +18704,8 @@ local getRandomInt = ____random.getRandomInt
18702
18704
  local ____rng = require("functions.rng")
18703
18705
  local isRNG = ____rng.isRNG
18704
18706
  local newRNG = ____rng.newRNG
18707
+ local ____sort = require("functions.sort")
18708
+ local sortNormal = ____sort.sortNormal
18705
18709
  local ____types = require("functions.types")
18706
18710
  local isNumber = ____types.isNumber
18707
18711
  local isTable = ____types.isTable
@@ -19060,7 +19064,7 @@ function ____exports.getArrayDuplicateElements(self, array)
19060
19064
  set:add(element)
19061
19065
  end
19062
19066
  local values = {__TS__Spread(duplicateElements)}
19063
- return __TS__ArraySort(values)
19067
+ return __TS__ArraySort(values, sortNormal)
19064
19068
  end
19065
19069
  --- Helper function to get an array containing the indexes of an array.
19066
19070
  --
@@ -19272,6 +19276,7 @@ return ____exports
19272
19276
  local ____lualib = require("lualib_bundle")
19273
19277
  local __TS__ArraySort = ____lualib.__TS__ArraySort
19274
19278
  local __TS__ArrayMap = ____lualib.__TS__ArrayMap
19279
+ local __TS__ArrayToSorted = ____lualib.__TS__ArrayToSorted
19275
19280
  local __TS__ArrayAt = ____lualib.__TS__ArrayAt
19276
19281
  local __TS__ArrayIncludes = ____lualib.__TS__ArrayIncludes
19277
19282
  local __TS__New = ____lualib.__TS__New
@@ -19280,6 +19285,8 @@ local ____ReadonlySet = require("types.ReadonlySet")
19280
19285
  local ReadonlySet = ____ReadonlySet.ReadonlySet
19281
19286
  local ____array = require("functions.array")
19282
19287
  local getRandomArrayElement = ____array.getRandomArrayElement
19288
+ local ____sort = require("functions.sort")
19289
+ local sortNormal = ____sort.sortNormal
19283
19290
  local ____types = require("functions.types")
19284
19291
  local isNumber = ____types.isNumber
19285
19292
  local isString = ____types.isString
@@ -19415,8 +19422,9 @@ end
19415
19422
  -- Throws an error if the provided enum is empty.
19416
19423
  function ____exports.getHighestEnumValue(self, transpiledEnum)
19417
19424
  local enumValues = ____exports.getEnumValues(nil, transpiledEnum)
19418
- local lastElement = __TS__ArrayAt(enumValues, -1)
19419
- assertDefined(nil, lastElement, "Failed to get the last value from an enum since the enum was empty.")
19425
+ local sortedValues = __TS__ArrayToSorted(enumValues, sortNormal)
19426
+ local lastElement = __TS__ArrayAt(sortedValues, -1)
19427
+ assertDefined(nil, lastElement, "Failed to get the highest value from an enum since the enum was empty.")
19420
19428
  return lastElement
19421
19429
  end
19422
19430
  --- Helper function to get the enum value with the lowest value.
@@ -19427,8 +19435,9 @@ end
19427
19435
  -- Throws an error if the provided enum is empty.
19428
19436
  function ____exports.getLowestEnumValue(self, transpiledEnum)
19429
19437
  local enumValues = ____exports.getEnumValues(nil, transpiledEnum)
19430
- local firstElement = enumValues[1]
19431
- assertDefined(nil, firstElement, "Failed to get the first value from an enum since the enum was empty.")
19438
+ local sortedValues = __TS__ArrayToSorted(enumValues, sortNormal)
19439
+ local firstElement = sortedValues[1]
19440
+ assertDefined(nil, firstElement, "Failed to get the lowest value from an enum since the enum was empty.")
19432
19441
  return firstElement
19433
19442
  end
19434
19443
  --- Helper function to get a random value from the provided enum.
@@ -44332,6 +44341,8 @@ local ____array = require("functions.array")
44332
44341
  local getArrayCombinations = ____array.getArrayCombinations
44333
44342
  local getRandomArrayElement = ____array.getRandomArrayElement
44334
44343
  local sumArray = ____array.sumArray
44344
+ local ____sort = require("functions.sort")
44345
+ local sortNormal = ____sort.sortNormal
44335
44346
  local ____types = require("functions.types")
44336
44347
  local isPrimitive = ____types.isPrimitive
44337
44348
  --- Helper function to get a sorted array based on the contents of a set.
@@ -44347,7 +44358,7 @@ function ____exports.getSortedSetValues(self, set)
44347
44358
  error(("Failed to get the sorted set values because the provided set was of type \"" .. tostring(arrayType)) .. "\". Having sets with non-primitive types doesn't make much sense in general, so you might need to rethink what you are doing.")
44348
44359
  end
44349
44360
  end
44350
- __TS__ArraySort(values)
44361
+ __TS__ArraySort(values, sortNormal)
44351
44362
  return values
44352
44363
  end
44353
44364
  --- Helper function to convert the keys of an object to a set.
@@ -45388,6 +45399,8 @@ local defaultMapGetPlayer = ____playerDataStructures.defaultMapGetPlayer
45388
45399
  local mapSetPlayer = ____playerDataStructures.mapSetPlayer
45389
45400
  local ____players = require("functions.players")
45390
45401
  local getPlayerFromPtr = ____players.getPlayerFromPtr
45402
+ local ____sort = require("functions.sort")
45403
+ local sortNormal = ____sort.sortNormal
45391
45404
  local ____utils = require("functions.utils")
45392
45405
  local ____repeat = ____utils["repeat"]
45393
45406
  local ____DefaultMap = require("classes.DefaultMap")
@@ -45511,8 +45524,8 @@ function PlayerCollectibleDetection.prototype.checkActiveItemsChanged(self, play
45511
45524
  oldCollectibleTypes[#oldCollectibleTypes + 1] = oldCollectibleType
45512
45525
  newCollectibleTypes[#newCollectibleTypes + 1] = newCollectibleType
45513
45526
  end
45514
- __TS__ArraySort(oldCollectibleTypes)
45515
- __TS__ArraySort(newCollectibleTypes)
45527
+ __TS__ArraySort(oldCollectibleTypes, sortNormal)
45528
+ __TS__ArraySort(newCollectibleTypes, sortNormal)
45516
45529
  if not arrayEquals(nil, oldCollectibleTypes, newCollectibleTypes) then
45517
45530
  self:updateCollectibleMapAndFire(player, nil)
45518
45531
  end
@@ -58456,15 +58469,14 @@ return ____exports
58456
58469
  end,
58457
58470
  ["functions.logMisc"] = function(...)
58458
58471
  local ____lualib = require("lualib_bundle")
58459
- local Map = ____lualib.Map
58460
58472
  local __TS__Spread = ____lualib.__TS__Spread
58461
58473
  local __TS__ArraySort = ____lualib.__TS__ArraySort
58462
58474
  local __TS__ArrayEntries = ____lualib.__TS__ArrayEntries
58463
58475
  local __TS__Iterator = ____lualib.__TS__Iterator
58464
- local Set = ____lualib.Set
58465
58476
  local __TS__TypeOf = ____lualib.__TS__TypeOf
58466
58477
  local __TS__ObjectKeys = ____lualib.__TS__ObjectKeys
58467
58478
  local __TS__New = ____lualib.__TS__New
58479
+ local Set = ____lualib.Set
58468
58480
  local ____exports = {}
58469
58481
  local ____isaac_2Dtypescript_2Ddefinitions = require("lua_modules.isaac-typescript-definitions.dist.index")
58470
58482
  local BossID = ____isaac_2Dtypescript_2Ddefinitions.BossID
@@ -58521,6 +58533,8 @@ local getRoomListIndex = ____roomData.getRoomListIndex
58521
58533
  local ____set = require("functions.set")
58522
58534
  local combineSets = ____set.combineSets
58523
58535
  local getSortedSetValues = ____set.getSortedSetValues
58536
+ local ____sort = require("functions.sort")
58537
+ local sortNormal = ____sort.sortNormal
58524
58538
  local ____table = require("functions.table")
58525
58539
  local iterateTableInOrder = ____table.iterateTableInOrder
58526
58540
  local ____trinkets = require("functions.trinkets")
@@ -58689,7 +58703,7 @@ function ____exports.logMap(map, name)
58689
58703
  local suffix = name == nil and "" or (" \"" .. name) .. "\""
58690
58704
  log(("Logging a TSTL map" .. suffix) .. ":")
58691
58705
  local mapKeys = {__TS__Spread(map:keys())}
58692
- __TS__ArraySort(mapKeys)
58706
+ __TS__ArraySort(mapKeys, sortNormal)
58693
58707
  for ____, key in ipairs(mapKeys) do
58694
58708
  local value = map:get(key)
58695
58709
  log(((" " .. tostring(key)) .. " --> ") .. tostring(value))
@@ -0,0 +1,12 @@
1
+ /**
2
+ * This is the custom JSON parser library called "json.lua". It is located at:
3
+ * https://github.com/rxi/json.lua
4
+ *
5
+ * This parser was measured to be 11.8 times faster than the vanilla parser at decoding a sample
6
+ * "save1.dat" file.
7
+ *
8
+ * @noSelfInFile
9
+ */
10
+
11
+ export function encode(data: unknown): string;
12
+ export function decode(data: string): unknown;