@@ -6,7 +6,6 @@ import { $_ } from '@aegis-framework/artemis';
66export class Dialog extends Action {
77
88 static canProceed ( ) {
9-
109 // Check if the type animation has finished and the Typed object still exists
1110 if ( ! Monogatari . global ( 'finishedTyping' ) && Monogatari . global ( 'textObject' ) !== null ) {
1211 // Get the string it was typing
@@ -20,8 +19,9 @@ export class Dialog extends Action {
2019 $_ ( `${ Monogatari . selector } [data-ui="say"]` ) . html ( str ) ;
2120 Monogatari . global ( 'finishedTyping' , true ) ;
2221 } else if ( $_ ( '[data-ui="text"]' ) . hasClass ( 'nvl' ) ) {
22+ const last = $_ ( '[data-ui="say"] [data-spoke] p' ) . last ( ) . get ( 0 ) ;
2323 Monogatari . global ( 'textObject' ) . destroy ( ) ;
24- $_ ( ` ${ Monogatari . selector } [data-ui="say"]: last-child` ) . html ( str ) ;
24+ $_ ( last ) . html ( str ) ;
2525 Monogatari . global ( 'finishedTyping' , true ) ;
2626 }
2727
@@ -62,6 +62,12 @@ export class Dialog extends Action {
6262 }
6363 }
6464 } ) ;
65+
66+ // The NVL mode has its own history so that when going back, all dialogs
67+ // that were shown on screen can be shown again instead of just showing
68+ // the last one.
69+ Monogatari . history ( 'nvl' ) ;
70+
6571 return Promise . resolve ( ) ;
6672 }
6773
@@ -73,6 +79,8 @@ export class Dialog extends Action {
7379 Monogatari . preference ( 'TextSpeed' , value ) ;
7480 } ) ;
7581
82+ // Detect scroll on the text element to remove the unread class used when
83+ // there's text not being shown in NVL mode.
7684 $_ ( `${ selector } [data-ui="text"]` ) . on ( 'scroll' , ( ) => {
7785 $_ ( `${ Monogatari . selector } [data-ui="text"]` ) . removeClass ( 'unread' ) ;
7886 } ) ;
@@ -146,6 +154,7 @@ export class Dialog extends Action {
146154 this . dialog = dialog . join ( ' ' ) ;
147155 } else {
148156 this . dialog = [ character , ...dialog ] . join ( ' ' ) ;
157+ this . nvl = false ;
149158 }
150159 }
151160 }
@@ -157,9 +166,59 @@ export class Dialog extends Action {
157166 return Promise . resolve ( ) ;
158167 }
159168
160- displayDialog ( dialog , character , animation ) {
169+ displayNvlDialog ( dialog , character , animation ) {
170+ if ( ! $_ ( `${ Monogatari . selector } [data-ui="text"]` ) . hasClass ( 'nvl' ) ) {
171+ Dialog . reset ( ) ;
172+ $_ ( `${ Monogatari . selector } [data-ui="text"]` ) . addClass ( 'nvl' ) ;
173+ }
174+
175+ // Remove contents from the dialog area.
176+ const previous = $_ ( `${ Monogatari . selector } [data-ui="text"]` ) . data ( 'speaking' ) ;
177+ $_ ( `${ Monogatari . selector } [data-ui="text"]` ) . data ( 'speaking' , character ) ;
178+
179+ // Check if the typing animation flag is set to true in order to show it
180+ if ( animation === true && Monogatari . setting ( 'TypeAnimation' ) === true && Monogatari . setting ( 'NVLTypeAnimation' ) === true ) {
181+
182+ // If the property is set to true, the animation will be shown
183+ // if it is set to false, even if the flag was set to true,
184+ // no animation will be shown in the game.
185+ if ( character !== 'narrator' ) {
186+ if ( previous !== character ) {
187+ $_ ( `${ Monogatari . selector } [data-ui="say"]` ) . append ( `<div data-spoke="${ character } " class='named'><span style='color:${ Monogatari . character ( character ) . Color } ;'>${ Monogatari . replaceVariables ( Monogatari . character ( character ) . Name ) } : </span><p></p></div>` ) ;
188+ } else {
189+ $_ ( `${ Monogatari . selector } [data-ui="say"]` ) . append ( `<div data-spoke="${ character } "><p></p></div>` ) ;
190+ }
191+
192+ } else {
193+ $_ ( `${ Monogatari . selector } [data-ui="say"]` ) . append ( `<div data-spoke="${ character } " class='unnamed'><p></p></div>` ) ;
194+ }
195+
196+ const elements = $_ ( '[data-ui="say"] [data-spoke] p' ) ;
197+ const last = elements . last ( ) . get ( 0 ) ;
198+
199+ Monogatari . global ( 'typedConfiguration' ) . strings = [ dialog ] ;
200+ Monogatari . global ( 'textObject' , new Typed ( last , Monogatari . global ( 'typedConfiguration' ) ) ) ;
201+
202+ } else {
203+ if ( character !== 'narrator' ) {
204+ if ( previous !== character ) {
205+ $_ ( `${ Monogatari . selector } [data-ui="say"]` ) . append ( `<div data-spoke="${ character } " class='named'><span style='color:${ Monogatari . character ( character ) . Color } ;'>${ Monogatari . replaceVariables ( Monogatari . character ( character ) . Name ) } : </span><p>${ dialog } </p></div>` ) ;
206+ } else {
207+ $_ ( `${ Monogatari . selector } [data-ui="say"]` ) . append ( `<div data-spoke="${ character } "><p>${ dialog } </p></div>` ) ;
208+ }
209+
210+ } else {
211+ $_ ( `${ Monogatari . selector } [data-ui="say"]` ) . append ( `<div data-spoke="${ character } " class='unnamed'><p>${ dialog } </p></div>` ) ;
212+ }
213+ Monogatari . global ( 'finishedTyping' , true ) ;
214+ }
215+ }
161216
217+ displayDialog ( dialog , character , animation ) {
162218 if ( this . nvl === false ) {
219+ if ( $_ ( `${ Monogatari . selector } [data-ui="text"]` ) . hasClass ( 'nvl' ) && this . _cycle === 'Application' ) {
220+ Monogatari . history ( 'nvl' ) . push ( $_ ( `${ Monogatari . selector } [data-ui="text"] [data-ui="say"]` ) . html ( ) ) ;
221+ }
163222 $_ ( `${ Monogatari . selector } [data-ui="text"]` ) . removeClass ( 'nvl' ) ;
164223
165224 // Destroy the previous textObject so the text is rewritten.
@@ -185,39 +244,7 @@ export class Dialog extends Action {
185244 Monogatari . global ( 'finishedTyping' , true ) ;
186245 }
187246 } else {
188- if ( ! $_ ( `${ Monogatari . selector } [data-ui="text"]` ) . hasClass ( 'nvl' ) ) {
189- Dialog . reset ( ) ;
190- $_ ( `${ Monogatari . selector } [data-ui="text"]` ) . addClass ( 'nvl' ) ;
191- }
192-
193- // Remove contents from the dialog area.
194- //$_(`${Monogatari.selector} [data-ui="say"]`).html ('');
195- const previous = $_ ( `${ Monogatari . selector } [data-ui="text"]` ) . data ( 'speaking' ) ;
196- $_ ( `${ Monogatari . selector } [data-ui="text"]` ) . data ( 'speaking' , character ) ;
197-
198- // Check if the typing animation flag is set to true in order to show it
199- /*if (animation === true && Monogatari.setting ('TypeAnimation') === true) {
200-
201- // If the property is set to true, the animation will be shown
202- // if it is set to false, even if the flag was set to true,
203- // no animation will be shown in the game.
204- $_(`${Monogatari.selector} [data-ui="say"]`).append ('<p></p>');
205- Monogatari.global ('typedConfiguration').strings = [dialog + '\n'];
206- Monogatari.global ('textObject', new Typed ('[data-ui="say"]:last-child', Monogatari.global ('typedConfiguration')));
207- } else {*/
208- if ( character !== 'narrator' ) {
209- if ( previous !== character ) {
210- $_ ( `${ Monogatari . selector } [data-ui="say"]` ) . append ( `<div data-spoke="${ character } " class='named'><span style='color:${ Monogatari . character ( character ) . Color } ;'>${ Monogatari . replaceVariables ( Monogatari . character ( character ) . Name ) } : </span><p>${ dialog } </p></div>` ) ;
211- } else {
212- $_ ( `${ Monogatari . selector } [data-ui="say"]` ) . append ( `<div data-spoke="${ character } "><p>${ dialog } </p></div>` ) ;
213- }
214-
215- } else {
216- $_ ( `${ Monogatari . selector } [data-ui="say"]` ) . append ( `<div data-spoke="${ this . id } " class='unnamed'><p>${ dialog } </p></div>` ) ;
217- }
218- Monogatari . global ( 'finishedTyping' , true ) ;
219-
220- //}
247+ this . displayNvlDialog ( dialog , character , animation ) ;
221248 }
222249
223250 Dialog . checkUnread ( ) ;
@@ -242,7 +269,7 @@ export class Dialog extends Action {
242269
243270 // Check if an expression or face image was used and if it exists and
244271 // display it
245- if ( typeof this . image !== 'undefined' ) {
272+ if ( typeof this . image !== 'undefined' && ! this . nvl ) {
246273 $_ ( `${ Monogatari . selector } [data-ui="face"]` ) . attribute ( 'src' , 'img/characters/' + this . image ) ;
247274 $_ ( `${ Monogatari . selector } [data-ui="face"]` ) . show ( ) ;
248275 }
@@ -264,8 +291,28 @@ export class Dialog extends Action {
264291 }
265292 }
266293
294+ willRevert ( ) {
295+ this . _action = 'revert' ;
296+ return Promise . resolve ( ) ;
297+ }
298+
267299 revert ( ) {
268- return this . apply ( ) ;
300+ // Check if the dialog to replay is a NVL one or not
301+ if ( this . nvl === true ) {
302+ if ( $_ ( `${ Monogatari . selector } [data-ui="text"]` ) . hasClass ( 'nvl' ) ) {
303+ $_ ( `${ Monogatari . selector } [data-ui="text"] [data-ui="say"] [data-spoke]` ) . last ( ) . remove ( ) ;
304+ return Promise . resolve ( ) ;
305+ } else {
306+ if ( Monogatari . history ( 'nvl' ) . length > 0 ) {
307+ $_ ( `${ Monogatari . selector } [data-ui="text"]` ) . addClass ( 'nvl' ) ;
308+ $_ ( `${ Monogatari . selector } [data-ui="text"] [data-ui="say"]` ) . html ( Monogatari . history ( 'nvl' ) . pop ( ) ) ;
309+ return Promise . resolve ( ) ;
310+ }
311+ return Promise . reject ( ) ;
312+ }
313+ } else {
314+ return this . apply ( ) ;
315+ }
269316 }
270317
271318}
0 commit comments