Open MattiaPontonioKineton opened 4 years ago
Can you provide an example that we can run and debug? Would really safe some time
state path
in the nested states, with complex state structures becomes less maintainable. Sounds weird that if I call this.somenthing
I go up in the tree even then down.this
changes in the state classes, there are classes so I want to use the features of classes.Anyway, I understand the behaviour and I can use it. For reference, here's an experiment of dealing with the state machine.
class StatesExample extends lng.Application {
_handleRight() {
this._setState('A1');
}
static _states() {
return [
class A1 extends this {
_handleDown() {
this._setState('A2');
}
_handleLeft() {
this._setState('');
}
_handleRight() {
this._setState('A1.B1');
}
static _states() {
return [
class B1 extends A1 {
_handleDown() {
this._setState('A1.B2');
}
_handleLeft() {
this._setState('A1');
}
},
class B2 extends A1 {
_handleUp() {
this._setState('A1.B1');
}
_handleLeft() {
this._setState('A1');
}
}
]
}
},
class A2 extends this {
_handleUp() {
this._setState('A1');
}
_handleLeft() {
this._setState('');
}
_handleRight() {
this._setState('A2.B1');
}
static _states() {
return [
class B1 extends A2 {
_handleDown() {
this._setState('A2.B2');
}
_handleLeft() {
this._setState('A2');
}
},
class B2 extends A2 {
_handleUp() {
this._setState('A2.B1');
}
_handleLeft() {
this._setState('A2');
}
}
]
}
}
]
}
}
const options = {stage: {w: 100, h: 100, clearColor: 0xFF000000, canvas2d: false, useImageWorker: false}, debug: true}
const app = new StatesExample(options);
window.app = app;
document.body.appendChild(app.stage.getCanvas());
$enter
of the stateMultiplayer
I immediately callthis._setState('Multiplayer.InitialState'))
Multiplayer.InitialState
I callthis._setState('Multiplayer.Play'))
Multiplayer
state is re-entered so the state goes tothis._setState('Multiplayer.InitialState'))
It should not happen because I'm even in the state
Multiplayer
from his nesting states so I don't expect tore-$enter
the parent state.Should be good if I call
this._setState('Play'))
in a nested state the Router searches inside the sibling's states and not starting from the grandparent.