import { Coordinates, DeleteItem, DisplayedItem, Location, MaterialItem, MaterialRules, MoveItem, MoveItemsAtOnce, XYCoordinates } from '@gamepark/rules-api'; import { ComponentType } from 'react'; import { LocationDescription, LocationHelpProps, MaterialDescriptionRecord } from '../components'; import { LocationOrigin } from './LocationOrigin'; export type SortFunction = ((item: MaterialItem) => number); /** * The face of a parent item a location is laid on. See {@link Locator.getParentFace}. */ export declare enum ParentFace { /** Printed on the front of the parent item, and out of reach while it shows its back. */ Front = 0, /** Printed on its back, and out of reach while it shows its front. */ Back = 1, /** Belongs to the parent item rather than to one of its faces, and follows whichever face is up. */ Up = 2 } /** * A Locator is responsible for placing item and locations (such as drop areas) on the Game Table. */ export declare class Locator
{
/**
* With the constructor, you can create new locators in one line.
* @example `new Locator({ coordinates: { x: -10, y: -5 } })`
* @param clone Object to clone into the class
*/
constructor(clone?: Partial ): Partial ;
/**
* @internal
* This function automatically create some drop location descriptions based on the context (dragged item, parent item).
*
* Do not override it but use {@link locationDescription},
* otherwise the images of the location descriptions will not be preloaded by the {@link MaterialImageLoader}.
*/
getLocationDescription(location: Location , context: MaterialContext | ItemContext ): LocationDescription | undefined;
/**
* @internal This function provides a custom location description for the current dragged item.
*/
protected generateLocationDescriptionFromDraggedItem(_location: Location , context: ItemContext ): LocationDescription | undefined;
/**
* This function can completely remove some items from the DOM.
* Hidden items are still rendered while an animation is active on them, so they can animate in or out.
* Use this for performance on items that most of the time don't need to appear (e.g. items beyond the display limit, or items on a hidden parent).
* {@link hide} and {@link ignore} are interchangeable aliases: override either one, the framework considers an item hidden if either returns true.
* @param item The item
* @param context The context of the item
* @returns true if the item must be removed from the DOM
*/
hide(item: MaterialItem , context: ItemContext ): boolean;
/**
* Alias of {@link hide}. You can override either — the framework treats the item as hidden if either returns true.
* @deprecated
*/
ignore(item: MaterialItem , context: ItemContext ): boolean;
/**
* Value returned by {@link getLocationOrigin} default implementation
*/
locationOrigin: LocationOrigin;
/**
* Return the origin position or the location on x and y axes before it is placed using css transform
* Origin: the (0, 0) coordinates
* Center: (xMax - xMin) / 2 or (yMax - yMin) / 2
* Min: xMin or yMin
* Max: xMax or yMax
* @param location Location to place
* @param context Context of the location in the game
* @returns the origin for the location
*/
getLocationOrigin(location: Location , context: LocationContext ): LocationOrigin;
/**
* Provide a list of css transform operations to place a location on the game table.
* @param location Location to place
* @param context Context of the location in the game
* @returns the css transform that will be applied to the location
*/
placeLocation(location: Location , context: LocationContext ): string[];
/**
* Provide a list of css transform operations to place an item on the game table.
* @param item Item to place
* @param context Context of the item in the game
* @returns the css transform that will be applied to the item
*/
placeItem(item: MaterialItem , context: ItemContext ): string[];
/**
* Provide a list of css transform operations to place an item on a parent item.
* @param item Item to place
* @param context Context of the item in the game
* @returns the css transform that will be applied to the item
*/
protected placeItemOnParent(item: MaterialItem , context: ItemContext ): string[];
/**
* If a location belongs to an item, returns the item
* @param location A location
* @param context Context of the game
* @returns the parent item of the location if any
*/
getParentItem(location: Location , context: MaterialContext ): MaterialItem | undefined;
/**
* Whether this item is placed on a parent item that no longer exists in the game state.
* This can happen for a short time during animations, when a parent item (e.g. a card) and its
* children (e.g. tokens placed on it) are deleted in quick succession: the children still exist while
* their delete animation plays, but their parent is already gone.
* Such orphan items cannot be positioned, so they should not be displayed.
* @param item The item
* @param context The context of the item
* @returns true if the item declares a parent item that does not exist (anymore)
*/
hasMissingParent(item: MaterialItem , context: MaterialContext ): boolean;
/**
* Position of the location on the parent item, in percentage. Use {@link getPositionOnParent} to provide a dynamic position.
*/
positionOnParent: XYCoordinates;
/**
* Place the center of the item in the plan of their parent item. This is ignored if "parentItemType" is undefined.
* Examples: {x: 0, y: 0} places the center of the item in the top-left corner of the parent item
* {x: 50, y: 50} centers the item in the parent item.
*
* @param _location Location of the item or area inside the parent item
* @param _context THe material game context
* @return {x, y} with "x" as a percentage from the parent's width, "y" a percentage of the height
*/
getPositionOnParent(_location: Location , _context: MaterialContext ): XYCoordinates;
/**
* Which face of the parent item the locations belong to. Use {@link getParentFace} to decide per location.
*/
parentFace: ParentFace;
/**
* Which face of the parent item a location belongs to, when that parent has 2 faces
* (see {@link FlatMaterialDescription}). A face turned away from the player is hidden by its backface-visibility,
* which takes it out of the page altogether, pointer events included: whatever is laid on it is invisible, and
* cannot be clicked or dropped onto. See {@link ParentFace} for what each value means.
*
* @param _location Location of the item or area inside the parent item
* @param _context The material game context
* @return the face of the parent item the location is laid on
*/
getParentFace(_location: Location , _context: MaterialContext ): ParentFace;
/**
* Coordinates of the location on the Game Table. Use {@link getCoordinates} to provide dynamic coordinates.
*/
coordinates: Partial , _context: MaterialContext ): unknown;
/**
* Computes the full position dependencies for an item, including the parent item's position dependencies
* when the item is placed on a dynamic parent (i.e. `location.parent !== undefined`).
*
* This method should not be overridden. Override {@link getPositionDependencies} instead.
*
* @param location A location in this area
* @param context Context of the game
* @returns Combined dependencies (own + parent chain). `undefined` if any locator in the chain opts out.
*/
getFullPositionDependencies(location: Location , context: MaterialContext ): unknown;
/**
* Provide the coordinates of a location on the Game Table.
*
* Called by {@link getLocationCoordinates} but can be used as the Hand, List or Pile "initial" position in subclasses.
*
* @param _location Location to position
* @param _context Context of the game
* @returns the x, y, z coordinates (in cm) of the location
*/
getCoordinates(_location: Location , _context: MaterialContext ): Partial , context: MaterialContext ): Partial , context: ItemContext ): Partial , _context: MaterialContext ): number;
/**
* Get the Z-axis rotation of an item. Defaults to {@link getRotateZ}.
* @param item item to place
* @param context Context of the item
* @returns the rotation (unit in {@link rotationUnit})
*/
getItemRotateZ(item: MaterialItem , context: ItemContext ): number;
/**
* The index of a location to place, if it matters in the locator's context (see {@link HandLocator}, {@link ListLocator} or {@link PileLocator}).
*
* Defaults to location.x first, y otherwise, z last.
*
* @param location Location to index in the location area (see {@link isSameLocationArea})
* @param _context Context of the game
* @returns the index of the location in the location area
*/
getLocationIndex(location: Location , _context: MaterialContext ): number | undefined;
/**
* Index of an item to place (fallback to {@link getLocationIndex} or item's displayIndex).
* @param item Item to place
* @param context Context of the item
* @returns the index of the item in the location area
*/
getItemIndex(item: MaterialItem , context: ItemContext ): number;
/**
* The total number of items in the same location area (see {@link isSameLocationArea}).
*
* @param location the location area
* @param context Context of the game
* @returns the total number of items in the location area
*/
countItems(location: Location , { rules }: MaterialContext ): number;
/**
* Any css transform to apply to the item when it is hovered by the pointer. See {@link HandLocator} override for example.
* @param _item The item
* @param _context Context of the item
* @returns the list of css transforms
*/
getHoverTransform(_item: MaterialItem , _context: ItemContext ): string[];
/**
* How items in the same location area are sorted for the help dialog navigation arrows.
*/
navigationSorts: SortFunction[];
/**
* How items in the same location area are sorted for the help dialog navigation arrows.
* @param _context Context of the game
* @returns The list of sort functions to sort the items.
*/
getNavigationSorts(_context: ItemContext ): SortFunction[];
/**
* Utility function for animation to know if the item is one that should be animated.
* @param item Item to consider
* @param context Context of the Item
* @param move Move to animate
* @returns true if the items must be animated
*/
isItemToAnimate(item: MaterialItem , context: ItemContext , move: MoveItem | DeleteItem | MoveItemsAtOnce )[], context: ItemContext ): Location [];
/**
* If set to true, each time an item is dragged over
*/
dropPreview: boolean;
/**
* If this function returns true, a preview of the dragged item will be displayed when it is over this location.
* @param _move The move that will be played if the item is dropped
* @param _context Context of the game
* @return true if a preview must be displayed
*/
showDropPreview(_move: MoveItem , _context: MaterialContext ): boolean;
help?: ComponentType = Record = {
rules: MaterialRules ;
material: Partial = MaterialContext & DisplayedItem (context: MaterialContext ): context is ItemContext ;
/**
* Help function to get an item from an ItemContext
* @param context Context of the item
* @return The item
*/
export declare function getItemFromContext ;
/**
* Context of a location in a displayed game.
* @property canDrop Whether some item is currently being dragged, and can be dropped in the location.
*/
export type LocationContext = MaterialContext & {
canDrop?: boolean;
};