mirror of
https://github.com/JannisX11/blockbench.git
synced 2024-11-21 01:13:37 +08:00
Import/export settings
This commit is contained in:
parent
12a997d277
commit
5f4fb00f08
@ -67,6 +67,26 @@ class Setting {
|
|||||||
delete Settings.structure[this.category].items[this.id];
|
delete Settings.structure[this.category].items[this.id];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
set(value) {
|
||||||
|
if (value === undefined || value === null) return;
|
||||||
|
let old_value = this.value;
|
||||||
|
|
||||||
|
if (this.type == 'number' && typeof value == 'number') {
|
||||||
|
if (this.snap) {
|
||||||
|
value = Math.round(value / this.snap) * this.snap;
|
||||||
|
}
|
||||||
|
this.value = Math.clamp(value, this.min, this.max)
|
||||||
|
} else if (this.type == 'toggle') {
|
||||||
|
this.value = !!value;
|
||||||
|
} else if (this.type == 'click') {
|
||||||
|
this.value = value;
|
||||||
|
} else if (typeof value == 'string') {
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
if (typeof this.onChange == 'function' && this.value !== old_value) {
|
||||||
|
this.onChange(this.value);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const Settings = {
|
const Settings = {
|
||||||
@ -336,6 +356,15 @@ const Settings = {
|
|||||||
structure.search_results.hidden = true;
|
structure.search_results.hidden = true;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
import(file) {
|
||||||
|
let data = JSON.parse(file.content);
|
||||||
|
for (let key in settings) {
|
||||||
|
let setting = settings[key];
|
||||||
|
if (setting instanceof Setting && data.settings[key] !== undefined) {
|
||||||
|
setting.set(data.settings[key]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
get(id) {
|
get(id) {
|
||||||
if (id && settings[id]) {
|
if (id && settings[id]) {
|
||||||
return settings[id].value;
|
return settings[id].value;
|
||||||
@ -362,6 +391,59 @@ function updateStreamerModeNotification() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BARS.defineActions(() => {
|
||||||
|
|
||||||
|
new Action('import_settings', {
|
||||||
|
icon: 'folder',
|
||||||
|
category: 'blockbench',
|
||||||
|
click: function () {
|
||||||
|
Blockbench.import({
|
||||||
|
resource_id: 'theme',
|
||||||
|
extensions: ['bbsettings'],
|
||||||
|
type: 'Blockbench Settings'
|
||||||
|
}, function(files) {
|
||||||
|
Settings.import(files[0]);
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
|
new Action('export_settings', {
|
||||||
|
icon: 'fas.fa-user-cog',
|
||||||
|
category: 'blockbench',
|
||||||
|
click: async function () {
|
||||||
|
let private_data = [];
|
||||||
|
var settings_copy = {}
|
||||||
|
for (var key in settings) {
|
||||||
|
settings_copy[key] = settings[key].value;
|
||||||
|
if (settings[key].value && settings[key].type == 'password') {
|
||||||
|
private_data.push(key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (private_data.length) {
|
||||||
|
await new Promise((resolve, reject) => {
|
||||||
|
Blockbench.showMessageBox({
|
||||||
|
title: 'dialog.export_private_settings.title',
|
||||||
|
message: tl('dialog.export_private_settings.message', [private_data.map(key => settings[key].name).join(', ')]),
|
||||||
|
buttons: ['dialog.export_private_settings.keep', 'dialog.export_private_settings.remove']
|
||||||
|
}, result => {
|
||||||
|
if (result == 1) {
|
||||||
|
private_data.forEach(key => {
|
||||||
|
delete settings_copy[key];
|
||||||
|
})
|
||||||
|
}
|
||||||
|
resolve()
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
Blockbench.export({
|
||||||
|
resource_id: 'theme',
|
||||||
|
type: 'Blockbench Settings',
|
||||||
|
extensions: ['bbsettings'],
|
||||||
|
content: autoStringify({settings: settings_copy})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
onVueSetup(function() {
|
onVueSetup(function() {
|
||||||
Settings.structure.search_results = {
|
Settings.structure.search_results = {
|
||||||
name: tl('dialog.settings.search_results'),
|
name: tl('dialog.settings.search_results'),
|
||||||
|
@ -14,6 +14,13 @@ function setupDragHandlers() {
|
|||||||
CustomTheme.import(files[0]);
|
CustomTheme.import(files[0]);
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
Blockbench.addDragHandler(
|
||||||
|
'settings',
|
||||||
|
{extensions: ['bbsettings']},
|
||||||
|
function(files) {
|
||||||
|
Settings.import(files[0]);
|
||||||
|
}
|
||||||
|
)
|
||||||
Blockbench.addDragHandler(
|
Blockbench.addDragHandler(
|
||||||
'plugin',
|
'plugin',
|
||||||
{extensions: ['bbplugin', 'js']},
|
{extensions: ['bbplugin', 'js']},
|
||||||
|
File diff suppressed because one or more lines are too long
@ -407,6 +407,11 @@
|
|||||||
"dialog.skin.texture": "Texture (Optional)",
|
"dialog.skin.texture": "Texture (Optional)",
|
||||||
"dialog.skin.pose": "Pose",
|
"dialog.skin.pose": "Pose",
|
||||||
"dialog.skin.layer_template": "Layer Texture",
|
"dialog.skin.layer_template": "Layer Texture",
|
||||||
|
|
||||||
|
"dialog.export_private_settings.title": "Private Settings",
|
||||||
|
"dialog.export_private_settings.message": "Your file contains the following private informations: **%0**. Remove these values if you plan to share the file with someone else.",
|
||||||
|
"dialog.export_private_settings.keep": "Keep",
|
||||||
|
"dialog.export_private_settings.remove": "Remove",
|
||||||
|
|
||||||
"dialog.settings.settings": "Settings",
|
"dialog.settings.settings": "Settings",
|
||||||
"dialog.settings.keybinds": "Keybindings",
|
"dialog.settings.keybinds": "Keybindings",
|
||||||
@ -793,6 +798,10 @@
|
|||||||
"action.export_theme.desc": "Create a theme file based on the current settings",
|
"action.export_theme.desc": "Create a theme file based on the current settings",
|
||||||
"action.reset_theme": "Reset Theme",
|
"action.reset_theme": "Reset Theme",
|
||||||
"action.reset_theme.desc": "Reset to the default Blockbench 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": "UV Window",
|
||||||
"action.uv_dialog.desc": "Open the UV dialog to see all faces next to each other",
|
"action.uv_dialog.desc": "Open the UV dialog to see all faces next to each other",
|
||||||
|
Loading…
Reference in New Issue
Block a user