import * as PIXI from 'pixi.js' ; import G from '../../../common/globals' ; import { Entity } from '../../../core/Entity' ; import { Slot } from '../../controls/Slot' ; import F from '../../controls/functions' ; /** Module Slots for Entity */ export class Recipe extends Slot { /** Blueprint Editor Entity reference */ private readonly m_Entity : Entity ; public constructor ( entity ) { super ( ) ; this . m_Entity = entity ; this . updateContent ( this . m_Entity . recipe ) ; this . on ( 'pointerdown' , ( e ) => this . onSlotPointerDown ( e ) ) ; this . onEntityChange ( 'recipe' , recipe => this . updateContent ( recipe ) ) ; } private onEntityChange ( event , fn ) { this . m_Entity . on ( event , fn ) ; this . once ( 'destroy' , ( ) => this . m_Entity . off ( event , fn ) ) ; } public destroy ( opts ? ) { this . emit ( 'destroy' ) ; super . destroy ( opts ) ; } /** Update Content Icon */ private updateContent ( recipe ) { if ( recipe === undefined ) { if ( this . content !== undefined ) { this . content = undefined ; } } else { this . content = F . CreateIcon ( recipe ) ; } this . emit ( 'changed' ) ; } /** Event handler for click on slot */ private onSlotPointerDown ( e ) { e . stopPropagation ( ) ; if ( e . data . button === 0 ) { G . UI . createInventory ( 'Select Recipe' , this . m_Entity . acceptedRecipes , name => { this . m_Entity . recipe = name ; } ) ; } else if ( e . data . button === 2 ) { this . m_Entity . recipe = undefined ; } } }