11import { Action } from './../lib/Action' ;
22// import Typed from './../lib/MonoTyped';
3- import { $_ } from '@aegis-framework/artemis/index ' ;
3+ import { $_ } from '@aegis-framework/artemis' ;
44
55export class Dialog extends Action {
66
@@ -9,10 +9,15 @@ export class Dialog extends Action {
99 let component = this . engine . element ( ) . find ( 'type-writer' ) . get ( 0 ) ;
1010 const centeredDialog = this . engine . element ( ) . find ( '[data-component="centered-dialog"]' ) ;
1111
12- if ( centeredDialog . isVisible ( ) ) {
12+ if ( centeredDialog . exists ( ) ) {
1313 component = centeredDialog . find ( '[data-content="wrapper"]' ) . get ( 0 ) ;
1414 }
1515
16+ // In NVL mode, there might not be a type-writer element in the text-box
17+ if ( ! component ) {
18+ return Promise . resolve ( this . engine . global ( 'finished_typing' ) ) ;
19+ }
20+
1621 if ( ! this . engine . global ( 'finished_typing' ) && component . state . strings . length ) {
1722 this . engine . stopTyping ( component ) ;
1823
@@ -24,7 +29,7 @@ export class Dialog extends Action {
2429
2530 static willProceed ( ) {
2631 const centeredDialog = this . engine . element ( ) . find ( '[data-component="centered-dialog"]' ) ;
27- if ( centeredDialog . isVisible ( ) ) {
32+ if ( centeredDialog . exists ( ) ) {
2833 centeredDialog . remove ( ) ;
2934 }
3035
@@ -233,9 +238,11 @@ export class Dialog extends Action {
233238 const textBox = this . engine . element ( ) . find ( '[data-component="text-box"]' ) ;
234239 const writer = textBox . find ( 'type-writer' ) . get ( 0 ) ;
235240
236- // If the text-box's typewriter is not emptied and ignored,
237- // it can cause the "finished_typing" variable to be set prematurely.
238- writer . setState ( { ignore : true , strings : [ ] } ) ;
241+ // If the text-box's typewriter exists, set it to ignore
242+ // (in NVL mode, there might not be a type-writer element)
243+ if ( writer ) {
244+ writer . setState ( { ignore : true , strings : [ ] } ) ;
245+ }
239246
240247 textBox . hide ( ) ;
241248 gameScreen . append ( element ) ;
@@ -276,40 +283,40 @@ export class Dialog extends Action {
276283 if ( character !== '_narrator' ) {
277284 if ( previous !== character ) {
278285 this . engine . element ( ) . find ( '[data-ui="say"] [data-spoke]' ) . last ( ) . addClass ( 'nvl-dialog-footer' ) ;
279- this . engine . element ( ) . find ( '[data-ui="say"]' ) . append ( `<div data-spoke="${ character } " class='named'><span style='color:${ this . engine . character ( character ) . color } ;'>${ this . engine . replaceVariables ( this . engine . character ( character ) . name ) } : </span><p ></p ></div>` ) ;
286+ this . engine . element ( ) . find ( '[data-ui="say"]' ) . append ( `<div data-spoke="${ character } " class='named'><span style='color:${ this . engine . character ( character ) . color } ;'>${ this . engine . replaceVariables ( this . engine . character ( character ) . name ) } : </span><type-writer ></type-writer ></div>` ) ;
280287 } else {
281- this . engine . element ( ) . find ( '[data-ui="say"]' ) . append ( `<div data-spoke="${ character } "><p ></p ></div>` ) ;
288+ this . engine . element ( ) . find ( '[data-ui="say"]' ) . append ( `<div data-spoke="${ character } "><type-writer ></type-writer ></div>` ) ;
282289 }
283290
284291 } else {
285292 if ( previous !== character ) {
286293 this . engine . element ( ) . find ( '[data-ui="say"] [data-spoke]' ) . last ( ) . addClass ( 'nvl-dialog-footer' ) ;
287294 }
288- this . engine . element ( ) . find ( '[data-ui="say"]' ) . append ( `<div data-spoke="${ character } " class='unnamed'><p ></p ></div>` ) ;
295+ this . engine . element ( ) . find ( '[data-ui="say"]' ) . append ( `<div data-spoke="${ character } " class='unnamed'><type-writer ></type-writer ></div>` ) ;
289296 }
290297
291- const elements = $_ ( '[data-ui="say"] [data-spoke] p ' ) ;
298+ const elements = $_ ( '[data-ui="say"] [data-spoke] type-writer ' ) ;
292299 const last = elements . last ( ) . get ( 0 ) ;
293300
294301 this . engine . global ( 'typedConfiguration' ) . strings = [ dialog ] ;
295302 this . engine . global ( 'finished_typing' , false ) ;
296- // NVL mode needs to be tested properly.
297- this . engine . element ( ) . find ( last ) . collection [ 0 ] . setState ( { strings : [ dialog ] } ) ;
303+
304+ last . setState ( { strings : [ dialog ] } ) ;
298305
299306 } else {
300307 if ( character !== '_narrator' ) {
301308 if ( previous !== character ) {
302309 this . engine . element ( ) . find ( '[data-ui="say"] [data-spoke]' ) . last ( ) . addClass ( 'nvl-dialog-footer' ) ;
303- this . engine . element ( ) . find ( '[data-ui="say"]' ) . append ( `<div data-spoke="${ character } " class='named'><span style='color:${ this . engine . character ( character ) . color } ;'>${ this . engine . replaceVariables ( this . engine . character ( character ) . name ) } : </span><p >${ clearDialog } </p ></div>` ) ;
310+ this . engine . element ( ) . find ( '[data-ui="say"]' ) . append ( `<div data-spoke="${ character } " class='named'><span style='color:${ this . engine . character ( character ) . color } ;'>${ this . engine . replaceVariables ( this . engine . character ( character ) . name ) } : </span><type-writer >${ clearDialog } </type-writer ></div>` ) ;
304311 } else {
305- this . engine . element ( ) . find ( '[data-ui="say"]' ) . append ( `<div data-spoke="${ character } "><p >${ dialog } </p ></div>` ) ;
312+ this . engine . element ( ) . find ( '[data-ui="say"]' ) . append ( `<div data-spoke="${ character } "><type-writer >${ dialog } </type-writer ></div>` ) ;
306313 }
307314
308315 } else {
309316 if ( previous !== character ) {
310317 this . engine . element ( ) . find ( '[data-ui="say"] [data-spoke]' ) . last ( ) . addClass ( 'nvl-dialog-footer' ) ;
311318 }
312- this . engine . element ( ) . find ( '[data-ui="say"]' ) . append ( `<div data-spoke="${ character } " class='unnamed'><p >${ clearDialog } </p ></div>` ) ;
319+ this . engine . element ( ) . find ( '[data-ui="say"]' ) . append ( `<div data-spoke="${ character } " class='unnamed'><type-writer >${ clearDialog } </type-writer ></div>` ) ;
313320 }
314321 this . engine . global ( 'finished_typing' , true ) ;
315322 this . engine . trigger ( 'didFinishTyping' ) ;
@@ -460,7 +467,9 @@ export class Dialog extends Action {
460467 }
461468 return Promise . reject ( 'No more dialogs on history from where to recover previous state.' ) ;
462469 }
463- const dialogs = textBox . content ( 'dialog' ) . find ( '[data-spoke]' ) ;
470+
471+ // Find all dialog entries and remove the last one
472+ const dialogs = this . engine . element ( ) . find ( '[data-ui="say"] [data-spoke]' ) ;
464473 // If it is being shown, then to go back, we need to remove the last dialog from it
465474 dialogs . last ( ) . remove ( ) ;
466475 return Promise . resolve ( ) ;
0 commit comments