Merge pull request #2386 from Azagwen/save_and_increment

This commit is contained in:
JannisX11 2024-08-29 23:34:49 +02:00 committed by GitHub
commit 22082baad9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 32 additions and 0 deletions

View File

@ -140,6 +140,7 @@ const MenuBar = {
new MenuSeparator('project'),
'save_project',
'save_project_as',
'save_project_incremental',
'convert_project',
'close_project',
new MenuSeparator('import_export'),

View File

@ -715,6 +715,34 @@ BARS.defineActions(function() {
}
})
new Action('save_project_incremental', {
icon: 'difference',
category: 'file',
keybind: new Keybind({key: 's', shift: true, alt: true}),
condition: isApp ? (() => Project && Project.save_path) : false,
click: function () {
saveTextures(true);
let projectTailRegex = /\.bbmodel$/;
let projectVerRegex = /([0-9]+)\.bbmodel$/;
let projectVerMatch = projectVerRegex.exec(Project.save_path);
let file_path;
if (projectVerMatch) {
let projectVer = parseInt(projectVerMatch[1]); // Parse & store project ver int (capturing group 1)
file_path = Project.save_path.replace(projectVerRegex, `${projectVer + 1}.bbmodel`);
} else {
file_path = Project.save_path.replace(projectTailRegex, "_1.bbmodel");
}
let original_file_path = file_path;
let i = 1;
while (fs.existsSync(file_path) && i < 100) {
file_path = original_file_path.replace(projectTailRegex, `_alt_${i == 1 ? '' : i}.bbmodel`);
i++;
}
codec.write(codec.compile(), file_path);
}
})
new Action('save_project_as', {
icon: 'save',
category: 'file',

View File

@ -551,6 +551,7 @@ ModelProject.prototype.menu = new Menu([
new MenuSeparator('save'),
'save_project',
'save_project_as',
'save_project_incremental',
'export_over',
'share_model',
new MenuSeparator('overview'),

View File

@ -1329,6 +1329,8 @@
"action.save_project.desc": "Saves the current model as a project file",
"action.save_project_as": "Save Project As",
"action.save_project_as.desc": "Saves the current model as a project file at a new location",
"action.save_project_incremental": "Save Project With Increment",
"action.save_project_incremental.desc": "Saves the current model as a project file with an increment (ex: project_2.bbmodel)",
"action.import_project": "Import Project",
"action.import_project.desc": "Import another project from a .bbmodel file into the current project",
"action.export_over": "Save Model",