Skip to content

Commit 9f44859

Browse files
committed
Add NVL type animation and allow going back
1 parent 8ca63ed commit 9f44859

7 files changed

Lines changed: 117 additions & 48 deletions

File tree

core/lib/Action.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
* for cleanup operations or any other thing that needs to be done
5151
* after the action was applied.
5252
*
53-
* While the Application clycle is all about executing the action, the Reverting
53+
* While the Application clycle is all about executing the action, the Revert
5454
* cycle is the opposite and it reverts the things the Application cycle does.
5555
* Reverting is used when the player goes back in the game and has equivalent
5656
* steps to the Application Cycle:
@@ -279,13 +279,25 @@ class Action {
279279
* Because of this function, you can always refere to the original statement
280280
* in the Application and Reverting cycles with this._statement;
281281
*
282-
* @param {type} statement description
283-
* @return {type} description
282+
* @param {string|Object|function} statement - The statement with which the action was run
284283
*/
285284
_setStatement (statement) {
286285
this._statement = statement;
287286
}
288287

288+
/**
289+
* _setCycle - This simple method is used to set what cycle the action is
290+
* currently performing. This is useful to know on those actions that may
291+
* use the apply or revert methods on any situation but that have slight
292+
* differences on the logic.
293+
*
294+
* @param {string} cycle - 'Application' if the action is running the application
295+
* cycle or 'Revert' if it's running the revert cycle.
296+
*/
297+
_setCycle (cycle) {
298+
this._cycle = cycle;
299+
}
300+
289301
/**
290302
* willApply - Method called before the application of an action
291303
*

core/lib/actions/Dialog.js

Lines changed: 85 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import { $_ } from '@aegis-framework/artemis';
66
export 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
}

core/lib/monogatari.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1088,6 +1088,7 @@ class Monogatari {
10881088
const act = new action (actionStatement);
10891089

10901090
act.setContext (Monogatari);
1091+
act._setCycle ('Revert');
10911092

10921093
return act.willRevert ().then (() => {
10931094
return act.revert ().then (() => {
@@ -1155,6 +1156,7 @@ class Monogatari {
11551156
if (matches === true) {
11561157
const act = new action (actionStatement);
11571158
act._setStatement (statement);
1159+
act._setCycle ('Application');
11581160
act.setContext (Monogatari);
11591161

11601162
return act.willApply ().then (() => {
@@ -1541,6 +1543,10 @@ Monogatari._settings = {
15411543
// Enables or disables the typing text animation for the whole game.
15421544
'TypeAnimation': true,
15431545

1546+
// Enables or disables the typing text animation in NVL dialogs for the
1547+
// whole game.
1548+
'NVLTypeAnimation': true,
1549+
15441550
// Enables or disables the typing animation for the narrator.
15451551
// If the previous property was set to false, the narrator won't shown
15461552
// the animation even if this is set to true.

dist/engine/monogatari.js

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/engine/monogatari.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/js/options.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ monogatari.settings({
4949
// Enables or disables the typing text animation for the whole game.
5050
'TypeAnimation': true,
5151

52+
// Enables or disables the typing text animation in NVL dialogs for the
53+
// whole game.
54+
'NVLTypeAnimation': true,
55+
5256
// Enables or disables the typing animation for the narrator.
5357
// If the previous property was set to false, the narrator won't shown
5458
// the animation even if this is set to true.

yarn.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33

44

55
"@aegis-framework/artemis@^0.3.5":
6-
version "0.3.5"
7-
resolved "https://registry.yarnpkg.com/@aegis-framework/artemis/-/artemis-0.3.5.tgz#c93b3e857cfb43be8663d38ad6431ebb57c5c177"
6+
version "0.3.6"
7+
resolved "https://registry.yarnpkg.com/@aegis-framework/artemis/-/artemis-0.3.6.tgz#2c0551a4efd8cc2da144b3c2d76d5d48517f8fba"
88

99
"@aegis-framework/kayros.css@^0.4.2":
1010
version "0.4.4"

0 commit comments

Comments
 (0)