From 930d972dc6fc96ca690c0a732af56ffb9741925b Mon Sep 17 00:00:00 2001 From: Vitaly Turovsky Date: Tue, 16 Apr 2024 07:22:27 +0300 Subject: [PATCH] feat: add jump button to new controls type --- src/controls.ts | 8 ++++++-- src/flyingSquidEvents.ts | 11 ++++++----- src/optionsStorage.ts | 17 ++++++++++++----- src/react/TouchAreasControls.tsx | 20 ++++++++++++++++---- 4 files changed, 40 insertions(+), 16 deletions(-) diff --git a/src/controls.ts b/src/controls.ts index 90ca29bf..a50e0e03 100644 --- a/src/controls.ts +++ b/src/controls.ts @@ -152,6 +152,11 @@ const uiCommand = (command: Command) => { } } +export const setSneaking = (state: boolean) => { + gameAdditionalState.isSneaking = state + bot.setControlState('sneak', state) +} + const onTriggerOrReleased = (command: Command, pressed: boolean) => { // always allow release! if (pressed && !isGameActive(true)) { @@ -166,8 +171,7 @@ const onTriggerOrReleased = (command: Command, pressed: boolean) => { bot.setControlState('jump', pressed) break case 'general.sneak': - gameAdditionalState.isSneaking = pressed - bot.setControlState('sneak', pressed) + setSneaking(pressed) break case 'general.sprint': // todo add setting to change behavior diff --git a/src/flyingSquidEvents.ts b/src/flyingSquidEvents.ts index 6bcde9fc..fbab268b 100644 --- a/src/flyingSquidEvents.ts +++ b/src/flyingSquidEvents.ts @@ -3,10 +3,11 @@ import { chatInputValueGlobal } from './react/ChatContainer' import { showNotification } from './react/NotificationProvider' export default () => { - localServer!.on('warpsLoaded', () => { - showNotification(`${localServer!.warps.length} Warps loaded`, 'Use /warp to teleport to a warp point.', false, 'label-alt', () => { - chatInputValueGlobal.value = '/warp ' - showModal({ reactType: 'chat' }) - }) + localServer!.on('warpsLoaded', () => { + if (!localServer) return + showNotification(`${localServer.warps.length} Warps loaded`, 'Use /warp to teleport to a warp point.', false, 'label-alt', () => { + chatInputValueGlobal.value = '/warp ' + showModal({ reactType: 'chat' }) }) + }) } diff --git a/src/optionsStorage.ts b/src/optionsStorage.ts index 689bae41..3333117f 100644 --- a/src/optionsStorage.ts +++ b/src/optionsStorage.ts @@ -32,17 +32,21 @@ const defaultOptions = { touchButtonsPosition: 12, touchControlsPositions: { action: [ - 90, - 70 + 70, + 85 ], sneak: [ 90, - 90 + 85 ], break: [ 70, - 70 - ] + 65 + ], + jump: [ + 90, + 65 + ], } as Record, touchControlsType: 'classic' as 'classic' | 'joystick-buttons', gpuPreference: 'default' as 'default' | 'high-performance' | 'low-power', @@ -97,6 +101,9 @@ const migrateOptions = (options: Partial>) => { if (Object.keys(options.touchControlsPositions ?? {}).length === 0) { options.touchControlsPositions = defaultOptions.touchControlsPositions } + if (options.touchControlsPositions?.jump === undefined) { + options.touchControlsPositions!.jump = defaultOptions.touchControlsPositions.jump + } return options } diff --git a/src/react/TouchAreasControls.tsx b/src/react/TouchAreasControls.tsx index 70dfe46d..e2a3fd87 100644 --- a/src/react/TouchAreasControls.tsx +++ b/src/react/TouchAreasControls.tsx @@ -1,11 +1,11 @@ import { CSSProperties, PointerEvent, PointerEventHandler, useEffect, useRef, useState } from 'react' import { proxy, ref, useSnapshot } from 'valtio' -import { contro } from '../controls' +import { contro, setSneaking } from '../controls' import worldInteractions from '../worldInteractions' import PixelartIcon from './PixelartIcon' import Button from './Button' -export type ButtonName = 'action' | 'sneak' | 'break' +export type ButtonName = 'action' | 'sneak' | 'break' | 'jump' type ButtonsPositions = Record @@ -62,7 +62,8 @@ export default ({ touchActive, setupActive, buttonsPositions, closeButtonsSetup let active = { action: false, sneak: bot.getControlState('sneak'), - break: false + break: false, + jump: bot.getControlState('jump'), }[name] const holdDown = { action () { @@ -71,13 +72,17 @@ export default ({ touchActive, setupActive, buttonsPositions, closeButtonsSetup document.dispatchEvent(new MouseEvent('mouseup', { button: 2 })) }, sneak () { - bot.setControlState('sneak', !bot.getControlState('sneak')) + setSneaking(!bot.getControlState('sneak')) active = bot.getControlState('sneak') }, break () { document.dispatchEvent(new MouseEvent('mousedown', { button: 0 })) worldInteractions.update() active = true + }, + jump () { + bot.setControlState('jump', true) + active = true } } const holdUp = { @@ -89,6 +94,10 @@ export default ({ touchActive, setupActive, buttonsPositions, closeButtonsSetup document.dispatchEvent(new MouseEvent('mouseup', { button: 0 })) worldInteractions.update() active = false + }, + jump () { + bot.setControlState('jump', false) + active = false } } @@ -193,6 +202,9 @@ export default ({ touchActive, setupActive, buttonsPositions, closeButtonsSetup
+
+ +