import { Conversation } from "./Conversation" ; import { GameObjectProperties } from "./MapInfo" ; import { GameScene } from "./scenes/GameScene" ; import { NPC } from "./entities/NPC" ; export class ConversationProxy extends NPC { public conversation : Conversation ; public constructor ( scene , x , y , properties ) { super ( scene , x , y , 16 , 16 ) ; this . conversation = this . generateConversation ( this . prepareContent ( properties . content ) ) ; this . scene . addGameObject ( this ) ; } private prepareContent ( content ? ) { if ( ! content ) { return [ "Nothing…" ] ; } return content . split ( ":::" ) ; } private generateConversation ( lines ) { const json = { "entry" : [ ] } ; lines . forEach ( ( line , index ) => { if ( index === lines . length - 1 ) { line += " @entry !end" ; } json . entry . push ( line ) ; } ) ; return new Conversation ( json , this ) ; } public draw ( ctx ) { if ( this . scene . showBounds ) this . drawBounds ( ) ; this . speechBubble . draw ( ctx ) ; } public update ( ) { if ( ! this . hasActiveConversation ( ) ) { this . scene . removeGameObject ( this ) ; } } }