isaacscript-common 84.0.1 → 84.1.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.
- package/dist/arrays/cachedEnumValues.js +33 -0
- package/dist/callbackClasses.js +289 -0
- package/dist/callbacks.js +181 -0
- package/dist/classes/DefaultMap.js +171 -0
- package/dist/classes/ModFeature.js +244 -0
- package/dist/classes/ModUpgraded.js +324 -0
- package/dist/classes/callbacks/EntityTakeDmgFilter.js +19 -0
- package/dist/classes/callbacks/EntityTakeDmgPlayer.js +29 -0
- package/dist/classes/callbacks/InputActionFilter.js +24 -0
- package/dist/classes/callbacks/InputActionPlayer.js +37 -0
- package/dist/classes/callbacks/PostAmbushFinished.js +40 -0
- package/dist/classes/callbacks/PostAmbushStarted.js +40 -0
- package/dist/classes/callbacks/PostBombExploded.js +24 -0
- package/dist/classes/callbacks/PostBombInitFilter.js +21 -0
- package/dist/classes/callbacks/PostBombInitLate.js +31 -0
- package/dist/classes/callbacks/PostBombRenderFilter.js +21 -0
- package/dist/classes/callbacks/PostBombUpdateFilter.js +21 -0
- package/dist/classes/callbacks/PostBoneSwing.js +53 -0
- package/dist/classes/callbacks/PostCollectibleEmpty.js +50 -0
- package/dist/classes/callbacks/PostCursedTeleport.js +119 -0
- package/dist/classes/callbacks/PostCustomRevive.js +17 -0
- package/dist/classes/callbacks/PostDiceRoomActivated.js +50 -0
- package/dist/classes/callbacks/PostDoorRender.js +24 -0
- package/dist/classes/callbacks/PostDoorUpdate.js +24 -0
- package/dist/classes/callbacks/PostEffectInitFilter.js +21 -0
- package/dist/classes/callbacks/PostEffectInitLate.js +31 -0
- package/dist/classes/callbacks/PostEffectRenderFilter.js +21 -0
- package/dist/classes/callbacks/PostEffectStateChanged.js +34 -0
- package/dist/classes/callbacks/PostEffectUpdateFilter.js +21 -0
- package/dist/classes/callbacks/PostEntityKillFilter.js +21 -0
- package/dist/classes/callbacks/PostEsauJr.js +12 -0
- package/dist/classes/callbacks/PostFamiliarInitFilter.js +21 -0
- package/dist/classes/callbacks/PostFamiliarInitLate.js +31 -0
- package/dist/classes/callbacks/PostFamiliarRenderFilter.js +21 -0
- package/dist/classes/callbacks/PostFamiliarStateChanged.js +34 -0
- package/dist/classes/callbacks/PostFamiliarUpdateFilter.js +21 -0
- package/dist/classes/callbacks/PostFirstEsauJr.js +12 -0
- package/dist/classes/callbacks/PostFirstFlip.js +12 -0
- package/dist/classes/callbacks/PostFlip.js +12 -0
- package/dist/classes/callbacks/PostGameEndFilter.js +21 -0
- package/dist/classes/callbacks/PostGameStartedReordered.js +14 -0
- package/dist/classes/callbacks/PostGameStartedReorderedLast.js +14 -0
- package/dist/classes/callbacks/PostGreedModeWave.js +35 -0
- package/dist/classes/callbacks/PostGridEntityBroken.js +14 -0
- package/dist/classes/callbacks/PostGridEntityCollision.js +28 -0
- package/dist/classes/callbacks/PostGridEntityCustomBroken.js +14 -0
- package/dist/classes/callbacks/PostGridEntityCustomCollision.js +24 -0
- package/dist/classes/callbacks/PostGridEntityCustomInit.js +14 -0
- package/dist/classes/callbacks/PostGridEntityCustomRemove.js +18 -0
- package/dist/classes/callbacks/PostGridEntityCustomRender.js +14 -0
- package/dist/classes/callbacks/PostGridEntityCustomStateChanged.js +14 -0
- package/dist/classes/callbacks/PostGridEntityCustomUpdate.js +14 -0
- package/dist/classes/callbacks/PostGridEntityInit.js +14 -0
- package/dist/classes/callbacks/PostGridEntityRemove.js +19 -0
- package/dist/classes/callbacks/PostGridEntityRender.js +14 -0
- package/dist/classes/callbacks/PostGridEntityStateChanged.js +14 -0
- package/dist/classes/callbacks/PostGridEntityUpdate.js +14 -0
- package/dist/classes/callbacks/PostHolyMantleRemoved.js +43 -0
- package/dist/classes/callbacks/PostItemDischarge.js +122 -0
- package/dist/classes/callbacks/PostItemPickup.js +14 -0
- package/dist/classes/callbacks/PostKeyboardChanged.js +46 -0
- package/dist/classes/callbacks/PostKnifeInitFilter.js +21 -0
- package/dist/classes/callbacks/PostKnifeInitLate.js +31 -0
- package/dist/classes/callbacks/PostKnifeRenderFilter.js +21 -0
- package/dist/classes/callbacks/PostKnifeUpdateFilter.js +21 -0
- package/dist/classes/callbacks/PostLaserInitFilter.js +21 -0
- package/dist/classes/callbacks/PostLaserInitLate.js +31 -0
- package/dist/classes/callbacks/PostLaserRenderFilter.js +21 -0
- package/dist/classes/callbacks/PostLaserUpdateFilter.js +21 -0
- package/dist/classes/callbacks/PostNPCDeathFilter.js +21 -0
- package/dist/classes/callbacks/PostNPCInitFilter.js +21 -0
- package/dist/classes/callbacks/PostNPCInitLate.js +31 -0
- package/dist/classes/callbacks/PostNPCRenderFilter.js +21 -0
- package/dist/classes/callbacks/PostNPCStateChanged.js +34 -0
- package/dist/classes/callbacks/PostNPCUpdateFilter.js +21 -0
- package/dist/classes/callbacks/PostNewLevelReordered.js +14 -0
- package/dist/classes/callbacks/PostNewRoomEarly.js +74 -0
- package/dist/classes/callbacks/PostNewRoomReordered.js +14 -0
- package/dist/classes/callbacks/PostPEffectUpdateReordered.js +14 -0
- package/dist/classes/callbacks/PostPickupChanged.js +14 -0
- package/dist/classes/callbacks/PostPickupCollect.js +38 -0
- package/dist/classes/callbacks/PostPickupInitFilter.js +21 -0
- package/dist/classes/callbacks/PostPickupInitFirst.js +33 -0
- package/dist/classes/callbacks/PostPickupInitLate.js +31 -0
- package/dist/classes/callbacks/PostPickupRenderFilter.js +21 -0
- package/dist/classes/callbacks/PostPickupSelectionFilter.js +29 -0
- package/dist/classes/callbacks/PostPickupStateChanged.js +34 -0
- package/dist/classes/callbacks/PostPickupUpdateFilter.js +21 -0
- package/dist/classes/callbacks/PostPitRender.js +24 -0
- package/dist/classes/callbacks/PostPitUpdate.js +24 -0
- package/dist/classes/callbacks/PostPlayerChangeHealth.js +47 -0
- package/dist/classes/callbacks/PostPlayerChangeStat.js +79 -0
- package/dist/classes/callbacks/PostPlayerChangeType.js +36 -0
- package/dist/classes/callbacks/PostPlayerCollectibleAdded.js +14 -0
- package/dist/classes/callbacks/PostPlayerCollectibleRemoved.js +14 -0
- package/dist/classes/callbacks/PostPlayerFatalDamage.js +83 -0
- package/dist/classes/callbacks/PostPlayerInitFirst.js +41 -0
- package/dist/classes/callbacks/PostPlayerInitLate.js +33 -0
- package/dist/classes/callbacks/PostPlayerRenderReordered.js +14 -0
- package/dist/classes/callbacks/PostPlayerUpdateReordered.js +14 -0
- package/dist/classes/callbacks/PostPoopRender.js +24 -0
- package/dist/classes/callbacks/PostPoopUpdate.js +24 -0
- package/dist/classes/callbacks/PostPressurePlateRender.js +24 -0
- package/dist/classes/callbacks/PostPressurePlateUpdate.js +24 -0
- package/dist/classes/callbacks/PostProjectileInitFilter.js +21 -0
- package/dist/classes/callbacks/PostProjectileInitLate.js +31 -0
- package/dist/classes/callbacks/PostProjectileKill.js +52 -0
- package/dist/classes/callbacks/PostProjectileRenderFilter.js +21 -0
- package/dist/classes/callbacks/PostProjectileUpdateFilter.js +21 -0
- package/dist/classes/callbacks/PostPurchase.js +90 -0
- package/dist/classes/callbacks/PostRockRender.js +24 -0
- package/dist/classes/callbacks/PostRockUpdate.js +24 -0
- package/dist/classes/callbacks/PostRoomClearChanged.js +46 -0
- package/dist/classes/callbacks/PostSacrifice.js +36 -0
- package/dist/classes/callbacks/PostSlotAnimationChanged.js +14 -0
- package/dist/classes/callbacks/PostSlotCollision.js +25 -0
- package/dist/classes/callbacks/PostSlotDestroyed.js +14 -0
- package/dist/classes/callbacks/PostSlotInit.js +14 -0
- package/dist/classes/callbacks/PostSlotRender.js +14 -0
- package/dist/classes/callbacks/PostSlotUpdate.js +14 -0
- package/dist/classes/callbacks/PostSpikesRender.js +24 -0
- package/dist/classes/callbacks/PostSpikesUpdate.js +24 -0
- package/dist/classes/callbacks/PostTNTRender.js +24 -0
- package/dist/classes/callbacks/PostTNTUpdate.js +24 -0
- package/dist/classes/callbacks/PostTearInitFilter.js +21 -0
- package/dist/classes/callbacks/PostTearInitLate.js +31 -0
- package/dist/classes/callbacks/PostTearInitVeryLate.js +35 -0
- package/dist/classes/callbacks/PostTearKill.js +52 -0
- package/dist/classes/callbacks/PostTearRenderFilter.js +21 -0
- package/dist/classes/callbacks/PostTearUpdateFilter.js +21 -0
- package/dist/classes/callbacks/PostTransformation.js +47 -0
- package/dist/classes/callbacks/PostTrinketBreak.js +70 -0
- package/dist/classes/callbacks/PostUsePillFilter.js +76 -0
- package/dist/classes/callbacks/PreBerserkDeath.js +41 -0
- package/dist/classes/callbacks/PreBombCollisionFilter.js +19 -0
- package/dist/classes/callbacks/PreCustomRevive.js +14 -0
- package/dist/classes/callbacks/PreEntitySpawnFilter.js +24 -0
- package/dist/classes/callbacks/PreFamiliarCollisionFilter.js +19 -0
- package/dist/classes/callbacks/PreGetPedestal.js +46 -0
- package/dist/classes/callbacks/PreItemPickup.js +14 -0
- package/dist/classes/callbacks/PreKnifeCollisionFilter.js +19 -0
- package/dist/classes/callbacks/PreNPCCollisionFilter.js +19 -0
- package/dist/classes/callbacks/PreNPCUpdateFilter.js +19 -0
- package/dist/classes/callbacks/PreNewLevel.js +51 -0
- package/dist/classes/callbacks/PreProjectileCollisionFilter.js +19 -0
- package/dist/classes/callbacks/PreRoomEntitySpawnFilter.js +26 -0
- package/dist/classes/callbacks/PreTearCollisionFilter.js +19 -0
- package/dist/classes/features/callbackLogic/CustomGridEntities.js +359 -0
- package/dist/classes/features/callbackLogic/CustomRevive.js +170 -0
- package/dist/classes/features/callbackLogic/EsauJrDetection.js +70 -0
- package/dist/classes/features/callbackLogic/FlipDetection.js +61 -0
- package/dist/classes/features/callbackLogic/GameReorderedCallbacks.js +220 -0
- package/dist/classes/features/callbackLogic/GridEntityCollisionDetection.js +62 -0
- package/dist/classes/features/callbackLogic/GridEntityRenderDetection.js +35 -0
- package/dist/classes/features/callbackLogic/GridEntityUpdateDetection.js +147 -0
- package/dist/classes/features/callbackLogic/ItemPickupDetection.js +68 -0
- package/dist/classes/features/callbackLogic/PickupChangeDetection.js +43 -0
- package/dist/classes/features/callbackLogic/PlayerCollectibleDetection.js +193 -0
- package/dist/classes/features/callbackLogic/PlayerReorderedCallbacks.js +109 -0
- package/dist/classes/features/callbackLogic/SlotDestroyedDetection.js +95 -0
- package/dist/classes/features/callbackLogic/SlotRenderDetection.js +48 -0
- package/dist/classes/features/callbackLogic/SlotUpdateDetection.js +52 -0
- package/dist/classes/features/other/CharacterHealthConversion.js +112 -0
- package/dist/classes/features/other/CharacterStats.js +68 -0
- package/dist/classes/features/other/CollectibleItemPoolType.js +75 -0
- package/dist/classes/features/other/CustomHotkeys.js +144 -0
- package/dist/classes/features/other/CustomItemPools.js +128 -0
- package/dist/classes/features/other/CustomPickups.js +118 -0
- package/dist/classes/features/other/CustomStages.js +471 -0
- package/dist/classes/features/other/CustomTrapdoors.js +596 -0
- package/dist/classes/features/other/DebugDisplay.js +699 -0
- package/dist/classes/features/other/DeployJSONRoom.js +301 -0
- package/dist/classes/features/other/DisableAllSound.js +90 -0
- package/dist/classes/features/other/DisableInputs.js +249 -0
- package/dist/classes/features/other/EdenStartingStatsHealth.js +197 -0
- package/dist/classes/features/other/ExtraConsoleCommands.js +292 -0
- package/dist/classes/features/other/FadeInRemover.js +67 -0
- package/dist/classes/features/other/FastReset.js +88 -0
- package/dist/classes/features/other/FlyingDetection.js +64 -0
- package/dist/classes/features/other/ForgottenSwitch.js +43 -0
- package/dist/classes/features/other/ItemPoolDetection.js +187 -0
- package/dist/classes/features/other/ModdedElementDetection.js +399 -0
- package/dist/classes/features/other/ModdedElementSets.js +1251 -0
- package/dist/classes/features/other/NoSirenSteal.js +88 -0
- package/dist/classes/features/other/Pause.js +197 -0
- package/dist/classes/features/other/PersistentEntities.js +168 -0
- package/dist/classes/features/other/PickupIndexCreation.js +229 -0
- package/dist/classes/features/other/PlayerCollectibleTracking.js +102 -0
- package/dist/classes/features/other/PonyDetection.js +86 -0
- package/dist/classes/features/other/PressInput.js +71 -0
- package/dist/classes/features/other/PreventChildEntities.js +60 -0
- package/dist/classes/features/other/PreventGridEntityRespawn.js +159 -0
- package/dist/classes/features/other/RerunDetection.js +69 -0
- package/dist/classes/features/other/RoomClearFrame.js +94 -0
- package/dist/classes/features/other/RoomHistory.js +196 -0
- package/dist/classes/features/other/RunInNFrames.js +323 -0
- package/dist/classes/features/other/RunNextRoom.js +53 -0
- package/dist/classes/features/other/RunNextRun.js +60 -0
- package/dist/classes/features/other/SaveDataManager.js +383 -0
- package/dist/classes/features/other/SpawnRockAltRewards.js +469 -0
- package/dist/classes/features/other/StageHistory.js +244 -0
- package/dist/classes/features/other/StartAmbush.js +62 -0
- package/dist/classes/features/other/TaintedLazarusPlayers.js +115 -0
- package/dist/classes/features/other/UnlockAchievementsDetection.js +60 -0
- package/dist/classes/features/other/customStages/backdrop.js +195 -0
- package/dist/classes/features/other/customStages/constants.js +19 -0
- package/dist/classes/features/other/customStages/gridEntities.js +177 -0
- package/dist/classes/features/other/customStages/shadows.js +67 -0
- package/dist/classes/features/other/customStages/streakText.js +222 -0
- package/dist/classes/features/other/customStages/utils.js +65 -0
- package/dist/classes/features/other/customStages/v.js +27 -0
- package/dist/classes/features/other/customStages/versusScreen.js +227 -0
- package/dist/classes/features/other/debugDisplay/DebugDisplayBomb.js +23 -0
- package/dist/classes/features/other/debugDisplay/DebugDisplayDoor.js +22 -0
- package/dist/classes/features/other/debugDisplay/DebugDisplayEffect.js +23 -0
- package/dist/classes/features/other/debugDisplay/DebugDisplayFamiliar.js +23 -0
- package/dist/classes/features/other/debugDisplay/DebugDisplayKnife.js +23 -0
- package/dist/classes/features/other/debugDisplay/DebugDisplayLaser.js +23 -0
- package/dist/classes/features/other/debugDisplay/DebugDisplayNPC.js +23 -0
- package/dist/classes/features/other/debugDisplay/DebugDisplayPickup.js +23 -0
- package/dist/classes/features/other/debugDisplay/DebugDisplayPit.js +22 -0
- package/dist/classes/features/other/debugDisplay/DebugDisplayPlayer.js +25 -0
- package/dist/classes/features/other/debugDisplay/DebugDisplayPoop.js +22 -0
- package/dist/classes/features/other/debugDisplay/DebugDisplayPressurePlate.js +25 -0
- package/dist/classes/features/other/debugDisplay/DebugDisplayProjectile.js +23 -0
- package/dist/classes/features/other/debugDisplay/DebugDisplayRock.js +22 -0
- package/dist/classes/features/other/debugDisplay/DebugDisplaySlot.js +22 -0
- package/dist/classes/features/other/debugDisplay/DebugDisplaySpikes.js +22 -0
- package/dist/classes/features/other/debugDisplay/DebugDisplayTNT.js +22 -0
- package/dist/classes/features/other/debugDisplay/DebugDisplayTear.js +23 -0
- package/dist/classes/features/other/debugDisplay/utils.js +13 -0
- package/dist/classes/features/other/extraConsoleCommands/commands.js +1598 -0
- package/dist/classes/features/other/extraConsoleCommands/subroutines.js +135 -0
- package/dist/classes/features/other/extraConsoleCommands/v.js +30 -0
- package/dist/classes/features/other/saveDataManager/constants.js +4 -0
- package/dist/classes/features/other/saveDataManager/glowingHourGlass.js +106 -0
- package/dist/classes/features/other/saveDataManager/loadFromDisk.js +69 -0
- package/dist/classes/features/other/saveDataManager/restoreDefaults.js +69 -0
- package/dist/classes/features/other/saveDataManager/saveToDisk.js +46 -0
- package/dist/classes/private/CustomCallback.js +59 -0
- package/dist/classes/private/Feature.js +39 -0
- package/dist/core/cachedClasses.js +61 -0
- package/dist/core/constants.js +289 -0
- package/dist/core/constantsFirstLast.js +98 -0
- package/dist/core/constantsVanilla.js +131 -0
- package/dist/core/upgradeMod.js +71 -0
- package/dist/customStageMetadata.json +1 -0
- package/dist/data/itempools.json +16625 -0
- package/dist/decorators.js +21 -0
- package/dist/enums/AmbushType.js +9 -0
- package/dist/enums/CornerType.js +11 -0
- package/dist/enums/HealthType.js +20 -0
- package/dist/enums/ISCFeature.js +65 -0
- package/dist/enums/LadderSubTypeCustom.js +20 -0
- package/dist/enums/ModCallbackCustom.js +2477 -0
- package/dist/enums/MysteriousPaperEffect.js +16 -0
- package/dist/enums/PlayerStat.js +37 -0
- package/dist/enums/PocketItemType.js +13 -0
- package/dist/enums/RockAltType.js +23 -0
- package/dist/enums/SaveDataKey.js +14 -0
- package/dist/enums/SerializationType.js +10 -0
- package/dist/enums/SlotDestructionType.js +22 -0
- package/dist/enums/private/GridEntityTypeCustom.js +10 -0
- package/dist/enums/private/SerializationBrand.js +42 -0
- package/dist/enums/private/StageTravelState.js +13 -0
- package/dist/enums/private/TrapdoorAnimation.js +9 -0
- package/dist/enums/private/UIStreakAnimation.js +10 -0
- package/dist/features.js +150 -0
- package/dist/functions/ambush.js +26 -0
- package/dist/functions/array.js +586 -0
- package/dist/functions/arrayLua.js +81 -0
- package/dist/functions/benchmark.js +36 -0
- package/dist/functions/bitSet128.js +64 -0
- package/dist/functions/bitwise.js +82 -0
- package/dist/functions/bombs.js +14 -0
- package/dist/functions/bosses.js +238 -0
- package/dist/functions/cards.js +164 -0
- package/dist/functions/challenges.js +117 -0
- package/dist/functions/characters.js +182 -0
- package/dist/functions/charge.js +251 -0
- package/dist/functions/chargeBar.js +54 -0
- package/dist/functions/collectibleTag.js +24 -0
- package/dist/functions/collectibles.js +581 -0
- package/dist/functions/color.js +88 -0
- package/dist/functions/console.js +18 -0
- package/dist/functions/curses.js +37 -0
- package/dist/functions/debugFunctions.js +108 -0
- package/dist/functions/decorators.js +113 -0
- package/dist/functions/deepCopy.js +406 -0
- package/dist/functions/deepCopyTests.js +361 -0
- package/dist/functions/dimensions.js +30 -0
- package/dist/functions/direction.js +78 -0
- package/dist/functions/doors.js +524 -0
- package/dist/functions/easing.js +327 -0
- package/dist/functions/effects.js +14 -0
- package/dist/functions/emptyRoom.js +79 -0
- package/dist/functions/entities.js +529 -0
- package/dist/functions/entitiesSpecific.js +582 -0
- package/dist/functions/entityTypes.js +9 -0
- package/dist/functions/enums.js +244 -0
- package/dist/functions/external.js +59 -0
- package/dist/functions/familiars.js +136 -0
- package/dist/functions/flag.js +146 -0
- package/dist/functions/frames.js +166 -0
- package/dist/functions/globals.js +291 -0
- package/dist/functions/gridEntities.js +990 -0
- package/dist/functions/gridEntitiesSpecific.js +456 -0
- package/dist/functions/gridIndex.js +35 -0
- package/dist/functions/hash.js +75 -0
- package/dist/functions/hex.js +57 -0
- package/dist/functions/input.js +185 -0
- package/dist/functions/isaacAPIClass.js +157 -0
- package/dist/functions/itemPool.js +118 -0
- package/dist/functions/jsonHelpers.js +73 -0
- package/dist/functions/jsonRoom.js +184 -0
- package/dist/functions/kColor.js +89 -0
- package/dist/functions/language.js +16 -0
- package/dist/functions/level.js +66 -0
- package/dist/functions/levelGrid.js +497 -0
- package/dist/functions/log.js +86 -0
- package/dist/functions/logEntities.js +308 -0
- package/dist/functions/logMisc.js +510 -0
- package/dist/functions/map.js +121 -0
- package/dist/functions/math.js +149 -0
- package/dist/functions/merge.js +159 -0
- package/dist/functions/mergeTests.js +313 -0
- package/dist/functions/minimap.js +204 -0
- package/dist/functions/modFeatures.js +39 -0
- package/dist/functions/newArray.js +30 -0
- package/dist/functions/nextStage.js +169 -0
- package/dist/functions/npcDataStructures.js +146 -0
- package/dist/functions/npcs.js +132 -0
- package/dist/functions/pickupVariants.js +63 -0
- package/dist/functions/pickups.js +168 -0
- package/dist/functions/pickupsSpecific.js +376 -0
- package/dist/functions/pills.js +200 -0
- package/dist/functions/playerCenter.js +53 -0
- package/dist/functions/playerCollectibles.js +300 -0
- package/dist/functions/playerDataStructures.js +145 -0
- package/dist/functions/playerEffects.js +63 -0
- package/dist/functions/playerHealth.js +604 -0
- package/dist/functions/playerIndex.js +186 -0
- package/dist/functions/playerTrinkets.js +149 -0
- package/dist/functions/players.js +471 -0
- package/dist/functions/pocketItems.js +165 -0
- package/dist/functions/positionVelocity.js +158 -0
- package/dist/functions/pressurePlate.js +26 -0
- package/dist/functions/projectiles.js +57 -0
- package/dist/functions/random.js +90 -0
- package/dist/functions/readOnly.js +33 -0
- package/dist/functions/render.js +36 -0
- package/dist/functions/revive.js +151 -0
- package/dist/functions/rng.js +140 -0
- package/dist/functions/rockAlt.js +50 -0
- package/dist/functions/roomData.js +155 -0
- package/dist/functions/roomGrid.js +97 -0
- package/dist/functions/roomShape.js +143 -0
- package/dist/functions/roomShapeWalls.js +187 -0
- package/dist/functions/roomTransition.js +43 -0
- package/dist/functions/rooms.js +782 -0
- package/dist/functions/run.js +121 -0
- package/dist/functions/seeds.js +22 -0
- package/dist/functions/serialization.js +98 -0
- package/dist/functions/set.js +215 -0
- package/dist/functions/slots.js +41 -0
- package/dist/functions/sort.js +158 -0
- package/dist/functions/sound.js +45 -0
- package/dist/functions/spawnCollectible.js +112 -0
- package/dist/functions/sprites.js +130 -0
- package/dist/functions/stage.js +540 -0
- package/dist/functions/stats.js +104 -0
- package/dist/functions/storyBosses.js +63 -0
- package/dist/functions/string.js +194 -0
- package/dist/functions/table.js +162 -0
- package/dist/functions/tears.js +128 -0
- package/dist/functions/transformations.js +89 -0
- package/dist/functions/trinketGive.js +145 -0
- package/dist/functions/trinkets.js +213 -0
- package/dist/functions/tstlClass.js +97 -0
- package/dist/functions/types.js +225 -0
- package/dist/functions/ui.js +148 -0
- package/dist/functions/utils.d.ts +2 -0
- package/dist/functions/utils.d.ts.map +1 -1
- package/dist/functions/utils.js +195 -0
- package/dist/functions/utils.lua +4 -1
- package/dist/functions/vector.js +150 -0
- package/dist/functions/versusScreen.js +58 -0
- package/dist/functions/weighted.js +57 -0
- package/dist/index.js +219 -0
- package/dist/index.rollup.d.ts +2 -0
- package/dist/indexLua.js +220 -0
- package/dist/interfaces/ChargeBarSprites.js +2 -0
- package/dist/interfaces/Corner.js +2 -0
- package/dist/interfaces/CustomStageTSConfig.js +2 -0
- package/dist/interfaces/GridEntityCustomData.js +2 -0
- package/dist/interfaces/JSONRoomsFile.js +2 -0
- package/dist/interfaces/PlayerHealth.js +2 -0
- package/dist/interfaces/PlayerStats.js +4 -0
- package/dist/interfaces/PocketItemDescription.js +2 -0
- package/dist/interfaces/RoomDescription.js +2 -0
- package/dist/interfaces/SaveData.js +98 -0
- package/dist/interfaces/StageHistoryEntry.js +2 -0
- package/dist/interfaces/TSTLClassMetatable.js +2 -0
- package/dist/interfaces/TrinketSituation.js +2 -0
- package/dist/interfaces/private/AddCallbackParametersCustom.js +4 -0
- package/dist/interfaces/private/CustomStage.js +2 -0
- package/dist/interfaces/private/CustomTrapdoorDescription.js +2 -0
- package/dist/interfaces/private/ModUpgradedInterface.js +2 -0
- package/dist/isaacscript-common.lua +5 -2
- package/dist/maps/PHDPillConversionsMap.js +23 -0
- package/dist/maps/cardNameToTypeMap.js +211 -0
- package/dist/maps/characterNameToTypeMap.js +91 -0
- package/dist/maps/collectibleNameToTypeMap.js +19 -0
- package/dist/maps/defaultPlayerStatMap.js +17 -0
- package/dist/maps/entityTypeVariantToBossIDMap.js +11 -0
- package/dist/maps/falsePHDPillConversionsMap.js +37 -0
- package/dist/maps/gridEntityTypeToBrokenStateMap.js +32 -0
- package/dist/maps/gridEntityXMLMap.js +133 -0
- package/dist/maps/itemPoolTypeToItemPoolName.js +38 -0
- package/dist/maps/keyboardToStringMap.js +71 -0
- package/dist/maps/pillNameToEffectMap.js +91 -0
- package/dist/maps/roomNameToTypeMap.js +43 -0
- package/dist/maps/roomShapeToTopLeftWallGridIndexMap.js +17 -0
- package/dist/maps/transformationNameToPlayerFormMap.js +35 -0
- package/dist/maps/trinketNameToTypeMap.js +19 -0
- package/dist/objects/LRoomShapeToRectangles.js +43 -0
- package/dist/objects/backdropTypeToRockAltType.js +68 -0
- package/dist/objects/batteryNames.js +13 -0
- package/dist/objects/bombNames.js +17 -0
- package/dist/objects/bossIDToEntityTypeVariant.js +228 -0
- package/dist/objects/bossNamePNGFileNames.js +120 -0
- package/dist/objects/bossNames.js +119 -0
- package/dist/objects/bossPortraitPNGFileNames.js +123 -0
- package/dist/objects/cardDescriptions.js +106 -0
- package/dist/objects/cardNames.js +106 -0
- package/dist/objects/challengeBosses.js +60 -0
- package/dist/objects/challengeCharacters.js +58 -0
- package/dist/objects/challengeCollectibleTypes.js +255 -0
- package/dist/objects/challengeNames.js +54 -0
- package/dist/objects/challengeTrinketType.js +58 -0
- package/dist/objects/characterDamageMultipliers.js +49 -0
- package/dist/objects/characterNames.js +48 -0
- package/dist/objects/characterSpritePNGFileNames.js +50 -0
- package/dist/objects/characterStartingCollectibleTypes.js +105 -0
- package/dist/objects/characterStartingTrinketTypes.js +90 -0
- package/dist/objects/chestNames.js +20 -0
- package/dist/objects/coinNames.js +16 -0
- package/dist/objects/coinSubTypeToValue.js +15 -0
- package/dist/objects/collectibleDescriptions.js +742 -0
- package/dist/objects/collectibleNames.js +745 -0
- package/dist/objects/colors.js +26 -0
- package/dist/objects/directionNames.js +11 -0
- package/dist/objects/directionToDegrees.js +11 -0
- package/dist/objects/directionToMoveAction.js +11 -0
- package/dist/objects/directionToShootAction.js +11 -0
- package/dist/objects/directionToVector.js +13 -0
- package/dist/objects/doorSlotFlagToDoorSlot.js +15 -0
- package/dist/objects/doorSlotToDirection.js +15 -0
- package/dist/objects/doorSlotToDoorSlotFlag.js +15 -0
- package/dist/objects/gridEntityTypeToANM2Name.js +37 -0
- package/dist/objects/heartNames.js +21 -0
- package/dist/objects/isaacAPIClassTypeToBrand.js +12 -0
- package/dist/objects/isaacAPIClassTypeToFunctions.js +46 -0
- package/dist/objects/itemPoolTypeToCollectibleTypesSet.js +57 -0
- package/dist/objects/kColors.js +27 -0
- package/dist/objects/keyNames.js +13 -0
- package/dist/objects/languageNames.js +13 -0
- package/dist/objects/oppositeDoorSlots.js +15 -0
- package/dist/objects/pillEffectClasses.js +57 -0
- package/dist/objects/pillEffectNames.js +57 -0
- package/dist/objects/pillEffectTypeToPillEffects.js +23 -0
- package/dist/objects/pillEffectTypes.js +57 -0
- package/dist/objects/playerNamePNGFileNames.js +57 -0
- package/dist/objects/playerPortraitPNGFileNames.js +54 -0
- package/dist/objects/roomShapeBounds.js +48 -0
- package/dist/objects/roomShapeCorners.js +330 -0
- package/dist/objects/roomShapeLayoutSizes.js +41 -0
- package/dist/objects/roomShapeToBottomRightPosition.js +25 -0
- package/dist/objects/roomShapeToDoorSlotCoordinates.js +111 -0
- package/dist/objects/roomShapeToDoorSlots.js +72 -0
- package/dist/objects/roomShapeToDoorSlotsToGridIndexDelta.js +118 -0
- package/dist/objects/roomShapeToGridWidth.js +20 -0
- package/dist/objects/roomShapeToTopLeftPosition.js +26 -0
- package/dist/objects/roomShapeVolumes.js +32 -0
- package/dist/objects/roomTypeNames.js +35 -0
- package/dist/objects/roomTypeSpecialGotoPrefixes.js +35 -0
- package/dist/objects/sackNames.js +11 -0
- package/dist/objects/slotNames.js +26 -0
- package/dist/objects/stageIDNames.js +43 -0
- package/dist/objects/stageToMusic.js +91 -0
- package/dist/objects/stageToStageID.js +117 -0
- package/dist/objects/stageTypeSuffixes.js +14 -0
- package/dist/objects/transformationNames.js +20 -0
- package/dist/objects/trinketDescriptions.js +199 -0
- package/dist/objects/trinketNames.js +202 -0
- package/dist/objects/versusScreenBackgroundColors.js +46 -0
- package/dist/objects/versusScreenDirtSpotColors.js +46 -0
- package/dist/patchErrorFunctions.js +65 -0
- package/dist/serialization.js +21 -0
- package/dist/sets/LRoomShapesSet.js +11 -0
- package/dist/sets/bigRoomShapesSet.js +14 -0
- package/dist/sets/bossSets.js +465 -0
- package/dist/sets/charactersThatStartWithAnActiveItemSet.js +18 -0
- package/dist/sets/charactersWithBlackHeartFromEternalHeartSet.js +9 -0
- package/dist/sets/charactersWithFreeDevilDealsSet.js +6 -0
- package/dist/sets/charactersWithNoRedHeartsSet.js +19 -0
- package/dist/sets/charactersWithNoSoulHeartsSet.js +16 -0
- package/dist/sets/consoleCommandsSet.js +64 -0
- package/dist/sets/entitiesWithArmorSet.js +59 -0
- package/dist/sets/familiarsThatShootPlayerTearsSet.js +15 -0
- package/dist/sets/itemConfigCardTypesForCards.js +14 -0
- package/dist/sets/lostStyleCharactersSet.js +16 -0
- package/dist/sets/mineShaftRoomSubTypesSet.js +12 -0
- package/dist/sets/narrowRoomShapesSet.js +11 -0
- package/dist/sets/poopGridEntityXMLTypesSet.js +16 -0
- package/dist/sets/redHeartSubTypesSet.js +10 -0
- package/dist/sets/repentanceBossIDsSet.js +30 -0
- package/dist/sets/sinEntityTypesSet.js +14 -0
- package/dist/sets/singleUseActiveCollectibleTypesSet.js +15 -0
- package/dist/shaderCrashFix.js +24 -0
- package/dist/shouldFire.js +226 -0
- package/dist/types/AddSubtract.js +2 -0
- package/dist/types/AllButFirst.js +2 -0
- package/dist/types/AllButLast.js +2 -0
- package/dist/types/AnyClass.js +2 -0
- package/dist/types/AnyEntity.js +2 -0
- package/dist/types/AnyFunction.js +2 -0
- package/dist/types/AnyGridEntity.js +2 -0
- package/dist/types/CompositionTypeSatisfiesEnum.js +11 -0
- package/dist/types/ConversionHeartSubType.js +2 -0
- package/dist/types/Decrement.js +2 -0
- package/dist/types/ERange.js +2 -0
- package/dist/types/EntityID.js +2 -0
- package/dist/types/FunctionTuple.js +2 -0
- package/dist/types/GridEntityID.js +2 -0
- package/dist/types/HasFunction.js +2 -0
- package/dist/types/IRange.js +2 -0
- package/dist/types/Immutable.js +2 -0
- package/dist/types/Increment.js +2 -0
- package/dist/types/LowercaseKeys.js +2 -0
- package/dist/types/NaturalNumbersLessThan.js +2 -0
- package/dist/types/NaturalNumbersLessThanOrEqualTo.js +2 -0
- package/dist/types/PickingUpItem.js +44 -0
- package/dist/types/PickupIndex.js +2 -0
- package/dist/types/PlayerIndex.js +2 -0
- package/dist/types/PossibleStatType.js +2 -0
- package/dist/types/PublicInterface.js +2 -0
- package/dist/types/ReadonlyMap.js +6 -0
- package/dist/types/ReadonlyRecord.js +2 -0
- package/dist/types/ReadonlySet.js +6 -0
- package/dist/types/StartsWithLowercase.js +2 -0
- package/dist/types/StartsWithUppercase.js +2 -0
- package/dist/types/TSTLClass.js +2 -0
- package/dist/types/Tuple.js +2 -0
- package/dist/types/TupleKeys.js +2 -0
- package/dist/types/TupleToIntersection.js +2 -0
- package/dist/types/TupleToUnion.js +2 -0
- package/dist/types/TupleWithLengthBetween.js +22 -0
- package/dist/types/TupleWithMaxLength.js +27 -0
- package/dist/types/UnionToIntersection.js +2 -0
- package/dist/types/UppercaseKeys.js +2 -0
- package/dist/types/WeightedArray.js +2 -0
- package/dist/types/WidenLiteral.js +2 -0
- package/dist/types/Writable.js +2 -0
- package/dist/types/private/CallbackTuple.js +2 -0
- package/dist/types/private/ModUpgradedWithFeatures.js +2 -0
- package/package.json +1 -1
- package/src/functions/utils.ts +4 -1
|
@@ -0,0 +1,586 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.swapArrayElements = exports.sumArray = exports.shuffleArrayInPlace = exports.shuffleArray = exports.setAllArrayElements = exports.isArrayInArray = exports.isArrayElementsUnique = exports.isArrayContiguous = exports.isArray = exports.includes = exports.getRandomArrayIndex = exports.getRandomArrayElementAndRemove = exports.getRandomArrayElement = exports.getLowestArrayElement = exports.getHighestArrayElement = exports.getArrayIndexes = exports.getArrayDuplicateElements = exports.getArrayCombinations = exports.filterMap = exports.emptyArray = exports.copyArray = exports.combineArrays = exports.arrayToString = exports.arrayRemoveIndexInPlace = exports.arrayRemoveIndex = exports.arrayRemoveInPlace = exports.arrayRemoveAllInPlace = exports.arrayRemoveAll = exports.arrayRemove = exports.arrayEquals = void 0;
|
|
4
|
+
const ReadonlySet_1 = require("../types/ReadonlySet");
|
|
5
|
+
const random_1 = require("./random");
|
|
6
|
+
const rng_1 = require("./rng");
|
|
7
|
+
const types_1 = require("./types");
|
|
8
|
+
const utils_1 = require("./utils");
|
|
9
|
+
/**
|
|
10
|
+
* Helper function for determining if two arrays contain the exact same elements. Note that this
|
|
11
|
+
* only performs a shallow comparison.
|
|
12
|
+
*/
|
|
13
|
+
function arrayEquals(array1, array2) {
|
|
14
|
+
if (array1.length !== array2.length) {
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
return array1.every((array1Element, i) => {
|
|
18
|
+
const array2Element = array2[i];
|
|
19
|
+
return array1Element === array2Element;
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
exports.arrayEquals = arrayEquals;
|
|
23
|
+
/**
|
|
24
|
+
* Builds a new array based on the original array without the specified element(s). Returns the new
|
|
25
|
+
* array. If the specified element(s) are not found in the array, it will simply return a shallow
|
|
26
|
+
* copy of the array.
|
|
27
|
+
*
|
|
28
|
+
* This function is variadic, meaning that you can specify N arguments to remove N elements.
|
|
29
|
+
*
|
|
30
|
+
* If there is more than one matching element in the array, this function will only remove the first
|
|
31
|
+
* matching element. If you want to remove all of the elements, use the `arrayRemoveAll` function
|
|
32
|
+
* instead.
|
|
33
|
+
*/
|
|
34
|
+
// eslint-disable-next-line isaacscript/no-mutable-return
|
|
35
|
+
function arrayRemove(originalArray, ...elementsToRemove) {
|
|
36
|
+
const elementsToRemoveSet = new ReadonlySet_1.ReadonlySet(elementsToRemove);
|
|
37
|
+
const array = [];
|
|
38
|
+
for (const element of originalArray) {
|
|
39
|
+
if (!elementsToRemoveSet.has(element)) {
|
|
40
|
+
array.push(element);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return array;
|
|
44
|
+
}
|
|
45
|
+
exports.arrayRemove = arrayRemove;
|
|
46
|
+
/**
|
|
47
|
+
* Shallow copies and removes the specified element(s) from the array. Returns the copied array. If
|
|
48
|
+
* the specified element(s) are not found in the array, it will simply return a shallow copy of the
|
|
49
|
+
* array.
|
|
50
|
+
*
|
|
51
|
+
* This function is variadic, meaning that you can specify N arguments to remove N elements.
|
|
52
|
+
*
|
|
53
|
+
* If there is more than one matching element in the array, this function will remove every matching
|
|
54
|
+
* element. If you want to only remove the first matching element, use the `arrayRemove` function
|
|
55
|
+
* instead.
|
|
56
|
+
*/
|
|
57
|
+
// eslint-disable-next-line isaacscript/no-mutable-return
|
|
58
|
+
function arrayRemoveAll(originalArray, ...elementsToRemove) {
|
|
59
|
+
const array = copyArray(originalArray);
|
|
60
|
+
arrayRemoveAllInPlace(array, ...elementsToRemove);
|
|
61
|
+
return array;
|
|
62
|
+
}
|
|
63
|
+
exports.arrayRemoveAll = arrayRemoveAll;
|
|
64
|
+
/**
|
|
65
|
+
* Removes all of the specified element(s) from the array. If the specified element(s) are not found
|
|
66
|
+
* in the array, this function will do nothing.
|
|
67
|
+
*
|
|
68
|
+
* This function is variadic, meaning that you can specify N arguments to remove N elements.
|
|
69
|
+
*
|
|
70
|
+
* If there is more than one matching element in the array, this function will remove every matching
|
|
71
|
+
* element. If you want to only remove the first matching element, use the `arrayRemoveInPlace`
|
|
72
|
+
* function instead.
|
|
73
|
+
*
|
|
74
|
+
* @returns True if one or more elements were removed, false otherwise.
|
|
75
|
+
*/
|
|
76
|
+
function arrayRemoveAllInPlace(
|
|
77
|
+
// eslint-disable-next-line isaacscript/prefer-readonly-parameter-types
|
|
78
|
+
array, ...elementsToRemove) {
|
|
79
|
+
let removedOneOrMoreElements = false;
|
|
80
|
+
for (const element of elementsToRemove) {
|
|
81
|
+
let index;
|
|
82
|
+
do {
|
|
83
|
+
index = array.indexOf(element);
|
|
84
|
+
if (index > -1) {
|
|
85
|
+
removedOneOrMoreElements = true;
|
|
86
|
+
array.splice(index, 1);
|
|
87
|
+
}
|
|
88
|
+
} while (index > -1);
|
|
89
|
+
}
|
|
90
|
+
return removedOneOrMoreElements;
|
|
91
|
+
}
|
|
92
|
+
exports.arrayRemoveAllInPlace = arrayRemoveAllInPlace;
|
|
93
|
+
/**
|
|
94
|
+
* Removes the specified element(s) from the array. If the specified element(s) are not found in the
|
|
95
|
+
* array, this function will do nothing.
|
|
96
|
+
*
|
|
97
|
+
* This function is variadic, meaning that you can specify N arguments to remove N elements.
|
|
98
|
+
*
|
|
99
|
+
* If there is more than one matching element in the array, this function will only remove the first
|
|
100
|
+
* matching element. If you want to remove all of the elements, use the `arrayRemoveAllInPlace`
|
|
101
|
+
* function instead.
|
|
102
|
+
*
|
|
103
|
+
* @returns The removed elements. This will be an empty array if no elements were removed.
|
|
104
|
+
*/
|
|
105
|
+
// eslint-disable-next-line isaacscript/no-mutable-return
|
|
106
|
+
function arrayRemoveInPlace(
|
|
107
|
+
// eslint-disable-next-line isaacscript/prefer-readonly-parameter-types
|
|
108
|
+
array, ...elementsToRemove) {
|
|
109
|
+
const removedElements = [];
|
|
110
|
+
for (const element of elementsToRemove) {
|
|
111
|
+
const index = array.indexOf(element);
|
|
112
|
+
if (index > -1) {
|
|
113
|
+
const removedElement = array.splice(index, 1);
|
|
114
|
+
removedElements.push(...removedElement);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
return removedElements;
|
|
118
|
+
}
|
|
119
|
+
exports.arrayRemoveInPlace = arrayRemoveInPlace;
|
|
120
|
+
/**
|
|
121
|
+
* Shallow copies and removes the elements at the specified indexes from the array. Returns the
|
|
122
|
+
* copied array. If the specified indexes are not found in the array, it will simply return a
|
|
123
|
+
* shallow copy of the array.
|
|
124
|
+
*
|
|
125
|
+
* This function is variadic, meaning that you can specify N arguments to remove N elements.
|
|
126
|
+
*/
|
|
127
|
+
// eslint-disable-next-line isaacscript/no-mutable-return
|
|
128
|
+
function arrayRemoveIndex(originalArray, ...indexesToRemove) {
|
|
129
|
+
const indexesToRemoveSet = new ReadonlySet_1.ReadonlySet(indexesToRemove);
|
|
130
|
+
const array = [];
|
|
131
|
+
for (const [i, element] of originalArray.entries()) {
|
|
132
|
+
if (!indexesToRemoveSet.has(i)) {
|
|
133
|
+
array.push(element);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
return array;
|
|
137
|
+
}
|
|
138
|
+
exports.arrayRemoveIndex = arrayRemoveIndex;
|
|
139
|
+
/**
|
|
140
|
+
* Removes the elements at the specified indexes from the array. If the specified indexes are not
|
|
141
|
+
* found in the array, this function will do nothing.
|
|
142
|
+
*
|
|
143
|
+
* This function is variadic, meaning that you can specify N arguments to remove N elements.
|
|
144
|
+
*
|
|
145
|
+
* @returns The removed elements. This will be an empty array if no elements were removed.
|
|
146
|
+
*/
|
|
147
|
+
// eslint-disable-next-line isaacscript/no-mutable-return
|
|
148
|
+
function arrayRemoveIndexInPlace(
|
|
149
|
+
// eslint-disable-next-line isaacscript/prefer-readonly-parameter-types
|
|
150
|
+
array, ...indexesToRemove) {
|
|
151
|
+
const legalIndexes = indexesToRemove.filter((i) => i >= 0 && i < array.length);
|
|
152
|
+
if (legalIndexes.length === 0) {
|
|
153
|
+
return [];
|
|
154
|
+
}
|
|
155
|
+
const legalIndexesSet = new ReadonlySet_1.ReadonlySet(legalIndexes);
|
|
156
|
+
const removedElements = [];
|
|
157
|
+
for (let i = array.length - 1; i >= 0; i--) {
|
|
158
|
+
if (legalIndexesSet.has(i)) {
|
|
159
|
+
const removedElement = array.splice(i, 1);
|
|
160
|
+
removedElements.push(...removedElement);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
return removedElements;
|
|
164
|
+
}
|
|
165
|
+
exports.arrayRemoveIndexInPlace = arrayRemoveIndexInPlace;
|
|
166
|
+
function arrayToString(array) {
|
|
167
|
+
if (array.length === 0) {
|
|
168
|
+
return "[]";
|
|
169
|
+
}
|
|
170
|
+
const strings = array.map((element) => tostring(element));
|
|
171
|
+
const commaSeparatedStrings = strings.join(", ");
|
|
172
|
+
return `[${commaSeparatedStrings}]`;
|
|
173
|
+
}
|
|
174
|
+
exports.arrayToString = arrayToString;
|
|
175
|
+
/**
|
|
176
|
+
* Helper function to combine two or more arrays. Returns a new array that is the composition of all
|
|
177
|
+
* of the specified arrays.
|
|
178
|
+
*
|
|
179
|
+
* This function is variadic, meaning that you can specify N arguments to combine N arrays. Note
|
|
180
|
+
* that this will only perform a shallow copy of the array elements.
|
|
181
|
+
*/
|
|
182
|
+
// eslint-disable-next-line isaacscript/no-mutable-return
|
|
183
|
+
function combineArrays(...arrays) {
|
|
184
|
+
const elements = [];
|
|
185
|
+
for (const array of arrays) {
|
|
186
|
+
for (const element of array) {
|
|
187
|
+
elements.push(element);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
return elements;
|
|
191
|
+
}
|
|
192
|
+
exports.combineArrays = combineArrays;
|
|
193
|
+
/**
|
|
194
|
+
* Helper function to perform a shallow copy.
|
|
195
|
+
*
|
|
196
|
+
* @param oldArray The array to copy.
|
|
197
|
+
* @param numElements Optional. If specified, will only copy the first N elements. By default, the
|
|
198
|
+
* entire array will be copied.
|
|
199
|
+
*/
|
|
200
|
+
// eslint-disable-next-line isaacscript/no-mutable-return
|
|
201
|
+
function copyArray(oldArray, numElements) {
|
|
202
|
+
// Using the spread operator was benchmarked to be faster than manually creating an array using
|
|
203
|
+
// the below algorithm.
|
|
204
|
+
if (numElements === undefined) {
|
|
205
|
+
return [...oldArray];
|
|
206
|
+
}
|
|
207
|
+
const newArrayWithFirstNElements = [];
|
|
208
|
+
for (let i = 0; i < numElements; i++) {
|
|
209
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
210
|
+
newArrayWithFirstNElements.push(oldArray[i]);
|
|
211
|
+
}
|
|
212
|
+
return newArrayWithFirstNElements;
|
|
213
|
+
}
|
|
214
|
+
exports.copyArray = copyArray;
|
|
215
|
+
/** Helper function to remove all of the elements in an array in-place. */
|
|
216
|
+
// eslint-disable-next-line isaacscript/prefer-readonly-parameter-types
|
|
217
|
+
function emptyArray(array) {
|
|
218
|
+
array.splice(0, array.length);
|
|
219
|
+
}
|
|
220
|
+
exports.emptyArray = emptyArray;
|
|
221
|
+
/**
|
|
222
|
+
* Helper function to perform a map and a filter at the same time. Similar to `Array.map`, provide a
|
|
223
|
+
* function that transforms a value, but return `undefined` if the value should be skipped. (Thus,
|
|
224
|
+
* this function cannot be used in situations where `undefined` can be a valid array element.)
|
|
225
|
+
*
|
|
226
|
+
* This function is useful because the `Array.map` method will always produce an array with the same
|
|
227
|
+
* amount of elements as the original array.
|
|
228
|
+
*
|
|
229
|
+
* This is named `filterMap` after the Rust function:
|
|
230
|
+
* https://doc.rust-lang.org/std/iter/struct.FilterMap.html
|
|
231
|
+
*/
|
|
232
|
+
// eslint-disable-next-line isaacscript/no-mutable-return
|
|
233
|
+
function filterMap(array, func) {
|
|
234
|
+
const newArray = [];
|
|
235
|
+
for (const element of array) {
|
|
236
|
+
const newElement = func(element);
|
|
237
|
+
if (newElement !== undefined) {
|
|
238
|
+
newArray.push(newElement);
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
return newArray;
|
|
242
|
+
}
|
|
243
|
+
exports.filterMap = filterMap;
|
|
244
|
+
/**
|
|
245
|
+
* Helper function to get all possible combinations of the given array. This includes the
|
|
246
|
+
* combination of an empty array.
|
|
247
|
+
*
|
|
248
|
+
* For example, if this function is provided an array containing 1, 2, and 3, then it will return an
|
|
249
|
+
* array containing the following arrays:
|
|
250
|
+
*
|
|
251
|
+
* - [] (if `includeEmptyArray` is set to true)
|
|
252
|
+
* - [1]
|
|
253
|
+
* - [2]
|
|
254
|
+
* - [3]
|
|
255
|
+
* - [1, 2]
|
|
256
|
+
* - [1, 3]
|
|
257
|
+
* - [2, 3]
|
|
258
|
+
* - [1, 2, 3]
|
|
259
|
+
*
|
|
260
|
+
* From: https://github.com/firstandthird/combinations/blob/master/index.js
|
|
261
|
+
*
|
|
262
|
+
* @param array The array to get the combinations of.
|
|
263
|
+
* @param includeEmptyArray Whether to include an empty array in the combinations.
|
|
264
|
+
* @param min Optional. The minimum number of elements to include in each combination. Default is 1.
|
|
265
|
+
* @param max Optional. The maximum number of elements to include in each combination. Default is
|
|
266
|
+
* the length of the array.
|
|
267
|
+
*/
|
|
268
|
+
function getArrayCombinations(array, includeEmptyArray, min, max) {
|
|
269
|
+
if (min === undefined || min <= 0) {
|
|
270
|
+
min = 1;
|
|
271
|
+
}
|
|
272
|
+
if (max === undefined || max <= 0) {
|
|
273
|
+
max = array.length;
|
|
274
|
+
}
|
|
275
|
+
const all = [];
|
|
276
|
+
for (let i = min; i < array.length; i++) {
|
|
277
|
+
addCombinations(i, array, [], all);
|
|
278
|
+
}
|
|
279
|
+
if (array.length === max) {
|
|
280
|
+
all.push(array);
|
|
281
|
+
}
|
|
282
|
+
// Finally, account for the empty array combination.
|
|
283
|
+
if (includeEmptyArray) {
|
|
284
|
+
all.unshift([]);
|
|
285
|
+
}
|
|
286
|
+
return all;
|
|
287
|
+
}
|
|
288
|
+
exports.getArrayCombinations = getArrayCombinations;
|
|
289
|
+
/** Mutates the `all` array in-place. */
|
|
290
|
+
function addCombinations(n, src, got,
|
|
291
|
+
// eslint-disable-next-line isaacscript/prefer-readonly-parameter-types
|
|
292
|
+
all) {
|
|
293
|
+
if (n === 0) {
|
|
294
|
+
if (got.length > 0) {
|
|
295
|
+
all[all.length] = got;
|
|
296
|
+
}
|
|
297
|
+
return;
|
|
298
|
+
}
|
|
299
|
+
for (const [i, element] of src.entries()) {
|
|
300
|
+
addCombinations(n - 1, src.slice(i + 1), [...got, element], all);
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
/**
|
|
304
|
+
* Helper function to get the duplicate elements in an array. Only one element for each value will
|
|
305
|
+
* be returned. The elements will be sorted before they are returned.
|
|
306
|
+
*/
|
|
307
|
+
function getArrayDuplicateElements(array) {
|
|
308
|
+
const duplicateElements = new Set();
|
|
309
|
+
const set = new Set();
|
|
310
|
+
for (const element of array) {
|
|
311
|
+
if (set.has(element)) {
|
|
312
|
+
duplicateElements.add(element);
|
|
313
|
+
}
|
|
314
|
+
set.add(element);
|
|
315
|
+
}
|
|
316
|
+
const values = [...duplicateElements];
|
|
317
|
+
return values.sort();
|
|
318
|
+
}
|
|
319
|
+
exports.getArrayDuplicateElements = getArrayDuplicateElements;
|
|
320
|
+
/**
|
|
321
|
+
* Helper function to get an array containing the indexes of an array.
|
|
322
|
+
*
|
|
323
|
+
* For example, an array of `["Apple", "Banana"]` would return an array of `[0, 1]`.
|
|
324
|
+
*
|
|
325
|
+
* Note that normally, you would use the `Object.keys` method to get the indexes of an array, but
|
|
326
|
+
* due to implementation details of TypeScriptToLua, this results in an array of 1 through N
|
|
327
|
+
* (instead of an array of 0 through N -1).
|
|
328
|
+
*/
|
|
329
|
+
function getArrayIndexes(array) {
|
|
330
|
+
return (0, utils_1.eRange)(array.length);
|
|
331
|
+
}
|
|
332
|
+
exports.getArrayIndexes = getArrayIndexes;
|
|
333
|
+
/**
|
|
334
|
+
* Helper function to get the highest value in an array. Returns undefined if there were no elements
|
|
335
|
+
* in the array.
|
|
336
|
+
*/
|
|
337
|
+
function getHighestArrayElement(array) {
|
|
338
|
+
if (array.length === 0) {
|
|
339
|
+
return undefined;
|
|
340
|
+
}
|
|
341
|
+
let highestValue;
|
|
342
|
+
for (const element of array) {
|
|
343
|
+
if (highestValue === undefined || element > highestValue) {
|
|
344
|
+
highestValue = element;
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
return highestValue;
|
|
348
|
+
}
|
|
349
|
+
exports.getHighestArrayElement = getHighestArrayElement;
|
|
350
|
+
/**
|
|
351
|
+
* Helper function to get the lowest value in an array. Returns undefined if there were no elements
|
|
352
|
+
* in the array.
|
|
353
|
+
*/
|
|
354
|
+
function getLowestArrayElement(array) {
|
|
355
|
+
if (array.length === 0) {
|
|
356
|
+
return undefined;
|
|
357
|
+
}
|
|
358
|
+
let lowestValue;
|
|
359
|
+
for (const element of array) {
|
|
360
|
+
if (lowestValue === undefined || element < lowestValue) {
|
|
361
|
+
lowestValue = element;
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
return lowestValue;
|
|
365
|
+
}
|
|
366
|
+
exports.getLowestArrayElement = getLowestArrayElement;
|
|
367
|
+
/**
|
|
368
|
+
* Helper function to get a random element from the provided array.
|
|
369
|
+
*
|
|
370
|
+
* If you want to get an unseeded element, you must explicitly pass `undefined` to the `seedOrRNG`
|
|
371
|
+
* parameter.
|
|
372
|
+
*
|
|
373
|
+
* @param array The array to get an element from.
|
|
374
|
+
* @param seedOrRNG The `Seed` or `RNG` object to use. If an `RNG` object is provided, the
|
|
375
|
+
* `RNG.Next` method will be called. If `undefined` is provided, it will default to
|
|
376
|
+
* a random seed.
|
|
377
|
+
* @param exceptions Optional. An array of elements to skip over if selected.
|
|
378
|
+
*/
|
|
379
|
+
function getRandomArrayElement(array, seedOrRNG, exceptions = []) {
|
|
380
|
+
if (array.length === 0) {
|
|
381
|
+
error("Failed to get a random array element since the provided array is empty.");
|
|
382
|
+
}
|
|
383
|
+
const arrayToUse = exceptions.length > 0 ? arrayRemove(array, ...exceptions) : array;
|
|
384
|
+
const randomIndex = getRandomArrayIndex(arrayToUse, seedOrRNG);
|
|
385
|
+
const randomElement = arrayToUse[randomIndex];
|
|
386
|
+
(0, utils_1.assertDefined)(randomElement, `Failed to get a random array element since the random index of ${randomIndex} was not valid.`);
|
|
387
|
+
return randomElement;
|
|
388
|
+
}
|
|
389
|
+
exports.getRandomArrayElement = getRandomArrayElement;
|
|
390
|
+
/**
|
|
391
|
+
* Helper function to get a random element from the provided array. Once the random element is
|
|
392
|
+
* decided, it is then removed from the array (in-place).
|
|
393
|
+
*
|
|
394
|
+
* If you want to get an unseeded element, you must explicitly pass `undefined` to the `seedOrRNG`
|
|
395
|
+
* parameter.
|
|
396
|
+
*
|
|
397
|
+
* @param array The array to get an element from.
|
|
398
|
+
* @param seedOrRNG The `Seed` or `RNG` object to use. If an `RNG` object is provided, the
|
|
399
|
+
* `RNG.Next` method will be called. If `undefined` is provided, it will default to
|
|
400
|
+
* a random seed.
|
|
401
|
+
* @param exceptions Optional. An array of elements to skip over if selected.
|
|
402
|
+
*/
|
|
403
|
+
function getRandomArrayElementAndRemove(
|
|
404
|
+
// eslint-disable-next-line isaacscript/prefer-readonly-parameter-types
|
|
405
|
+
array, seedOrRNG, exceptions = []) {
|
|
406
|
+
const randomArrayElement = getRandomArrayElement(array, seedOrRNG, exceptions);
|
|
407
|
+
arrayRemoveInPlace(array, randomArrayElement);
|
|
408
|
+
return randomArrayElement;
|
|
409
|
+
}
|
|
410
|
+
exports.getRandomArrayElementAndRemove = getRandomArrayElementAndRemove;
|
|
411
|
+
/**
|
|
412
|
+
* Helper function to get a random index from the provided array.
|
|
413
|
+
*
|
|
414
|
+
* If you want to get an unseeded index, you must explicitly pass `undefined` to the `seedOrRNG`
|
|
415
|
+
* parameter.
|
|
416
|
+
*
|
|
417
|
+
* @param array The array to get the index from.
|
|
418
|
+
* @param seedOrRNG The `Seed` or `RNG` object to use. If an `RNG` object is provided, the
|
|
419
|
+
* `RNG.Next` method will be called. If `undefined` is provided, it will default to
|
|
420
|
+
* a random seed.
|
|
421
|
+
* @param exceptions Optional. An array of indexes that will be skipped over when getting the random
|
|
422
|
+
* index. Default is an empty array.
|
|
423
|
+
*/
|
|
424
|
+
function getRandomArrayIndex(array, seedOrRNG, exceptions = []) {
|
|
425
|
+
if (array.length === 0) {
|
|
426
|
+
error("Failed to get a random array index since the provided array is empty.");
|
|
427
|
+
}
|
|
428
|
+
return (0, random_1.getRandomInt)(0, array.length - 1, seedOrRNG, exceptions);
|
|
429
|
+
}
|
|
430
|
+
exports.getRandomArrayIndex = getRandomArrayIndex;
|
|
431
|
+
/**
|
|
432
|
+
* Similar to the `Array.includes` method, but works on a widened version of the array.
|
|
433
|
+
*
|
|
434
|
+
* This is useful when the normal `Array.includes` produces a type error from an array that uses an
|
|
435
|
+
* `as const` assertion.
|
|
436
|
+
*/
|
|
437
|
+
function includes(array, searchElement) {
|
|
438
|
+
const widenedArray = array;
|
|
439
|
+
return widenedArray.includes(searchElement);
|
|
440
|
+
}
|
|
441
|
+
exports.includes = includes;
|
|
442
|
+
/**
|
|
443
|
+
* Since Lua uses tables for every non-primitive data structure, it is non-trivial to determine if a
|
|
444
|
+
* particular table is being used as an array. `isArray` returns true if:
|
|
445
|
+
*
|
|
446
|
+
* - the table contains all numerical indexes that are contiguous, starting at 1
|
|
447
|
+
* - the table has no keys (i.e. an "empty" table)
|
|
448
|
+
*
|
|
449
|
+
* @param object The object to analyze.
|
|
450
|
+
* @param ensureContiguousValues Optional. Whether the Lua table has to have all contiguous keys in
|
|
451
|
+
* order to be considered an array. Default is true.
|
|
452
|
+
*/
|
|
453
|
+
function isArray(object, ensureContiguousValues = true) {
|
|
454
|
+
if (!(0, types_1.isTable)(object)) {
|
|
455
|
+
return false;
|
|
456
|
+
}
|
|
457
|
+
// First, if there is a metatable, this cannot be a simple array and must be a more complex
|
|
458
|
+
// object.
|
|
459
|
+
const metatable = getmetatable(object);
|
|
460
|
+
if (metatable !== undefined) {
|
|
461
|
+
return false;
|
|
462
|
+
}
|
|
463
|
+
// Second, handle the case of an "empty" table.
|
|
464
|
+
const keys = Object.keys(object);
|
|
465
|
+
if (keys.length === 0) {
|
|
466
|
+
return true;
|
|
467
|
+
}
|
|
468
|
+
// Third, handle the case of non-numerical keys.
|
|
469
|
+
const hasAllNumberKeys = keys.every((key) => (0, types_1.isNumber)(key));
|
|
470
|
+
if (!hasAllNumberKeys) {
|
|
471
|
+
return false;
|
|
472
|
+
}
|
|
473
|
+
// Fourth, check for non-contiguous elements. (Lua tables start at an index of 1.)
|
|
474
|
+
if (ensureContiguousValues) {
|
|
475
|
+
for (let i = 1; i <= keys.length; i++) {
|
|
476
|
+
const element = object.get(i);
|
|
477
|
+
if (element === undefined) {
|
|
478
|
+
return false;
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
return true;
|
|
483
|
+
}
|
|
484
|
+
exports.isArray = isArray;
|
|
485
|
+
/**
|
|
486
|
+
* Helper function to see if every element in the array is N + 1.
|
|
487
|
+
*
|
|
488
|
+
* For example, `[2, 3, 4]` would return true, and `[2, 3, 5]` would return false.
|
|
489
|
+
*/
|
|
490
|
+
function isArrayContiguous(array) {
|
|
491
|
+
let lastValue;
|
|
492
|
+
for (const element of array) {
|
|
493
|
+
if (lastValue === undefined) {
|
|
494
|
+
lastValue = element - 1;
|
|
495
|
+
}
|
|
496
|
+
if (element !== lastValue - 1) {
|
|
497
|
+
return false;
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
return true;
|
|
501
|
+
}
|
|
502
|
+
exports.isArrayContiguous = isArrayContiguous;
|
|
503
|
+
/**
|
|
504
|
+
* Helper function to check if all the elements of an array are unique within that array.
|
|
505
|
+
*
|
|
506
|
+
* Under the hood, this is performed by converting the array to a set.
|
|
507
|
+
*/
|
|
508
|
+
function isArrayElementsUnique(array) {
|
|
509
|
+
const set = new Set(array);
|
|
510
|
+
return set.size === array.length;
|
|
511
|
+
}
|
|
512
|
+
exports.isArrayElementsUnique = isArrayElementsUnique;
|
|
513
|
+
/** Checks if an array is in the provided 2-dimensional array. */
|
|
514
|
+
function isArrayInArray(arrayToMatch, parentArray) {
|
|
515
|
+
return parentArray.some((element) => arrayEquals(element, arrayToMatch));
|
|
516
|
+
}
|
|
517
|
+
exports.isArrayInArray = isArrayInArray;
|
|
518
|
+
/** Helper function to set every element in an array to a specific value. */
|
|
519
|
+
// eslint-disable-next-line isaacscript/prefer-readonly-parameter-types
|
|
520
|
+
function setAllArrayElements(array, value) {
|
|
521
|
+
for (let i = 0; i < array.length; i++) {
|
|
522
|
+
array[i] = value;
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
exports.setAllArrayElements = setAllArrayElements;
|
|
526
|
+
/**
|
|
527
|
+
* Shallow copies and shuffles the array using the Fisher-Yates algorithm. Returns the copied array.
|
|
528
|
+
*
|
|
529
|
+
* If you want an unseeded shuffle, you must explicitly pass `undefined` to the `seedOrRNG`
|
|
530
|
+
* parameter.
|
|
531
|
+
*
|
|
532
|
+
* From: https://stackoverflow.com/questions/2450954/how-to-randomize-shuffle-a-javascript-array
|
|
533
|
+
*
|
|
534
|
+
* @param originalArray The array to shuffle.
|
|
535
|
+
* @param seedOrRNG The `Seed` or `RNG` object to use. If an `RNG` object is provided, the
|
|
536
|
+
* `RNG.Next` method will be called. If `undefined` is provided, it will default to
|
|
537
|
+
* a random seed.
|
|
538
|
+
*/
|
|
539
|
+
// eslint-disable-next-line isaacscript/no-mutable-return
|
|
540
|
+
function shuffleArray(originalArray, seedOrRNG) {
|
|
541
|
+
const array = copyArray(originalArray);
|
|
542
|
+
shuffleArrayInPlace(array, seedOrRNG);
|
|
543
|
+
return array;
|
|
544
|
+
}
|
|
545
|
+
exports.shuffleArray = shuffleArray;
|
|
546
|
+
/**
|
|
547
|
+
* Shuffles the provided array in-place using the Fisher-Yates algorithm.
|
|
548
|
+
*
|
|
549
|
+
* If you want an unseeded shuffle, you must explicitly pass `undefined` to the `seedOrRNG`
|
|
550
|
+
* parameter.
|
|
551
|
+
*
|
|
552
|
+
* From: https://stackoverflow.com/questions/2450954/how-to-randomize-shuffle-a-javascript-array
|
|
553
|
+
*
|
|
554
|
+
* @param array The array to shuffle.
|
|
555
|
+
* @param seedOrRNG The `Seed` or `RNG` object to use. If an `RNG` object is provided, the
|
|
556
|
+
* `RNG.Next` method will be called. If `undefined` is provided, it will default to
|
|
557
|
+
* a random seed.
|
|
558
|
+
*/
|
|
559
|
+
function shuffleArrayInPlace(
|
|
560
|
+
// eslint-disable-next-line isaacscript/prefer-readonly-parameter-types
|
|
561
|
+
array, seedOrRNG) {
|
|
562
|
+
let currentIndex = array.length;
|
|
563
|
+
const rng = (0, rng_1.isRNG)(seedOrRNG) ? seedOrRNG : (0, rng_1.newRNG)(seedOrRNG);
|
|
564
|
+
while (currentIndex > 0) {
|
|
565
|
+
currentIndex--;
|
|
566
|
+
const randomIndex = getRandomArrayIndex(array, rng);
|
|
567
|
+
swapArrayElements(array, currentIndex, randomIndex);
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
exports.shuffleArrayInPlace = shuffleArrayInPlace;
|
|
571
|
+
/** Helper function to sum every value in an array together. */
|
|
572
|
+
function sumArray(array) {
|
|
573
|
+
return array.reduce((accumulator, element) => accumulator + element, 0);
|
|
574
|
+
}
|
|
575
|
+
exports.sumArray = sumArray;
|
|
576
|
+
/**
|
|
577
|
+
* Helper function to swap two different array elements. (The elements will be swapped in-place.)
|
|
578
|
+
*/
|
|
579
|
+
// eslint-disable-next-line isaacscript/prefer-readonly-parameter-types
|
|
580
|
+
function swapArrayElements(array, i, j) {
|
|
581
|
+
const value1 = array[i]; // eslint-disable-line @typescript-eslint/no-non-null-assertion
|
|
582
|
+
const value2 = array[j]; // eslint-disable-line @typescript-eslint/no-non-null-assertion
|
|
583
|
+
array[i] = value2;
|
|
584
|
+
array[j] = value1;
|
|
585
|
+
}
|
|
586
|
+
exports.swapArrayElements = swapArrayElements;
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* These are a collection of functions for non-TypeScript users so that they can access some of
|
|
4
|
+
* useful methods offered on the `Array` class in the JavaScript standard library.
|
|
5
|
+
*
|
|
6
|
+
* If you are a TypeScript user, you should never use these functions, and instead use the more
|
|
7
|
+
* idiomatic object-oriented approach.
|
|
8
|
+
*
|
|
9
|
+
* @module
|
|
10
|
+
*/
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.some = exports.map = exports.join = exports.forEach = exports.find = exports.filter = exports.every = void 0;
|
|
13
|
+
/**
|
|
14
|
+
* Helper function for non-TypeScript users to check if every element in the array is equal to a
|
|
15
|
+
* condition.
|
|
16
|
+
*
|
|
17
|
+
* Internally, this just calls `Array.every`.
|
|
18
|
+
*/
|
|
19
|
+
function every(array, func) {
|
|
20
|
+
return array.every(func);
|
|
21
|
+
}
|
|
22
|
+
exports.every = every;
|
|
23
|
+
/**
|
|
24
|
+
* Helper function for non-TypeScript users to filter the elements in an array. Returns the filtered
|
|
25
|
+
* array.
|
|
26
|
+
*
|
|
27
|
+
* Internally, this just calls `Array.filter`.
|
|
28
|
+
*/
|
|
29
|
+
function filter(array, func) {
|
|
30
|
+
return array.filter(func);
|
|
31
|
+
}
|
|
32
|
+
exports.filter = filter;
|
|
33
|
+
/**
|
|
34
|
+
* Helper function for non-TypeScript users to find an element in an array.
|
|
35
|
+
*
|
|
36
|
+
* Internally, this just calls `Array.find`.
|
|
37
|
+
*/
|
|
38
|
+
function find(array, func) {
|
|
39
|
+
return array.find(func);
|
|
40
|
+
}
|
|
41
|
+
exports.find = find;
|
|
42
|
+
/**
|
|
43
|
+
* Helper function for non-TypeScript users to iterate over an array.
|
|
44
|
+
*
|
|
45
|
+
* Internally, this just calls `Array.forEach`.
|
|
46
|
+
*/
|
|
47
|
+
function forEach(array, func) {
|
|
48
|
+
array.forEach(func); // eslint-disable-line unicorn/no-array-for-each
|
|
49
|
+
}
|
|
50
|
+
exports.forEach = forEach;
|
|
51
|
+
// `includes` is not included since there is a normal array helper function of that name.
|
|
52
|
+
/**
|
|
53
|
+
* Helper function for non-TypeScript users to convert an array to a string with the specified
|
|
54
|
+
* separator.
|
|
55
|
+
*
|
|
56
|
+
* Internally, this just calls `Array.join`.
|
|
57
|
+
*/
|
|
58
|
+
function join(array, separator) {
|
|
59
|
+
return array.join(separator);
|
|
60
|
+
}
|
|
61
|
+
exports.join = join;
|
|
62
|
+
/**
|
|
63
|
+
* Helper function for non-TypeScript users to convert all of the elements in an array to something
|
|
64
|
+
* else.
|
|
65
|
+
*
|
|
66
|
+
* Internally, this just calls `Array.map`.
|
|
67
|
+
*/
|
|
68
|
+
function map(array, func) {
|
|
69
|
+
return array.map(func);
|
|
70
|
+
}
|
|
71
|
+
exports.map = map;
|
|
72
|
+
/**
|
|
73
|
+
* Helper function for non-TypeScript users to check if one or more elements in the array is equal
|
|
74
|
+
* to a condition.
|
|
75
|
+
*
|
|
76
|
+
* Internally, this just calls `Array.some`.
|
|
77
|
+
*/
|
|
78
|
+
function some(array, func) {
|
|
79
|
+
return array.some(func);
|
|
80
|
+
}
|
|
81
|
+
exports.some = some;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.benchmark = void 0;
|
|
4
|
+
const log_1 = require("./log");
|
|
5
|
+
/**
|
|
6
|
+
* Helper function to benchmark the performance of a function.
|
|
7
|
+
*
|
|
8
|
+
* This function is variadic, which means that you can supply as many functions as you want to
|
|
9
|
+
* benchmark.
|
|
10
|
+
*
|
|
11
|
+
* This function uses the `Isaac.GetTime` method to record how long the function took to execute.
|
|
12
|
+
* This method only reports time in milliseconds. For this reason, if you are benchmarking smaller
|
|
13
|
+
* functions, then you should provide a very high value for the number of trials.
|
|
14
|
+
*
|
|
15
|
+
* @returns An array containing the average time in milliseconds for each function. (This will also
|
|
16
|
+
* be printed to the log.)
|
|
17
|
+
*/
|
|
18
|
+
function benchmark(numTrials, ...functions) {
|
|
19
|
+
(0, log_1.log)(`Benchmarking ${functions.length} function(s) with ${numTrials} trials.`);
|
|
20
|
+
const averages = [];
|
|
21
|
+
for (const [i, func] of functions.entries()) {
|
|
22
|
+
let totalTimeMilliseconds = 0;
|
|
23
|
+
for (let j = 0; j < numTrials; j++) {
|
|
24
|
+
const startTimeMilliseconds = Isaac.GetTime();
|
|
25
|
+
func();
|
|
26
|
+
const endTimeMilliseconds = Isaac.GetTime();
|
|
27
|
+
const elapsedTimeMilliseconds = endTimeMilliseconds - startTimeMilliseconds;
|
|
28
|
+
totalTimeMilliseconds += elapsedTimeMilliseconds;
|
|
29
|
+
}
|
|
30
|
+
const averageTimeMilliseconds = totalTimeMilliseconds / numTrials;
|
|
31
|
+
(0, log_1.log)(`The average time of the function at index ${i} is: ${averageTimeMilliseconds} milliseconds`);
|
|
32
|
+
averages.push(averageTimeMilliseconds);
|
|
33
|
+
}
|
|
34
|
+
return averages;
|
|
35
|
+
}
|
|
36
|
+
exports.benchmark = benchmark;
|