Skip to content

Commit 4f7b756

Browse files
Adds basic script nodes.
1 parent f4e877c commit 4f7b756

12 files changed

+284
-122
lines changed

src/main.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@ class Boot extends Phaser.Scene {
2222
preload() {
2323

2424
this.load.pack("pack", "assets/preload-asset-pack.json");
25+
}
26+
27+
create() {
2528

26-
this.load.on(Phaser.Loader.Events.COMPLETE, () => this.scene.start("Preload"));
29+
this.scene.start("Preload");
2730
}
2831
}

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

100644100755
Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
12
// You can write more code here
3+
24
/* START OF COMPILED CODE */
35

46
class CallbackActionScript extends ScriptNode {
@@ -7,22 +9,26 @@ class CallbackActionScript extends ScriptNode {
79
super(parent);
810

911
/* START-USER-CTR-CODE */
10-
// Write your code here.
11-
/* END-USER-CTR-CODE */
12+
// Write your code here.
13+
/* END-USER-CTR-CODE */
1214
}
1315

1416
/** @type {() => void} */
1517
callback;
1618

1719
/* START-USER-CODE */
18-
execute() {
19-
if (this.callback) {
20-
this.callback();
21-
}
22-
}
20+
21+
execute() {
22+
23+
if (this.callback) {
24+
25+
this.callback();
26+
}
27+
}
28+
2329
/* END-USER-CODE */
2430
}
2531

2632
/* END OF COMPILED CODE */
27-
// You can write more code here
2833

34+
// You can write more code here

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

100644100755
Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
12
// You can write more code here
3+
24
/* START OF COMPILED CODE */
35

46
class ExecActionScript extends ScriptNode {
@@ -7,22 +9,26 @@ class ExecActionScript extends ScriptNode {
79
super(parent);
810

911
/* START-USER-CTR-CODE */
10-
// Write your code here.
11-
/* END-USER-CTR-CODE */
12+
// Write your code here.
13+
/* END-USER-CTR-CODE */
1214
}
1315

1416
/** @type {ScriptNode} */
1517
targetAction;
1618

1719
/* START-USER-CODE */
18-
execute() {
19-
if (this.targetAction) {
20-
this.targetAction.execute();
21-
}
22-
}
20+
21+
execute() {
22+
23+
if (this.targetAction) {
24+
25+
this.targetAction.execute();
26+
}
27+
}
28+
2329
/* END-USER-CODE */
2430
}
2531

2632
/* END OF COMPILED CODE */
27-
// You can write more code here
2833

34+
// You can write more code here

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

100644100755
Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
12
// You can write more code here
3+
24
/* START OF COMPILED CODE */
35

46
class OnEventScript extends ScriptNode {
@@ -7,19 +9,22 @@ class OnEventScript extends ScriptNode {
79
super(parent);
810

911
/* START-USER-CTR-CODE */
10-
/* END-USER-CTR-CODE */
12+
/* END-USER-CTR-CODE */
1113
}
1214

1315
/** @type {string} */
1416
eventName = "";
1517

1618
/* START-USER-CODE */
17-
awake() {
18-
this.gameObject?.on(this.eventName, this.executeChildren, this);
19-
}
19+
20+
awake() {
21+
22+
this.gameObject.on(this.eventName, this.executeChildren, this);
23+
}
24+
2025
/* END-USER-CODE */
2126
}
2227

2328
/* END OF COMPILED CODE */
24-
// You can write more code here
2529

30+
// You can write more code here

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

100644100755
Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
12
// You can write more code here
3+
24
/* START OF COMPILED CODE */
35

46
class OnKeyboardEventScript extends ScriptNode {
@@ -7,25 +9,31 @@ class OnKeyboardEventScript extends ScriptNode {
79
super(parent);
810

911
/* START-USER-CTR-CODE */
10-
// Write your code here.
11-
/* END-USER-CTR-CODE */
12+
// Write your code here.
13+
/* END-USER-CTR-CODE */
1214
}
1315

1416
/** @type {string} */
1517
eventName = "";
1618

1719
/* START-USER-CODE */
18-
awake() {
19-
if (!this.eventName) {
20-
return;
21-
}
22-
this.scene.input.keyboard?.on(this.eventName, () => {
23-
this.executeChildren();
24-
});
25-
}
20+
21+
awake() {
22+
23+
if (!this.eventName) {
24+
25+
return;
26+
}
27+
28+
this.scene.input.keyboard.on(this.eventName, () => {
29+
30+
this.executeChildren();
31+
});
32+
}
33+
2634
/* END-USER-CODE */
2735
}
2836

2937
/* END OF COMPILED CODE */
30-
// You can write more code here
3138

39+
// You can write more code here

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

100644100755
Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
12
// You can write more code here
3+
24
/* START OF COMPILED CODE */
35

46
class OnPointerDownScript extends OnEventScript {
@@ -10,23 +12,30 @@ class OnPointerDownScript extends OnEventScript {
1012
this.eventName = "pointerdown";
1113

1214
/* START-USER-CTR-CODE */
13-
// Write your code here.
14-
/* END-USER-CTR-CODE */
15+
// Write your code here.
16+
/* END-USER-CTR-CODE */
1517
}
1618

1719
/* START-USER-CODE */
18-
awake() {
19-
if (!this.gameObject) {
20-
return;
21-
}
22-
if (!this.gameObject.input) {
23-
this.gameObject.setInteractive();
24-
}
25-
super.awake();
26-
}
20+
21+
awake() {
22+
23+
if (!this.gameObject) {
24+
25+
return;
26+
}
27+
28+
if (!this.gameObject.input) {
29+
30+
this.gameObject.setInteractive();
31+
}
32+
33+
super.awake();
34+
}
35+
2736
/* END-USER-CODE */
2837
}
2938

