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); /** * Types of items placed by the locator since it was created * @internal * @protected */ protected itemTypes: M[]; /** * If the locator places items on top of another item (a game board for instance), the type of the parent item must be provided here. */ parentItemType?: M; /** * The maximum number of items do display. */ limit?: number; /** * The rotation unit to use. See {@link getRotateZ} */ rotationUnit: string; /** * Declare this field if you always need to display one location that does not depend on the context. See {@link getLocations}. */ location?: Partial>; /** * Declare this field if you always need to display some locations that does not depend on the context. See {@link getLocations}. */ locations: Partial>[]; /** * Override this if you need to display some locations on the Game Table that depends on the context. * By default, return any {@link location} or {@link locations}. */ getLocations(_context: MaterialContext): Partial>[]; /** * If you need do display custom locations in the game, provide their description here. */ locationDescription?: LocationDescription; /** * @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; /** * Declare which parts of the game state affect the positioning of items in this location area. * * The returned value is compared with deep equality between renders. If it hasn't changed, the item's position * is assumed unchanged and the re-render is skipped. * * Return `undefined` to opt out of the optimization (item always re-renders on state change). * * **Default**: `{}` — position only depends on the item's own location data, never on external game state. * * **When to override**: only when the position depends on game state that can **change during the game**. * If you override `getCoordinates()` or `getItemCoordinates()` and read such a value from `context.rules`, return * it here so items reposition when it changes. Otherwise they won't. * * Reading values that are **fixed for the whole game** (e.g. the number of players, the chosen options, or a board * layout decided at setup) does *not* require an override: the position can never change once the game has started, * so the default `{}` is already correct. Declaring such constants is harmless but pointless. * * @param _location A location in this area * @param _context Context of the game * @returns A value representing the external dependencies. Compared with deep equality. */ getPositionDependencies(_location: Location, _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; /** * Provide the coordinates of a location on the Game Table. * * Fallback to {@link getCoordinates} but the differences appear in subclasses {@link ListLocator}, {@link PileLocator}, {@link HandLocator}. * * @param location Location to position * @param context Context of the game * @returns the x, y, z coordinates (in cm) of the location */ getLocationCoordinates(location: Location, context: MaterialContext): Partial; /** * Provide the coordinates of the center of an item on the Game Table. * * @param item Item being placed * @param context Context of the item in the game * @return The x, y, z coordinates in cm of the center of the item on the table */ getItemCoordinates(item: MaterialItem, context: ItemContext): Partial; /** * The default Z-axis rotation of the items or locations to place if {@link getRotateZ} is not overridden. */ rotateZ: number; /** * Get the Z-axis rotation of a location. * @param _location Location to place * @param _context Context of the location * @returns the rotation (unit in {@link rotationUnit}) */ getRotateZ(_location: Location, _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): boolean; /** * Given an item being dragged, and all the moves for this item going to this location type, this function must return the list of valid drop locations * for the item * @param moves Legal movements for the item * @param context Context of the item * @return the drop locations to display */ getDropLocations(moves: (MoveItem | 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>; } /** * A record of item locators, to provide to the game context. */ export type ItemLocatorRecord

= Record>; /** * Data structure for the context of a game displayed. * @property rules The rules of the game with current game state. * @property material The record of the material descriptions to display the items. * @property locators The record of the locators to place the items. * @property player The player currently displaying the game. Undefined for spectators. */ export type MaterialContext

= { rules: MaterialRules; material: Partial>; locators: Partial>; player?: P; }; /** * Data structure for the context of an item in a game displayed. * @property isDragging True when the item is currently being dragged by the user. */ export type ItemContext

= MaterialContext & DisplayedItem & { isDragging?: boolean; }; /** * Type guard to test if some MaterialContext is also an item context. * @param context Context of the game * @returns true if the context also hold information about a specific item in the game. */ export declare function isItemContext

(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: Omit, 'displayIndex'>): MaterialItem; /** * 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; };