add a way to go back in ui with gamepad & notification impr

This commit is contained in:
Vitaly 2023-09-22 23:09:23 +03:00
commit 038b8cd1e6
3 changed files with 20 additions and 7 deletions

View file

@ -30,6 +30,10 @@ export const contro = new ControMax({
chat: [['KeyT', 'Enter'], null],
command: ['Slash', null],
},
ui: {
back: [null/* 'Escape' */, 'B'],
click: [null, 'A'],
}
// waila: {
// showLookingBlockRecipe: ['Numpad3'],
// showLookingBlockUsages: ['Numpad4']
@ -117,9 +121,20 @@ subscribe(activeModalStack, () => {
}
})
const uiCommand = (command: Command) => {
if (command === 'ui.back') {
hideCurrentModal()
} else if (command === 'ui.click') {
// todo cursor
}
}
const onTriggerOrReleased = (command: Command, pressed: boolean) => {
// always allow release!
if (pressed && !isGameActive(true)) return
if (pressed && !isGameActive(true)) {
uiCommand(command)
return
}
if (stringStartsWith(command, 'general')) {
// handle general commands
switch (command) {
@ -308,8 +323,8 @@ addEventListener('mousedown', (e) => {
if (e.button === 1) {
const block = bot.blockAtCursor(/* 6 */5)
if (!block) return
const Item = require('prismarine-item')(bot.version);
const item = new Item(block.type, 1, 0);
const Item = require('prismarine-item')(bot.version)
const item = new Item(block.type, 1, 0)
bot.creative.setInventorySlot(bot.inventory.hotbarStart + bot.quickBarSlot, item)
bot.updateHeldItem()
}

View file

@ -15,7 +15,7 @@ const initialNotification = {
export const notification = proxy(initialNotification)
export const showNotification = (/** @type {Partial<typeof notification>} */newNotification) => {
Object.assign(notification, newNotification, initialNotification)
Object.assign(notification, { show: true, ...newNotification }, initialNotification)
}
window.notification = notification

View file

@ -38,8 +38,6 @@ export const pointerLock = {
}
const displayBrowserProblem = () => {
notification.show = true
// todo use notification stack
notification.autoHide = true
notification.message = navigator['keyboard'] ? 'Browser Limitation: Click on screen, enable Auto Fullscreen or F11' : 'Browser Limitation: Click on screen or use fullscreen in Chrome'
}
if (!(document.fullscreenElement && navigator['keyboard']) && this.justHitEscape) {
@ -70,7 +68,7 @@ window.getScreenRefreshRate = getScreenRefreshRate
/**
* Allows to obtain the estimated Hz of the primary monitor in the system.
*/
export function getScreenRefreshRate() {
export function getScreenRefreshRate(): Promise<number> {
let requestId = null
let callbackTriggered = false
let resolve