UNPKG

isaacscript-common

Version:

Helper functions and features for IsaacScript mods.

77 lines 3.65 kB
import type { CopyableIsaacAPIClassType, Direction } from "isaac-typescript-definitions"; export type SerializedVector = LuaMap<string, unknown> & { readonly __serializedVectorBrand: symbol; readonly __kind: CopyableIsaacAPIClassType.VECTOR; }; /** Helper function to copy a `Vector` Isaac API class. */ export declare function copyVector(vector: Vector): Vector; /** * Helper function to convert a `SerializedVector` object to a normal `RNG` object. (This is used by * the save data manager when reading data from the "save#.dat" file.) */ export declare function deserializeVector(vector: SerializedVector): Vector; /** * Helper function to measure a vector to see if it has a non-zero length using a threshold to * ignore extremely small values. * * Use this function instead of explicitly checking if the length is 0 because vectors in the game * are unlikely to ever be exactly set to 0. Instead, they will always have some miniscule length. * * @param vector The vector to measure. * @param threshold Optional. The threshold from 0 to consider to be a non-zero vector. Default is * 0.01. */ export declare function doesVectorHaveLength(vector: Vector, threshold?: number): boolean; /** * Given an array of vectors, this helper function returns the closest one to a provided reference * vector. * * @param referenceVector The vector to compare against. * @param vectors The array of vectors to look through. */ export declare function getClosestVectorTo(referenceVector: Vector, vectors: readonly Vector[]): Vector | undefined; /** * Helper function to get a random vector between (-1, -1) and (1, 1). * * To get random vectors with a bigger length, multiply this with a number. * * Use this over the `RandomVector` function when you need the vector to be seeded. * * If you want to generate an unseeded vector, you must explicitly pass `undefined` to the * `seedOrRNG` parameter. * * @param seedOrRNG The `Seed` or `RNG` object to use. If an `RNG` object is provided, the * `RNG.Next` method will be called. If `undefined` is provided, it will default to * a random seed. */ export declare function getRandomVector(seedOrRNG: Seed | RNG | undefined): Readonly<Vector>; /** * Used to determine is the given table is a serialized `Vector` object created by the `deepCopy` * function. */ export declare function isSerializedVector(object: unknown): object is SerializedVector; /** Helper function to check if something is an instantiated `Vector` object. */ export declare function isVector(object: unknown): object is Vector; /** * Helper function to convert a `Vector` object to a `SerializedVector` object. (This is used by the * save data manager when writing data from the "save#.dat" file.) */ export declare function serializeVector(vector: Vector): SerializedVector; /** * Helper function to compare two vectors for equality. * * This function is useful because vectors are not directly comparable. In other words, `Vector(1.2) * === Vector(1.2)` will be equal to false. */ export declare function vectorEquals(vector1: Vector, vector2: Vector): boolean; /** Helper function for finding out which way a vector is pointing. */ export declare function vectorToDirection(vector: Vector): Direction; /** * Helper function to convert a vector to a string. * * @param vector The vector to convert. * @param round Optional. If true, will round the vector values to the nearest integer. Default is * false. */ export declare function vectorToString(vector: Vector, round?: boolean): string; //# sourceMappingURL=vector.d.ts.map