Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Group Exporter #542

Merged
merged 6 commits into from
May 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions plugins/outliner_group_exporter/LICENSE.MD
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 MrCrayfish

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
12 changes: 12 additions & 0 deletions plugins/outliner_group_exporter/about.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Group Exporter is a simple plugin that allows you to export groups from the outliner as a model. Only the cubes that are contained within the group will be exported. This plugin is only for the Java Block/Item format, and supporting custom formats.

## How to use Group Exporter

- **Step 1:** Select a group in the outliner
- **Step 2:** Right click the group and hover the option "Export"
- **Step 3:** Click the format you want to export as
- **Step 4:** Follow the steps as you would normally when exporting

## License

Group Exporter is available under MIT
Binary file added plugins/outliner_group_exporter/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions plugins/outliner_group_exporter/members.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
maintainers:
- MrCrayfish
83 changes: 83 additions & 0 deletions plugins/outliner_group_exporter/outliner_group_exporter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
(function() {
var separator;
var actionExportGroup;
var originalExportFunction;
BBPlugin.register('outliner_group_exporter', {
title: 'Group Exporter',
author: 'MrCrayfish',
icon: 'icon.png',
description: 'A simple plugin to allow you to export a group from the outliner as a model. Only cubes inside the group will be exported.',
tags: ['Minecraft Java Edition'],
version: '0.0.1',
min_version: '4.10.1',
variant: 'both',
onload() {
// Setup action and separator
separator = new MenuSeparator('export');
actionExportGroup = {
name: "Export",
id: 'export_outliner_group',
icon: 'insert_drive_file',
category: 'export',
// Only allow on java_block format or custom formats that can support it (e.g. ones that use Cubes)
condition: () => Format.id === 'java_block' || Format.allowOutlinerGroupExporting,
children() {
return MenuBar.menus.file.structure.find(menu => menu.id === 'export')?.children;
}
};

// Append the separator and action to group menu
Group.prototype.menu.addAction(separator);
Group.prototype.menu.addAction(actionExportGroup);

let restrictCubes = (restrict) => {
if(!restrict)
return;

// Get the top parent group
let group = getCurrentGroup();

// If none selected, just return
if(!group) {
return;
}

// Find children cubes in the group
let selectedCubes = [];
group.forEachChild(cube => {
selectedCubes.push(cube);
}, Cube, false);

// Update export flag on all cubes
Cube.all.forEach(cube => {
cube.export = selectedCubes.includes(cube);
});
}

// Resets the export flag on all cubes
let resetCubes = (restrict) => {
if(!restrict)
return;
Cube.all.forEach(cube => {
cube.export = true;
});
}

// Override export function
originalExportFunction = Codec.prototype.export;
Codec.prototype.export = async function () {
// Check if the menu is open. Is this okay for web/mobile app?
let restrict = Group.prototype.menu == Menu.open;
restrictCubes(restrict);
originalExportFunction.call(this);
resetCubes(restrict);
};
},
onunload() {
// Clean up
Codec.prototype.export = originalExportFunction;
Group.prototype.menu.removeAction(separator);
Group.prototype.menu.removeAction('export_outliner_group');
}
});
})()
Loading