isaacscript-common
Version:
Helper functions and features for IsaacScript mods.
66 lines (65 loc) • 2.95 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.fillLevelWithRedRooms = fillLevelWithRedRooms;
exports.getLevelBossIDs = getLevelBossIDs;
exports.levelHasBossID = levelHasBossID;
exports.levelHasRoomType = levelHasRoomType;
const isaac_typescript_definitions_1 = require("isaac-typescript-definitions");
const cachedEnumValues_1 = require("../cachedEnumValues");
const cachedClasses_1 = require("../core/cachedClasses");
const array_1 = require("./array");
const levelGrid_1 = require("./levelGrid");
const rooms_1 = require("./rooms");
/** Helper function to fill every possible level grid square with a red room. */
function fillLevelWithRedRooms() {
const level = cachedClasses_1.game.GetLevel();
let numRoomsInGrid;
do {
const roomsInGrid = (0, rooms_1.getRoomsInsideGrid)();
numRoomsInGrid = roomsInGrid.length;
for (const roomDescriptor of roomsInGrid) {
for (const doorSlot of cachedEnumValues_1.DOOR_SLOT_VALUES) {
if ((0, levelGrid_1.isDoorSlotValidAtGridIndexForRedRoom)(doorSlot, roomDescriptor.GridIndex)) {
level.MakeRedRoomDoor(roomDescriptor.GridIndex, doorSlot);
}
}
}
} while (numRoomsInGrid !== (0, rooms_1.getNumRooms)());
}
/**
* Helper function to get the boss IDs of all of the Boss Rooms on this floor. (This is equivalent
* to the sub-type of the room data.)
*
* Note that this will only look at Boss Rooms inside of the grid, so e.g. Reverse Emperor card
* rooms will not count.
*/
function getLevelBossIDs() {
const roomsInsideGrid = (0, rooms_1.getRoomsInsideGrid)();
return (0, array_1.filterMap)(roomsInsideGrid, (roomDescriptor) => roomDescriptor.Data !== undefined
&& roomDescriptor.Data.Type === isaac_typescript_definitions_1.RoomType.BOSS
&& roomDescriptor.Data.StageID === isaac_typescript_definitions_1.StageID.SPECIAL_ROOMS
? roomDescriptor.Data.Subtype
: undefined);
}
/**
* Helper function to check if the current floor has a Boss Room that matches the boss ID provided.
*
* This function is variadic, meaning that you can pass as many boss IDs as you want to check for.
* It will return true if one or more of the boss IDs are matched.
*/
function levelHasBossID(...bossIDs) {
const levelBossIDs = getLevelBossIDs();
const levelBossIDsSet = new Set(levelBossIDs);
return bossIDs.some((bossID) => levelBossIDsSet.has(bossID));
}
/**
* Helper function to check to see if the current floor has one or more of a specific room type in
* it.
*
* This function is variadic, meaning that you can pass as many room types as you want to check for.
* This function will return true if any of the room types are found.
*/
function levelHasRoomType(...roomTypes) {
const roomDescriptors = (0, levelGrid_1.getRoomDescriptorsForType)(...roomTypes);
return roomDescriptors.length > 0;
}