@duydang2311/ragemp-utils
Version:
A collection of utilities for RAGE Multiplayer JavaScript module.
155 lines (150 loc) • 5.3 kB
TypeScript
/**
* Represents a 2D vector with x and y coordinates.
*/
interface Vector2 {
/**
* The x coordinate of the vector.
*/
readonly x: number;
/**
* The y coordinate of the vector.
*/
readonly y: number;
}
declare const distanceSquared: {
(a: IVector3, b: IVector3): number;
(a: Vector2, b: Vector2): number;
};
interface Grid2D<T> {
/**
* The minimum x and y coordinates of the grid.
*/
readonly min: Vector2;
/**
* The maximum x and y coordinates of the grid.
*/
readonly max: Vector2;
/**
* The size of each cell in the grid in pixels.
*/
readonly cellSize: number;
/**
* The number of rows in the grid.
*/
readonly rows: number;
/**
* The number of columns in the grid.
*/
readonly columns: number;
/**
* A method to get the cell index for a given x, y coordinate.
* @param coords - The x, y coordinates to get the cell index for.
* @returns The index of the cell.
* @throws {Error} If the coordinates are out of bounds for the grid.
*/
cellAt(coords: Vector2): number;
/**
* A method to get the cell index for a given x, y coordinate.
* @param coords - The x, y coordinates to get the cell index for.
* @param radius - The radius around the coordinates to search for cells.
* @returns The index of the cell.
* @throws {Error} If the coordinates are out of bounds for the grid.
*/
nearbyCells(coords: Vector2, radius: number): number[];
/**
* Adds an item to the grid at the specified coordinates.
* @param item - The item to add to the grid.
* @param coords - The x, y coordinates to add the item at.
* @param radius - The radius around the coordinates to search for cells.
* @return {number} The id of the item added to the grid.
* @throws {Error} If the coordinates are out of bounds for the grid.
*/
add(item: T, coords: Vector2, radius?: number): number;
/**
* Removes an item from the grid by its id.
* @param id - The id of the item to remove.
* @return {boolean} True if the item was removed, false otherwise.
*/
remove(id: number): boolean;
/**
* Updates the coordinates and optionally the radius of an item in the grid.
* @param id - The id of the item to update.
* @param coords - The new x, y coordinates for the item.
* @param radius - The new radius for the item (optional).
* @return {boolean} True if the item was updated successfully, false if the item was not found.
* @throws {Error} If the coordinates are out of bounds for the grid.
*/
update(id: number, coords: Vector2, radius?: number): boolean;
}
interface CreateSpatialGrid2DOptions {
min?: Vector2;
max?: Vector2;
cellSize?: number;
}
declare class SpatialGrid2D<T> implements Grid2D<T> {
#private;
static readonly DEFAULT_MIN_X = -4000;
static readonly DEFAULT_MAX_X = 4000;
static readonly DEFAULT_MIN_Y = -4000;
static readonly DEFAULT_MAX_Y = 8000;
static readonly DEFAULT_CELL_SIZE = 128;
constructor(options?: CreateSpatialGrid2DOptions);
get min(): Vector2;
get max(): Vector2;
get cellSize(): number;
get rows(): number;
get columns(): number;
cellAt(coords: Vector2): number;
nearbyCells(coords: Vector2, radius: number): number[];
add(item: T, coords: Vector2, radius?: number): number;
update(id: number, coords: Vector2, radius?: number): boolean;
remove(id: number): boolean;
}
interface LocalMarker {
type: RageEnums.Markers;
position: IVector3;
destination: IVector3;
rotation: IVector3;
scale: IVector3;
radius: number;
color: RGBA;
bobUpAndDown: boolean;
faceCamera: boolean;
rotate: boolean;
textureDict: string | null;
textureName: string | null;
drawOnEnts: boolean;
render(): void;
}
declare class RageMpLocalMarker implements LocalMarker {
#private;
constructor(type: RageEnums.Markers, position: IVector3, destination: IVector3, rotation: IVector3, scale: IVector3, radius: number, color: RGBA, bobUpAndDown?: boolean, faceCamera?: boolean, rotate?: boolean, textureDict?: string | null, textureName?: string | null, drawOnEnts?: boolean);
get type(): number;
get position(): IVector3;
get destination(): IVector3;
get rotation(): IVector3;
get scale(): IVector3;
get radius(): number;
get color(): RGBA;
get bobUpAndDown(): boolean;
get faceCamera(): boolean;
get rotate(): boolean;
get textureDict(): string | null;
get textureName(): string | null;
get drawOnEnts(): boolean;
set type(value: number);
set position(value: IVector3);
set destination(value: IVector3);
set rotation(value: IVector3);
set scale(value: IVector3);
set radius(value: number);
set color(value: RGBA);
set bobUpAndDown(value: boolean);
set faceCamera(value: boolean);
set rotate(value: boolean);
set textureDict(value: string | null);
set textureName(value: string | null);
set drawOnEnts(value: boolean);
render(): void;
}
export { type CreateSpatialGrid2DOptions, type LocalMarker, RageMpLocalMarker, SpatialGrid2D, type Vector2, distanceSquared };