ecspresso
Version:
A minimal Entity-Component-System library for typescript and javascript.
45 lines (44 loc) • 2.11 kB
TypeScript
/**
* Isometric Depth Sort Plugin for ECSpresso
*
* Sets PixiJS `zIndex` on entities based on their world-space position,
* ensuring correct visual overlap in isometric rendering. Entities with
* higher world X + Y values render in front.
*
* Requires `rootContainer` from the renderer2D plugin.
* Enables `sortableChildren` on the root container at initialization.
*/
import type { BasePluginOptions } from 'ecspresso';
import type { ComponentsConfig, ResourcesConfig } from '../../type-utils';
import type { TransformComponentTypes } from '../spatial/transform';
import type { Renderer2DComponentTypes, Renderer2DResourceTypes } from '../rendering/renderer2D';
/**
* Optional component that offsets an entity's depth sort value.
* Entities with a positive depthOffset render in front of entities
* at the same world position (e.g., a player on top of a ground tile).
*/
export interface IsoDepthSortComponentTypes {
depthOffset: number;
}
type IsoDepthSortRequires = ComponentsConfig<TransformComponentTypes & Pick<Renderer2DComponentTypes, 'sprite' | 'graphics' | 'container'>> & ResourcesConfig<Renderer2DResourceTypes>;
export interface IsoDepthSortPluginOptions<G extends string = 'isometric'> extends BasePluginOptions<G> {
/** Custom depth function. Receives world-space x/y, returns a sort key.
* Default: `(x, y) => x + y` */
depthFn?: (worldX: number, worldY: number) => number;
}
/**
* Create an isometric depth sort plugin.
*
* Adds a render-phase system that sets PixiJS `zIndex` based on world-space
* position, enabling correct front-to-back ordering in isometric views.
*
* @example
* ```typescript
* const ecs = ECSpresso.create()
* .withPlugin(createRenderer2DPlugin({ ... }))
* .withPlugin(createIsoDepthSortPlugin())
* .build();
* ```
*/
export declare function createIsoDepthSortPlugin<G extends string = 'isometric'>(options?: IsoDepthSortPluginOptions<G>): import("ecspresso").Plugin<import("ecspresso").WithComponents<import("ecspresso").EmptyConfig, IsoDepthSortComponentTypes>, IsoDepthSortRequires, never, G, never, never>;
export {};