BlueGit

blue-star speeltuin

child accessor by name (ex. children.btnGames)

timfa wsadhelios · pushed by timfa

Authored 2022-10-24 · 4 years ago

Hash
a58888334c26c706577038066841d6e336fcc8fb
Parent
ed656e16
4 files changed +9 −13
src/minigame/frog/frogScene.js +1 −1
@@ -102,7 +102,7 @@ class FrogScene extends Scene
102 102 }
103 103 if (this.windowDestroyTweens.length > 0)
104 104 {
105 let frogButton = MainMenu.Instance.getChildButton("btnGames").getChildButton("btnFrog");
105 let frogButton = MainMenu.Instance.children.btnGames.children.btnFrog;
106 106 frogButton.moveToActiveState(800, () => frogButton.moveToInactiveState(800));
107 107
108 108 this.windowDestroyTweens.forEach(t => t.start());
@@ -102,7 +102,7 @@ class FrogScene extends Scene
102 }
102 }
103 if (this.windowDestroyTweens.length > 0)
103 if (this.windowDestroyTweens.length > 0)
104 {
104 {
105 let frogButton = MainMenu.Instance.getChildButton("btnGames").getChildButton("btnFrog");
105 let frogButton = MainMenu.Instance.children.btnGames.children.btnFrog;
106 frogButton.moveToActiveState(800, () => frogButton.moveToInactiveState(800));
106 frogButton.moveToActiveState(800, () => frogButton.moveToInactiveState(800));
107
107
108 this.windowDestroyTweens.forEach(t => t.start());
108 this.windowDestroyTweens.forEach(t => t.start());
src/objects/menus/1-baseMenu.js +2 −7
@@ -1,6 +1,6 @@
1 1 class BaseMenu extends BaseMenuButton
2 2 {
3 children = []; // {label, button}
3 children = {};
4 4
5 5 state = 0;
6 6 prevState = null;
@@ -37,7 +37,7 @@ class BaseMenu extends BaseMenuButton
37 37
38 38 addChildButton (label, childButton)
39 39 {
40 this.children.push({ label: label, button: childButton });
40 this.children[label] = childButton;
41 41 childButton.parent = this;
42 42 childButton.moveOnParentOpen();
43 43 childButton.moveOnParentClose();
@@ -47,11 +47,6 @@ class BaseMenu extends BaseMenuButton
47 47 }
48 48 }
49 49
50 getChildButton (label)
51 {
52 return this.children.filter(e => e.label == label)[0].button;
53 }
54
55 50 moveSelfOnOpen (once)
56 51 {
57 52 this.isOpened.add((a, b) => this.moveToActiveState(a, b), this, once);
@@ -1,6 +1,6 @@
1class BaseMenu extends BaseMenuButton
1class BaseMenu extends BaseMenuButton
2{
2{
3 children = []; // {label, button}
3 children = {};
4
4
5 state = 0;
5 state = 0;
6 prevState = null;
6 prevState = null;
@@ -37,7 +37,7 @@ class BaseMenu extends BaseMenuButton
37
37
38 addChildButton (label, childButton)
38 addChildButton (label, childButton)
39 {
39 {
40 this.children.push({ label: label, button: childButton });
40 this.children[label] = childButton;
41 childButton.parent = this;
41 childButton.parent = this;
42 childButton.moveOnParentOpen();
42 childButton.moveOnParentOpen();
43 childButton.moveOnParentClose();
43 childButton.moveOnParentClose();
@@ -47,11 +47,6 @@ class BaseMenu extends BaseMenuButton
47 }
47 }
48 }
48 }
49
49
50 getChildButton (label)
51 {
52 return this.children.filter(e => e.label == label)[0].button;
53 }
54
55 moveSelfOnOpen (once)
50 moveSelfOnOpen (once)
56 {
51 {
57 this.isOpened.add((a, b) => this.moveToActiveState(a, b), this, once);
52 this.isOpened.add((a, b) => this.moveToActiveState(a, b), this, once);
src/objects/menus/btnGames.js +3 −3
@@ -46,14 +46,14 @@ class BtnGames extends BaseMenu
46 46
47 47 getNextTargetPosition ()
48 48 {
49 if (this.children == 0)
49 let buttonArray = Object.values(this.children);
50 if (buttonArray == 0)
50 51 {
51 52 return new vector(this.transform.position.x + this.transform.size.x * 2 + this.buttonPadding, this.transform.position.y + this.buttonPadding);
52 53 }
53 54 else
54 55 {
55 let previous = this.children[this.children.length - 1].button;
56
56 let previous = buttonArray[buttonArray.length - 1];
57 57 current.endPos = new vector(
58 58 previous.targetPosition.x,
59 59 previous.targetPosition.y + previous.transform.size.y + this.buttonPadding);
@@ -46,14 +46,14 @@ class BtnGames extends BaseMenu
46
46
47 getNextTargetPosition ()
47 getNextTargetPosition ()
48 {
48 {
49 if (this.children == 0)
49 let buttonArray = Object.values(this.children);
50 if (buttonArray == 0)
50 {
51 {
51 return new vector(this.transform.position.x + this.transform.size.x * 2 + this.buttonPadding, this.transform.position.y + this.buttonPadding);
52 return new vector(this.transform.position.x + this.transform.size.x * 2 + this.buttonPadding, this.transform.position.y + this.buttonPadding);
52 }
53 }
53 else
54 else
54 {
55 {
55 let previous = this.children[this.children.length - 1].button;
56 let previous = buttonArray[buttonArray.length - 1];
56
57 current.endPos = new vector(
57 current.endPos = new vector(
58 previous.targetPosition.x,
58 previous.targetPosition.x,
59 previous.targetPosition.y + previous.transform.size.y + this.buttonPadding);
59 previous.targetPosition.y + previous.transform.size.y + this.buttonPadding);
src/objects/menus/mainMenu.js +3 −2
@@ -47,13 +47,14 @@ class MainMenu extends BaseMenu
47 47
48 48 getNextOriginPosition ()
49 49 {
50 if (this.children.length == 0)
50 let buttonArray = Object.values(this.children);
51 if (buttonArray.length == 0)
51 52 {
52 53 return new vector(this.transform.position.x + this.buttonXOffset, this.transform.position.y + this.transform.size.y + this.buttonPadding);
53 54 }
54 55 else
55 56 {
56 return new vector(this.transform.position.x + this.buttonXOffset, this.children[this.children.length - 1].button.transform.position.y + this.children[this.children.length - 1].button.transform.size.y + this.buttonPadding);
57 return new vector(this.transform.position.x + this.buttonXOffset, buttonArray[buttonArray.length - 1].transform.position.y + buttonArray[buttonArray.length - 1].transform.size.y + this.buttonPadding);
57 58
58 59 }
59 60 }
@@ -47,13 +47,14 @@ class MainMenu extends BaseMenu
47
47
48 getNextOriginPosition ()
48 getNextOriginPosition ()
49 {
49 {
50 if (this.children.length == 0)
50 let buttonArray = Object.values(this.children);
51 if (buttonArray.length == 0)
51 {
52 {
52 return new vector(this.transform.position.x + this.buttonXOffset, this.transform.position.y + this.transform.size.y + this.buttonPadding);
53 return new vector(this.transform.position.x + this.buttonXOffset, this.transform.position.y + this.transform.size.y + this.buttonPadding);
53 }
54 }
54 else
55 else
55 {
56 {
56 return new vector(this.transform.position.x + this.buttonXOffset, this.children[this.children.length - 1].button.transform.position.y + this.children[this.children.length - 1].button.transform.size.y + this.buttonPadding);
57 return new vector(this.transform.position.x + this.buttonXOffset, buttonArray[buttonArray.length - 1].transform.position.y + buttonArray[buttonArray.length - 1].transform.size.y + this.buttonPadding);
57
58
58 }
59 }
59 }
60 }