isaacscript-common 10.0.1 → 10.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.
Files changed (68) hide show
  1. package/dist/index.d.ts +66 -19
  2. package/dist/isaacscript-common.lua +181 -88
  3. package/dist/package.lua +2 -2
  4. package/dist/src/features/deployJSONRoom.d.ts +16 -6
  5. package/dist/src/features/deployJSONRoom.d.ts.map +1 -1
  6. package/dist/src/features/deployJSONRoom.lua +16 -6
  7. package/dist/src/functions/bitSet128.d.ts +2 -1
  8. package/dist/src/functions/bitSet128.d.ts.map +1 -1
  9. package/dist/src/functions/color.d.ts +2 -3
  10. package/dist/src/functions/color.d.ts.map +1 -1
  11. package/dist/src/functions/curses.d.ts +1 -1
  12. package/dist/src/functions/curses.lua +1 -1
  13. package/dist/src/functions/deepCopy.d.ts +2 -1
  14. package/dist/src/functions/deepCopy.d.ts.map +1 -1
  15. package/dist/src/functions/deepCopy.lua +19 -25
  16. package/dist/src/functions/deepCopyTests.lua +13 -26
  17. package/dist/src/functions/kColor.d.ts +2 -3
  18. package/dist/src/functions/kColor.d.ts.map +1 -1
  19. package/dist/src/functions/rng.d.ts +2 -2
  20. package/dist/src/functions/rng.d.ts.map +1 -1
  21. package/dist/src/functions/serialization.d.ts +11 -4
  22. package/dist/src/functions/serialization.d.ts.map +1 -1
  23. package/dist/src/functions/serialization.lua +15 -0
  24. package/dist/src/functions/vector.d.ts +2 -1
  25. package/dist/src/functions/vector.d.ts.map +1 -1
  26. package/dist/src/functions/weighted.d.ts +6 -0
  27. package/dist/src/functions/weighted.d.ts.map +1 -0
  28. package/dist/src/functions/weighted.lua +35 -0
  29. package/dist/src/index.d.ts +2 -1
  30. package/dist/src/index.d.ts.map +1 -1
  31. package/dist/src/index.lua +8 -0
  32. package/dist/src/interfaces/SaveData.d.ts +3 -8
  33. package/dist/src/interfaces/SaveData.d.ts.map +1 -1
  34. package/dist/src/objects/isaacAPIClassTypeToBrand.d.ts +1 -1
  35. package/dist/src/objects/isaacAPIClassTypeToBrand.d.ts.map +1 -1
  36. package/dist/src/objects/isaacAPIClassTypeToBrand.lua +2 -2
  37. package/dist/src/objects/isaacAPIClassTypeToFunctions.d.ts +36 -8
  38. package/dist/src/objects/isaacAPIClassTypeToFunctions.d.ts.map +1 -1
  39. package/dist/src/objects/isaacAPIClassTypeToFunctions.lua +42 -7
  40. package/dist/src/types/WeightedArray.d.ts +4 -0
  41. package/dist/src/types/WeightedArray.d.ts.map +1 -0
  42. package/dist/src/types/{SerializedIsaacAPIClass.lua → WeightedArray.lua} +0 -0
  43. package/package.json +2 -2
  44. package/src/features/deployJSONRoom.ts +16 -6
  45. package/src/features/saveDataManager/exports.ts +1 -1
  46. package/src/functions/bitSet128.ts +2 -0
  47. package/src/functions/color.ts +2 -0
  48. package/src/functions/curses.ts +1 -1
  49. package/src/functions/deepCopy.ts +25 -15
  50. package/src/functions/deepCopyTests.ts +19 -41
  51. package/src/functions/initArray.ts +1 -1
  52. package/src/functions/kColor.ts +2 -0
  53. package/src/functions/rng.ts +2 -0
  54. package/src/functions/serialization.ts +72 -18
  55. package/src/functions/vector.ts +5 -1
  56. package/src/functions/weighted.ts +36 -0
  57. package/src/index.ts +2 -1
  58. package/src/interfaces/SaveData.ts +4 -3
  59. package/src/objects/isaacAPIClassTypeToBrand.ts +1 -1
  60. package/src/objects/isaacAPIClassTypeToFunctions.ts +58 -9
  61. package/src/types/WeightedArray.ts +2 -0
  62. package/dist/src/enums/private/CopyableIsaacAPIClassType.d.ts +0 -12
  63. package/dist/src/enums/private/CopyableIsaacAPIClassType.d.ts.map +0 -1
  64. package/dist/src/enums/private/CopyableIsaacAPIClassType.lua +0 -10
  65. package/dist/src/types/SerializedIsaacAPIClass.d.ts +0 -11
  66. package/dist/src/types/SerializedIsaacAPIClass.d.ts.map +0 -1
  67. package/src/enums/private/CopyableIsaacAPIClassType.ts +0 -11
  68. package/src/types/SerializedIsaacAPIClass.ts +0 -9
@@ -1,6 +1,6 @@
1
1
  --[[
2
2
 
3
- isaacscript-common 10.0.1
3
+ isaacscript-common 10.0.2
4
4
 
5
5
  This is the "isaacscript-common" library, which was created with the IsaacScript tool.
6
6
 
@@ -4268,6 +4268,14 @@ do
4268
4268
  end
4269
4269
  end
4270
4270
  end
4271
+ do
4272
+ local ____export = require("lua_modules.isaac-typescript-definitions.dist.src.enums.CopyableIsaacAPIClassType")
4273
+ for ____exportKey, ____exportValue in pairs(____export) do
4274
+ if ____exportKey ~= "default" then
4275
+ ____exports[____exportKey] = ____exportValue
4276
+ end
4277
+ end
4278
+ end
4271
4279
  do
4272
4280
  local ____export = require("lua_modules.isaac-typescript-definitions.dist.src.enums.CurseID")
4273
4281
  for ____exportKey, ____exportValue in pairs(____export) do
@@ -4853,7 +4861,7 @@ return ____exports
4853
4861
  ["lua_modules.isaac-typescript-definitions.dist.package"] = function(...)
4854
4862
  return {
4855
4863
  name = "isaac-typescript-definitions",
4856
- version = "7.0.0",
4864
+ version = "7.2.0",
4857
4865
  description = "TypeScript definitions for The Binding of Isaac: Repentance.",
4858
4866
  keywords = {"isaac", "rebirth", "afterbirth", "repentance"},
4859
4867
  homepage = "https://isaacscript.github.io/",
@@ -10007,7 +10015,7 @@ ____exports.SwingerVariant.SWINGER = 0
10007
10015
  ____exports.SwingerVariant[____exports.SwingerVariant.SWINGER] = "SWINGER"
10008
10016
  ____exports.SwingerVariant.SWINGER_HEAD = 1
10009
10017
  ____exports.SwingerVariant[____exports.SwingerVariant.SWINGER_HEAD] = "SWINGER_HEAD"
10010
- ____exports.SwingerVariant.SWINGER_NECK = 2
10018
+ ____exports.SwingerVariant.SWINGER_NECK = 10
10011
10019
  ____exports.SwingerVariant[____exports.SwingerVariant.SWINGER_NECK] = "SWINGER_NECK"
10012
10020
  --- For `EntityType.DIP` (217).
10013
10021
  ____exports.DipVariant = {}
@@ -11012,6 +11020,17 @@ ____exports.ControllerIndex.CONTROLLER_2 = 2
11012
11020
  ____exports.ControllerIndex[____exports.ControllerIndex.CONTROLLER_2] = "CONTROLLER_2"
11013
11021
  ____exports.ControllerIndex.CONTROLLER_3 = 3
11014
11022
  ____exports.ControllerIndex[____exports.ControllerIndex.CONTROLLER_3] = "CONTROLLER_3"
11023
+ return ____exports
11024
+ end,
11025
+ ["lua_modules.isaac-typescript-definitions.dist.src.enums.CopyableIsaacAPIClassType"] = function(...)
11026
+ local ____exports = {}
11027
+ --- An enum containing the Isaac API classes that can be safely copied / serialized.
11028
+ ____exports.CopyableIsaacAPIClassType = {}
11029
+ ____exports.CopyableIsaacAPIClassType.BIT_SET_128 = "BitSet128"
11030
+ ____exports.CopyableIsaacAPIClassType.COLOR = "Color"
11031
+ ____exports.CopyableIsaacAPIClassType.K_COLOR = "KColor"
11032
+ ____exports.CopyableIsaacAPIClassType.RNG = "RNG"
11033
+ ____exports.CopyableIsaacAPIClassType.VECTOR = "Vector"
11015
11034
  return ____exports
11016
11035
  end,
11017
11036
  ["lua_modules.isaac-typescript-definitions.dist.src.enums.CurseID"] = function(...)
@@ -26888,18 +26907,6 @@ ____exports.SerializationType.SERIALIZE = 1
26888
26907
  ____exports.SerializationType[____exports.SerializationType.SERIALIZE] = "SERIALIZE"
26889
26908
  ____exports.SerializationType.DESERIALIZE = 2
26890
26909
  ____exports.SerializationType[____exports.SerializationType.DESERIALIZE] = "DESERIALIZE"
26891
- return ____exports
26892
- end,
26893
- ["src.enums.private.CopyableIsaacAPIClassType"] = function(...)
26894
- local ____exports = {}
26895
- --- - This must match the JSDoc comments for `deepCopy` and `merge`.
26896
- -- - This must match the `SerializableIsaacAPIClass` type union.
26897
- ____exports.CopyableIsaacAPIClassType = {}
26898
- ____exports.CopyableIsaacAPIClassType.BIT_SET_128 = "BitSet128"
26899
- ____exports.CopyableIsaacAPIClassType.COLOR = "Color"
26900
- ____exports.CopyableIsaacAPIClassType.K_COLOR = "KColor"
26901
- ____exports.CopyableIsaacAPIClassType.RNG = "RNG"
26902
- ____exports.CopyableIsaacAPIClassType.VECTOR = "Vector"
26903
26910
  return ____exports
26904
26911
  end,
26905
26912
  ["src.features.saveDataManager.saveDataManagerConstants"] = function(...)
@@ -29619,8 +29626,8 @@ return ____exports
29619
29626
  end,
29620
29627
  ["src.objects.isaacAPIClassTypeToBrand"] = function(...)
29621
29628
  local ____exports = {}
29622
- local ____CopyableIsaacAPIClassType = require("src.enums.private.CopyableIsaacAPIClassType")
29623
- local CopyableIsaacAPIClassType = ____CopyableIsaacAPIClassType.CopyableIsaacAPIClassType
29629
+ local ____isaac_2Dtypescript_2Ddefinitions = require("lua_modules.isaac-typescript-definitions.dist.src.index")
29630
+ local CopyableIsaacAPIClassType = ____isaac_2Dtypescript_2Ddefinitions.CopyableIsaacAPIClassType
29624
29631
  local ____SerializationBrand = require("src.enums.private.SerializationBrand")
29625
29632
  local SerializationBrand = ____SerializationBrand.SerializationBrand
29626
29633
  ____exports.ISAAC_API_CLASS_TYPE_TO_BRAND = {
@@ -29833,44 +29840,75 @@ return ____exports
29833
29840
  end,
29834
29841
  ["src.objects.isaacAPIClassTypeToFunctions"] = function(...)
29835
29842
  local ____exports = {}
29836
- local ____CopyableIsaacAPIClassType = require("src.enums.private.CopyableIsaacAPIClassType")
29837
- local CopyableIsaacAPIClassType = ____CopyableIsaacAPIClassType.CopyableIsaacAPIClassType
29843
+ local ____isaac_2Dtypescript_2Ddefinitions = require("lua_modules.isaac-typescript-definitions.dist.src.index")
29844
+ local CopyableIsaacAPIClassType = ____isaac_2Dtypescript_2Ddefinitions.CopyableIsaacAPIClassType
29838
29845
  local ____bitSet128 = require("src.functions.bitSet128")
29839
29846
  local copyBitSet128 = ____bitSet128.copyBitSet128
29840
29847
  local deserializeBitSet128 = ____bitSet128.deserializeBitSet128
29848
+ local isBitSet128 = ____bitSet128.isBitSet128
29841
29849
  local isSerializedBitSet128 = ____bitSet128.isSerializedBitSet128
29842
29850
  local serializeBitSet128 = ____bitSet128.serializeBitSet128
29843
29851
  local ____color = require("src.functions.color")
29844
29852
  local copyColor = ____color.copyColor
29845
29853
  local deserializeColor = ____color.deserializeColor
29854
+ local isColor = ____color.isColor
29846
29855
  local isSerializedColor = ____color.isSerializedColor
29847
29856
  local serializeColor = ____color.serializeColor
29848
29857
  local ____kColor = require("src.functions.kColor")
29849
29858
  local copyKColor = ____kColor.copyKColor
29850
29859
  local deserializeKColor = ____kColor.deserializeKColor
29860
+ local isKColor = ____kColor.isKColor
29851
29861
  local isSerializedKColor = ____kColor.isSerializedKColor
29852
29862
  local serializeKColor = ____kColor.serializeKColor
29853
29863
  local ____rng = require("src.functions.rng")
29854
29864
  local copyRNG = ____rng.copyRNG
29855
29865
  local deserializeRNG = ____rng.deserializeRNG
29866
+ local isRNG = ____rng.isRNG
29856
29867
  local isSerializedRNG = ____rng.isSerializedRNG
29857
29868
  local serializeRNG = ____rng.serializeRNG
29858
29869
  local ____vector = require("src.functions.vector")
29859
29870
  local copyVector = ____vector.copyVector
29860
29871
  local deserializeVector = ____vector.deserializeVector
29861
29872
  local isSerializedVector = ____vector.isSerializedVector
29873
+ local isVector = ____vector.isVector
29862
29874
  local serializeVector = ____vector.serializeVector
29863
29875
  ____exports.ISAAC_API_CLASS_TYPE_TO_FUNCTIONS = {
29864
- [CopyableIsaacAPIClassType.BIT_SET_128] = {isSerialized = isSerializedBitSet128, copy = copyBitSet128, serialize = serializeBitSet128, deserialize = deserializeBitSet128},
29865
- [CopyableIsaacAPIClassType.COLOR] = {isSerialized = isSerializedColor, copy = copyColor, serialize = serializeColor, deserialize = deserializeColor},
29866
- [CopyableIsaacAPIClassType.K_COLOR] = {isSerialized = isSerializedKColor, copy = copyKColor, serialize = serializeKColor, deserialize = deserializeKColor},
29867
- [CopyableIsaacAPIClassType.RNG] = {isSerialized = isSerializedRNG, copy = copyRNG, serialize = serializeRNG, deserialize = deserializeRNG},
29868
- [CopyableIsaacAPIClassType.VECTOR] = {isSerialized = isSerializedVector, copy = copyVector, serialize = serializeVector, deserialize = deserializeVector}
29876
+ [CopyableIsaacAPIClassType.BIT_SET_128] = {
29877
+ is = isBitSet128,
29878
+ isSerialized = isSerializedBitSet128,
29879
+ copy = copyBitSet128,
29880
+ serialize = serializeBitSet128,
29881
+ deserialize = deserializeBitSet128
29882
+ },
29883
+ [CopyableIsaacAPIClassType.COLOR] = {
29884
+ is = isColor,
29885
+ isSerialized = isSerializedColor,
29886
+ copy = copyColor,
29887
+ serialize = serializeColor,
29888
+ deserialize = deserializeColor
29889
+ },
29890
+ [CopyableIsaacAPIClassType.K_COLOR] = {
29891
+ is = isKColor,
29892
+ isSerialized = isSerializedKColor,
29893
+ copy = copyKColor,
29894
+ serialize = serializeKColor,
29895
+ deserialize = deserializeKColor
29896
+ },
29897
+ [CopyableIsaacAPIClassType.RNG] = {
29898
+ is = isRNG,
29899
+ isSerialized = isSerializedRNG,
29900
+ copy = copyRNG,
29901
+ serialize = serializeRNG,
29902
+ deserialize = deserializeRNG
29903
+ },
29904
+ [CopyableIsaacAPIClassType.VECTOR] = {
29905
+ is = isVector,
29906
+ isSerialized = isSerializedVector,
29907
+ copy = copyVector,
29908
+ serialize = serializeVector,
29909
+ deserialize = deserializeVector
29910
+ }
29869
29911
  }
29870
- return ____exports
29871
- end,
29872
- ["src.types.SerializedIsaacAPIClass"] = function(...)
29873
- local ____exports = {}
29874
29912
  return ____exports
29875
29913
  end,
29876
29914
  ["src.functions.serialization"] = function(...)
@@ -29939,6 +29977,21 @@ function ____exports.deserializeIsaacAPIClass(self, serializedIsaacAPIClass)
29939
29977
  end
29940
29978
  return functions:deserialize(serializedIsaacAPIClass)
29941
29979
  end
29980
+ --- Helper function to generically check if a given object is a copyable Isaac API class. (This is
29981
+ -- used by the save data manager when determining what is safe to copy.)
29982
+ --
29983
+ -- For the list of supported classes, see the `CopyableIsaacAPIClassType` enum.
29984
+ function ____exports.isCopyableIsaacAPIClass(self, object)
29985
+ local allFunctions = __TS__ObjectValues(ISAAC_API_CLASS_TYPE_TO_FUNCTIONS)
29986
+ local isFunctions = __TS__ArrayMap(
29987
+ allFunctions,
29988
+ function(____, functions) return functions.is end
29989
+ )
29990
+ return __TS__ArraySome(
29991
+ isFunctions,
29992
+ function(____, identityFunction) return identityFunction(nil, object) end
29993
+ )
29994
+ end
29942
29995
  --- Helper function to generically check if a given Lua table is a serialized Isaac API class. (This
29943
29996
  -- is used by the save data manager when reading data from the "save#.dat" file.)
29944
29997
  --
@@ -29977,18 +30030,16 @@ return ____exports
29977
30030
  end,
29978
30031
  ["src.functions.deepCopy"] = function(...)
29979
30032
  local ____lualib = require("lualib_bundle")
29980
- local Set = ____lualib.Set
29981
30033
  local __TS__New = ____lualib.__TS__New
29982
30034
  local Map = ____lualib.Map
30035
+ local Set = ____lualib.Set
29983
30036
  local __TS__Iterator = ____lualib.__TS__Iterator
29984
30037
  local __TS__ArraySort = ____lualib.__TS__ArraySort
29985
30038
  local __TS__ArraySome = ____lualib.__TS__ArraySome
29986
30039
  local ____exports = {}
29987
- local deepCopyTable, deepCopyDefaultMap, getNewDefaultMap, deepCopyMap, deepCopySet, deepCopyTSTLClass, deepCopyArray, deepCopyNormalLuaTable, getCopiedEntries, checkMetatable, deepCopyUserdata, COPYABLE_ISAAC_API_CLASS_TYPES_SET
30040
+ local deepCopyTable, deepCopyDefaultMap, getNewDefaultMap, deepCopyMap, deepCopySet, deepCopyTSTLClass, deepCopyArray, deepCopyNormalLuaTable, getCopiedEntries, checkMetatable, deepCopyUserdata
29988
30041
  local ____DefaultMap = require("src.classes.DefaultMap")
29989
30042
  local DefaultMap = ____DefaultMap.DefaultMap
29990
- local ____CopyableIsaacAPIClassType = require("src.enums.private.CopyableIsaacAPIClassType")
29991
- local CopyableIsaacAPIClassType = ____CopyableIsaacAPIClassType.CopyableIsaacAPIClassType
29992
30043
  local ____SerializationBrand = require("src.enums.private.SerializationBrand")
29993
30044
  local SerializationBrand = ____SerializationBrand.SerializationBrand
29994
30045
  local ____SerializationType = require("src.enums.SerializationType")
@@ -29999,8 +30050,6 @@ local ____serializationBrands = require("src.features.saveDataManager.serializat
29999
30050
  local isSerializationBrand = ____serializationBrands.isSerializationBrand
30000
30051
  local ____array = require("src.functions.array")
30001
30052
  local isArray = ____array.isArray
30002
- local ____enums = require("src.functions.enums")
30003
- local getEnumValues = ____enums.getEnumValues
30004
30053
  local ____isaacAPIClass = require("src.functions.isaacAPIClass")
30005
30054
  local getIsaacAPIClassName = ____isaacAPIClass.getIsaacAPIClassName
30006
30055
  local ____log = require("src.functions.log")
@@ -30008,6 +30057,7 @@ local log = ____log.log
30008
30057
  local ____serialization = require("src.functions.serialization")
30009
30058
  local copyIsaacAPIClass = ____serialization.copyIsaacAPIClass
30010
30059
  local deserializeIsaacAPIClass = ____serialization.deserializeIsaacAPIClass
30060
+ local isCopyableIsaacAPIClass = ____serialization.isCopyableIsaacAPIClass
30011
30061
  local isSerializedIsaacAPIClass = ____serialization.isSerializedIsaacAPIClass
30012
30062
  local serializeIsaacAPIClass = ____serialization.serializeIsaacAPIClass
30013
30063
  local ____tstlClass = require("src.functions.tstlClass")
@@ -30091,6 +30141,9 @@ function ____exports.deepCopy(self, value, serializationType, traversalDescripti
30091
30141
  if serializationType == SerializationType.SERIALIZE then
30092
30142
  error((("The deep copy function does not support serialization of \"" .. traversalDescription) .. "\", since it is type: ") .. valueType)
30093
30143
  end
30144
+ if serializationType == SerializationType.DESERIALIZE then
30145
+ error((("The deep copy function does not support deserialization of \"" .. traversalDescription) .. "\", since it is type: ") .. valueType)
30146
+ end
30094
30147
  return value
30095
30148
  end
30096
30149
  end
@@ -30242,15 +30295,15 @@ function deepCopyDefaultMap(self, defaultMap, serializationType, traversalDescri
30242
30295
  end
30243
30296
  function getNewDefaultMap(self, defaultMap, serializationType, traversalDescription, constructorArg)
30244
30297
  repeat
30245
- local ____switch34 = serializationType
30246
- local ____cond34 = ____switch34 == SerializationType.NONE
30247
- if ____cond34 then
30298
+ local ____switch35 = serializationType
30299
+ local ____cond35 = ____switch35 == SerializationType.NONE
30300
+ if ____cond35 then
30248
30301
  do
30249
30302
  return __TS__New(DefaultMap, constructorArg)
30250
30303
  end
30251
30304
  end
30252
- ____cond34 = ____cond34 or ____switch34 == SerializationType.SERIALIZE
30253
- if ____cond34 then
30305
+ ____cond35 = ____cond35 or ____switch35 == SerializationType.SERIALIZE
30306
+ if ____cond35 then
30254
30307
  do
30255
30308
  local newDefaultMap = {}
30256
30309
  newDefaultMap[SerializationBrand.DEFAULT_MAP] = ""
@@ -30258,8 +30311,8 @@ function getNewDefaultMap(self, defaultMap, serializationType, traversalDescript
30258
30311
  return newDefaultMap
30259
30312
  end
30260
30313
  end
30261
- ____cond34 = ____cond34 or ____switch34 == SerializationType.DESERIALIZE
30262
- if ____cond34 then
30314
+ ____cond35 = ____cond35 or ____switch35 == SerializationType.DESERIALIZE
30315
+ if ____cond35 then
30263
30316
  do
30264
30317
  if isDefaultMap(nil, defaultMap) then
30265
30318
  error(("The deep copy function failed to deserialize a default map of \"" .. traversalDescription) .. "\", since it was not a Lua table.")
@@ -30459,7 +30512,7 @@ function getCopiedEntries(self, object, serializationType, traversalDescription,
30459
30512
  local value = ____value[2]
30460
30513
  do
30461
30514
  if isSerializationBrand(nil, key) then
30462
- goto __continue87
30515
+ goto __continue88
30463
30516
  end
30464
30517
  traversalDescription = getTraversalDescription(nil, key, traversalDescription)
30465
30518
  local newValue = ____exports.deepCopy(
@@ -30481,7 +30534,7 @@ function getCopiedEntries(self, object, serializationType, traversalDescription,
30481
30534
  end
30482
30535
  copiedEntries[#copiedEntries + 1] = {keyToUse, newValue}
30483
30536
  end
30484
- ::__continue87::
30537
+ ::__continue88::
30485
30538
  end
30486
30539
  return {entries = copiedEntries, convertedNumberKeysToStrings = convertNumberKeysToStrings}
30487
30540
  end
@@ -30494,15 +30547,12 @@ function checkMetatable(self, luaMap, traversalDescription)
30494
30547
  error(("The deepCopy function detected that " .. tableDescription) .. " has a metatable. Copying tables with metatables is not supported, unless they are explicitly handled by the save data manager. (e.g. TypeScriptToLua Maps, TypeScriptToLua Sets, etc.)")
30495
30548
  end
30496
30549
  function deepCopyUserdata(self, value, serializationType, traversalDescription)
30497
- if SAVE_DATA_MANAGER_DEBUG then
30498
- log(nil, "deepCopy is copying userdata.")
30499
- end
30500
30550
  local classType = getIsaacAPIClassName(nil, value)
30501
30551
  if classType == nil then
30502
30552
  error("The deep copy function was not able to derive the Isaac API class type for: " .. traversalDescription)
30503
30553
  end
30504
- if not COPYABLE_ISAAC_API_CLASS_TYPES_SET:has(classType) then
30505
- error((("The deep copy function does not support copying \"" .. traversalDescription) .. "\", since it is an Isaac API class of type: ") .. classType)
30554
+ if not isCopyableIsaacAPIClass(nil, value) then
30555
+ error((("The deep copy function does not support serializing \"" .. traversalDescription) .. "\", since it is an Isaac API class of type: ") .. classType)
30506
30556
  end
30507
30557
  repeat
30508
30558
  local ____switch99 = serializationType
@@ -30521,15 +30571,12 @@ function deepCopyUserdata(self, value, serializationType, traversalDescription)
30521
30571
  ____cond99 = ____cond99 or ____switch99 == SerializationType.DESERIALIZE
30522
30572
  if ____cond99 then
30523
30573
  do
30524
- return deserializeIsaacAPIClass(nil, value)
30574
+ error(("The deep copy function can not deserialize \"" .. traversalDescription) .. "\", since it is userdata.")
30525
30575
  end
30576
+ break
30526
30577
  end
30527
30578
  until true
30528
30579
  end
30529
- COPYABLE_ISAAC_API_CLASS_TYPES_SET = __TS__New(
30530
- Set,
30531
- getEnumValues(nil, CopyableIsaacAPIClassType)
30532
- )
30533
30580
  return ____exports
30534
30581
  end,
30535
30582
  ["src.interfaces.SaveData"] = function(...)
@@ -31937,7 +31984,7 @@ local ____flag = require("src.functions.flag")
31937
31984
  local hasFlag = ____flag.hasFlag
31938
31985
  --- Helper function to get the actual bit flag for modded curses.
31939
31986
  --
31940
- -- Will throw a runtime error if the provided curse does not exist.
31987
+ -- Will throw a run-time error if the provided curse does not exist.
31941
31988
  --
31942
31989
  -- Use this over the `Isaac.GetCurseIdByName` method because that will return an integer instead of
31943
31990
  -- a bit flag.
@@ -45571,16 +45618,21 @@ end
45571
45618
  -- Specifically, this will clear the current room of all entities and grid entities, and then spawn
45572
45619
  -- all of the entries and grid entities in the provided JSON room.
45573
45620
  --
45621
+ -- You can create JSON rooms by using the `convert-xml-to-json` tool (e.g. `npx convert-xml-to-json
45622
+ -- my-rooms.xml`).
45623
+ --
45574
45624
  -- This function is meant to be used in the `POST_NEW_ROOM` callback.
45575
45625
  --
45576
45626
  -- For example:
45577
45627
  --
45578
45628
  -- ```ts
45579
45629
  --
45580
- -- import customRooms from "./customRooms";
45630
+ -- import customRooms from "./customRooms.json";
45581
45631
  --
45582
- -- const firstJSONRoom = customRooms.rooms.room[0];
45583
- -- deployJSONRoom(firstJSONRoom);
45632
+ -- export function postNewRoom(): void {
45633
+ -- const firstJSONRoom = customRooms.rooms.room[0];
45634
+ -- deployJSONRoom(firstJSONRoom);
45635
+ -- }
45584
45636
  -- ```
45585
45637
  --
45586
45638
  -- @param jsonRoom The JSON room to deploy. *
@@ -45618,6 +45670,9 @@ end
45618
45670
  -- Specifically, this will clear the current room of all entities and grid entities, and then spawn
45619
45671
  -- all of the entries and grid entities in one of the provided JSON rooms.
45620
45672
  --
45673
+ -- You can create JSON rooms by using the `convert-xml-to-json` tool (e.g. `npx convert-xml-to-json
45674
+ -- my-rooms.xml`).
45675
+ --
45621
45676
  -- This function is meant to be used in the `POST_NEW_ROOM` callback.
45622
45677
  --
45623
45678
  -- Note that this function does not simply choose a random element in the provided array; it will
@@ -45627,10 +45682,12 @@ end
45627
45682
  -- For example:
45628
45683
  --
45629
45684
  -- ```ts
45630
- -- import customRooms from "./customRooms";
45685
+ -- import customRooms from "./customRooms.json";
45631
45686
  --
45632
- -- const jsonRooms = customRooms.rooms.room;
45633
- -- deployRandomJSONRoom(jsonRooms);
45687
+ -- export function postNewRoom(): void {
45688
+ -- const jsonRooms = customRooms.rooms.room;
45689
+ -- deployRandomJSONRoom(jsonRooms);
45690
+ -- }
45634
45691
  -- ```
45635
45692
  --
45636
45693
  -- @param jsonRooms An array of JSON rooms to randomly select from. In practice, this will be
@@ -46846,7 +46903,7 @@ return ____exports
46846
46903
  ["package"] = function(...)
46847
46904
  return {
46848
46905
  name = "isaacscript-common",
46849
- version = "10.0.1",
46906
+ version = "10.0.2",
46850
46907
  description = "Helper functions and features for IsaacScript mods.",
46851
46908
  keywords = {"isaac", "rebirth", "afterbirth", "repentance"},
46852
46909
  homepage = "https://isaacscript.github.io/",
@@ -46857,7 +46914,7 @@ return {
46857
46914
  type = "commonjs",
46858
46915
  main = "dist/src/index",
46859
46916
  types = "dist/src/index.d.ts",
46860
- dependencies = {["isaac-typescript-definitions"] = "^7.0.0"}
46917
+ dependencies = {["isaac-typescript-definitions"] = "^7.2.0"}
46861
46918
  }
46862
46919
  end,
46863
46920
  ["src.functions.map"] = function(...)
@@ -48334,8 +48391,7 @@ function copiedObjectHasKeyAndValueString(self)
48334
48391
  local keyToLookFor = "abc"
48335
48392
  local valueToLookFor = "def"
48336
48393
  local oldObject = {abc = valueToLookFor}
48337
- local newTable = deepCopy(nil, oldObject, SerializationType.NONE, "copiedObjectHasKeyAndValueString")
48338
- local newObject = newTable
48394
+ local newObject = deepCopy(nil, oldObject, SerializationType.NONE, "copiedObjectHasKeyAndValueString")
48339
48395
  local value = newObject[keyToLookFor]
48340
48396
  if value == nil then
48341
48397
  error("The copied object did not have a key of: " .. keyToLookFor)
@@ -48352,8 +48408,7 @@ function copiedTableHasKeyAndValueNumber(self)
48352
48408
  local valueToLookFor = 456
48353
48409
  local oldTable = {}
48354
48410
  oldTable[keyToLookFor] = valueToLookFor
48355
- local newObject = deepCopy(nil, oldTable, SerializationType.NONE, "copiedTableHasKeyAndValueNumber")
48356
- local newTable = newObject
48411
+ local newTable = deepCopy(nil, oldTable, SerializationType.NONE, "copiedTableHasKeyAndValueNumber")
48357
48412
  local value = newTable[keyToLookFor]
48358
48413
  if value == nil then
48359
48414
  error("The copied object did not have a key of: " .. tostring(keyToLookFor))
@@ -48370,8 +48425,7 @@ function copiedTableDoesNotCoerceTypes(self)
48370
48425
  local valueToLookFor = 456
48371
48426
  local oldTable = {}
48372
48427
  oldTable[keyToLookFor] = valueToLookFor
48373
- local newObject = deepCopy(nil, oldTable, SerializationType.NONE, "copiedTableDoesNotCoerceTypes")
48374
- local newTable = newObject
48428
+ local newTable = deepCopy(nil, oldTable, SerializationType.NONE, "copiedTableDoesNotCoerceTypes")
48375
48429
  local keyString = tostring(keyToLookFor)
48376
48430
  local valueString = tostring(valueToLookFor)
48377
48431
  local valueFromString = newTable[keyString]
@@ -48387,8 +48441,7 @@ function copiedObjectHasNoReferencesForPrimitivesForward(self)
48387
48441
  local originalStringValue = "abcdef"
48388
48442
  local originalNumberValue = 123
48389
48443
  local oldObject = {abc = originalStringValue, def = originalNumberValue}
48390
- local newTable = deepCopy(nil, oldObject, SerializationType.NONE, "copiedObjectHasNoReferencesForPrimitivesForward")
48391
- local newObject = newTable
48444
+ local newObject = deepCopy(nil, oldObject, SerializationType.NONE, "copiedObjectHasNoReferencesForPrimitivesForward")
48392
48445
  oldObject.abc = "newValue"
48393
48446
  if oldObject.abc == newObject.abc then
48394
48447
  error("The copied object has a string reference going forward.")
@@ -48402,8 +48455,7 @@ function copiedObjectHasNoReferencesForPrimitivesBackward(self)
48402
48455
  local originalStringValue = "abcdef"
48403
48456
  local originalNumberValue = 123
48404
48457
  local oldObject = {abc = originalStringValue, def = originalNumberValue}
48405
- local newTable = deepCopy(nil, oldObject, SerializationType.NONE, "copiedObjectHasNoReferencesForPrimitivesBackward")
48406
- local newObject = newTable
48458
+ local newObject = deepCopy(nil, oldObject, SerializationType.NONE, "copiedObjectHasNoReferencesForPrimitivesBackward")
48407
48459
  newObject.abc = "newValue"
48408
48460
  if newObject.abc == oldObject.abc then
48409
48461
  error("The copied object has a string reference going backward.")
@@ -48415,8 +48467,7 @@ function copiedObjectHasNoReferencesForPrimitivesBackward(self)
48415
48467
  end
48416
48468
  function copiedObjectHasNoReferencesForArray(self)
48417
48469
  local oldObject = {abc = {1, 2, 3}}
48418
- local newTable = deepCopy(nil, oldObject, SerializationType.NONE, "copiedObjectHasNoReferencesForArray")
48419
- local newObject = newTable
48470
+ local newObject = deepCopy(nil, oldObject, SerializationType.NONE, "copiedObjectHasNoReferencesForArray")
48420
48471
  if oldObject.abc == newObject.abc then
48421
48472
  error("The copied object has the same point to the child array.")
48422
48473
  end
@@ -48443,8 +48494,7 @@ function copiedObjectHasChildObject(self)
48443
48494
  local keyToLookFor = "def"
48444
48495
  local valueToLookFor = "ghi"
48445
48496
  local oldObject = {abc = {def = valueToLookFor}}
48446
- local newTable = deepCopy(nil, oldObject, SerializationType.NONE, "copiedObjectHasChildObject")
48447
- local newObject = newTable
48497
+ local newObject = deepCopy(nil, oldObject, SerializationType.NONE, "copiedObjectHasChildObject")
48448
48498
  local childObject = newObject[childObjectIndex]
48449
48499
  if childObject == nil then
48450
48500
  error("Failed to find the child object at index: " .. childObjectIndex)
@@ -48468,8 +48518,7 @@ function copiedMapIsMap(self)
48468
48518
  local valueToLookFor = "def"
48469
48519
  local oldMap = __TS__New(Map)
48470
48520
  oldMap:set(keyToLookFor, valueToLookFor)
48471
- local newObject = deepCopy(nil, oldMap, SerializationType.NONE, "copiedMapIsMap")
48472
- local newMap = newObject
48521
+ local newMap = deepCopy(nil, oldMap, SerializationType.NONE, "copiedMapIsMap")
48473
48522
  if not isTSTLMap(nil, newMap) then
48474
48523
  error("The copied Map was not a Map and has a type of: " .. __TS__TypeOf(newMap))
48475
48524
  end
@@ -48479,8 +48528,7 @@ function copiedMapHasValue(self)
48479
48528
  local valueToLookFor = "def"
48480
48529
  local oldMap = __TS__New(Map)
48481
48530
  oldMap:set(keyToLookFor, valueToLookFor)
48482
- local newTable = deepCopy(nil, oldMap, SerializationType.NONE, "copiedMapHasValue")
48483
- local newMap = newTable
48531
+ local newMap = deepCopy(nil, oldMap, SerializationType.NONE, "copiedMapHasValue")
48484
48532
  if not isTSTLMap(nil, newMap) then
48485
48533
  error("The copied Map was not a Map and has a type of: " .. __TS__TypeOf(newMap))
48486
48534
  end
@@ -48496,8 +48544,7 @@ function copiedSetIsSet(self)
48496
48544
  local valueToLookFor = "abc"
48497
48545
  local oldSet = __TS__New(Set)
48498
48546
  oldSet:add(valueToLookFor)
48499
- local newTable = deepCopy(nil, oldSet, SerializationType.NONE, "copiedSetIsSet")
48500
- local newSet = newTable
48547
+ local newSet = deepCopy(nil, oldSet, SerializationType.NONE, "copiedSetIsSet")
48501
48548
  if not isTSTLSet(nil, newSet) then
48502
48549
  error("The copied Set was not a Set and has a type of: " .. __TS__TypeOf(newSet))
48503
48550
  end
@@ -48506,8 +48553,7 @@ function copiedSetHasValue(self)
48506
48553
  local valueToLookFor = "abc"
48507
48554
  local oldSet = __TS__New(Set)
48508
48555
  oldSet:add(valueToLookFor)
48509
- local newTable = deepCopy(nil, oldSet, SerializationType.NONE, "copiedSetHasValue")
48510
- local newSet = newTable
48556
+ local newSet = deepCopy(nil, oldSet, SerializationType.NONE, "copiedSetHasValue")
48511
48557
  if not isTSTLSet(nil, newSet) then
48512
48558
  error("The copied Set was not a Set and has a type of: " .. __TS__TypeOf(newSet))
48513
48559
  end
@@ -48524,8 +48570,7 @@ function copiedMapHasChildMap(self)
48524
48570
  local keyToLookFor = "childMap"
48525
48571
  local oldMap = __TS__New(Map)
48526
48572
  oldMap:set(keyToLookFor, oldChildMap)
48527
- local newTable = deepCopy(nil, oldMap, SerializationType.NONE, "copiedMapHasChildMap")
48528
- local newMap = newTable
48573
+ local newMap = deepCopy(nil, oldMap, SerializationType.NONE, "copiedMapHasChildMap")
48529
48574
  if not isTSTLMap(nil, newMap) then
48530
48575
  error("The copied Map was not a Map and had a type of: " .. __TS__TypeOf(newMap))
48531
48576
  end
@@ -48557,8 +48602,7 @@ function copiedDefaultMapHasChildDefaultMap(self)
48557
48602
  local oldChildMap = oldParentMap:getAndSetDefault(parentMapKey)
48558
48603
  oldChildMap:getAndSetDefault(childMapKey1)
48559
48604
  oldChildMap:set(childMapKey2, childMapCustomValue)
48560
- local newTable = deepCopy(nil, oldParentMap, SerializationType.NONE, "copiedDefaultMapHasChildDefaultMap")
48561
- local newParentMap = newTable
48605
+ local newParentMap = deepCopy(nil, oldParentMap, SerializationType.NONE, "copiedDefaultMapHasChildDefaultMap")
48562
48606
  if not isDefaultMap(nil, newParentMap) then
48563
48607
  error("The copied parent DefaultMap was not a DefaultMap and had a type of: " .. __TS__TypeOf(newParentMap))
48564
48608
  end
@@ -54833,6 +54877,47 @@ function ____exports.getVanillaTrinketSet(self)
54833
54877
  lazyInitVanillaTrinketTypes(nil)
54834
54878
  return VANILLA_TRINKET_TYPES_SET
54835
54879
  end
54880
+ return ____exports
54881
+ end,
54882
+ ["src.types.WeightedArray"] = function(...)
54883
+ local ____exports = {}
54884
+ return ____exports
54885
+ end,
54886
+ ["src.functions.weighted"] = function(...)
54887
+ local ____lualib = require("lualib_bundle")
54888
+ local __TS__ArrayMap = ____lualib.__TS__ArrayMap
54889
+ local ____exports = {}
54890
+ local ____array = require("src.functions.array")
54891
+ local arrayToString = ____array.arrayToString
54892
+ local sumArray = ____array.sumArray
54893
+ local ____random = require("src.functions.random")
54894
+ local getRandomFloat = ____random.getRandomFloat
54895
+ local ____rng = require("src.functions.rng")
54896
+ local getRandomSeed = ____rng.getRandomSeed
54897
+ --- Get a random value from a `WeightedArray`. (The second element in the array is the weight.)
54898
+ function ____exports.getRandomFromWeightedArray(self, weightedArray, seedOrRNG)
54899
+ if seedOrRNG == nil then
54900
+ seedOrRNG = getRandomSeed(nil)
54901
+ end
54902
+ if #weightedArray == 0 then
54903
+ error("Failed to get a random element from a weighted array since the provided array was empty.")
54904
+ end
54905
+ local weights = __TS__ArrayMap(
54906
+ weightedArray,
54907
+ function(____, tuple) return tuple[2] end
54908
+ )
54909
+ local totalWeight = sumArray(nil, weights)
54910
+ local randomWeight = getRandomFloat(nil, 0, totalWeight, seedOrRNG)
54911
+ local weightAccumulator = 0
54912
+ for ____, tuple in ipairs(weightedArray) do
54913
+ local element, weight = table.unpack(tuple)
54914
+ weightAccumulator = weightAccumulator + weight
54915
+ if weightAccumulator >= randomWeight then
54916
+ return element
54917
+ end
54918
+ end
54919
+ error("Failed to get a random element from a weighted array: " .. arrayToString(nil, weightedArray))
54920
+ end
54836
54921
  return ____exports
54837
54922
  end,
54838
54923
  ["src.objects.colors"] = function(...)
@@ -56096,6 +56181,14 @@ do
56096
56181
  end
56097
56182
  end
56098
56183
  end
56184
+ do
56185
+ local ____export = require("src.functions.weighted")
56186
+ for ____exportKey, ____exportValue in pairs(____export) do
56187
+ if ____exportKey ~= "default" then
56188
+ ____exports[____exportKey] = ____exportValue
56189
+ end
56190
+ end
56191
+ end
56099
56192
  do
56100
56193
  local ____export = require("src.maps.cardNameToTypeMap")
56101
56194
  for ____exportKey, ____exportValue in pairs(____export) do
package/dist/package.lua CHANGED
@@ -1,6 +1,6 @@
1
1
  return {
2
2
  name = "isaacscript-common",
3
- version = "10.0.1",
3
+ version = "10.0.2",
4
4
  description = "Helper functions and features for IsaacScript mods.",
5
5
  keywords = {"isaac", "rebirth", "afterbirth", "repentance"},
6
6
  homepage = "https://isaacscript.github.io/",
@@ -11,5 +11,5 @@ return {
11
11
  type = "commonjs",
12
12
  main = "dist/src/index",
13
13
  types = "dist/src/index.d.ts",
14
- dependencies = {["isaac-typescript-definitions"] = "^7.0.0"}
14
+ dependencies = {["isaac-typescript-definitions"] = "^7.2.0"}
15
15
  }
@@ -6,16 +6,21 @@ import { JSONRoom } from "../interfaces/JSONRoomsFile";
6
6
  * Specifically, this will clear the current room of all entities and grid entities, and then spawn
7
7
  * all of the entries and grid entities in the provided JSON room.
8
8
  *
9
+ * You can create JSON rooms by using the `convert-xml-to-json` tool (e.g. `npx convert-xml-to-json
10
+ * my-rooms.xml`).
11
+ *
9
12
  * This function is meant to be used in the `POST_NEW_ROOM` callback.
10
13
  *
11
14
  * For example:
12
15
  *
13
16
  * ```ts
14
17
  *
15
- * import customRooms from "./customRooms";
18
+ * import customRooms from "./customRooms.json";
16
19
  *
17
- * const firstJSONRoom = customRooms.rooms.room[0];
18
- * deployJSONRoom(firstJSONRoom);
20
+ * export function postNewRoom(): void {
21
+ * const firstJSONRoom = customRooms.rooms.room[0];
22
+ * deployJSONRoom(firstJSONRoom);
23
+ * }
19
24
  * ```
20
25
  *
21
26
  * @param jsonRoom The JSON room to deploy. *
@@ -30,6 +35,9 @@ export declare function deployJSONRoom(jsonRoom: JSONRoom | Readonly<JSONRoom>,
30
35
  * Specifically, this will clear the current room of all entities and grid entities, and then spawn
31
36
  * all of the entries and grid entities in one of the provided JSON rooms.
32
37
  *
38
+ * You can create JSON rooms by using the `convert-xml-to-json` tool (e.g. `npx convert-xml-to-json
39
+ * my-rooms.xml`).
40
+ *
33
41
  * This function is meant to be used in the `POST_NEW_ROOM` callback.
34
42
  *
35
43
  * Note that this function does not simply choose a random element in the provided array; it will
@@ -39,10 +47,12 @@ export declare function deployJSONRoom(jsonRoom: JSONRoom | Readonly<JSONRoom>,
39
47
  * For example:
40
48
  *
41
49
  * ```ts
42
- * import customRooms from "./customRooms";
50
+ * import customRooms from "./customRooms.json";
43
51
  *
44
- * const jsonRooms = customRooms.rooms.room;
45
- * deployRandomJSONRoom(jsonRooms);
52
+ * export function postNewRoom(): void {
53
+ * const jsonRooms = customRooms.rooms.room;
54
+ * deployRandomJSONRoom(jsonRooms);
55
+ * }
46
56
  * ```
47
57
  *
48
58
  * @param jsonRooms An array of JSON rooms to randomly select from. In practice, this will be
@@ -1 +1 @@
1
- {"version":3,"file":"deployJSONRoom.d.ts","sourceRoot":"","sources":["../../../src/features/deployJSONRoom.ts"],"names":[],"mappings":";;AAuDA,OAAO,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AAuKvD;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,cAAc,CAC5B,QAAQ,EAAE,QAAQ,GAAG,QAAQ,CAAC,QAAQ,CAAC,EACvC,SAAS,GAAE,IAAI,GAAG,GAAqB,EACvC,OAAO,UAAQ,GACd,IAAI,CAuBN;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAgB,oBAAoB,CAClC,SAAS,EAAE,QAAQ,EAAE,GAAG,SAAS,QAAQ,EAAE,EAC3C,SAAS,GAAE,IAAI,GAAG,GAAqB,EACvC,OAAO,UAAQ,GACd,IAAI,CAaN;AAED;;;;;;;;;GASG;AACH,wBAAgB,SAAS,CAAC,mBAAmB,EAAE,OAAO,GAAG,IAAI,CAwB5D"}
1
+ {"version":3,"file":"deployJSONRoom.d.ts","sourceRoot":"","sources":["../../../src/features/deployJSONRoom.ts"],"names":[],"mappings":";;AAuDA,OAAO,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AAuKvD;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,wBAAgB,cAAc,CAC5B,QAAQ,EAAE,QAAQ,GAAG,QAAQ,CAAC,QAAQ,CAAC,EACvC,SAAS,GAAE,IAAI,GAAG,GAAqB,EACvC,OAAO,UAAQ,GACd,IAAI,CAuBN;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,wBAAgB,oBAAoB,CAClC,SAAS,EAAE,QAAQ,EAAE,GAAG,SAAS,QAAQ,EAAE,EAC3C,SAAS,GAAE,IAAI,GAAG,GAAqB,EACvC,OAAO,UAAQ,GACd,IAAI,CAaN;AAED;;;;;;;;;GASG;AACH,wBAAgB,SAAS,CAAC,mBAAmB,EAAE,OAAO,GAAG,IAAI,CAwB5D"}