BlueGit

blue-star speeltuin

fix drawing image based on the element in SIRT, baseMenu simplification

timfa wsadhelios · pushed by timfa

Authored 2022-10-24 · 4 years ago

Hash
8812a3bf1d3d77f3b0fee63a38603f43a96afa62
Parent
2d3f3a6c
2 files changed +25 −14
src/minigame/simpleImagesRenderTween.js +5 −2
@@ -53,10 +53,13 @@ class SimpleImagesRenderTween extends GameObject
53 53 {
54 54 let context = this;
55 55 this.imageDataPerRequest.forEach(arr => arr.data.forEach(e =>
56 context.scene.game.images.fruit.draw(context.scene,
56 e.image.draw(
57 context.scene,
57 58 e.position.x, e.position.y,
58 59 e.image.width * e.size.x, game.images.fruit.height * e.size.y,
59 0, 0, 0, 1, e.subImage)));
60 0, 0, 0, 1, e.subImage
61 )
62 ));
60 63 }
61 64
62 65 createTween (context, currentRequest)
@@ -53,10 +53,13 @@ class SimpleImagesRenderTween extends GameObject
53 {
53 {
54 let context = this;
54 let context = this;
55 this.imageDataPerRequest.forEach(arr => arr.data.forEach(e =>
55 this.imageDataPerRequest.forEach(arr => arr.data.forEach(e =>
56 context.scene.game.images.fruit.draw(context.scene,
56 e.image.draw(
57 context.scene,
57 e.position.x, e.position.y,
58 e.position.x, e.position.y,
58 e.image.width * e.size.x, game.images.fruit.height * e.size.y,
59 e.image.width * e.size.x, game.images.fruit.height * e.size.y,
59 0, 0, 0, 1, e.subImage)));
60 0, 0, 0, 1, e.subImage
61 )
62 ));
60 }
63 }
61
64
62 createTween (context, currentRequest)
65 createTween (context, currentRequest)
src/objects/menus/1-baseMenu.js +20 −12
@@ -20,12 +20,12 @@ class BaseMenu extends BaseMenuButton
20 20
21 21 openOnParentOpen ()
22 22 {
23 this.parent.isOpened.add((cont) => this.open(null, cont), this);
23 this.parent.isOpened.add(() => this.open(), this);
24 24 }
25 25
26 26 closeOnParentClose ()
27 27 {
28 this.parent.isClosed.add((cont) => this.close(null, cont), this);
28 this.parent.isClosed.add(() => this.close(), this);
29 29 }
30 30
31 31 addedToScene ()
@@ -47,14 +47,14 @@ class BaseMenu extends BaseMenuButton
47 47 }
48 48 }
49 49
50 moveSelfOnOpen (once)
50 moveSelfOnOpen ()
51 51 {
52 this.isOpened.add((a, b) => this.moveToActiveState(a, b), this, once);
52 this.isOpened.add((a, b) => this.moveToActiveState(a, b), this);
53 53 }
54 54
55 moveSelfOnClose (once)
55 moveSelfOnClose ()
56 56 {
57 this.isClosed.add((a, b) => this.moveToInactiveState(a, b), this, once);
57 this.isClosed.add((a, b) => this.moveToInactiveState(a, b), this);
58 58 }
59 59
60 60 onClick (btn)
@@ -64,7 +64,7 @@ class BaseMenu extends BaseMenuButton
64 64 this.close();
65 65 }
66 66
67 open (callback, context)
67 open (callback)
68 68 {
69 69 if (this.state == MenuStates.open)
70 70 {
@@ -72,10 +72,10 @@ class BaseMenu extends BaseMenuButton
72 72 }
73 73 this.prevState = MenuStates.closed;
74 74 this.state = MenuStates.moving;
75 this.isOpened.dispatch(this.tOpen, () => { this.notifyDone(MenuStates.open); callback && callback.apply(context); });
75 this.isOpened.dispatch(this.tOpen, () => this.notifyDone(MenuStates.open, callback));
76 76 }
77 77
78 close (callback, context)
78 close (callback)
79 79 {
80 80 if (this.state == MenuStates.closed || this.state == MenuStates.moving && this.prevState == MenuStates.open)
81 81 {
@@ -83,12 +83,20 @@ class BaseMenu extends BaseMenuButton
83 83 }
84 84 this.prevState = MenuStates.open;
85 85 this.state = MenuStates.moving;
86 this.isClosed.dispatch(this.tClose, () => { this.notifyDone(MenuStates.closed); callback && callback.apply(context); });
86 this.isClosed.dispatch(this.tClose, () => this.notifyDone(MenuStates.closed, callback));
87 87 }
88 88
89 notifyDone (state)
89 /**
90 * gets called when children complete their movement.
91 * Callback is the one received from open(callback), and gets called only once per state change
92 */
93 notifyDone (state, callback)
90 94 {
91 this.state = state;
95 if (this.state != state)
96 {
97 this.state = state;
98 callback && callback.apply(this);
99 }
92 100 }
93 101
94 102
@@ -20,12 +20,12 @@ class BaseMenu extends BaseMenuButton
20
20
21 openOnParentOpen ()
21 openOnParentOpen ()
22 {
22 {
23 this.parent.isOpened.add((cont) => this.open(null, cont), this);
23 this.parent.isOpened.add(() => this.open(), this);
24 }
24 }
25
25
26 closeOnParentClose ()
26 closeOnParentClose ()
27 {
27 {
28 this.parent.isClosed.add((cont) => this.close(null, cont), this);
28 this.parent.isClosed.add(() => this.close(), this);
29 }
29 }
30
30
31 addedToScene ()
31 addedToScene ()
@@ -47,14 +47,14 @@ class BaseMenu extends BaseMenuButton
47 }
47 }
48 }
48 }
49
49
50 moveSelfOnOpen (once)
50 moveSelfOnOpen ()
51 {
51 {
52 this.isOpened.add((a, b) => this.moveToActiveState(a, b), this, once);
52 this.isOpened.add((a, b) => this.moveToActiveState(a, b), this);
53 }
53 }
54
54
55 moveSelfOnClose (once)
55 moveSelfOnClose ()
56 {
56 {
57 this.isClosed.add((a, b) => this.moveToInactiveState(a, b), this, once);
57 this.isClosed.add((a, b) => this.moveToInactiveState(a, b), this);
58 }
58 }
59
59
60 onClick (btn)
60 onClick (btn)
@@ -64,7 +64,7 @@ class BaseMenu extends BaseMenuButton
64 this.close();
64 this.close();
65 }
65 }
66
66
67 open (callback, context)
67 open (callback)
68 {
68 {
69 if (this.state == MenuStates.open)
69 if (this.state == MenuStates.open)
70 {
70 {
@@ -72,10 +72,10 @@ class BaseMenu extends BaseMenuButton
72 }
72 }
73 this.prevState = MenuStates.closed;
73 this.prevState = MenuStates.closed;
74 this.state = MenuStates.moving;
74 this.state = MenuStates.moving;
75 this.isOpened.dispatch(this.tOpen, () => { this.notifyDone(MenuStates.open); callback && callback.apply(context); });
75 this.isOpened.dispatch(this.tOpen, () => this.notifyDone(MenuStates.open, callback));
76 }
76 }
77
77
78 close (callback, context)
78 close (callback)
79 {
79 {
80 if (this.state == MenuStates.closed || this.state == MenuStates.moving && this.prevState == MenuStates.open)
80 if (this.state == MenuStates.closed || this.state == MenuStates.moving && this.prevState == MenuStates.open)
81 {
81 {
@@ -83,12 +83,20 @@ class BaseMenu extends BaseMenuButton
83 }
83 }
84 this.prevState = MenuStates.open;
84 this.prevState = MenuStates.open;
85 this.state = MenuStates.moving;
85 this.state = MenuStates.moving;
86 this.isClosed.dispatch(this.tClose, () => { this.notifyDone(MenuStates.closed); callback && callback.apply(context); });
86 this.isClosed.dispatch(this.tClose, () => this.notifyDone(MenuStates.closed, callback));
87 }
87 }
88
88
89 notifyDone (state)
89 /**
90 * gets called when children complete their movement.
91 * Callback is the one received from open(callback), and gets called only once per state change
92 */
93 notifyDone (state, callback)
90 {
94 {
91 this.state = state;
95 if (this.state != state)
96 {
97 this.state = state;
98 callback && callback.apply(this);
99 }
92 }
100 }
93
101
94
102