/**
 * Patch PIXI event handling.
 *
 * - Proxy PIXI events to be compatible with EventDispatcher
 * - Implements event bubbling on `dispatchEvent` when `bubbles` is true.
 */ import { DisplayObject , utils } from "pixi.js" ; import EventEmitter = utils . EventEmitter ; import { IEvent } from "@robotlegsjs/core" ; const EventDispatcherMixin = { addEventListener ( this , type , listener , context ? ) { this . on ( type , listener , context ) ; } , hasEventListener ( this , type , listener ? ) { return this . listenerCount ( type ) > 0 ; } , removeEventListener ( this , type , listener ? , context ? , once ? ) { this . off ( type , listener , context , once ) ; } , willTrigger ( type ) { return this . hasEventListener ( type ) ; } , dispatchEvent ( this , event ) { event . target = this ; let currentTarget = this ; do { event . currentTarget = currentTarget ; event . currentTarget . emit ( event . type , event ) ; currentTarget = ( currentTarget as DisplayObject ) . parent ; } while ( currentTarget && event . bubbles ) ; } } ; Object . assign ( DisplayObject . prototype , EventDispatcherMixin ) ; Object . assign ( EventEmitter . prototype , EventDispatcherMixin ) ;