Import and export keymaps

This commit is contained in:
JannisX11 2021-04-25 19:40:15 +02:00
parent 5f4fb00f08
commit 5b51db0583
7 changed files with 82 additions and 20 deletions

View File

@ -355,6 +355,7 @@
<div id="setting" class="tab_content">
<h2 class="tl i_b">dialog.settings.settings</h2>
<div class="bar next_to_title" id="settings_title_bar"></div>
<div class="search_bar">
<input type="text" class="dark_bordered" id="settings_search_bar" oninput="Settings.updateSearch()">

View File

@ -1492,12 +1492,6 @@ const BARS = {
//Settings
new Action('reset_keybindings', {
icon: 'replay',
category: 'blockbench',
work_in_dialog: true,
click: function () {Keybinds.reset()}
})
new Action('open_dev_tools', {
name: 'menu.help.developer.dev_tools',
icon: 'fas.fa-tools',
@ -1825,7 +1819,6 @@ const BARS = {
}
BarItems.move_tool.select()
BarItems.reset_keybindings.toElement('#keybinds_title_bar')
BarItems.uv_dialog.toElement('#uv_title_bar')
BarItems.uv_dialog_full.toElement('#uv_title_bar')
},

View File

@ -357,6 +357,65 @@ onVueSetup(function() {
}
})
BARS.defineActions(() => {
new Action('import_keymap', {
icon: 'folder',
category: 'blockbench',
click: function () {
Blockbench.import({
resource_id: 'config',
extensions: ['bbkeymap'],
type: 'Blockbench Keymap'
}, function(files) {
let {keys} = JSON.parse(files[0].content);
Keybinds.actions.forEach(keybind_item => {
if (keys[keybind_item.id] == null) {
keybind_item.keybind.clear();
} else {
keybind_item.keybind.set(keys[keybind_item.id]).save(false);
}
})
Keybinds.save();
TickUpdates.keybind_conflicts = true;
})
}
})
new Action('export_keymap', {
icon: 'keyboard_hide',
category: 'blockbench',
click: async function () {
var keys = {}
for (var key in Keybinds.stored) {
if (Keybinds.stored[key].key == -1) {
keys[key] = null;
} else {
keys[key] = new oneLiner(Keybinds.stored[key])
}
}
Blockbench.export({
resource_id: 'config',
type: 'Blockbench Keymap',
extensions: ['bbkeymap'],
content: compileJSON({keys})
})
}
})
new Action('reset_keybindings', {
icon: 'replay',
category: 'blockbench',
work_in_dialog: true,
click: function () {Keybinds.reset()}
})
BarItems.import_keymap.toElement('#keybinds_title_bar')
BarItems.export_keymap.toElement('#keybinds_title_bar')
BarItems.reset_keybindings.toElement('#keybinds_title_bar')
})
window.addEventListener('blur', event => {
if (Pressing.alt) {
if (Toolbox.original && Toolbox.original.alt_tool) {

View File

@ -398,7 +398,7 @@ BARS.defineActions(() => {
category: 'blockbench',
click: function () {
Blockbench.import({
resource_id: 'theme',
resource_id: 'config',
extensions: ['bbsettings'],
type: 'Blockbench Settings'
}, function(files) {
@ -435,13 +435,15 @@ BARS.defineActions(() => {
})
}
Blockbench.export({
resource_id: 'theme',
resource_id: 'config',
type: 'Blockbench Settings',
extensions: ['bbsettings'],
content: autoStringify({settings: settings_copy})
content: compileJSON({settings: settings_copy})
})
}
})
BarItems.import_settings.toElement('#settings_title_bar')
BarItems.export_settings.toElement('#settings_title_bar')
})
onVueSetup(function() {

View File

@ -210,7 +210,7 @@ BARS.defineActions(function() {
category: 'blockbench',
click: function () {
Blockbench.import({
resource_id: 'theme',
resource_id: 'config',
extensions: ['bbstyle', 'bbtheme'],
type: 'Blockbench Theme'
}, function(files) {
@ -223,10 +223,10 @@ BARS.defineActions(function() {
category: 'blockbench',
click: function () {
Blockbench.export({
resource_id: 'theme',
resource_id: 'config',
type: 'Blockbench Theme',
extensions: ['bbtheme'],
content: autoStringify(CustomTheme.data)
content: compileJSON(CustomTheme.data)
})
}
})

File diff suppressed because one or more lines are too long

View File

@ -783,14 +783,25 @@
"action.edit_session": "Edit Session...",
"action.edit_session.desc": "Connect to an edit session to collaborate with other users",
"action.reset_keybindings": "Reset Keybindings",
"action.reset_keybindings.desc": "Reset all keybindings to Blockbench's defaults",
"action.load_plugin": "Load Plugin from File",
"action.load_plugin.desc": "Load a plugin by importing the source file",
"action.load_plugin_from_url": "Load Plugin from URL",
"action.load_plugin_from_url.desc": "Load a plugin from a server by specifying the URL",
"action.reload_plugins": "Reload Plugins",
"action.reload_plugins.desc": "Reload all development plugins",
"action.import_settings": "Import Settings",
"action.import_settings.desc": "Import a .bbsettings file",
"action.export_settings": "Export Settings",
"action.export_settings.desc": "Export the Blockbench settings as a .bbsettings file",
"action.reset_keybindings": "Reset Keybindings",
"action.reset_keybindings.desc": "Reset all keybindings to Blockbench's defaults",
"action.import_keymap": "Import Keymap",
"action.import_keymap.desc": "Import keybindings a .bbkeymap file",
"action.export_keymap": "Export Keymap",
"action.export_keymap.desc": "Export the current keybindings as a .bbkeymap file",
"action.reset_layout": "Reset Layout",
"action.reset_layout.desc": "Reset the layout to Blockbench's default",
"action.import_theme": "Import Theme",
@ -798,10 +809,6 @@
"action.export_theme.desc": "Create a theme file based on the current settings",
"action.reset_theme": "Reset Theme",
"action.reset_theme.desc": "Reset to the default Blockbench theme",
"action.import_settings": "Import Settings",
"action.import_settings.desc": "Import a .bbsettings file",
"action.export_settings": "Export Settings",
"action.export_settings.desc": "Export the Blockbench settings as a .bbsettings file",
"action.uv_dialog": "UV Window",
"action.uv_dialog.desc": "Open the UV dialog to see all faces next to each other",