@hydroperx/tiles
Version:
Metro tile layout
112 lines (111 loc) • 3.42 kB
TypeScript
/**
* A tile in the `BaseLayout` class.
*/
export declare class BaseTile {
x: number;
y: number;
width: number;
height: number;
/**
* @param x X coordinate in small tiles unit (1x1).
* @param y Y coordinate in small tiles unit (1x1).
* @param width Width in small tiles unit (1x1).
* @param height Height in small tiles unit (1x1).
*/
constructor(x: number, y: number, width: number, height: number);
/**
* Checks whether two tiles intersect.
*/
intersects(other: BaseTile): boolean;
/**
* Clones tile data.
*/
clone(): BaseTile;
}
/**
* A layout mimmicking the Windows 8 or 10's live tile layout.
*
* Tiles have a minimum position of (0, 0), and the maximum
* position is either infinite, or:
*
* - If `width` is given in the constructor, maximum X = `width`.
* - If `height` is given in the constructor, maximum Y = `height`.
*/
export declare class BaseLayout {
/**
* Tile data.
*/
tiles: Map<string, BaseTile>;
/**
* Maximum width.
*/
private maxWidth?;
/**
* Maximum height.
*/
private maxHeight?;
/**
* Constructor.
*
* - A `width` may be specified to limit how far tiles can go horizontally.
* - A `height` may be specified to limit how far tiles can go vertically.
*/
constructor({ width, height }: {
width?: number;
height?: number;
});
/**
* Returns whether a specific tile exists.
*/
hasTile(id: string): boolean;
/**
* Returns the size of the layout in small tile units (1x1).
*/
getLayoutSize(): {
width: number;
height: number;
};
/**
* Attempts to add a tile, shifting any overlapping tiles as needed.
*
* If `x` and `y` are given as `null`, then this method always succeeds,
* as the tile will be added into the best last position.
*
* @param x X coordinate in small tiles unit (1x1), or `null`.
* @param y Y coordinate in small tiles unit (1x1), or `null`.
* @throws A TypeError if either x or y are null, but not both are null.
* @returns `true` if there was no unsolvable conflict, and `false` otherwise.
*/
addTile(id: string, x: number | null, y: number | null, width: number, height: number): boolean;
/**
* Attempts to move a tile, shifting overlapping tiles as needed.
*
* @param x X coordinate in small tiles unit (1x1).
* @param y Y coordinate in small tiles unit (1x1).
* @returns `true` if there was no unsolvable conflict, and `false` otherwise.
*/
moveTile(id: string, x: number, y: number): boolean;
/**
* Attempts to resize a tile, shifting overlapping tiles as needed.
*
* @returns `true` if there was no unsolvable conflict, and `false` otherwise.
*/
resizeTile(id: string, width: number, height: number): boolean;
/**
* Removes a tile, pushing any bottom-located neighbours at fitting horizontal line
* towards the removed tile.
*/
removeTile(id: string): void;
/**
* Clears everything.
*/
clear(): void;
private resolveConflicts;
private findBestPosition;
private findAvailableNearbyPosition;
private findAvailablePositionFor;
private getIntersectingTiles;
private tryShiftTileCluster;
private snapshot;
private restoreSnapshot;
}