UNPKG

isaacscript-common

Version:

Helper functions and features for IsaacScript mods.

30 lines (29 loc) 1.32 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getDimension = getDimension; exports.inDimension = inDimension; const isaac_typescript_definitions_1 = require("isaac-typescript-definitions"); const cachedClasses_1 = require("../core/cachedClasses"); const constants_1 = require("../core/constants"); const roomData_1 = require("./roomData"); /** * Helper function to get the current dimension. Most of the time, this will be `Dimension.MAIN`, * but it can change if e.g. the player is in the mirror world of Downpour/Dross. */ function getDimension() { const level = cachedClasses_1.game.GetLevel(); const roomGridIndex = (0, roomData_1.getRoomGridIndex)(); const roomDescription = level.GetRoomByIdx(roomGridIndex, isaac_typescript_definitions_1.Dimension.CURRENT); const currentRoomHash = GetPtrHash(roomDescription); for (const dimension of constants_1.DIMENSIONS) { const dimensionRoomDescription = level.GetRoomByIdx(roomGridIndex, dimension); const dimensionRoomHash = GetPtrHash(dimensionRoomDescription); if (dimensionRoomHash === currentRoomHash) { return dimension; } } error("Failed to get the current dimension."); } function inDimension(dimension) { return dimension === getDimension(); }