feat: add jump button to new controls type
This commit is contained in:
parent
a2b23b6806
commit
930d972dc6
4 changed files with 40 additions and 16 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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 <name> 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 <name> to teleport to a warp point.', false, 'label-alt', () => {
|
||||
chatInputValueGlobal.value = '/warp '
|
||||
showModal({ reactType: 'chat' })
|
||||
})
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<string, [number, number]>,
|
||||
touchControlsType: 'classic' as 'classic' | 'joystick-buttons',
|
||||
gpuPreference: 'default' as 'default' | 'high-performance' | 'low-power',
|
||||
|
|
@ -97,6 +101,9 @@ const migrateOptions = (options: Partial<AppOptions & Record<string, any>>) => {
|
|||
if (Object.keys(options.touchControlsPositions ?? {}).length === 0) {
|
||||
options.touchControlsPositions = defaultOptions.touchControlsPositions
|
||||
}
|
||||
if (options.touchControlsPositions?.jump === undefined) {
|
||||
options.touchControlsPositions!.jump = defaultOptions.touchControlsPositions.jump
|
||||
}
|
||||
|
||||
return options
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<ButtonName, [number, number]>
|
||||
|
||||
|
|
@ -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
|
|||
<div {...buttonProps('sneak')}>
|
||||
<PixelartIcon iconName='arrow-down' />
|
||||
</div>
|
||||
<div {...buttonProps('jump')}>
|
||||
<PixelartIcon iconName='arrow-up' />
|
||||
</div>
|
||||
<div {...buttonProps('break')}>
|
||||
<MineIcon />
|
||||
</div>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue