isaacscript-common 4.0.2 → 4.0.5

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 (370) hide show
  1. package/callbacks/postPlayerCollectible.lua +4 -2
  2. package/functions/collectibleSet.d.ts +37 -2
  3. package/functions/collectibleSet.lua +62 -15
  4. package/functions/player.lua +3 -4
  5. package/package.json +2 -2
  6. package/cachedClasses.ts +0 -39
  7. package/callbacks/customRevive.ts +0 -215
  8. package/callbacks/itemPickup.ts +0 -101
  9. package/callbacks/postAmbush.ts +0 -73
  10. package/callbacks/postBombExploded.ts +0 -26
  11. package/callbacks/postBombInitLate.ts +0 -36
  12. package/callbacks/postBoneSwing.ts +0 -64
  13. package/callbacks/postCollectibleInitFirst.ts +0 -40
  14. package/callbacks/postCursedTeleport.ts +0 -185
  15. package/callbacks/postCustomDoorEnter.ts +0 -292
  16. package/callbacks/postDiceRoomActivated.ts +0 -60
  17. package/callbacks/postDoorRender.ts +0 -26
  18. package/callbacks/postDoorUpdate.ts +0 -26
  19. package/callbacks/postEffectInitLate.ts +0 -36
  20. package/callbacks/postEffectStateChanged.ts +0 -43
  21. package/callbacks/postEsauJr.ts +0 -109
  22. package/callbacks/postFamiliarInitLate.ts +0 -36
  23. package/callbacks/postFamiliarStateChanged.ts +0 -43
  24. package/callbacks/postFlip.ts +0 -90
  25. package/callbacks/postGreedModeWave.ts +0 -41
  26. package/callbacks/postGridEntity.ts +0 -164
  27. package/callbacks/postGridEntityCollision.ts +0 -69
  28. package/callbacks/postGridEntityRender.ts +0 -26
  29. package/callbacks/postHolyMantleRemoved.ts +0 -55
  30. package/callbacks/postItemDischarged.ts +0 -154
  31. package/callbacks/postKnifeInitLate.ts +0 -36
  32. package/callbacks/postLaserInitLate.ts +0 -36
  33. package/callbacks/postNPCInitLate.ts +0 -36
  34. package/callbacks/postNPCStateChanged.ts +0 -42
  35. package/callbacks/postNewRoomEarly.ts +0 -96
  36. package/callbacks/postPickupCollect.ts +0 -48
  37. package/callbacks/postPickupInitFirst.ts +0 -70
  38. package/callbacks/postPickupInitLate.ts +0 -36
  39. package/callbacks/postPickupStateChanged.ts +0 -43
  40. package/callbacks/postPitRender.ts +0 -26
  41. package/callbacks/postPitUpdate.ts +0 -26
  42. package/callbacks/postPlayerChangeHealth.ts +0 -62
  43. package/callbacks/postPlayerChangeType.ts +0 -56
  44. package/callbacks/postPlayerCollectible.ts +0 -113
  45. package/callbacks/postPlayerFatalDamage.ts +0 -141
  46. package/callbacks/postPlayerInitLate.ts +0 -37
  47. package/callbacks/postPlayerReordered.ts +0 -142
  48. package/callbacks/postPoopRender.ts +0 -26
  49. package/callbacks/postPoopUpdate.ts +0 -26
  50. package/callbacks/postPressurePlateRender.ts +0 -26
  51. package/callbacks/postPressurePlateUpdate.ts +0 -26
  52. package/callbacks/postProjectileInitLate.ts +0 -36
  53. package/callbacks/postPurchase.ts +0 -64
  54. package/callbacks/postRockRender.ts +0 -26
  55. package/callbacks/postRockUpdate.ts +0 -26
  56. package/callbacks/postRoomClearChanged.ts +0 -57
  57. package/callbacks/postSacrifice.ts +0 -64
  58. package/callbacks/postSlotDestroyed.ts +0 -92
  59. package/callbacks/postSlotInitUpdate.ts +0 -68
  60. package/callbacks/postSlotRender.ts +0 -69
  61. package/callbacks/postSpikesRender.ts +0 -26
  62. package/callbacks/postSpikesUpdate.ts +0 -26
  63. package/callbacks/postTNTRender.ts +0 -26
  64. package/callbacks/postTNTUpdate.ts +0 -26
  65. package/callbacks/postTearInitLate.ts +0 -36
  66. package/callbacks/postTearInitVeryLate.ts +0 -41
  67. package/callbacks/postTransformation.ts +0 -59
  68. package/callbacks/postTrinketBreak.ts +0 -112
  69. package/callbacks/preBerserkDeath.ts +0 -49
  70. package/callbacks/preNewLevel.ts +0 -55
  71. package/callbacks/reorderedCallbacks.ts +0 -168
  72. package/callbacks/subscriptions/postAmbushFinished.ts +0 -32
  73. package/callbacks/subscriptions/postAmbushStarted.ts +0 -32
  74. package/callbacks/subscriptions/postBombInitLate.ts +0 -32
  75. package/callbacks/subscriptions/postBoneExploded.ts +0 -32
  76. package/callbacks/subscriptions/postBoneSwing.ts +0 -24
  77. package/callbacks/subscriptions/postCollectibleInitFirst.ts +0 -37
  78. package/callbacks/subscriptions/postCursedTeleport.ts +0 -24
  79. package/callbacks/subscriptions/postCustomDoorEnter.ts +0 -45
  80. package/callbacks/subscriptions/postCustomRevive.ts +0 -36
  81. package/callbacks/subscriptions/postDiceRoomActivated.ts +0 -38
  82. package/callbacks/subscriptions/postDoorRender.ts +0 -35
  83. package/callbacks/subscriptions/postDoorUpdate.ts +0 -35
  84. package/callbacks/subscriptions/postEffectInitLate.ts +0 -32
  85. package/callbacks/subscriptions/postEffectStateChanged.ts +0 -40
  86. package/callbacks/subscriptions/postEsauJr.ts +0 -24
  87. package/callbacks/subscriptions/postFamiliarInitLate.ts +0 -32
  88. package/callbacks/subscriptions/postFamiliarStateChanged.ts +0 -40
  89. package/callbacks/subscriptions/postFirstEsauJr.ts +0 -24
  90. package/callbacks/subscriptions/postFirstFlip.ts +0 -24
  91. package/callbacks/subscriptions/postFlip.ts +0 -22
  92. package/callbacks/subscriptions/postGameStartedReordered.ts +0 -24
  93. package/callbacks/subscriptions/postGreedModeWave.ts +0 -24
  94. package/callbacks/subscriptions/postGridEntityBroken.ts +0 -51
  95. package/callbacks/subscriptions/postGridEntityCollision.ts +0 -54
  96. package/callbacks/subscriptions/postGridEntityInit.ts +0 -51
  97. package/callbacks/subscriptions/postGridEntityRemove.ts +0 -52
  98. package/callbacks/subscriptions/postGridEntityRender.ts +0 -51
  99. package/callbacks/subscriptions/postGridEntityStateChanged.ts +0 -55
  100. package/callbacks/subscriptions/postGridEntityUpdate.ts +0 -51
  101. package/callbacks/subscriptions/postHolyMantleRemoved.ts +0 -48
  102. package/callbacks/subscriptions/postItemDischarged.ts +0 -43
  103. package/callbacks/subscriptions/postItemPickup.ts +0 -64
  104. package/callbacks/subscriptions/postKnifeInitLate.ts +0 -32
  105. package/callbacks/subscriptions/postLaserInitLate.ts +0 -32
  106. package/callbacks/subscriptions/postNPCInitLate.ts +0 -32
  107. package/callbacks/subscriptions/postNPCStateChanged.ts +0 -42
  108. package/callbacks/subscriptions/postNewLevelReordered.ts +0 -22
  109. package/callbacks/subscriptions/postNewRoomEarly.ts +0 -22
  110. package/callbacks/subscriptions/postNewRoomReordered.ts +0 -22
  111. package/callbacks/subscriptions/postPEffectUpdateReordered.ts +0 -40
  112. package/callbacks/subscriptions/postPickupCollect.ts +0 -35
  113. package/callbacks/subscriptions/postPickupInitFirst.ts +0 -32
  114. package/callbacks/subscriptions/postPickupInitLate.ts +0 -32
  115. package/callbacks/subscriptions/postPickupStateChanged.ts +0 -40
  116. package/callbacks/subscriptions/postPitRender.ts +0 -35
  117. package/callbacks/subscriptions/postPitUpdate.ts +0 -35
  118. package/callbacks/subscriptions/postPlayerChangeHealth.ts +0 -49
  119. package/callbacks/subscriptions/postPlayerChangeType.ts +0 -40
  120. package/callbacks/subscriptions/postPlayerCollectibleAdded.ts +0 -38
  121. package/callbacks/subscriptions/postPlayerCollectibleRemoved.ts +0 -38
  122. package/callbacks/subscriptions/postPlayerFatalDamage.ts +0 -68
  123. package/callbacks/subscriptions/postPlayerInitLate.ts +0 -40
  124. package/callbacks/subscriptions/postPlayerInitReordered.ts +0 -40
  125. package/callbacks/subscriptions/postPlayerRenderReordered.ts +0 -40
  126. package/callbacks/subscriptions/postPlayerUpdateReordered.ts +0 -40
  127. package/callbacks/subscriptions/postPoopRender.ts +0 -35
  128. package/callbacks/subscriptions/postPoopUpdate.ts +0 -35
  129. package/callbacks/subscriptions/postPressurePlateRender.ts +0 -37
  130. package/callbacks/subscriptions/postPressurePlateUpdate.ts +0 -37
  131. package/callbacks/subscriptions/postProjectileInitLate.ts +0 -35
  132. package/callbacks/subscriptions/postPurchase.ts +0 -31
  133. package/callbacks/subscriptions/postRockRender.ts +0 -35
  134. package/callbacks/subscriptions/postRockUpdate.ts +0 -35
  135. package/callbacks/subscriptions/postRoomClearChanged.ts +0 -30
  136. package/callbacks/subscriptions/postSacrifice.ts +0 -43
  137. package/callbacks/subscriptions/postSlotAnimationChanged.ts +0 -40
  138. package/callbacks/subscriptions/postSlotDestroyed.ts +0 -55
  139. package/callbacks/subscriptions/postSlotInit.ts +0 -32
  140. package/callbacks/subscriptions/postSlotRender.ts +0 -32
  141. package/callbacks/subscriptions/postSlotUpdate.ts +0 -32
  142. package/callbacks/subscriptions/postSpikesRender.ts +0 -35
  143. package/callbacks/subscriptions/postSpikesUpdate.ts +0 -35
  144. package/callbacks/subscriptions/postTNTRender.ts +0 -35
  145. package/callbacks/subscriptions/postTNTUpdate.ts +0 -35
  146. package/callbacks/subscriptions/postTearInitLate.ts +0 -32
  147. package/callbacks/subscriptions/postTearInitVeryLate.ts +0 -32
  148. package/callbacks/subscriptions/postTransformation.ts +0 -40
  149. package/callbacks/subscriptions/postTrinketBreak.ts +0 -38
  150. package/callbacks/subscriptions/preBerserkDeath.ts +0 -42
  151. package/callbacks/subscriptions/preCustomRevive.ts +0 -46
  152. package/callbacks/subscriptions/preItemPickup.ts +0 -64
  153. package/callbacks/subscriptions/preNewLevel.ts +0 -24
  154. package/classes/DefaultMap.ts +0 -174
  155. package/classes/ModUpgraded.ts +0 -84
  156. package/constants.ts +0 -162
  157. package/constantsFirstLast.ts +0 -217
  158. package/enums/AmbushType.ts +0 -4
  159. package/enums/HealthType.ts +0 -16
  160. package/enums/ModCallbackCustom.ts +0 -1278
  161. package/enums/PocketItemType.ts +0 -8
  162. package/enums/SerializationType.ts +0 -5
  163. package/enums/SlotDestructionType.ts +0 -4
  164. package/enums/private/CopyableIsaacAPIClassType.ts +0 -7
  165. package/enums/private/SaveDataKey.ts +0 -14
  166. package/enums/private/SerializationBrand.ts +0 -42
  167. package/features/characterHealthConversion.ts +0 -111
  168. package/features/characterStats.ts +0 -61
  169. package/features/debugDisplay/debugDisplay.ts +0 -221
  170. package/features/debugDisplay/exports.ts +0 -368
  171. package/features/debugDisplay/v.ts +0 -65
  172. package/features/deployJSONRoom.ts +0 -743
  173. package/features/disableInputs.ts +0 -193
  174. package/features/disableSound.ts +0 -77
  175. package/features/extraConsoleCommands/commandsDisplay.ts +0 -290
  176. package/features/extraConsoleCommands/commandsSubroutines.ts +0 -139
  177. package/features/extraConsoleCommands/init.ts +0 -334
  178. package/features/extraConsoleCommands/listCommands.ts +0 -1299
  179. package/features/extraConsoleCommands/v.ts +0 -14
  180. package/features/fadeInRemover.ts +0 -60
  181. package/features/fastReset.ts +0 -75
  182. package/features/forgottenSwitch.ts +0 -50
  183. package/features/getCollectibleItemPoolType.ts +0 -66
  184. package/features/persistentEntities.ts +0 -183
  185. package/features/playerInventory.ts +0 -135
  186. package/features/ponyDetection.ts +0 -74
  187. package/features/preventCollectibleRotation.ts +0 -115
  188. package/features/runInNFrames.ts +0 -148
  189. package/features/saveDataManager/constants.ts +0 -4
  190. package/features/saveDataManager/exports.ts +0 -229
  191. package/features/saveDataManager/load.ts +0 -99
  192. package/features/saveDataManager/main.ts +0 -195
  193. package/features/saveDataManager/maps.ts +0 -13
  194. package/features/saveDataManager/merge.ts +0 -194
  195. package/features/saveDataManager/save.ts +0 -74
  196. package/features/saveDataManager/serializationBrand.ts +0 -16
  197. package/features/sirenHelpers.ts +0 -129
  198. package/features/taintedLazarusPlayers.ts +0 -113
  199. package/featuresInitialized.ts +0 -20
  200. package/functions/ambush.ts +0 -47
  201. package/functions/array.ts +0 -410
  202. package/functions/benchmark.ts +0 -36
  203. package/functions/bitwise.ts +0 -24
  204. package/functions/bombs.ts +0 -12
  205. package/functions/boss.ts +0 -227
  206. package/functions/cacheFlag.ts +0 -12
  207. package/functions/cards.ts +0 -271
  208. package/functions/challenges.ts +0 -13
  209. package/functions/character.ts +0 -126
  210. package/functions/charge.ts +0 -237
  211. package/functions/chargeBar.ts +0 -67
  212. package/functions/collectibleCacheFlag.ts +0 -90
  213. package/functions/collectibleSet.ts +0 -56
  214. package/functions/collectibleTag.ts +0 -89
  215. package/functions/collectibles.ts +0 -659
  216. package/functions/color.ts +0 -128
  217. package/functions/debug.ts +0 -68
  218. package/functions/deepCopy.ts +0 -535
  219. package/functions/deepCopyTests.ts +0 -386
  220. package/functions/direction.ts +0 -49
  221. package/functions/doors.ts +0 -347
  222. package/functions/easing.ts +0 -182
  223. package/functions/eden.ts +0 -47
  224. package/functions/effects.ts +0 -20
  225. package/functions/entity.ts +0 -439
  226. package/functions/entitySpecific.ts +0 -889
  227. package/functions/entityTypes.ts +0 -6
  228. package/functions/enums.ts +0 -146
  229. package/functions/familiars.ts +0 -106
  230. package/functions/flag.ts +0 -165
  231. package/functions/flying.ts +0 -117
  232. package/functions/globals.ts +0 -242
  233. package/functions/gridEntity.ts +0 -511
  234. package/functions/gridEntitySpecific.ts +0 -112
  235. package/functions/input.ts +0 -139
  236. package/functions/isaacAPIClass.ts +0 -67
  237. package/functions/jsonHelpers.ts +0 -45
  238. package/functions/jsonRoom.ts +0 -100
  239. package/functions/kColor.ts +0 -129
  240. package/functions/language.ts +0 -13
  241. package/functions/level.ts +0 -31
  242. package/functions/log.ts +0 -720
  243. package/functions/map.ts +0 -56
  244. package/functions/math.ts +0 -149
  245. package/functions/mergeTests.ts +0 -288
  246. package/functions/npc.ts +0 -148
  247. package/functions/pickupVariants.ts +0 -60
  248. package/functions/pickups.ts +0 -499
  249. package/functions/pills.ts +0 -205
  250. package/functions/player.ts +0 -1056
  251. package/functions/playerDataStructures.ts +0 -150
  252. package/functions/playerHealth.ts +0 -382
  253. package/functions/playerIndex.ts +0 -195
  254. package/functions/pocketItems.ts +0 -149
  255. package/functions/positionVelocity.ts +0 -188
  256. package/functions/random.ts +0 -77
  257. package/functions/revive.ts +0 -201
  258. package/functions/rng.ts +0 -172
  259. package/functions/roomData.ts +0 -199
  260. package/functions/roomGrid.ts +0 -109
  261. package/functions/roomShape.ts +0 -80
  262. package/functions/rooms.ts +0 -648
  263. package/functions/run.ts +0 -36
  264. package/functions/saveFile.ts +0 -128
  265. package/functions/seeds.ts +0 -19
  266. package/functions/serialization.ts +0 -91
  267. package/functions/set.ts +0 -95
  268. package/functions/sound.ts +0 -9
  269. package/functions/spawnCollectible.ts +0 -104
  270. package/functions/sprite.ts +0 -107
  271. package/functions/stage.ts +0 -125
  272. package/functions/string.ts +0 -47
  273. package/functions/table.ts +0 -189
  274. package/functions/tears.ts +0 -32
  275. package/functions/transformations.ts +0 -131
  276. package/functions/trinketCacheFlag.ts +0 -60
  277. package/functions/trinketGive.ts +0 -157
  278. package/functions/trinkets.ts +0 -215
  279. package/functions/tstlClass.ts +0 -157
  280. package/functions/types.ts +0 -36
  281. package/functions/ui.ts +0 -138
  282. package/functions/utils.ts +0 -189
  283. package/functions/vector.ts +0 -126
  284. package/index.ts +0 -172
  285. package/initCustomCallbacks.ts +0 -132
  286. package/initFeatures.ts +0 -39
  287. package/interfaces/AddCallbackParameterCustom.ts +0 -188
  288. package/interfaces/ChargeBarSprites.ts +0 -12
  289. package/interfaces/JSONDoor.ts +0 -13
  290. package/interfaces/JSONEntity.ts +0 -16
  291. package/interfaces/JSONRoom.ts +0 -36
  292. package/interfaces/JSONRooms.ts +0 -12
  293. package/interfaces/JSONSpawn.ts +0 -14
  294. package/interfaces/PlayerHealth.ts +0 -16
  295. package/interfaces/PocketItemDescription.ts +0 -9
  296. package/interfaces/SaveData.ts +0 -29
  297. package/interfaces/TrinketSituation.ts +0 -9
  298. package/interfaces/private/TSTLClassMetatable.ts +0 -8
  299. package/maps/PHDPillConversions.ts +0 -21
  300. package/maps/cardMap.ts +0 -209
  301. package/maps/characterMap.ts +0 -87
  302. package/maps/collectibleDescriptionMap.ts +0 -732
  303. package/maps/collectibleNameMap.ts +0 -731
  304. package/maps/defaultPlayerStatMap.ts +0 -17
  305. package/maps/falsePHDPillConversions.ts +0 -35
  306. package/maps/gridEntityTypeToBrokenStateMap.ts +0 -50
  307. package/maps/gridEntityXMLMap.ts +0 -176
  308. package/maps/pillEffectMap.ts +0 -88
  309. package/maps/roomShapeToTopLeftWallGridIndexMap.ts +0 -18
  310. package/maps/roomTypeMap.ts +0 -40
  311. package/maps/trinketDescriptionMap.ts +0 -200
  312. package/maps/trinketNameMap.ts +0 -198
  313. package/objects/LRoomShapeToRectangles.ts +0 -44
  314. package/objects/callbackRegisterFunctions.ts +0 -187
  315. package/objects/cardDescriptions.ts +0 -105
  316. package/objects/cardNames.ts +0 -105
  317. package/objects/cardTypes.ts +0 -104
  318. package/objects/challengeNames.ts +0 -52
  319. package/objects/characterNames.ts +0 -48
  320. package/objects/coinSubTypeToValue.ts +0 -14
  321. package/objects/colors.ts +0 -16
  322. package/objects/directionNames.ts +0 -11
  323. package/objects/directionToDegrees.ts +0 -11
  324. package/objects/directionToVector.ts +0 -12
  325. package/objects/doorSlotFlagToDoorSlot.ts +0 -16
  326. package/objects/doorSlotToDirection.ts +0 -14
  327. package/objects/isaacAPIClassTypeToBrand.ts +0 -11
  328. package/objects/isaacAPIClassTypeToCopyFunction.ts +0 -18
  329. package/objects/languageNames.ts +0 -13
  330. package/objects/oppositeDoorSlots.ts +0 -15
  331. package/objects/pillEffectClasses.ts +0 -63
  332. package/objects/pillEffectNames.ts +0 -57
  333. package/objects/pillEffectTypes.ts +0 -62
  334. package/objects/roomShapeBounds.ts +0 -71
  335. package/objects/roomShapeLayoutSizes.ts +0 -45
  336. package/objects/roomShapeToBottomRightPosition.ts +0 -25
  337. package/objects/roomShapeToDoorSlots.ts +0 -83
  338. package/objects/roomShapeToDoorSlotsToGridIndexDelta.ts +0 -127
  339. package/objects/roomShapeToGridWidth.ts +0 -21
  340. package/objects/roomShapeToTopLeftPosition.ts +0 -26
  341. package/objects/roomShapeVolumes.ts +0 -38
  342. package/objects/roomTypeNames.ts +0 -36
  343. package/objects/serializedIsaacAPIClassTypeToIdentityFunction.ts +0 -14
  344. package/objects/stageTypeToLetter.ts +0 -15
  345. package/objects/transformationNames.ts +0 -18
  346. package/patchErrorFunctions.ts +0 -92
  347. package/sets/LRoomShapesSet.ts +0 -8
  348. package/sets/bossSets.ts +0 -470
  349. package/sets/charactersThatStartWithAnActiveItemSet.ts +0 -16
  350. package/sets/charactersWithBlackHeartFromEternalHeartSet.ts +0 -7
  351. package/sets/charactersWithFreeDevilDealsSet.ts +0 -4
  352. package/sets/charactersWithNoRedHeartsSet.ts +0 -17
  353. package/sets/charactersWithNoSoulHeartsSet.ts +0 -14
  354. package/sets/chestPickupVariantsSet.ts +0 -16
  355. package/sets/familiarsThatShootPlayerTearsSet.ts +0 -13
  356. package/sets/lostStyleCharactersSet.ts +0 -13
  357. package/sets/mineShaftRoomSubTypesSet.ts +0 -10
  358. package/sets/redHeartSubTypesSet.ts +0 -7
  359. package/sets/sinEntityTypesSet.ts +0 -11
  360. package/sets/singleUseActiveCollectibleTypesSet.ts +0 -13
  361. package/sets/storyBossesSet.ts +0 -17
  362. package/types/AnyEntity.ts +0 -12
  363. package/types/AwaitingTextInput.d.ts +0 -2
  364. package/types/CollectibleIndex.ts +0 -16
  365. package/types/PickingUpItem.ts +0 -89
  366. package/types/PlayerIndex.ts +0 -13
  367. package/types/private/IsaacAPIClass.ts +0 -3
  368. package/types/private/SerializedIsaacAPIClass.ts +0 -3
  369. package/types/private/TSTLClass.ts +0 -3
  370. package/upgradeMod.ts +0 -55
@@ -1,535 +0,0 @@
1
- import { DefaultMap } from "../classes/DefaultMap";
2
- import { CopyableIsaacAPIClassType } from "../enums/private/CopyableIsaacAPIClassType";
3
- import { SerializationBrand } from "../enums/private/SerializationBrand";
4
- import { SerializationType } from "../enums/SerializationType";
5
- import { SAVE_DATA_MANAGER_DEBUG } from "../features/saveDataManager/constants";
6
- import { isSerializationBrand } from "../features/saveDataManager/serializationBrand";
7
- import { TSTLClass } from "../types/private/TSTLClass";
8
- import { isArray } from "./array";
9
- import { getEnumValues } from "./enums";
10
- import { getIsaacAPIClassName } from "./isaacAPIClass";
11
- import { log, logTable } from "./log";
12
- import {
13
- copyIsaacAPIClass,
14
- deserializeIsaacAPIClass,
15
- isSerializedIsaacAPIClass,
16
- } from "./serialization";
17
- import {
18
- getTSTLClassName,
19
- isDefaultMap,
20
- isTSTLMap,
21
- isTSTLSet,
22
- isUserDefinedTSTLClass,
23
- newTSTLClass,
24
- } from "./tstlClass";
25
- import { isNumber, isPrimitive } from "./types";
26
- import { getTraversalDescription, twoDimensionalSort } from "./utils";
27
-
28
- const COPYABLE_ISAAC_API_CLASS_TYPES_SET = new Set<string>(
29
- getEnumValues(CopyableIsaacAPIClassType),
30
- );
31
-
32
- /**
33
- * `deepCopy` is a semi-generic deep cloner. It will recursively copy all of the values so that none
34
- * of the nested references remain.
35
- *
36
- * It supports the following object types:
37
- *
38
- * - Primitives (i.e. strings, numbers, and booleans)
39
- * - `LuaTable` / basic TSTL objects
40
- * - TSTL `Map`
41
- * - TSTL `Set`
42
- * - TSTL classes
43
- * - `DefaultMap`
44
- * - Isaac `Color` objects
45
- * - Isaac `KColor` objects
46
- * - Isaac `RNG` objects
47
- * - Isaac `Vector` objects
48
- *
49
- * It does not support:
50
- * - objects with values of `null` (since that transpiles to `nil`)
51
- * - other Isaac API objects such as `EntityPtr` (that have a type of "userdata")
52
- *
53
- * @param value The primitive or object to copy.
54
- * @param serializationType Has 3 possible values. Can leave objects as-is, or can serialize objects
55
- * to Lua tables, or can deserialize Lua tables to objects. Default is
56
- * `SerializationType.NONE`.
57
- * @param traversalDescription Used to track the current key that we are operating on.
58
- */
59
- export function deepCopy(
60
- value: unknown,
61
- serializationType = SerializationType.NONE,
62
- traversalDescription = "",
63
- ): unknown {
64
- // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
65
- if (SAVE_DATA_MANAGER_DEBUG) {
66
- let logString = `deepCopy is operating on: ${traversalDescription}`;
67
- if (serializationType === SerializationType.SERIALIZE) {
68
- logString += " (serializing)";
69
- } else if (serializationType === SerializationType.DESERIALIZE) {
70
- logString += " (deserializing)";
71
- }
72
- logString += `: ${value}`;
73
- log(logString);
74
- }
75
-
76
- const valueType = type(value);
77
- switch (valueType) {
78
- // First, handling the trivial case of primitives.
79
- case "nil":
80
- case "boolean":
81
- case "number":
82
- case "string": {
83
- return value;
84
- }
85
-
86
- // Second, handle values that cannot be serialized.
87
- case "function":
88
- case "thread": {
89
- if (serializationType === SerializationType.SERIALIZE) {
90
- error(
91
- `The deep copy function does not support serialization of "${traversalDescription}", since it is type: ${valueType}`,
92
- );
93
- }
94
-
95
- // We cannot copy this, so simply return the reference.
96
- return value;
97
- }
98
-
99
- case "table": {
100
- const luaTable = value as LuaTable<AnyNotNil, unknown>;
101
- return deepCopyTable(luaTable, serializationType, traversalDescription);
102
- }
103
-
104
- case "userdata": {
105
- return deepCopyUserdata(value, serializationType, traversalDescription);
106
- }
107
- }
108
- }
109
-
110
- function deepCopyTable(
111
- luaTable: LuaTable<AnyNotNil, unknown>,
112
- serializationType: SerializationType,
113
- traversalDescription: string,
114
- ) {
115
- // First, handle the cases of TSTL classes or serialized TSTL classes.
116
- if (isDefaultMap(luaTable) || luaTable.has(SerializationBrand.DEFAULT_MAP)) {
117
- return deepCopyDefaultMap(
118
- luaTable,
119
- serializationType,
120
- traversalDescription,
121
- );
122
- }
123
-
124
- if (isTSTLMap(luaTable) || luaTable.has(SerializationBrand.MAP)) {
125
- return deepCopyMap(luaTable, serializationType, traversalDescription);
126
- }
127
-
128
- if (isTSTLSet(luaTable) || luaTable.has(SerializationBrand.SET)) {
129
- return deepCopySet(luaTable, serializationType, traversalDescription);
130
- }
131
-
132
- const className = getTSTLClassName(luaTable);
133
-
134
- if (className === "WeakMap") {
135
- error(
136
- `The deep copy function does not support copying the "WeakMap" class for: ${traversalDescription}`,
137
- );
138
- }
139
-
140
- if (className === "WeakSet") {
141
- error(
142
- `The deep copy function does not support copying the "WeakSet" class for: ${traversalDescription}`,
143
- );
144
- }
145
-
146
- if (isUserDefinedTSTLClass(luaTable)) {
147
- return deepCopyTSTLClass(luaTable, serializationType, traversalDescription);
148
- }
149
-
150
- // This is not a TSTL Map/Set/class. If it has a metatable, abort.
151
- checkMetatable(luaTable, traversalDescription);
152
-
153
- // Handle the special case of serialized Isaac API classes.
154
- if (
155
- isSerializedIsaacAPIClass(luaTable) &&
156
- serializationType === SerializationType.DESERIALIZE
157
- ) {
158
- return deserializeIsaacAPIClass(luaTable);
159
- }
160
-
161
- // Handle the special case of an array.
162
- if (isArray(luaTable)) {
163
- return deepCopyArray(luaTable, serializationType, traversalDescription);
164
- }
165
-
166
- // Base case: copy a normal Lua table
167
- return deepCopyNormalLuaTable(
168
- luaTable,
169
- serializationType,
170
- traversalDescription,
171
- );
172
- }
173
-
174
- function deepCopyDefaultMap(
175
- defaultMap: DefaultMap<AnyNotNil, unknown> | LuaTable<AnyNotNil, unknown>,
176
- serializationType: SerializationType,
177
- traversalDescription: string,
178
- ) {
179
- // First, handle the special case of serializing a DefaultMap instantiated with a factory
180
- // function. If this is the case, then we cannot serialize it, so we serialize it as a normal
181
- // `Map` instead. We do not throw a runtime error because the merge function does not need to
182
- // instantiate the DefaultMap class in most circumstances.
183
- const constructorArg = isDefaultMap(defaultMap)
184
- ? defaultMap.getConstructorArg()
185
- : undefined;
186
- if (
187
- serializationType === SerializationType.SERIALIZE &&
188
- !isPrimitive(constructorArg)
189
- ) {
190
- return deepCopyMap(defaultMap, serializationType, traversalDescription);
191
- }
192
-
193
- const newDefaultMap = getNewDefaultMap(
194
- defaultMap,
195
- serializationType,
196
- traversalDescription,
197
- constructorArg,
198
- );
199
-
200
- const { entries, convertedNumberKeysToStrings } = getCopiedEntries(
201
- defaultMap,
202
- serializationType,
203
- traversalDescription,
204
- );
205
-
206
- if (convertedNumberKeysToStrings) {
207
- // Differentiating between the two types looks superfluous but is necessary for TSTL to produce
208
- // the proper set method call.
209
- if (isDefaultMap(newDefaultMap)) {
210
- newDefaultMap.set(SerializationBrand.OBJECT_WITH_NUMBER_KEYS, "");
211
- } else {
212
- newDefaultMap.set(SerializationBrand.OBJECT_WITH_NUMBER_KEYS, "");
213
- }
214
- }
215
-
216
- for (const [key, value] of entries) {
217
- // Differentiating between the two types looks superfluous but is necessary for TSTL to produce
218
- // the proper set method call.
219
- if (isDefaultMap(newDefaultMap)) {
220
- newDefaultMap.set(key, value);
221
- } else {
222
- newDefaultMap.set(key, value);
223
- }
224
- }
225
-
226
- return newDefaultMap;
227
- }
228
-
229
- /**
230
- * The new default map with either be a TSTL `DefaultMap` class or a Lua table, depending on whether
231
- * we are serializing or not.
232
- */
233
- function getNewDefaultMap(
234
- defaultMap: DefaultMap<AnyNotNil, unknown> | LuaTable<AnyNotNil, unknown>,
235
- serializationType: SerializationType,
236
- traversalDescription: string,
237
- constructorArg: unknown,
238
- ) {
239
- switch (serializationType) {
240
- case SerializationType.NONE: {
241
- // eslint-disable-next-line isaacscript/no-invalid-default-map
242
- return new DefaultMap(constructorArg);
243
- }
244
-
245
- case SerializationType.SERIALIZE: {
246
- // Since we are serializing, the new object will be a Lua table. (At this point, we already
247
- // handled the special case of a DefaultMap instantiated with a factory function.)
248
- const newDefaultMap = new LuaTable<AnyNotNil, unknown>();
249
- newDefaultMap.set(SerializationBrand.DEFAULT_MAP, "");
250
- newDefaultMap.set(SerializationBrand.DEFAULT_MAP_VALUE, constructorArg);
251
-
252
- return newDefaultMap;
253
- }
254
-
255
- case SerializationType.DESERIALIZE: {
256
- if (isDefaultMap(defaultMap)) {
257
- error(
258
- `The deep copy function failed to deserialize a default map of "${traversalDescription}", since it was not a Lua table.`,
259
- );
260
- }
261
-
262
- const defaultMapValue = defaultMap.get(
263
- SerializationBrand.DEFAULT_MAP_VALUE,
264
- );
265
- if (defaultMapValue === undefined) {
266
- error(
267
- `The deep copy function failed to deserialize a default map of "${traversalDescription}", since there was no serialization brand of: ${SerializationBrand.DEFAULT_MAP_VALUE}`,
268
- );
269
- }
270
-
271
- // eslint-disable-next-line isaacscript/no-invalid-default-map
272
- return new DefaultMap(defaultMapValue);
273
- }
274
- }
275
- }
276
-
277
- function deepCopyMap(
278
- map: Map<AnyNotNil, unknown> | LuaTable<AnyNotNil, unknown>,
279
- serializationType: SerializationType,
280
- traversalDescription: string,
281
- ) {
282
- let newMap: Map<AnyNotNil, unknown> | LuaTable<AnyNotNil, unknown>;
283
- if (serializationType === SerializationType.SERIALIZE) {
284
- // Since we are serializing, the new object will be a Lua table.
285
- newMap = new LuaTable<AnyNotNil, unknown>();
286
- newMap.set(SerializationBrand.MAP, "");
287
- } else {
288
- newMap = new Map();
289
- }
290
-
291
- const { entries, convertedNumberKeysToStrings } = getCopiedEntries(
292
- map,
293
- serializationType,
294
- traversalDescription,
295
- );
296
-
297
- if (convertedNumberKeysToStrings) {
298
- // Differentiating between the two types looks superfluous but is necessary for TSTL to produce
299
- // the proper set method call.
300
- if (isTSTLMap(newMap)) {
301
- newMap.set(SerializationBrand.OBJECT_WITH_NUMBER_KEYS, "");
302
- } else {
303
- newMap.set(SerializationBrand.OBJECT_WITH_NUMBER_KEYS, "");
304
- }
305
- }
306
-
307
- for (const [key, value] of entries) {
308
- // Differentiating between the two types looks superfluous but is necessary for TSTL to produce
309
- // the proper set method call.
310
- if (isTSTLMap(newMap)) {
311
- newMap.set(key, value);
312
- } else {
313
- newMap.set(key, value);
314
- }
315
- }
316
-
317
- return newMap;
318
- }
319
-
320
- function deepCopySet(
321
- set: Set<AnyNotNil> | LuaTable<AnyNotNil, unknown>,
322
- serializationType: SerializationType,
323
- traversalDescription: string,
324
- ) {
325
- let newSet: Set<AnyNotNil> | LuaTable<AnyNotNil, string>;
326
- if (serializationType === SerializationType.SERIALIZE) {
327
- // For serialization purposes, we represent a `Set` as a table with keys that match the
328
- // keys/values in the Set and values of an empty string.
329
- newSet = new LuaTable<AnyNotNil, string>();
330
- newSet.set(SerializationBrand.SET, "");
331
- } else {
332
- newSet = new Set();
333
- }
334
-
335
- const { entries, convertedNumberKeysToStrings } = getCopiedEntries(
336
- set,
337
- serializationType,
338
- traversalDescription,
339
- );
340
-
341
- if (convertedNumberKeysToStrings) {
342
- // Differentiating between the two types looks superfluous but is necessary for TSTL to produce
343
- // the proper set method call.
344
- if (isTSTLSet(newSet)) {
345
- // We should never be serializing an object of type Set.
346
- error(
347
- "The deep copy function cannot convert number keys to strings for a Set.",
348
- );
349
- } else {
350
- newSet.set(SerializationBrand.OBJECT_WITH_NUMBER_KEYS, "");
351
- }
352
- }
353
-
354
- for (const [key] of entries) {
355
- // Differentiating between the two types looks superfluous but is necessary for TSTL to produce
356
- // the proper set method call.
357
- if (isTSTLSet(newSet)) {
358
- newSet.add(key);
359
- } else {
360
- newSet.set(key, "");
361
- }
362
- }
363
-
364
- return newSet;
365
- }
366
-
367
- function deepCopyTSTLClass(
368
- tstlClass: TSTLClass,
369
- serializationType: SerializationType,
370
- traversalDescription: string,
371
- ) {
372
- let newClass: TSTLClass | LuaTable<AnyNotNil, unknown>;
373
- if (serializationType === SerializationType.SERIALIZE) {
374
- // Since we are serializing, the new object will be a Lua table.
375
- newClass = new LuaTable<AnyNotNil, unknown>();
376
- // (We do not brand it with the class type because we will not have the associated class
377
- // constructor during deserialization, so knowing what type of class it is is pointless.)
378
- } else {
379
- newClass = newTSTLClass(tstlClass);
380
- }
381
-
382
- const { entries, convertedNumberKeysToStrings } = getCopiedEntries(
383
- tstlClass,
384
- serializationType,
385
- traversalDescription,
386
- );
387
-
388
- if (convertedNumberKeysToStrings) {
389
- newClass.set(SerializationBrand.OBJECT_WITH_NUMBER_KEYS, "");
390
- }
391
-
392
- for (const [key, value] of entries) {
393
- newClass.set(key, value);
394
- }
395
-
396
- return newClass;
397
- }
398
-
399
- function deepCopyArray(
400
- array: unknown[],
401
- serializationType: SerializationType,
402
- traversalDescription: string,
403
- ) {
404
- const newArray: unknown[] = [];
405
-
406
- for (const value of array) {
407
- const newValue = deepCopy(value, serializationType, traversalDescription);
408
- newArray.push(newValue);
409
- }
410
-
411
- return newArray;
412
- }
413
-
414
- function deepCopyNormalLuaTable(
415
- luaTable: LuaTable<AnyNotNil, unknown>,
416
- serializationType: SerializationType,
417
- traversalDescription: string,
418
- ) {
419
- const newTable = new LuaTable<AnyNotNil, unknown>();
420
- const { entries, convertedNumberKeysToStrings } = getCopiedEntries(
421
- luaTable,
422
- serializationType,
423
- traversalDescription,
424
- );
425
-
426
- if (convertedNumberKeysToStrings) {
427
- newTable.set(SerializationBrand.OBJECT_WITH_NUMBER_KEYS, "");
428
- }
429
-
430
- for (const [key, value] of entries) {
431
- newTable.set(key, value);
432
- }
433
-
434
- return newTable;
435
- }
436
-
437
- /**
438
- * Recursively clones the object's entries, automatically converting number keys to strings, if
439
- * necessary.
440
- */
441
- function getCopiedEntries(
442
- object: unknown,
443
- serializationType: SerializationType,
444
- traversalDescription: string,
445
- ): {
446
- entries: Array<[key: AnyNotNil, value: unknown]>;
447
- convertedNumberKeysToStrings: boolean;
448
- } {
449
- // First, shallow copy the entries. We cannot use "pairs" to iterate over a Map or Set. We cannot
450
- // use "[...pairs(object)]", as it results in a run-time error.
451
- const entries: Array<[key: AnyNotNil, value: unknown]> = [];
452
- if (isTSTLMap(object) || isTSTLSet(object) || isDefaultMap(object)) {
453
- for (const [key, value] of object.entries()) {
454
- entries.push([key, value]);
455
- }
456
- } else {
457
- for (const [key, value] of pairs(object)) {
458
- entries.push([key, value]);
459
- }
460
- }
461
-
462
- // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
463
- if (SAVE_DATA_MANAGER_DEBUG) {
464
- logTable(entries);
465
- entries.sort(twoDimensionalSort);
466
- }
467
-
468
- const hasNumberKeys = entries.some(([key]) => isNumber(key));
469
- const convertNumberKeysToStrings =
470
- serializationType === SerializationType.SERIALIZE && hasNumberKeys;
471
-
472
- // Second, deep copy the entries.
473
- const copiedEntries: Array<[key: AnyNotNil, value: unknown]> = [];
474
- for (const [key, value] of entries) {
475
- // When deserializing, we do not need to copy the serialization brands that are used to denote
476
- // the object type.
477
- if (isSerializationBrand(key)) {
478
- continue;
479
- }
480
-
481
- traversalDescription = getTraversalDescription(key, traversalDescription);
482
- const newValue = deepCopy(value, serializationType, traversalDescription);
483
-
484
- const keyToUse = convertNumberKeysToStrings ? tostring(key) : key;
485
- copiedEntries.push([keyToUse, newValue]);
486
- }
487
-
488
- return {
489
- entries: copiedEntries,
490
- convertedNumberKeysToStrings: convertNumberKeysToStrings,
491
- };
492
- }
493
-
494
- /**
495
- * Lua tables can have metatables, which make writing a generic deep cloner impossible. The deep
496
- * copy function will refuse to copy a table type that has a metatable, outside of specifically
497
- * supported TSTL objects.
498
- */
499
- function checkMetatable(luaTable: LuaTable, traversalDescription: string) {
500
- const metatable = getmetatable(luaTable);
501
- if (metatable === undefined) {
502
- return;
503
- }
504
-
505
- const tableDescription =
506
- traversalDescription === ""
507
- ? "the table to copy"
508
- : `"${traversalDescription}"`;
509
-
510
- error(
511
- `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.)`,
512
- );
513
- }
514
-
515
- /** Isaac API classes are of type "userdata". End-user code cannot create userdata. */
516
- function deepCopyUserdata(
517
- value: unknown,
518
- serializationType: SerializationType,
519
- traversalDescription: string,
520
- ) {
521
- const classType = getIsaacAPIClassName(value);
522
- if (classType === undefined) {
523
- error(
524
- `The deep copy function was not able to derive the Isaac API class type for: ${traversalDescription}`,
525
- );
526
- }
527
-
528
- if (!COPYABLE_ISAAC_API_CLASS_TYPES_SET.has(classType)) {
529
- error(
530
- `The deep copy function does not support copying "${traversalDescription}", since it is an Isaac API class of type: ${classType}`,
531
- );
532
- }
533
-
534
- return copyIsaacAPIClass(value, serializationType);
535
- }