Skip to content

Commit

Permalink
v0.7.2 input handling bugfixes (#173)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderclarktx authored Aug 24, 2024
1 parent 64d014b commit 7bf17cd
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
14 changes: 7 additions & 7 deletions core/src/ecs/systems/ui/InputSystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const KeyBuffer = (b?: KeyMouse[]) => {
}
}

// InputSystem handles all keyboard/joystick inputs
// InputSystem handles keyboard/mouse/joystick inputs
export const InputSystem = ClientSystemBuilder({
id: "InputSystem",
init: (world) => {
Expand All @@ -37,16 +37,17 @@ export const InputSystem = ClientSystemBuilder({
let mouseEvent: XY = { x: 0, y: 0 };

renderer?.app.canvas.addEventListener("pointermove", (event) => {
if (XYdifferent(mouseEvent, { x: event.offsetX, y: event.offsetY }, 50)) return;
if (CurrentJoystickPosition.active && XYdifferent(mouseEvent, { x: event.offsetX, y: event.offsetY }, 100)) return;

mouseEvent = { x: event.offsetX, y: event.offsetY };
mouse = renderer.camera.toWorldCoords({ x: event.offsetX, y: event.offsetY })
});

renderer?.app.canvas.addEventListener("pointerdown", (event) => {
// ignore clicks if the joystick just became active
if (!joystickOn && CurrentJoystickPosition.active) return;

if (clickableClickedThisFrame.value === world.tick + 1) return;

mouseEvent = { x: event.offsetX, y: event.offsetY };
mouse = renderer.camera.toWorldCoords({ x: event.offsetX, y: event.offsetY })

Expand All @@ -62,6 +63,9 @@ export const InputSystem = ClientSystemBuilder({

document.addEventListener("pointerup", (event) => {
const key = event.button === 0 ? "mb1" : "mb2";

if (key === "mb1" && joystickOn && !CurrentJoystickPosition.active) return;

bufferedDown.remove(key);
});

Expand Down Expand Up @@ -243,10 +247,6 @@ export const InputSystem = ClientSystemBuilder({
return;
}

if (clickableClickedThisFrame.value || (CurrentJoystickPosition.active && !joystickOn)) {
bufferedDown.remove("mb1");
}

const character = world.client?.playerEntity.components.controlling.getControlledEntity(world);
if (!character) return;

Expand Down
2 changes: 1 addition & 1 deletion docs/piggo-gg-min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion web/src/components/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export const Header = ({ world, netState, setNetState }: HeaderProps) => (

<div style={{ position: 'absolute', right: 0, bottom: 0 }}>
<span style={{ fontFamily: "sans-serif", fontSize: 14, marginRight: 5, verticalAlign: "-70%" }}>
v<b>0.7.1</b>
v<b>0.7.2</b>
</span>
<a style={{ margin: 0, color: "inherit", textDecoration: "none" }} target="_blank" href="https://discord.gg/VfFG9XqDpJ">
<FaDiscord size={20} style={{ color: "white", verticalAlign: "-80%" }}></FaDiscord>
Expand Down

0 comments on commit 7bf17cd

Please sign in to comment.