3039
/* END OF COMPILED CODE */
31-
// You can write more code here
3240

41+
// You can write more code here

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

100644100755
Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
12
// You can write more code here
3+
24
/* START OF COMPILED CODE */
35

46
class OnSceneAwakeScript extends ScriptNode {
@@ -7,17 +9,20 @@ class OnSceneAwakeScript extends ScriptNode {
79
super(parent);
810

911
/* START-USER-CTR-CODE */
10-
// Write your code here.
11-
/* END-USER-CTR-CODE */
12+
// Write your code here.
13+
/* END-USER-CTR-CODE */
1214
}
1315

1416
/* START-USER-CODE */
15-
awake() {
16-
this.executeChildren();
17-
}
17+
18+
awake() {
19+
20+
this.executeChildren();
21+
}
22+
1823
/* END-USER-CODE */
1924
}
2025

2126
/* END OF COMPILED CODE */
22-
// You can write more code here
2327

28+
// You can write more code here
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# JavaScript version of the `script-nodes-basic` project
22

3-
The content of this repo is created by an automatic process of compiling the [script-nodes-basic](../script-nodes-basic/) project to JavaScript.
3+
The JavaScript version of the [Basic Script Node](https://github.com/PhaserEditor2D/script-nodes-basic) project.
44

5-
Read the original project for documentation.
5+
Go to the original project for documentation.

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

100644100755
Lines changed: 57 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
12
// You can write more code here
3+
24
/* START OF COMPILED CODE */
35

46
class RootScriptNode extends ScriptNode {
@@ -7,56 +9,69 @@ class RootScriptNode extends ScriptNode {
79
super(parent);
810

911
/* START-USER-CTR-CODE */
10-
// Write your code here.
11-
/* END-USER-CTR-CODE */
12+
// Write your code here.
13+
/* END-USER-CTR-CODE */
1214
}
1315

1416
/** @type {string} */
1517
key = "scripts";
1618

1719
/* START-USER-CODE */
18-
/**
19-
* Gets the RootScript object set into the game object.
20-
* It lookups the script node in using the `key` parameter as attribute of the game object.
21-
*
22-
* @param gameObject The game object where the root script is set.
23-
* @param key The key used to set root script into the game object. It is `"scripts"` by default.
24-
* @returns The root script.
25-
*/
26-
static getRoot(gameObject, key = "scripts") {
27-
return gameObject[`RootScript__${key}`];
28-
}
29-
/**
30-
* Gets the children of the root script registered in the given game object, using the given key.
31-
*
32-
* @param gameObject The game object containing the root script.
33-
* @param key The key used to register the root script in the game object.
34-
* @returns The chidlren of the root script.
35-
*/
36-
static getChildren(gameObject, key = "scripts") {
37-
const root = this.getRoot(gameObject, key);
38-
if (root) {
39-
return root.children;
40-
}
41-
return [];
42-
}
43-
/**
44-
* Gets the root script associated to the game object, using the given key.
45-
*
46-
* @param gameObject The game object where the root script is set.
47-
* @param key The key used for registering the root script in the game object.
48-
* @returns The root script.
49-
*/
50-
static hasRoot(gameObject, key = "scripts") {
51-
const script = this.getRoot(gameObject, key);
52-
return script !== undefined;
53-
}
54-
awake() {
55-
this.gameObject[`RootScript__${this.key}`] = this;
56-
}
20+
21+
/**
22+
* Gets the RootScript object set into the game object.
23+
* It lookups the script node in using the `key` parameter as attribute of the game object.
24+
*
25+
* @param {Phaser.GameObjects.GameObject} gameObject The game object where the root script is set.
26+
* @param {string} key The key used to set root script into the game object. It is `"scripts"` by default.
27+
* @returns {RootScriptNode} The root script.
28+
*/
29+
static getRoot(gameObject, key = "scripts") {
30+
31+
return gameObject[`RootScript__${key}`];
32+
}
33+
34+
/**
35+
* Gets the children of the root script registered in the given game object, using the given key.
36+
*
37+
* @param {Phaser.GameObjects.GameObject} gameObject The game object containing the root script.
38+
* @param {string} key The key used to register the root script in the game object.
39+
* @returns {ScriptNode[]} The chidlren of the root script.
40+
*/
41+
static getChildren(gameObject, key = "scripts") {
42+
43+
const root = this.getRoot(gameObject, key);
44+
45+
if (root) {
46+
47+
return root.children;
48+
}
49+
50+
return [];
51+
}
52+
53+
/**
54+
* Gets the root script associated to the game object, using the given key.
55+
*
56+
* @param {Phaser.GameObjects.GameObject} gameObject The game object where the root script is set.
57+
* @param {string} key The key used for registering the root script in the game object.
58+
* @returns {boolean} Has root script?
59+
*/
60+
static hasRoot(gameObject, key = "scripts") {
61+
62+
const script = this.getRoot(gameObject, key);
63+
64+
return script !== undefined;
65+
}
66+
67+
awake() {
68+
69+
this.gameObject[`RootScript__${this.key}`] = this;
70+
}
71+
5772
/* END-USER-CODE */
5873
}
5974

6075
/* END OF COMPILED CODE */
61-
// You can write more code here
6276

77+
// You can write more code here

0 commit comments

Comments
 (0)