feat: joystick use

This commit is contained in:
cha0s 2021-04-25 06:30:42 -05:00
parent ac3a980a43
commit 827e9b6d67
2 changed files with 12 additions and 3 deletions

View File

@ -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) {

View File

@ -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'},
],