UNPKG

agentjs-core

Version:

A comprehensive agent-based modeling framework with built-in p5.js visualization

217 lines 5 kB
/** * InputManager - Handles mouse, keyboard, and touch input for visualization */ import { EventEmitter } from 'eventemitter3'; import type { Agent } from '../core/agents/Agent'; import type { AgentId, Position } from '../types/core'; import type { Camera } from './Camera'; /** Input configuration */ export interface InputConfig { readonly mouse: { enableSelection: boolean; enableDragging: boolean; dragThreshold: number; }; readonly keyboard: { enableShortcuts: boolean; shortcuts: Map<string, string>; }; readonly touch: { enableGestures: boolean; pinchSensitivity: number; }; } /** Selection rectangle */ export interface SelectionRect { startX: number; startY: number; endX: number; endY: number; } /** Input event types */ export interface InputEvents { agentSelected: { agent: Agent; position: Position; }; agentDeselected: { agent: Agent; }; multipleSelected: { agents: Agent[]; }; selectionCleared: void; dragStart: { startPos: Position; }; dragEnd: { endPos: Position; }; contextMenu: { position: Position; agent?: Agent; }; } /** * InputManager - Comprehensive input handling system * * Features: * - Mouse click and drag handling * - Agent selection (single and multi-select) * - Keyboard shortcuts * - Touch gesture preparation * - Context menu support * * Educational Context: Enables interactive exploration * of agent simulations through direct manipulation. */ export declare class InputManager extends EventEmitter<InputEvents> { /** Input configuration */ private config; /** Reference to camera for coordinate conversion */ private camera; /** Map of agents for selection */ private agents; /** Currently selected agents */ private selectedAgents; /** Mouse state */ private mouseState; /** Selection rectangle for multi-select */ private selectionRect; /** Keyboard state */ private keyState; /** Canvas element for event binding */ private canvas; /** Bound event handlers for cleanup */ private boundHandlers; constructor(camera: Camera, config?: Partial<InputConfig>); /** * Initialize input handling with canvas element */ initialize(canvasElement: HTMLElement): void; /** * Bind all input event handlers */ private bindEvents; /** * Add event handler with cleanup tracking */ private addHandler; /** * Handle mouse down events */ private handleMouseDown; /** * Handle mouse move events */ private handleMouseMove; /** * Handle mouse up events */ private handleMouseUp; /** * Handle mouse wheel events */ private handleWheel; /** * Handle context menu events */ private handleContextMenu; /** * Handle keyboard down events */ private handleKeyDown; /** * Handle keyboard up events */ private handleKeyUp; /** * Execute keyboard action */ private executeKeyboardAction; /** * Handle touch start events */ private handleTouchStart; /** * Handle touch move events */ private handleTouchMove; /** * Handle touch end events */ private handleTouchEnd; /** * Start selection process */ private startSelection; /** * Update selection rectangle */ private updateSelectionRect; /** * Complete rectangle selection */ private completeRectangleSelection; /** * Handle single click selection */ private handleSingleClick; /** * Find agent at world position */ private findAgentAtPosition; /** * Find agents within rectangle */ private findAgentsInRectangle; /** * Set agents map for selection */ setAgents(agents: Map<AgentId, Agent>): void; /** * Add agent to selection */ private addToSelection; /** * Remove agent from selection */ private removeFromSelection; /** * Toggle agent selection */ private toggleSelection; /** * Set selection to specific agents */ private setSelection; /** * Select all agents */ private selectAllAgents; /** * Clear all selections */ clearSelection(): void; /** * Get currently selected agents */ getSelectedAgents(): Agent[]; /** * Check if agent is selected */ isSelected(agent: Agent): boolean; /** * Get current selection rectangle for rendering */ getSelectionRect(): SelectionRect | null; /** * Update input configuration */ updateConfig(newConfig: Partial<InputConfig>): void; /** * Clean up event listeners */ destroy(): void; } //# sourceMappingURL=InputManager.d.ts.map