Skip to content

Commit bc1d0b2

Browse files
committed
Add fix for centered mode, nvl mode and some imports
1 parent 670e0a9 commit bc1d0b2

File tree

33 files changed

+165
-52
lines changed

33 files changed

+165
-52
lines changed

cypress/e2e/actions/choices.spec.js

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,50 @@ context ('Choices', function () {
4545
}
4646
}
4747
}});
48+
49+
this.monogatari.$ ('nvlChoice', {'Choice':{
50+
'Dialog': 'nvl This is a choice',
51+
'One': {
52+
'Text': 'One',
53+
'Do': 'One'
54+
},
55+
'Two': {
56+
'Text': 'Two',
57+
'Do': 'Two'
58+
},
59+
'Three': {
60+
'Text': 'Three',
61+
'Do': 'Three'
62+
},
63+
'Disabled': {
64+
'Text': 'Disabled',
65+
'Do': 'Disabled',
66+
'Clickable': function () {
67+
return false;
68+
}
69+
},
70+
'Hidden': {
71+
'Text': 'Hidden',
72+
'Do': 'Hidden',
73+
'Condition': function () {
74+
return false;
75+
}
76+
},
77+
'OnClick': {
78+
'Text': 'On Click',
79+
'Do': 'On Click',
80+
'onClick': function () {
81+
this.storage ('clicked', true);
82+
}
83+
},
84+
'OnChosen': {
85+
'Text': 'On Chosen',
86+
'Do': 'On Chosen',
87+
'onChosen': function () {
88+
this.storage ({ clicked: true });
89+
}
90+
}
91+
}});
4892
});
4993

5094
});
@@ -524,5 +568,37 @@ context ('Choices', function () {
524568

525569
// });
526570

571+
it ('Works with NVL mode', function () {
572+
cy.loadTestAssets ({nvl: true});
573+
this.monogatari.setting ('TypeAnimation', false);
574+
this.monogatari.script ({
575+
'Start': [
576+
'nvl Before',
577+
'$ nvlChoice',
578+
'nvl After'
579+
]
580+
});
581+
582+
cy.start ();
583+
cy.proceed ();
584+
585+
cy.get ('text-box').contains ('Before');
586+
587+
cy.proceed ();
527588

589+
cy.get ('text-box').contains ('This is a choice');
590+
591+
cy.get ('[data-choice="One"]').click ();
592+
593+
cy.get ('text-box').contains ('One');
594+
595+
cy.rollback ();
596+
cy.get ('text-box').contains ('This is a choice');
597+
598+
cy.rollback ();
599+
cy.get ('text-box').contains ('Before');
600+
601+
cy.rollback ();
602+
cy.get ('text-box').contains ('Before');
603+
});
528604
});

debug/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import './vendor/prism.js';
22
import { FancyError } from '../src/lib/FancyError';
3-
import { $_ready } from '@aegis-framework/artemis/index';
3+
import { $_ready } from '@aegis-framework/artemis';
44

55
window.addEventListener('error', (event) => {
66
const { message, lineno, filename } = event;

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@monogatari/core",
3-
"version": "2.5.0",
3+
"version": "2.5.1",
44
"main": "lib/monogatari.node.js",
55
"module": "lib/monogatari.module.js",
66
"css": "dist/engine/core/monogatari.css",

src/actions/Canvas.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Action } from '../lib/Action';
2-
import { Util } from '@aegis-framework/artemis/index';
2+
import { Util } from '@aegis-framework/artemis';
33
import { FancyError } from './../lib/FancyError';
44

55
export class Canvas extends Action {

src/actions/Choice.js

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Action } from '../lib/Action';
2-
import { Util } from '@aegis-framework/artemis/index';
2+
import { Util } from '@aegis-framework/artemis';
33

44
export class Choice extends Action {
55

@@ -234,24 +234,40 @@ export class Choice extends Action {
234234
revert () {
235235
const choice = this.engine.history ('choice')[this.engine.history ('choice').length - 1];
236236

237-
237+
// First, revert the action that was chosen
238238
return this.engine.revert (this.statement[choice].Do, false).then (() => {
239239
if (typeof this.statement[choice].onRevert === 'function') {
240240
return Util.callAsync (this.statement[choice].onRevert, this.engine);
241241
}
242242
return Promise.resolve ();
243243
}).then (() => {
244+
// Clean up timer if it exists
244245
if (typeof this.statement.Timer === 'object' && this.statement.Timer !== null) {
245246
this.engine.global ('_ChoiceTimer').pop ();
246247
}
247248

249+
// If there was a dialog, revert it first
248250
if (typeof this.statement.Dialog === 'string') {
249251
const dialogLog = this.engine.component ('dialog-log');
250252
if (typeof dialogLog !== 'undefined') {
251253
dialogLog.instances (instance => instance.pop ());
252254
}
255+
256+
// // Revert the dialog that was shown with the choice
257+
// const dialogAction = this.engine.prepareAction (this.statement.Dialog, { cycle: 'Revert' });
258+
// return dialogAction.willRevert ().then (() => {
259+
// return dialogAction.revert ().then (() => {
260+
// return dialogAction.didRevert ();
261+
// });
262+
// });
253263
}
254264

265+
return Promise.resolve ();
266+
}).then (() => {
267+
// Remove any existing choice container before re-applying
268+
this.engine.element ().find ('choice-container').remove ();
269+
270+
// Now re-apply the choice to show it again
255271
const action = this.engine.prepareAction (this._statement, { cycle: 'Application' });
256272
return action.willApply ().then (() => {
257273
return action.apply ().then (() => {

src/actions/Conditional.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Action } from '../lib/Action';
2-
import { Util } from '@aegis-framework/artemis/index';
2+
import { Util } from '@aegis-framework/artemis';
33
import { FancyError } from '../lib/FancyError';
44

55
export class Conditional extends Action {

src/actions/Dialog.js

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Action } from './../lib/Action';
22
// import Typed from './../lib/MonoTyped';
3-
import { $_ } from '@aegis-framework/artemis/index';
3+
import { $_ } from '@aegis-framework/artemis';
44

55
export 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 ();

src/actions/Function.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Action } from './../lib/Action';
2-
import { Util } from '@aegis-framework/artemis/index';
2+
import { Util } from '@aegis-framework/artemis';
33
import { FancyError } from '../lib/FancyError';
44

55
export class ReversibleFunction extends Action {

src/actions/HideCanvas.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Action } from './../lib/Action';
2-
import { Util } from '@aegis-framework/artemis/index';
2+
import { Util } from '@aegis-framework/artemis';
33

44
export class HideCanvas extends Action {
55

src/actions/InputModal.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Action } from './../lib/Action';
2-
import { Util } from '@aegis-framework/artemis/index';
2+
import { Util } from '@aegis-framework/artemis';
33

44
export class InputModal extends Action {
55

0 commit comments

Comments
 (0)