isaacscript-common
Version:
Helper functions and features for IsaacScript mods.
143 lines (142 loc) • 6.19 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getGridIndexDelta = getGridIndexDelta;
exports.getRoomShapeBottomRightPosition = getRoomShapeBottomRightPosition;
exports.getRoomShapeBounds = getRoomShapeBounds;
exports.getRoomShapeCharges = getRoomShapeCharges;
exports.getRoomShapeCorners = getRoomShapeCorners;
exports.getRoomShapeLayoutSize = getRoomShapeLayoutSize;
exports.getRoomShapeTopLeftPosition = getRoomShapeTopLeftPosition;
exports.getRoomShapeVolume = getRoomShapeVolume;
exports.getRoomShapeWidth = getRoomShapeWidth;
exports.is2x1RoomShape = is2x1RoomShape;
exports.isBigRoomShape = isBigRoomShape;
exports.isLRoomShape = isLRoomShape;
exports.isNarrowRoom = isNarrowRoom;
exports.isRoomShapeDoubleCharge = isRoomShapeDoubleCharge;
const isaac_typescript_definitions_1 = require("isaac-typescript-definitions");
const roomShapeBounds_1 = require("../objects/roomShapeBounds");
const roomShapeCorners_1 = require("../objects/roomShapeCorners");
const roomShapeLayoutSizes_1 = require("../objects/roomShapeLayoutSizes");
const roomShapeToBottomRightPosition_1 = require("../objects/roomShapeToBottomRightPosition");
const roomShapeToDoorSlotsToGridIndexDelta_1 = require("../objects/roomShapeToDoorSlotsToGridIndexDelta");
const roomShapeToGridWidth_1 = require("../objects/roomShapeToGridWidth");
const roomShapeToTopLeftPosition_1 = require("../objects/roomShapeToTopLeftPosition");
const roomShapeVolumes_1 = require("../objects/roomShapeVolumes");
const LRoomShapesSet_1 = require("../sets/LRoomShapesSet");
const bigRoomShapesSet_1 = require("../sets/bigRoomShapesSet");
const narrowRoomShapesSet_1 = require("../sets/narrowRoomShapesSet");
/**
* Helper function to get the grid index delta that a door out of the given room shape would lead
* to. For example, if you went through the bottom door in a room of `RoomShape.SHAPE_1x2`, you
* would end up in a room with a grid index that is +26 units from the `SafeGridIndex` of where you
* started.
*/
function getGridIndexDelta(roomShape, doorSlot) {
const doorSlotToGridIndexMap = roomShapeToDoorSlotsToGridIndexDelta_1.ROOM_SHAPE_TO_DOOR_SLOTS_TO_GRID_INDEX_DELTA[roomShape];
return doorSlotToGridIndexMap.get(doorSlot);
}
/**
* Helper function to see if a given room shape will grant a single charge or a double charge to the
* player's active item(s).
*
* For example, `RoomShape.SHAPE_2x2` will return 2.
*/
function getRoomShapeBottomRightPosition(roomShape) {
return roomShapeToBottomRightPosition_1.ROOM_SHAPE_TO_BOTTOM_RIGHT_POSITION[roomShape];
}
/**
* Helper function to get the grid position of the bottom-right tile of a given room shape.
*
* "Vector(0, 0)" corresponds to the top left tile of a room, not including the walls. (The top-left
* wall would be at "Vector(-1, -1)".)
*/
function getRoomShapeBounds(roomShape) {
return roomShapeBounds_1.ROOM_SHAPE_BOUNDS[roomShape];
}
/**
* Helper function to get the number of charges that a given room shape will grant to a player upon
* clearing it.
*
* For example, `RoomShape.SHAPE_2x2` will return 2.
*/
function getRoomShapeCharges(roomShape) {
return isRoomShapeDoubleCharge(roomShape) ? 2 : 1;
}
/**
* Helper function to get the corners that exist in the given room shape.
*
* Note that these corner locations are not accurate for the Mother Boss Room and the Home closet
* rooms. (Those rooms have custom shapes.)
*/
function getRoomShapeCorners(roomShape) {
return roomShapeCorners_1.ROOM_SHAPE_CORNERS[roomShape];
}
/**
* Helper function to get the dimensions of a room shape's layout. This is NOT the size of the
* room's actual contents! For that, use the `getRoomShapeBounds` function.
*
* For example, a horizontal narrow room has a layout size of equal to that of a 1x1 room.
*/
function getRoomShapeLayoutSize(roomShape) {
return roomShapeLayoutSizes_1.ROOM_SHAPE_LAYOUT_SIZES[roomShape];
}
/**
* Helper function to get the grid position of the top-left tile of a given room shape.
*
* "Vector(0, 0)" corresponds to the top left tile of a room, not including the walls. (The top-left
* wall would be at "Vector(-1, -1)".)
*/
function getRoomShapeTopLeftPosition(roomShape) {
return roomShapeToTopLeftPosition_1.ROOM_SHAPE_TO_TOP_LEFT_POSITION[roomShape];
}
/**
* Helper function to get the volume of a room shape, which is the amount of tiles that are inside
* the room.
*
* (This cannot be directly calculated from the bounds since L rooms are a special case.)
*/
function getRoomShapeVolume(roomShape) {
return roomShapeVolumes_1.ROOM_SHAPE_VOLUMES[roomShape];
}
function getRoomShapeWidth(roomShape) {
return roomShapeToGridWidth_1.ROOM_SHAPE_TO_GRID_WIDTH[roomShape];
}
/**
* Helper function to determine if the provided room is equal to `RoomShape.1x2` (4) or
* `RoomShape.2x1` (6).
*/
function is2x1RoomShape(roomShape) {
return roomShape === isaac_typescript_definitions_1.RoomShape.SHAPE_1x2 || roomShape === isaac_typescript_definitions_1.RoomShape.SHAPE_2x1;
}
/**
* Helper function to detect if the provided room shape is big. Specifically, this is all 1x2 rooms,
* 2x2 rooms, and L rooms.
*/
function isBigRoomShape(roomShape) {
return bigRoomShapesSet_1.BIG_ROOM_SHAPES_SET.has(roomShape);
}
/**
* Helper function to determine if the provided room is equal to `RoomShape.LTL` (9),
* `RoomShape.LTR` (10), `RoomShape.LBL` (11), or `RoomShape.LBR` (12).
*/
function isLRoomShape(roomShape) {
return LRoomShapesSet_1.L_ROOM_SHAPES_SET.has(roomShape);
}
/**
* Helper function to determine if the provided room is equal to `RoomShape.IH` (2), `RoomShape.IV`
* (3), `RoomShape.IIV` (5), or `RoomShape.IIH` (7).
*/
function isNarrowRoom(roomShape) {
return narrowRoomShapesSet_1.NARROW_ROOM_SHAPES_SET.has(roomShape);
}
/**
* Helper function to see if a given room shape will grant a single charge or a double charge to the
* player's active item(s).
*
* For example, `RoomShape.SHAPE_2x2` will return true.
*/
function isRoomShapeDoubleCharge(roomShape) {
// 2x2 rooms and L rooms should grant 2 charges.
return roomShape >= isaac_typescript_definitions_1.RoomShape.SHAPE_2x2;
}