Skip to content

Commit 67a57ce

Browse files
Gets latest script nodes.
1 parent ddc3411 commit 67a57ce

17 files changed

+230
-135
lines changed

src/script-nodes-basic-js/CallbackActionScript.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,16 @@ class CallbackActionScript extends ScriptNode {
1313
/* END-USER-CTR-CODE */
1414
}
1515

16-
/** @type {() => void} */
16+
/** @type {(...args: any[]) => void} */
1717
callback;
1818

1919
/* START-USER-CODE */
2020

21-
execute() {
21+
execute(...args) {
2222

2323
if (this.callback) {
2424

25-
this.callback();
25+
this.callback(...args);
2626
}
2727
}
2828

src/script-nodes-basic-js/CallbackActionScript.scene

100644100755
+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
"customDefinition": false,
3434
"type": {
3535
"id": "expression",
36-
"expressionType": "() => void"
36+
"expressionType": "(...args: any[]) => void"
3737
}
3838
}
3939
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
2+
// You can write more code here
3+
4+
/* START OF COMPILED CODE */
5+
6+
class EmitEventActionScript extends ScriptNode {
7+
8+
constructor(parent) {
9+
super(parent);
10+
11+
/* START-USER-CTR-CODE */
12+
// Write your code here.
13+
/* END-USER-CTR-CODE */
14+
}
15+
16+
/** @type {string} */
17+
eventName = "";
18+
/** @type {"game.events"|"scene.events"|"scene.loader"|"scene.input"|"scene.input.keyboard"|"scene.anims"|"gameObject"} */
19+
eventEmitter = "gameObject";
20+
21+
/* START-USER-CODE */
22+
23+
/**
24+
* @param {...any} args
25+
*/
26+
execute(...args) {
27+
28+
/** @type {Phaser.Events.EventEmitter | null | undefined} */
29+
let emitter;
30+
31+
switch (this.eventEmitter) {
32+
case "game.events":
33+
34+
emitter = this.scene.game.events;
35+
break;
36+
37+
case "scene.events":
38+
39+
emitter = this.scene.events;
40+
break;
41+
42+
case "scene.loader":
43+
44+
emitter = this.scene.load;
45+
break;
46+
47+
case "scene.input":
48+
49+
emitter = this.scene.input;
50+
break;
51+
52+
case "scene.input.keyboard":
53+
54+
emitter = this.scene.input.keyboard;
55+
break;
56+
57+
case "scene.anims":
58+
59+
emitter = this.scene.anims;
60+
break;
61+
62+
case "gameObject":
63+
64+
emitter = this.gameObject;
65+
break;
66+
}
67+
68+
if (emitter) {
69+
70+
emitter.emit(this.eventName, ...args);
71+
}
72+
}
73+
74+
/* END-USER-CODE */
75+
}
76+
77+
/* END OF COMPILED CODE */
78+
79+
// You can write more code here

src/script-nodes-basic-js/OnKeyboardEventScript.scene renamed to src/script-nodes-basic-js/EmitEventActionScript.scene

+23-4
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
{
2-
"id": "23b8f1c7-9348-4ce0-a6cd-82998c9cc812",
2+
"id": "757fdd95-b5cc-4c5b-adef-a26b5965d851",
33
"sceneType": "PREFAB",
44
"settings": {
55
"preloadMethodName": "",
66
"preloadPackFiles": [],
77
"createMethodName": "",
8-
"borderWidth": 1280,
9-
"borderHeight": 720
8+
"borderWidth": 1920,
9+
"borderHeight": 1080
1010
},
1111
"displayList": [
1212
{
1313
"type": "ScriptNode",
14-
"id": "c53ebbfa-4527-4877-ac3c-6dba9003fe20",
14+
"id": "584759c2-8656-4641-90e0-7779b698b559",
1515
"label": "scriptnode_1",
1616
"components": [],
1717
"list": []
@@ -34,6 +34,25 @@
3434
"type": {
3535
"id": "string"
3636
}
37+
},
38+
{
39+
"name": "eventEmitter",
40+
"label": "Event Emitter",
41+
"tooltip": "The source of the events (EventEmitter).",
42+
"defValue": "gameObject",
43+
"customDefinition": false,
44+
"type": {
45+
"id": "option",
46+
"options": [
47+
"game.events",
48+
"scene.events",
49+
"scene.loader",
50+
"scene.input",
51+
"scene.input.keyboard",
52+
"scene.anims",
53+
"gameObject"
54+
]
55+
}
3756
}
3857
]
3958
}

