Skip to content

Commit

Permalink
feat: The commit also adds a new keybind action for the 'F4' key, all…
Browse files Browse the repository at this point in the history
…owing the user to cycle through different game modes. Depending on the current game mode, the bot's chat command is updated accordingly.
  • Loading branch information
zardoy committed Sep 10, 2024
1 parent 2c971f3 commit 18bf1aa
Showing 1 changed file with 51 additions and 19 deletions.
70 changes: 51 additions & 19 deletions src/controls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,27 @@ const alwaysPressedHandledCommand = (command: Command) => {
hideCurrentModal()
}
}
if (command === 'advanced.lockUrl') {
lockUrl()
}
}

function lockUrl () {
let newQs = ''
if (fsState.saveLoaded) {
const save = localServer!.options.worldFolder.split('/').at(-1)
newQs = `loadSave=${save}`
} else if (process.env.NODE_ENV === 'development') {
newQs = `reconnect=1`
} else {
const qs = new URLSearchParams()
const { server, version } = localStorage
qs.set('server', server)
if (version) qs.set('version', version)
newQs = String(qs.toString())
}

window.history.replaceState({}, '', `${window.location.pathname}?${newQs}`)
}

function cycleHotbarSlot (dir: 1 | -1) {
Expand Down Expand Up @@ -390,24 +411,6 @@ contro.on('trigger', ({ command }) => {
break
}
}
if (command === 'advanced.lockUrl') {
let newQs = ''
if (fsState.saveLoaded) {
const save = localServer!.options.worldFolder.split('/').at(-1)
newQs = `loadSave=${save}`
} else if (process.env.NODE_ENV === 'development') {
newQs = `reconnect=1`
} else {
const qs = new URLSearchParams()
const { server, version } = localStorage
qs.set('server', server)
if (version) qs.set('version', version)
newQs = String(qs.toString())
}

window.history.replaceState({}, '', `${window.location.pathname}?${newQs}`)
// return
}

if (command === 'ui.pauseMenu') {
showModal({ reactType: 'pause-screen' })
Expand Down Expand Up @@ -472,7 +475,36 @@ export const f3Keybinds = [
await completeTexturePackInstall('default', 'default')
}
},
mobileTitle: 'Open Widget'
mobileTitle: 'Reload Textures'
},
{
key: 'F4',
async action () {
switch (bot.game.gameMode) {
case 'creative': {
bot.chat('/gamemode survival')

break
}
case 'survival': {
bot.chat('/gamemode adventure')

break
}
case 'adventure': {
bot.chat('/gamemode spectator')

break
}
case 'spectator': {
bot.chat('/gamemode creative')

break
}
// No default
}
},
mobileTitle: 'Cycle Game Mode'
}
]

Expand Down

0 comments on commit 18bf1aa

Please sign in to comment.