forked from PrismarineJS/prismarine-web-client
-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
--------- Co-authored-by: gguio <[email protected]> Co-authored-by: Vitaly <[email protected]>
- Loading branch information
1 parent
6375df1
commit 6bf1085
Showing
21 changed files
with
857 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
import { guiOptionsScheme, tryFindOptionConfig } from './optionsGuiScheme' | ||
import { options } from './optionsStorage' | ||
|
||
export const customCommandsConfig = { | ||
chat: { | ||
input: [ | ||
{ | ||
type: 'text', | ||
placeholder: 'Command to send e.g. gamemode creative' | ||
} | ||
], | ||
handler ([command]) { | ||
bot.chat(`/${command.replace(/^\//, '')}`) | ||
} | ||
}, | ||
setOrToggleSetting: { | ||
input: [ | ||
{ | ||
type: 'select', | ||
// maybe title case? | ||
options: Object.keys(options) | ||
}, | ||
{ | ||
type: 'select', | ||
options: ['toggle', 'set'] | ||
}, | ||
([setting = '', action = ''] = []) => { | ||
const value = options[setting] | ||
if (!action || value === undefined || action === 'toggle') return null | ||
if (action === 'set') { | ||
const getBase = () => { | ||
const config = tryFindOptionConfig(setting as any) | ||
if (config && 'values' in config) { | ||
return { | ||
type: 'select', | ||
options: config.values | ||
} | ||
} | ||
if (config?.type === 'toggle' || typeof value === 'boolean') { | ||
return { | ||
type: 'select', | ||
options: ['true', 'false'] | ||
} | ||
} | ||
if (config?.type === 'slider' || value.type === 'number') { | ||
return { | ||
type: 'number', | ||
} | ||
} | ||
return { | ||
type: 'text' | ||
} | ||
} | ||
return { | ||
...getBase(), | ||
placeholder: value | ||
} | ||
} | ||
} | ||
], | ||
handler ([setting, action, value]) { | ||
if (action === 'toggle') { | ||
const value = options[setting] | ||
const config = tryFindOptionConfig(setting) | ||
if (config && 'values' in config && config.values) { | ||
const { values } = config | ||
const currentIndex = values.indexOf(value) | ||
const nextIndex = (currentIndex + 1) % values.length | ||
options[setting] = values[nextIndex] | ||
} else { | ||
options[setting] = typeof value === 'boolean' ? !value : typeof value === 'number' ? value + 1 : value | ||
} | ||
} else { | ||
options[setting] = value | ||
} | ||
} | ||
}, | ||
jsScripts: { | ||
input: [ | ||
{ | ||
type: 'text', | ||
placeholder: 'JavaScript code to run in main thread (sensitive!)' | ||
} | ||
], | ||
handler ([code]) { | ||
// eslint-disable-next-line no-new-func -- this is a feature, not a bug | ||
new Function(code)() | ||
} | ||
}, | ||
// openCommandsScreen: {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.