Skip to content

Commit 64dc679

Browse files
committed
Update syntax to latest specification
1 parent 14331ae commit 64dc679

16 files changed

Lines changed: 798 additions & 674 deletions
Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,20 @@ import { Action } from '../Action';
22
import { Monogatari } from '../monogatari';
33
import { $_ } from '@aegis-framework/artemis';
44

5-
export class Hide extends Action {
5+
export class HideCharacter extends Action {
66

7-
static matchString ([ action ]) {
8-
return action === 'hide';
7+
static matchString ([ hide, type ]) {
8+
return hide === 'hide' && type === 'character';
99
}
1010

11-
constructor ([ action, asset, ...classes ]) {
11+
constructor ([ hide, type, asset, ...classes ]) {
1212
super ();
1313
this.asset = asset;
1414

1515
if (typeof Monogatari.character (this.asset) !== 'undefined') {
1616
this.element = $_(`${Monogatari.selector} [data-character="${this.asset}"]`);
17-
this.state = 'characters';
1817
} else {
19-
this.element = $_(`${Monogatari.selector} [data-image="${this.asset}"]`);
20-
this.state = 'images';
18+
// TODO: Add FancyError for when the character does not exist
2119
}
2220

2321
if (typeof classes !== 'undefined') {
@@ -40,16 +38,12 @@ export class Hide extends Action {
4038
this.element.remove ();
4139
}
4240

43-
const show = Monogatari.state (this.state).filter ((item) => {
41+
const show = Monogatari.state ('characters').filter ((item) => {
4442
const [ , asset, ] = item.split (' ');
4543
return asset !== this.asset;
4644
});
4745

48-
if (this.state == 'characters') {
49-
Monogatari.state ({ characters: show });
50-
} else if (this.state == 'images') {
51-
Monogatari.state ({ images: show });
52-
}
46+
Monogatari.state ({ characters: show });
5347

5448
return Promise.resolve ();
5549
}
@@ -59,18 +53,14 @@ export class Hide extends Action {
5953
}
6054

6155
willRevert () {
62-
if (typeof Monogatari.character (this.asset) !== 'undefined' && Monogatari.history ('character').length > 0) {
63-
this.history = 'character';
64-
} else if (typeof Monogatari.asset ('images', this.asset) !== 'undefined' && Monogatari.history ('image').length > 0) {
65-
this.history = 'image';
66-
} else {
56+
if (Monogatari.history ('character').length <= 0) {
6757
return Promise.reject ();
6858
}
6959
return Promise.resolve ();
7060
}
7161

7262
revert () {
73-
$_(`${Monogatari.selector} #game`).append (Monogatari.history (this.history).pop ());
63+
$_(`${Monogatari.selector} #game`).append (Monogatari.history ('character').pop ());
7464
return Promise.resolve ();
7565
}
7666

@@ -79,6 +69,6 @@ export class Hide extends Action {
7969
}
8070
}
8171

82-
Hide.id = 'Hide';
72+
HideCharacter.id = 'Hide::Character';
8373

84-
Monogatari.registerAction (Hide);
74+
Monogatari.registerAction (HideCharacter);

core/lib/actions/HideImage.js

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import { Action } from '../Action';
2+
import { Monogatari } from '../monogatari';
3+
import { $_ } from '@aegis-framework/artemis';
4+
5+
export class HideImage extends Action {
6+
7+
static matchString ([ hide, type ]) {
8+
return hide === 'hide' && type === 'image';
9+
}
10+
11+
constructor ([ hide, type, asset, ...classes ]) {
12+
super ();
13+
this.asset = asset;
14+
15+
this.element = $_(`${Monogatari.selector} [data-image="${this.asset}"]`);
16+
17+
if (typeof classes !== 'undefined') {
18+
this.classes = classes;
19+
} else {
20+
this.classes = [];
21+
}
22+
this.classes = this.classes.filter ((c) => (c !== 'at' && c !== 'with'));
23+
}
24+
25+
apply () {
26+
this.element.removeClass ();
27+
this.element.addClass ('animated');
28+
if (this.classes.length > 0) {
29+
for (const newClass of this.classes) {
30+
this.element.addClass (newClass);
31+
}
32+
this.element.data ('visibility', 'invisible');
33+
} else {
34+
this.element.remove ();
35+
}
36+
37+
const show = Monogatari.state ('images').filter ((item) => {
38+
const [ , asset, ] = item.split (' ');
39+
return asset !== this.asset;
40+
});
41+
42+
Monogatari.state ({ images: show });
43+
44+
return Promise.resolve ();
45+
}
46+
47+
didApply () {
48+
return Promise.resolve (true);
49+
}
50+
51+
willRevert () {
52+
if (Monogatari.history ('image').length <= 0) {
53+
return Promise.reject ();
54+
}
55+
return Promise.resolve ();
56+
}
57+
58+
revert () {
59+
$_(`${Monogatari.selector} #game`).append (Monogatari.history ('image').pop ());
60+
return Promise.resolve ();
61+
}
62+
63+
didRevert () {
64+
return Promise.resolve (true);
65+
}
66+
}
67+
68+
HideImage.id = 'Hide::Image';
69+
70+
Monogatari.registerAction (HideImage);

core/lib/actions/HideParticles.js

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import { Action } from '../Action';
2+
import { Monogatari } from '../monogatari';
3+
import { $_ } from '@aegis-framework/artemis';
4+
5+
/* global pJSDom */
6+
7+
export class HideParticles extends Action {
8+
9+
static matchString ([ hide, type ]) {
10+
return hide === 'hide' && type === 'particles';
11+
}
12+
13+
constructor ([ hide, type ]) {
14+
super ();
15+
}
16+
17+
apply () {
18+
try {
19+
if (typeof pJSDom === 'object') {
20+
if (pJSDom.length > 0) {
21+
for (let i = 0; i < pJSDom.length; i++) {
22+
if (typeof pJSDom[i].pJS !== 'undefined') {
23+
cancelAnimationFrame (pJSDom[i].pJS.fn.drawAnimFrame);
24+
pJSDom.shift ();
25+
}
26+
}
27+
}
28+
}
29+
} catch (e) {
30+
console.error ('An error ocurred while trying to stop particle system.');
31+
}
32+
33+
Monogatari.state ({
34+
particles: ''
35+
});
36+
$_(`${Monogatari.selector} #particles-js`).html ('');
37+
return Promise.resolve ();
38+
}
39+
40+
didApply () {
41+
return Promise.resolve (true);
42+
}
43+
44+
revert () {
45+
if (Monogatari.history ('particle').length > 0) {
46+
const last = Monogatari.history ('particle').pop ();
47+
return Monogatari.run (last, false);
48+
}
49+
return Promise.resolve ();
50+
}
51+
52+
didRevert () {
53+
return Promise.resolve (true);
54+
}
55+
}
56+
57+
HideParticles.id = 'Hide::Particles';
58+
59+
Monogatari.registerAction (HideParticles);

core/lib/actions/Message.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ export class Message extends Action {
4949
return Promise.resolve ();
5050
}
5151

52-
static matchString ([ action, type ]) {
53-
return action === 'display' && type === 'message';
52+
static matchString ([ show, type ]) {
53+
return show === 'show' && type === 'message';
5454
}
5555

5656
static messages (object = null) {
@@ -65,10 +65,9 @@ export class Message extends Action {
6565
}
6666
}
6767

68-
constructor ([ action, type, asset ]) {
68+
constructor ([ show, type, message ]) {
6969
super ();
70-
this.type = type;
71-
this.message = Message.messages (asset);
70+
this.message = Message.messages (message);
7271
}
7372

7473
willApply () {

core/lib/actions/Notify.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ export class Notify extends Action {
1616
}
1717
}
1818

19-
static matchString ([ action ]) {
20-
return action === 'notify';
19+
static matchString ([ show, type ]) {
20+
return show === 'show' && type === 'notification';
2121
}
2222

2323
static notifications (object = null) {
@@ -32,7 +32,7 @@ export class Notify extends Action {
3232
}
3333
}
3434

35-
constructor ([ action, name, time ]) {
35+
constructor ([ show, type, name, time ]) {
3636
super ();
3737

3838
// First check if HTML5 notifications are available
@@ -151,7 +151,7 @@ export class Notify extends Action {
151151
}
152152
}
153153

154-
Notify.id = 'Notify';
154+
Notify.id = 'Notification';
155155
Notify._configuration = {
156156
notifications: {}
157157
};

core/lib/actions/Particles.js

Lines changed: 4 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import { Action } from '../Action';
22
import { Monogatari } from '../monogatari';
3-
import { $_ } from '@aegis-framework/artemis';
43

5-
/* global particlesJS, pJSDom */
4+
/* global particlesJS */
65

76
export class Particles extends Action {
87

@@ -44,30 +43,8 @@ export class Particles extends Action {
4443
return Promise.resolve ();
4544
}
4645

47-
static matchString ([ action ]) {
48-
return action === 'particles';
49-
}
50-
51-
static stop () {
52-
try {
53-
if (typeof pJSDom === 'object') {
54-
if (pJSDom.length > 0) {
55-
for (let i = 0; i < pJSDom.length; i++) {
56-
if (typeof pJSDom[i].pJS !== 'undefined') {
57-
cancelAnimationFrame (pJSDom[i].pJS.fn.drawAnimFrame);
58-
pJSDom.shift ();
59-
}
60-
}
61-
}
62-
}
63-
} catch (e) {
64-
console.error ('An error ocurred while trying to stop particle system.');
65-
}
66-
67-
Monogatari.state ({
68-
particles: ''
69-
});
70-
$_(`${Monogatari.selector} #particles-js`).html ('');
46+
static matchString ([ show, type ]) {
47+
return show === 'show' && type === 'particles';
7148
}
7249

7350
static particles (object = null) {
@@ -82,7 +59,7 @@ export class Particles extends Action {
8259
}
8360
}
8461

85-
constructor ([ action, name ]) {
62+
constructor ([ show, type, name ]) {
8663
super ();
8764
if (typeof Particles.particles (name) !== 'undefined') {
8865
this.particles = Particles.particles (name);

core/lib/actions/Scene.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@ export class Scene extends Action {
3333
return Promise.resolve ();
3434
}
3535

36-
static matchString ([ action ]) {
37-
return action === 'scene';
36+
static matchString ([ show, type ]) {
37+
return show === 'show' && type === 'scene';
3838
}
3939

40-
constructor ([ action, scene, separator, ...classes ]) {
40+
constructor ([ show, type, scene, separator, ...classes ]) {
4141
super ();
4242
this.scene = scene;
4343
this.property = 'background-image';

0 commit comments

Comments
 (0)