diff --git a/plugins/outliner_group_exporter/LICENSE.MD b/plugins/outliner_group_exporter/LICENSE.MD new file mode 100644 index 00000000..931cb081 --- /dev/null +++ b/plugins/outliner_group_exporter/LICENSE.MD @@ -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. diff --git a/plugins/outliner_group_exporter/about.md b/plugins/outliner_group_exporter/about.md new file mode 100644 index 00000000..01ff1a1f --- /dev/null +++ b/plugins/outliner_group_exporter/about.md @@ -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 \ No newline at end of file diff --git a/plugins/outliner_group_exporter/icon.png b/plugins/outliner_group_exporter/icon.png new file mode 100644 index 00000000..ed63c59a Binary files /dev/null and b/plugins/outliner_group_exporter/icon.png differ diff --git a/plugins/outliner_group_exporter/members.yml b/plugins/outliner_group_exporter/members.yml new file mode 100644 index 00000000..c3f4b246 --- /dev/null +++ b/plugins/outliner_group_exporter/members.yml @@ -0,0 +1,2 @@ +maintainers: + - MrCrayfish \ No newline at end of file diff --git a/plugins/outliner_group_exporter/outliner_group_exporter.js b/plugins/outliner_group_exporter/outliner_group_exporter.js new file mode 100644 index 00000000..d995dd1e --- /dev/null +++ b/plugins/outliner_group_exporter/outliner_group_exporter.js @@ -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'); + } + }); +})() \ No newline at end of file