From 827e9b6d675c0f87d6b0286505e06d87dcf298ce Mon Sep 17 00:00:00 2001 From: cha0s Date: Sun, 25 Apr 2021 06:30:42 -0500 Subject: [PATCH] feat: joystick use --- packages/universe/src/components/play/ui/index.jsx | 14 +++++++++++--- packages/universe/src/server/packets/join.js | 1 + 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/packages/universe/src/components/play/ui/index.jsx b/packages/universe/src/components/play/ui/index.jsx index 203ddf2..24434e8 100644 --- a/packages/universe/src/components/play/ui/index.jsx +++ b/packages/universe/src/components/play/ui/index.jsx @@ -67,9 +67,17 @@ const PlayUi = () => { const inputNormalizer = new InputNormalizer(); inputNormalizer.listen(window.document.body); selfEntity.listenForInput(inputNormalizer); - selfEntity.actionRegistry.setTransformerFor('UseItem', (type) => ( - (-1 !== ['buttonPress', 'keyDown'].indexOf(type)) ? selfEntity.activeSlotIndex : -1 - )); + selfEntity.actionRegistry.setTransformerFor('UseItem', (type, value) => { + switch (type) { + case 'joystick': + return value === 0 ? -1 : selfEntity.activeSlotIndex; + case 'buttonPress': + case 'keyDown': + return selfEntity.activeSlotIndex; + default: + return -1; + } + }); const inputHandle = setInterval(() => { const actionStream = selfEntity.drainInput(); if (actionStream.length > 0) { diff --git a/packages/universe/src/server/packets/join.js b/packages/universe/src/server/packets/join.js index b4e65a2..045bf70 100644 --- a/packages/universe/src/server/packets/join.js +++ b/packages/universe/src/server/packets/join.js @@ -93,6 +93,7 @@ export default (latus) => class ServerJoin extends Join() { {type: 'key', index: 'd'}, ], UseItem: [ + {type: 'joystick', index: 4, axis: 1}, {type: 'button', index: 0}, {type: 'key', index: 'ArrowLeft'}, ],