import { EntityAttributes } from '../../../phaser/entities/cc-entity' ; import { DomSanitizer } from '@angular/platform-browser' ; import { SecurityContext } from '@angular/core' ; export interface EventType { type : string ; } export interface EventTypeChild { title ? : string ; draggable ? : boolean ; events : AbstractEvent < any > [ ] ; } export abstract class AbstractEvent < T extends EventType > { public info = '---' ; public children : EventTypeChild [ ] = [ ] ; constructor ( private domSanitizer , public data , public actionStep = false ) { } protected abstract generateNewDataInternal ( ) ; public generateNewData ( ) { const data = this . generateNewDataInternal ( ) ; data . type = this . data . type ; this . data = < any > data ; } public abstract getAttributes ( ) ; public abstract update ( ) ; public export ( ) { return JSON . parse ( JSON . stringify ( this . data ) ) ; } protected combineStrings ( ... values ) { return values . join ( ' ' ) ; } protected getAllPropStrings ( ) { const keys = Object . keys ( this . data ) ; return keys . filter ( key => key !== 'type' ) . map ( key => this . getPropString ( key ) ) . join ( ' ' ) ; } protected getPropString ( key , value ? ) { if ( ! value ) { value = this . data [ key as keyof T ] ; } const attr = this . getAttributes ( ) ; if ( attr && attr [ key ] ) { const type = attr [ key ] . type ; if ( type === 'Color' ) { value = this . getColorRectangle ( value ) ; } else if ( type === 'Vec2' && value ) { value = this . getVec2String ( value . x , value . y ) ; } else if ( type === 'Entity' ) { value = '[' + value . name + ']' ; } } return `<span style="display: inline-block;"><span style="color: #858585">${ key }</span>: ${ value }</span>` ; } protected getVec2String ( x , y ) { return `(${ this . sanitize ( x ) }, ${ this . sanitize ( y ) })` ; } protected getTypeString ( color ) { color = this . sanitize ( color ) ; return this . getBoldString ( this . data . type , color ) ; } protected getBoldString ( text , color ) { return `<b style="color: ${ this . sanitize ( color ) }">${ text }</b>` ; } protected getColoredString ( text , color ) { return `<span style="color: ${ this . sanitize ( color ) }">${ text }</span>` ; } protected getColorRectangle ( color ) { return `<span style="background-color: ${ this . sanitize ( color ) };">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>` ; } private sanitize ( val ) { return this . domSanitizer . sanitize ( SecurityContext . HTML , val ) || '' ; } }