src/script-nodes-basic-js/ExecActionScript.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ class ExecActionScript extends ScriptNode {
1818

1919
/* START-USER-CODE */
2020

21-
execute() {
21+
execute(...args) {
2222

2323
if (this.targetAction) {
2424

25-
this.targetAction.execute();
25+
this.targetAction.execute(...args);
2626
}
2727
}
2828

src/script-nodes-basic-js/ExecActionScript.scene

100644100755
File mode changed.

src/script-nodes-basic-js/OnEventScript.js

+69-1
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,80 @@ class OnEventScript extends ScriptNode {
1414

1515
/** @type {string} */
1616
eventName = "";
17+
/** @type {"game.events"|"scene.events"|"scene.loader"|"scene.input"|"scene.input.keyboard"|"scene.anims"|"gameObject"} */
18+
eventEmitter = "gameObject";
19+
/** @type {boolean} */
20+
once = false;
1721

1822
/* START-USER-CODE */
1923

2024
awake() {
2125

22-
this.gameObject.on(this.eventName, this.executeChildren, this);
26+
/** @type {Phaser.Events.EventEmitter | null | undefined} */
27+
let emitter;
28+
29+
switch (this.eventEmitter) {
30+
case "game.events":
31+
32+
emitter = this.scene.game.events;
33+
break;
34+
35+
case "scene.events":
36+
37+
emitter = this.scene.events;
38+
break;
39+
40+
case "scene.loader":
41+
42+
emitter = this.scene.load;
43+
break;
44+
45+
case "scene.input":
46+
47+
emitter = this.scene.input;
48+
break;
49+
50+
case "scene.input.keyboard":
51+
52+
emitter = this.scene.input.keyboard;
53+
break;
54+
55+
case "scene.anims":
56+
57+
emitter = this.scene.anims;
58+
break;
59+
60+
case "gameObject":
61+
62+
emitter = this.gameObject;
63+
break;
64+
}
65+
66+
if (emitter) {
67+
68+
if (this.once) {
69+
70+
emitter.once(this.eventName, this.executeChildren, this);
71+
72+
} else {
73+
74+
emitter.on(this.eventName, this.executeChildren, this);
75+
}
76+
77+
switch (this.eventEmitter) {
78+
case "scene.anims":
79+
case "scene.events":
80+
case "scene.input":
81+
case "scene.input.keyboard":
82+
case "scene.loader":
83+
84+
this.scene.events.on(Phaser.Scenes.Events.SHUTDOWN, () => {
85+
86+
emitter?.off(this.eventName, this.executeChildren, this);
87+
});
88+
break;
89+
}
90+
}
2391
}
2492

2593
/* END-USER-CODE */

src/script-nodes-basic-js/OnEventScript.scene

100644100755
+29
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,35 @@
3434
"type": {
3535
"id": "string"
3636
}
37+
},
38+
{
39+
"name": "eventEmitter",
40+
"label": "Event Emitter",
41+
"tooltip": "The events emitter to register on.",
42+
"defValue": "gameObject",
43+
"customDefinition": false,
44+
"type": {
45+
"id": "option",
46+
"options": [
47+
"game.events",
48+
"scene.events",
49+
"scene.loader",
50+
"scene.input",
51+
"scene.input.keyboard",
52+
"scene.anims",
53+
"gameObject"
54+
]
55+
}
56+
},
57+
{
58+
"name": "once",
59+
"label": "Once",
60+
"tooltip": "Listens once?",
61+
"defValue": false,
62+
"customDefinition": false,
63+
"type": {
64+
"id": "boolean"
65+
}
3766
}
3867
]
3968
}

src/script-nodes-basic-js/OnKeyboardEventScript.js

-39
This file was deleted.

src/script-nodes-basic-js/OnPointerDownScript.scene

100644100755
File mode changed.

src/script-nodes-basic-js/OnSceneAwakeScript.js

-28
This file was deleted.

src/script-nodes-basic-js/OnSceneAwakeScript.scene

-27
This file was deleted.

0 commit comments

Comments
 (0)