-
-
Notifications
You must be signed in to change notification settings - Fork 126
Expand file tree
/
Copy pathindex.js
More file actions
806 lines (756 loc) · 31.5 KB
/
index.js
File metadata and controls
806 lines (756 loc) · 31.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
import './vendor/prism.js';
// This global object signals to FancyError that we're in debug mode and
// fancy errors should be displayed. Without this, FancyError.show() will
// not display any errors.
if (typeof window === 'object') {
window.MonogatariDebug = {
enabled: true,
version: '1.0.0'
};
}
/**
* Register all error templates with the FancyError class.
* This is called after the Monogatari engine is loaded to ensure we use
* the same FancyError instance that the engine uses.
* @param FancyError
*/
function registerErrors(FancyError) {
// Canvas Action
FancyError.register('action:canvas:invalid_mode', {
title: 'The canvas mode provided ("{{mode}}") is not valid.',
message: 'Monogatari attempted to show a canvas object but the mode "{{mode}}" was not found in the canvas action configuration as a valid mode.',
props: {
'Mode Provided': '{{mode}}',
'You may have meant one of these': '{{validModes}}',
'Statement': '{{statement}}',
'Label': '{{label}}',
'Step': '{{step}}',
'Help': {
'_': 'Check your statement and make sure there are no typos on the mode you provided.'
}
}
});
FancyError.register('action:canvas:object_not_found', {
title: 'The canvas object "{{name}}" was not found or is invalid',
message: 'Monogatari attempted to retrieve an object named "{{name}}" but it didn\'t exist in the canvas objects.',
props: {
'Canvas': '{{name}}',
'You may have meant': '{{availableObjects}}',
'Label': '{{label}}',
'Step': '{{step}}',
'Help': {
'_': 'Check the object\'s name is correct and that you have defined it previously. A canvas object is defined as follows:',
'_1': `
<pre>
<code class='language-javascript'>
this.engine.action ('Canvas').objects ({
stars: {
start: () => {},
stop: () => {},
restart: () => {},
layers: [],
state: {},
props: {}
}
});
</code>
</pre>
`,
'_2': 'Notice the object defined uses a name or an id, in this case it was set to "stars" and to show it, you must use that exact name:',
'_3': `
<pre><code class='language-javascript'>"show canvas stars background"</code></pre>
`
}
}
});
// Dialog Action
FancyError.register('action:dialog:textbox_hidden', {
title: 'A dialog is being shown while the textbox is hidden',
message: 'Monogatari attempted to display a dialog but the textbox is currently hidden. The dialog will still be shown, but the player may not be able to see it.',
props: {
'Statement': '{{statement}}',
'Label': '{{label}}',
'Step': '{{step}}',
'Help': {
'_': 'If you intentionally hid the textbox, make sure to show it again before displaying dialog:',
'_1': `
<pre><code class='language-javascript'>"show textbox"</code></pre>
`,
'_2': 'If you want to show visual elements without dialog while the textbox is hidden, use non-dialog actions like show image or show character.'
}
}
});
// Message Action
FancyError.register('action:message:not_found', {
title: 'The message "{{id}}" was not found',
message: 'Monogatari attempted to retrieve a message named "{{id}}" but it didn\'t exist in the messages object.',
props: {
'Message': '{{id}}',
'You may have meant': '{{availableMessages}}',
'Label': '{{label}}',
'Step': '{{step}}',
'Help': {
'_': 'Check the message name is correct and that you have defined it previously. A Message is defined as follows:',
'_1': `
<pre>
<code class='language-javascript'>
this.engine.action ('message').mesages ({
'Welcome': {
title: 'Welcome!',
subtitle: 'This is the Monogatari VN Engine',
body: 'This is where the magic gets done!'
}
});
</code>
</pre>
`,
'_2': 'Notice the message defined uses a name or an id, in this case it was set to "Welcome" and to show it, you must use that exact name:',
'_3': `
<pre><code class='language-javascript'>"show message Welcome"</code></pre>
`
}
}
});
// HideCharacterLayer Action
FancyError.register('action:hide_character_layer:character_not_found', {
title: 'The character "{{asset}}" does not exist',
message: 'Monogatari attempted to get information about the character "{{asset}}" but it wasn\'t found on the characters object.',
props: {
'Missing Character': '{{asset}}',
'You may have meant one of these': '{{availableCharacters}}',
'Statement': '{{statement}}',
'Label': '{{label}}',
'Step': '{{step}}',
'Help': {
'_': 'Check your characters object and your script to make sure the character exists and that it does not have a typo in it.'
}
}
});
FancyError.register('action:hide_character_layer:layer_not_shown', {
title: 'The character layer "{{layer}}" can\'t hide because it\'s not being shown',
message: 'Monogatari attempted to hide the layer "{{layer}}" of the character "{{asset}}" but it was not being shown.',
props: {
'Missing Layer': '{{layer}}',
'Character': '{{asset}}',
'You may have meant one of these': '{{availableCharacters}}',
'Statement': '{{statement}}',
'Label': '{{label}}',
'Step': '{{step}}',
'Help': {
'_': 'Check that before this hide action you have a show action that shows the character you want to hide.'
}
}
});
// HideCharacter Action
FancyError.register('action:hide_character:character_not_found', {
title: 'The character "{{asset}}" does not exist',
message: 'Monogatari attempted to get information about the character "{{asset}}" but it wasn\'t found on the characters object.',
props: {
'Missing Character': '{{asset}}',
'You may have meant one of these': '{{availableCharacters}}',
'Statement': '{{statement}}',
'Label': '{{label}}',
'Step': '{{step}}',
'Help': {
'_': 'Check your characters object and your script to make sure the character exists and that it does not have a typo in it.'
}
}
});
FancyError.register('action:hide_character:not_shown', {
title: 'The character "{{asset}}" can\'t hide because it\'s not being shown',
message: 'Monogatari attempted to hide the character "{{asset}}" but it was not being shown.',
props: {
'Missing Character': '{{asset}}',
'You may have meant one of these': '{{availableCharacters}}',
'Statement': '{{statement}}',
'Label': '{{label}}',
'Step': '{{step}}',
'Help': {
'_': 'Check that before this hide action you have a show action that shows the character you want to hide.'
}
}
});
// ShowCharacter Action
FancyError.register('action:show_character:character_not_found', {
title: 'The character "{{asset}}" does not exist',
message: 'Monogatari attempted to show the character "{{asset}}" but it wasn\'t found on the characters object.',
props: {
'Missing Character': '{{asset}}',
'You may have meant one of these': '{{availableCharacters}}',
'Statement': '{{statement}}',
'Label': '{{label}}',
'Step': '{{step}}',
'Help': {
'_': 'Check your characters object and your script to make sure the character exists and that it does not have a typo in it.'
}
}
});
FancyError.register('action:show_character:sprite_not_found', {
title: 'The sprite "{{sprite}}" for character "{{asset}}" does not exist',
message: 'Monogatari attempted to show the character "{{asset}}" with sprite "{{sprite}}" but the sprite wasn\'t found.',
props: {
'Character': '{{asset}}',
'Missing Sprite': '{{sprite}}',
'Available Sprites': '{{availableSprites}}',
'Statement': '{{statement}}',
'Label': '{{label}}',
'Step': '{{step}}',
'Help': {
'_': 'Check that the sprite name is correctly defined in your character\'s sprites object.'
}
}
});
// ShowCharacterLayer Action
FancyError.register('action:show_character_layer:character_not_found', {
title: 'The character "{{asset}}" does not exist',
message: 'Monogatari attempted to show a layer for character "{{asset}}" but the character wasn\'t found on the characters object.',
props: {
'Missing Character': '{{asset}}',
'Layer': '{{layer}}',
'You may have meant one of these': '{{availableCharacters}}',
'Statement': '{{statement}}',
'Label': '{{label}}',
'Step': '{{step}}',
'Help': {
'_': 'Check your characters object and your script to make sure the character exists and that it does not have a typo in it.'
}
}
});
FancyError.register('action:show_character_layer:sprite_not_found', {
title: 'The sprite "{{sprite}}" for layer "{{layer}}" of character "{{asset}}" does not exist',
message: 'Monogatari attempted to show a character layer but the sprite wasn\'t found in the layer assets.',
props: {
'Character': '{{asset}}',
'Layer': '{{layer}}',
'Missing Sprite': '{{sprite}}',
'Available Sprites': '{{availableSprites}}',
'Statement': '{{statement}}',
'Label': '{{label}}',
'Step': '{{step}}',
'Help': {
'_': 'Check that the sprite name is correctly defined in your character\'s layer_assets object for this layer.'
}
}
});
// HideImage Action
FancyError.register('action:hide_image:not_shown', {
title: 'The image "{{asset}}" can\'t hide because it\'s not being shown',
message: 'Monogatari attempted to hide the image "{{asset}}" but it was not being shown.',
props: {
'Missing Image': '{{asset}}',
'Statement': '{{statement}}',
'Label': '{{label}}',
'Step': '{{step}}',
'Help': {
'_': 'Check that before this hide action you have a show action that shows the image you want to hide.'
}
}
});
// HideCanvas Action
FancyError.register('action:hide_canvas:not_shown', {
title: 'The canvas "{{name}}" can\'t hide because it\'s not being shown',
message: 'Monogatari attempted to hide the canvas "{{name}}" but it was not being shown.',
props: {
'Canvas': '{{name}}',
'Statement': '{{statement}}',
'Label': '{{label}}',
'Step': '{{step}}',
'Help': {
'_': 'Check that before this hide action you have a show action that shows the canvas you want to hide.'
}
}
});
// Conditional Action
FancyError.register('action:conditional:negative_value', {
title: 'Conditional condition returned a negative number "{{value}}".',
message: 'The `Condition` function returned "{{value}}" and only positive numbers are allowed for numeric values.',
props: {
'Problematic Value': '{{value}}',
'You may have meant one of these': '{{availableBranches}}'
}
});
FancyError.register('action:conditional:non_integer_value', {
title: 'Conditional condition returned a non-integer value "{{value}}".',
message: 'The `Condition` function returned "{{value}}" and only integer numbers are allowed for numeric values.',
props: {
'Problematic Value': '{{value}}',
'You may have meant one of these': '{{availableBranches}}'
}
});
FancyError.register('action:conditional:branch_not_found', {
title: 'Conditional attempted to execute a non existent branch "{{branch}}"',
message: 'The `Condition` function returned "{{branch}}" as the branch to execute but it does not exist.',
props: {
'Problematic Branch': '{{branch}}',
'You may have meant one of these': '{{availableBranches}}'
}
});
// Notification Action
FancyError.register('action:notification:invalid_time', {
title: 'The specified time was not an integer',
message: 'Monogatari attempted to transform the given time into an integer value but failed.',
props: {
'Specified time': '{{time}}',
'Statement': '{{statement}}',
'Label': '{{label}}',
'Step': '{{step}}',
'Help': {
'_': 'Check if the value you provided is actually an integer (whole number). Remember the value used must be given in milliseconds and must not be mixed with characters other than numbers.',
'_1': 'For example, the following statement would make a notification go away after 5 seconds:',
'_3': `
<pre><code class='language-javascript'>"show notification Welcome 5000"</code></pre>
`
}
}
});
FancyError.register('action:notification:not_found', {
title: 'The notification "{{name}}" was not found',
message: 'Monogatari attempted to retrieve a notification named "{{name}}" but it didn\'t exist in the notifications object.',
props: {
'Notification': '{{name}}',
'You may have meant': '{{availableNotifications}}',
'Label': '{{label}}',
'Step': '{{step}}',
'Help': {
'_': 'Check the notification\'s name is correct and that you have defined it previously. A Notification is defined as follows:',
'_1': `
<pre>
<code class='language-javascript'>
this.engine.action ('Notification').notifications ({
'Welcome': {
title: 'Welcome!',
body: 'This is the Monogatari VN Engine',
icon: ''
}
});
</code>
</pre>
`,
'_2': 'Notice the notification defined uses a name or an id, in this case it was set to "Welcome" and to show it, you must use that exact name:',
'_3': `
<pre><code class='language-javascript'>"show notification Welcome"</code></pre>
`
}
}
});
// Function Action
FancyError.register('action:function:apply_error', {
title: 'An error occurred while trying to revert a Reversible Function.',
message: 'Monogatari attempted to run the `Apply` method of a Reversible Function but an error occurred.',
props: {
'Label': '{{label}}',
'Step': '{{step}}',
'Help': {
'_': 'Check the code for your function, there may be additional information in the console.',
}
}
});
FancyError.register('action:function:revert_error', {
title: 'An error occurred while trying to revert a Reversible Function.',
message: 'Monogatari attempted to run the `Revert` method of a Reversible Function but an error occurred.',
props: {
'Label': '{{label}}',
'Step': '{{step}}',
'Help': {
'_': 'Check the code for your function, there may be additional information in the console.',
}
}
});
// Video Action
FancyError.register('action:video:invalid_mode', {
title: 'The video mode provided ("{{mode}}") is not valid.',
message: 'Monogatari attempted to play a video but the mode "{{mode}}" was not found in the video action configuration as a valid mode.',
props: {
'Mode Provided': '{{mode}}',
'You may have meant one of these': '{{validModes}}',
'Statement': '{{statement}}',
'Label': '{{label}}',
'Step': '{{step}}',
'Help': {
'_': 'Check your statement and make sure there are no typos on the mode you provided.'
}
}
});
// Wait Action
FancyError.register('action:wait:invalid_time', {
title: 'The specified time was not an integer',
message: 'Monogatari attempted to transform the given time into an integer value but failed.',
props: {
'Specified time': '{{time}}',
'Statement': '{{statement}}',
'Label': '{{label}}',
'Step': '{{step}}',
'Help': {
'_': 'Check if the value you provided is actually an integer (whole number). Remember the value used must be given in milliseconds and must not be mixed with characters other than numbers.',
'_1': 'For example, the following statement would make the game wait for 5 seconds:',
'_3': `
<pre><code class='language-javascript'>"wait 5000"</code></pre>
`
}
}
});
// Vibrate Action
FancyError.register('action:vibrate:invalid_time', {
title: 'The specified time was not an integer',
message: 'Monogatari attempted to transform the given time into an integer value but failed.',
props: {
'Specified time': '{{time}}',
'Statement': '{{statement}}',
'Label': '{{label}}',
'Step': '{{step}}',
'Help': {
'_': 'Check if the value you provided is actually an integer (whole number). Remember the value used must be given in milliseconds and must not be mixed with characters other than numbers.',
'_1': 'For example, the following statement would make the device vibrate for 5 seconds:',
'_3': `
<pre><code class='language-javascript'>"vibrate 5000"</code></pre>
`,
'_4': 'If you wanted to make the device vibrate on a pattern, this is a correct syntax:',
'_5': `
<pre><code class='language-javascript'>"vibrate 5000 100 4000 200 3000"</code></pre>
`
}
}
});
// Jump Action
FancyError.register('action:jump:label_not_found', {
title: 'The label "{{targetLabel}}" does not exist',
message: 'Monogatari attempted to jump to the label named "{{targetLabel}}" but it wasn\'t found on the script.',
props: {
'Missing Label': '{{targetLabel}}',
'You may have meant one of these': '{{availableLabels}}',
'Statement': '{{statement}}',
'Label': '{{label}}',
'Step': '{{step}}',
'Help': {
'_': 'Check if the label in your jump statement is correct and that you have also defined it correctly.'
}
}
});
// Language Selection Screen
FancyError.register('component:language_selection_screen:metadata_not_found', {
title: 'Metadata for language "{{language}}" could not be found.',
message: 'Monogatari attempted to retrieve the metadata for this language but it does not exists',
props: {
'Language Not Found': '{{language}}',
'You may have meant one of these': '{{availableLanguages}}',
'Help': {
'_': 'Please check that you have defined the metadata for this language. Remember the metadata is defined as follows:',
'_1': `
<pre>
<code class='language-javascript'>
monogatari.languageMetadata ("Español", {
"code": "es",
"icon": "🇲🇽"
});
</code>
</pre>
`,
'Documentation': '<a href="https://developers.monogatari.io/documentation/v/develop/configuration-options/game-configuration/internationalization/" target="_blank">Internationalization</a>'
}
}
});
// ----------------------------------------------------------------------------
// Engine Errors
// ----------------------------------------------------------------------------
// Translation Errors
FancyError.register('engine:translation:key_not_found', {
title: 'Translation for string "{{key}}" could not be found',
message: 'Monogatari attempted to find a translation for the current language set in the preferences but there was none.',
props: {
'String Not Found': '{{key}}',
'Language': '{{language}}',
'Found in these elements': '{{elements}}',
'You may have meant one of these': '{{availableStrings}}',
'Help': {
'_': 'Please check that this string has been correctly defined in your translations. A translation is defined as follows:',
'_1': `
<pre>
<code class='language-javascript'>
monogatari.translation ("YourLanguage", {
"SomeString": "Your Translation"
});
</code>
</pre>
`,
'_2': 'You may also want to check if the [data-string] property of the HTML elements above is correct or if they have a typo.',
'Documentation': '<a href="https://developers.monogatari.io/documentation/v/develop/configuration-options/game-configuration/internationalization/" target="_blank">Internationalization</a>'
}
}
});
FancyError.register('engine:translation:language_not_found', {
title: 'Language could not be found',
message: 'Monogatari attempted to translate the UI using the current language set in the preferences but no translations could be found for it.',
props: {
'Problematic Language': '{{language}}',
'You may have meant one of these': '{{availableLanguages}}',
'Help': {
'_': 'Please check if you have defined correctly the translations for this language, translations are defined as follows:',
'_1': `
<pre>
<code class='language-javascript'>
monogatari.translation ("YourLanguage", {
"SomeString": "Your Translation"
});
</code>
</pre>
`,
'_2': 'You may also want to check if the value of your language selector is right:',
'_3': '{{languageSelectorValue}}',
'Documentation': '<a href="https://developers.monogatari.io/documentation/v/develop/configuration-options/game-configuration/internationalization/" target="_blank">Internationalization</a>'
}
}
});
// Component Registration Errors
FancyError.register('engine:component:already_registered', {
title: 'Unable to register component "{{tag}}"',
message: 'Monogatari attempted to register a component but another component had already been registered for the same tag.',
props: {
'Component / Tag': '{{component}}',
'Help': {
'_': 'Once a component for a tag has been registered and the setup has completed, it can not be replaced or removed. Try removing the conflicting component first:',
'_1': '{{unregisterCode}}',
}
}
});
FancyError.register('engine:component:unregister_after_setup', {
title: 'Unable to unregister component "{{component}}"',
message: 'Monogatari attempted to unregister a component but the setup had already happened.',
props: {
'Component': '{{component}}',
'Help': {
'_': 'Components can only be unregistered before the setup step is completed.',
'_1': 'Try performing this action before the <code class="language-javascript">monogatari.init ()</code> function is called.'
}
}
});
// Script Errors
FancyError.register('engine:script:language_not_found', {
title: 'Script Language "{{language}}" Was Not Found',
message: 'Monogatari attempted to retrieve the script for this language but it does not exists',
props: {
'Language Not Found': '{{language}}',
'MultiLanguage Setting': '{{multiLanguageSetting}}',
'You may have meant one of these': '{{availableLanguages}}',
'Help': {
'_': 'If your game is not a multilanguage game, change the setting on your options.js file',
'_1': `
<pre>
<code class='language-javascript'>
"MultiLanguage": false,
</code>
</pre>
`,
'_2': 'If your game is a multilanguage game, please check that the language label is correctly written on your script. Remember a multilanguage script looks like this:',
'_3': `
<pre>
<code class='language-javascript'>
monogatari.script ({
'English': {
'Start': [
'Hi, welcome to your first Visual Novel with Monogatari.'
]
},
'Español': {
'Start': [
'Hola, bienvenido a tu primer Novela Visual con Monogatari'
]
}
});
</code>
</pre>
`
}
}
});
FancyError.register('engine:script:label_not_found', {
title: '"{{startLabel}}" Label was not found',
message: 'Monogatari tried to get your start label but it couldn\'t find it in your script.',
props: {
'Start Label on your Settings': '{{startLabel}}',
'Labels Available': '{{availableLabels}}',
'Help': {
'_': 'Please check that the label exists in your script.'
}
}
});
// Storage Errors
FancyError.register('engine:storage:variable_not_found', {
title: 'Variable "{{variable}}" does not exists in your storage',
message: 'Monogatari attempted to interpolate a variable from your storage but it doesn\'t exists.',
props: {
'Script Statement': '{{statement}}',
'Part Not Found': '{{partNotFound}}',
'Variables Available in Storage': '{{availableVariables}}',
'Help': {
'_': 'Please check your storage object and make sure the variable you are using exists.',
'_1': 'You should also make sure that there is no typo in your script and that the variable names in your script and storage match.',
'Documentation': '<a href="https://developers.monogatari.io/documentation/v/develop/building-blocks/data-storage/" target="_blank">Storage</a>'
}
}
});
// Runtime Errors
FancyError.register('engine:run:function_error', {
title: 'An error occurred while trying to run a Function.',
message: 'Monogatari attempted to run a function on the script but an error occurred.',
props: {
'Label': '{{label}}',
'Step': '{{step}}',
'Help': {
'_': 'More details should be available at the console.',
}
}
});
// Lifecycle Errors
FancyError.register('engine:lifecycle:should_proceed_error', {
title: 'An error ocurred while trying to execute a shouldProceed function.',
message: 'Monogatari attempted to execute the function but an error ocurred.',
props: {
'Error Message': '{{errorMessage}}',
'Help': {
'_': 'More details should be available at the console.',
}
}
});
FancyError.register('engine:lifecycle:will_proceed_error', {
title: 'An error ocurred while trying to execute a willProceed function.',
message: 'Monogatari attempted to execute the function but an error ocurred.',
props: {
'Error Message': '{{errorMessage}}',
'Help': {
'_': 'More details should be available at the console.',
}
}
});
FancyError.register('engine:lifecycle:should_rollback_error', {
title: 'An error ocurred while trying to execute a shouldRollback function.',
message: 'Monogatari attempted to execute the function but an error ocurred.',
props: {
'Error Message': '{{errorMessage}}',
'Help': {
'_': 'More details should be available at the console.',
}
}
});
FancyError.register('engine:lifecycle:will_rollback_error', {
title: 'An error ocurred while trying to execute a willRollback function.',
message: 'Monogatari attempted to execute the function but an error ocurred.',
props: {
'Error Message': '{{errorMessage}}',
'Help': {
'_': 'More details should be available at the console.',
}
}
});
// Music Errors
FancyError.register('engine:music:not_defined', {
title: 'The music "{{music}}" is not defined.',
message: 'Monogatari attempted to find a definition of a music asset but there was none.',
props: {
'Music Not Found': '{{music}}',
'You may have meant one of these': '{{availableMusic}}',
'Help': {
'_': 'Please check that you have correctly defined this music asset and wrote its name correctly in the `MainScreenMusic` variable',
'_1': `
<pre>
<code class='language-javascript'>
'MainScreenMusic': 'TheKeyToYourMusicAsset'
</code>
</pre>
`,
}
}
});
// Element Errors
FancyError.register('engine:element:not_ready', {
title: 'Main element is not ready yet',
message: 'Monogatari attempted to execute a function when the main element was not fully loaded yet.',
props: {
'Trace': 'You should be able to see an error with the order in which functions were executed in your browser\'s console (Ctrl + Shift + i). The last one should be part of your code and that\'s the one that needs to be changed.',
'Help': {
'_': 'Please wrap or move your code into a $_ready () function block to wait for the page to be fully loaded before executing it.',
'_1': `
<pre>
<code class='language-javascript'>
monogatari.ready ('#monogatari', () => {
// Your code should go here
});
</code>
</pre>
`
}
}
});
// Component Lifecycle Errors
FancyError.register('engine:component:lifecycle_error', {
title: 'Error in component <{{tag}}> during {{lifecycle}}',
message: 'An error occurred while executing the {{lifecycle}} lifecycle method.',
props: {
'Component': '{{tag}}',
'Lifecycle Method': '{{lifecycle}}',
'Error Message': '{{errorMessage}}',
'Stack Trace': '{{stackTrace}}',
'Help': {
'_': 'Check the console for more details about this error.',
'_1': 'Make sure all async operations in lifecycle methods are properly handled.'
}
}
});
FancyError.register('engine:storage:filesystem_no_bridge', {
title: 'FileSystem storage requires a desktop environment',
message: 'The FileSystem storage adapter is only available in Electron or Electrobun. Change your Storage adapter to IndexedDB or LocalStorage for browser-based games.',
props: {
'Suggested Fix': 'Set Storage.Adapter to "IndexedDB" in your game settings, or run your game in an Electron or Electrobun wrapper.',
}
});
FancyError.register('engine:screenshots:storage_incompatible', {
title: 'Screenshot saving requires IndexedDB or custom storage',
message: 'Automatic screenshot saving is not supported with LocalStorage or SessionStorage due to storage size limits. Either change your Storage adapter to IndexedDB or provide custom onSaveScreenshot and onLoadScreenshot callbacks.',
props: {
'Current Adapter': '{{adapter}}',
'Suggested Fix': 'Set Storage.Adapter to "IndexedDB" in your game settings, or provide custom onSaveScreenshot/onLoadScreenshot callbacks.',
}
});
}
// Wait for Monogatari to be available, then register all errors with its
// FancyError instance. This ensures we use the same instance the engine uses.
if (typeof window === 'object') {
// Poll for Monogatari to be available (it loads after this script)
const waitForMonogatari = () => {
if (window.Monogatari && window.Monogatari.FancyError) {
registerErrors(window.Monogatari.FancyError);
} else {
// Check again on next frame
requestAnimationFrame(waitForMonogatari);
}
};
// Start checking
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', waitForMonogatari);
} else {
waitForMonogatari();
}
}
if (typeof window === 'object') {
window.addEventListener('error', (event) => {
const { message, lineno, filename } = event;
// Once the DOM is ready, a Fancy Error will be shown providing more information
window.addEventListener('DOMContentLoaded', () => {
// Use Monogatari's FancyError if available
const FancyError = window.Monogatari?.FancyError;
if (FancyError) {
FancyError.show (
'An Unknown Error Occurred',
message,
{
'File': filename,
'Line': lineno,
'Help': {
'_': 'This is most likely a scripting error, please check your script and JavaScript code for missing commas or incorrect syntax.',
'_1': 'There may be additional information on your browser\'s console. You can open your console by pressing Ctrl + Shift + I'
}
}
);
}
});
});
}