in share/src/components/Joystick.tsx [281:351]
protected setHandlePosition(x: number, y: number, animation = false) {
if (this.joystickHandle) {
this.joystickHandle.setAttribute("cx", "" + x)
this.joystickHandle.setAttribute("cy", "" + y)
this.handleX = x;
this.handleY = y;
if (!animation) {
if (this.getHandleDistance() < 5) {
this.clearButtonPresses();
}
else {
const { simulator } = this.props;
const angle = this.getHandleAngle();
const octet = (5 + Math.floor((angle / (Math.PI / 4)) - 0.5)) % 8;
if (octet === this.lastOctet) return;
this.lastOctet = octet;
let left = false;
let right = false;
let up = false;
let down = false;
switch (octet) {
case 0:
left = true;
break;
case 1:
left = true;
up = true;
break;
case 2:
up = true;
break;
case 3:
up = true;
right = true;
break;
case 4:
right = true;
break;
case 5:
right = true;
down = true;
break;
case 6:
down = true;
break;
case 7:
left = true;
down = true;
break;
}
if (down) simulator.pressButton(SimulatorButton.Down);
else simulator.releaseButton(SimulatorButton.Down);
if (up) simulator.pressButton(SimulatorButton.Up);
else simulator.releaseButton(SimulatorButton.Up);
if (left) simulator.pressButton(SimulatorButton.Left);
else simulator.releaseButton(SimulatorButton.Left);
if (right) simulator.pressButton(SimulatorButton.Right);
else simulator.releaseButton(SimulatorButton.Right);
}
}
}
}