From f968331a5f656735ae71b52f8280aeeb88747327 Mon Sep 17 00:00:00 2001 From: MrCrayfish <4958241+MrCrayfish@users.noreply.github.com> Date: Thu, 23 May 2024 02:17:27 +0930 Subject: [PATCH 1/6] Create group exporter plugin --- plugins/group_exporter/LICENSE.MD | 21 ++++ plugins/group_exporter/about.md | 14 +++ plugins/group_exporter/icon.png | Bin 0 -> 421 bytes plugins/group_exporter/members.yml | 2 + .../group_exporter/outliner_group_exporter.js | 101 ++++++++++++++++++ 5 files changed, 138 insertions(+) create mode 100644 plugins/group_exporter/LICENSE.MD create mode 100644 plugins/group_exporter/about.md create mode 100644 plugins/group_exporter/icon.png create mode 100644 plugins/group_exporter/members.yml create mode 100644 plugins/group_exporter/outliner_group_exporter.js diff --git a/plugins/group_exporter/LICENSE.MD b/plugins/group_exporter/LICENSE.MD new file mode 100644 index 00000000..931cb081 --- /dev/null +++ b/plugins/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/group_exporter/about.md b/plugins/group_exporter/about.md new file mode 100644 index 00000000..f264b713 --- /dev/null +++ b/plugins/group_exporter/about.md @@ -0,0 +1,14 @@ +# Group Exporter + +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/group_exporter/icon.png b/plugins/group_exporter/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ed63c59a1d5963ebeab24d362958d10de8735b32 GIT binary patch literal 421 zcmeAS@N?(olHy`uVBq!ia0vp^1|ZDA1|-9oezpTC#^NA%Cx&(BWL^R}Ea{HEjtmSN z`?>!lvI6;>1s;*b3=DjSL74G){)!Z!pk#?_L`iUdT1k0gQ7S`0VrE{6US4X6f{C7i zo{>SDdL%Q@R8dbC$B+!?w>S549(Leqdl+pPDpoYLFlhM+naG3AF#@v zHT&)KUhmrV;*a*b?N1jl&AIq9Jfy+aY8p@=hLOWm=#?z*y4tp9;SIL0t}4HXScJxw zX9`f(?O0YW`71+Iq3d3%)&c#Ov24s4jcu-r``x~T1v92CNbbCs^@;t0JeTREApKd- z7naZDGH7~M`66~1Q_q4*xvJ?08KM>>wunu*Xt!wlEUtpIE&VUnE@PS_`Bu4VwI$1m xWlVpfS$~-Sd2IyrOVd%G4Kp~!KEHU&UEnc2X~Bk9z#wH{@O1TaS?83{1OQ(Wr*8lN literal 0 HcmV?d00001 diff --git a/plugins/group_exporter/members.yml b/plugins/group_exporter/members.yml new file mode 100644 index 00000000..c3f4b246 --- /dev/null +++ b/plugins/group_exporter/members.yml @@ -0,0 +1,2 @@ +maintainers: + - MrCrayfish \ No newline at end of file diff --git a/plugins/group_exporter/outliner_group_exporter.js b/plugins/group_exporter/outliner_group_exporter.js new file mode 100644 index 00000000..f6b6c787 --- /dev/null +++ b/plugins/group_exporter/outliner_group_exporter.js @@ -0,0 +1,101 @@ +(function() { + var separator; + var actionExportGroup; + var originalExportFunction; + var originalGroupOpenContext; + 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() { + // Add translations + window.Language.addTranslations('en', { + 'action.export_outliner_group': "Export..." + }); + + // Setup action and separator + separator = new MenuSeparator('export'); + actionExportGroup = new Action('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 + }); + + // 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 = actionExportGroup.menu_node.classList.contains("opened"); + restrictCubes(restrict); + originalExportFunction.call(this); + resetCubes(restrict); + }; + + // Patch the context menu to include export options. Have to do this lazily + let patchedMenu = false; + originalGroupOpenContext = Group.prototype.showContextMenu; + Group.prototype.showContextMenu = function(event) { + if(!patchedMenu) { + MenuBar.menus.file.structure.forEach(menu => { + if(menu.id === 'export') { + actionExportGroup.children = menu.children.slice(0); + } + }); + patchedMenu = true; + } + originalGroupOpenContext.call(this, event); + } + }, + onunload() { + // Clean up + Codec.prototype.export = originalExportFunction; + Group.prototype.showContextMenu = originalGroupOpenContext; + Group.prototype.menu.removeAction(separator); + Group.prototype.menu.removeAction(actionExportGroup); + actionExportGroup.delete(); + } + }); +})() \ No newline at end of file From ea852550f3c8e906520326b5165d1d5bb1080071 Mon Sep 17 00:00:00 2001 From: MrCrayfish <4958241+MrCrayfish@users.noreply.github.com> Date: Wed, 29 May 2024 11:45:52 +0930 Subject: [PATCH 2/6] Fix inconsistency with plugin id and directory --- .../LICENSE.MD | 0 .../about.md | 0 .../icon.png | Bin .../members.yml | 0 .../outliner_group_exporter.js | 0 5 files changed, 0 insertions(+), 0 deletions(-) rename plugins/{group_exporter => outliner_group_exporter}/LICENSE.MD (100%) rename plugins/{group_exporter => outliner_group_exporter}/about.md (100%) rename plugins/{group_exporter => outliner_group_exporter}/icon.png (100%) rename plugins/{group_exporter => outliner_group_exporter}/members.yml (100%) rename plugins/{group_exporter => outliner_group_exporter}/outliner_group_exporter.js (100%) diff --git a/plugins/group_exporter/LICENSE.MD b/plugins/outliner_group_exporter/LICENSE.MD similarity index 100% rename from plugins/group_exporter/LICENSE.MD rename to plugins/outliner_group_exporter/LICENSE.MD diff --git a/plugins/group_exporter/about.md b/plugins/outliner_group_exporter/about.md similarity index 100% rename from plugins/group_exporter/about.md rename to plugins/outliner_group_exporter/about.md diff --git a/plugins/group_exporter/icon.png b/plugins/outliner_group_exporter/icon.png similarity index 100% rename from plugins/group_exporter/icon.png rename to plugins/outliner_group_exporter/icon.png diff --git a/plugins/group_exporter/members.yml b/plugins/outliner_group_exporter/members.yml similarity index 100% rename from plugins/group_exporter/members.yml rename to plugins/outliner_group_exporter/members.yml diff --git a/plugins/group_exporter/outliner_group_exporter.js b/plugins/outliner_group_exporter/outliner_group_exporter.js similarity index 100% rename from plugins/group_exporter/outliner_group_exporter.js rename to plugins/outliner_group_exporter/outliner_group_exporter.js From 7cf4e72928e11f9e00e69841d07c31a2dcf54550 Mon Sep 17 00:00:00 2001 From: MrCrayfish <4958241+MrCrayfish@users.noreply.github.com> Date: Wed, 29 May 2024 11:46:27 +0930 Subject: [PATCH 3/6] Remove plugin name from about.md --- plugins/outliner_group_exporter/about.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/plugins/outliner_group_exporter/about.md b/plugins/outliner_group_exporter/about.md index f264b713..01ff1a1f 100644 --- a/plugins/outliner_group_exporter/about.md +++ b/plugins/outliner_group_exporter/about.md @@ -1,5 +1,3 @@ -# Group Exporter - 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 From 514ec999a59de629306fd1f81e61005894ac5160 Mon Sep 17 00:00:00 2001 From: MrCrayfish <4958241+MrCrayfish@users.noreply.github.com> Date: Wed, 29 May 2024 11:57:44 +0930 Subject: [PATCH 4/6] Remove unnecessary patch to context menu --- .../outliner_group_exporter.js | 22 ++++--------------- 1 file changed, 4 insertions(+), 18 deletions(-) diff --git a/plugins/outliner_group_exporter/outliner_group_exporter.js b/plugins/outliner_group_exporter/outliner_group_exporter.js index f6b6c787..2f1e37bd 100644 --- a/plugins/outliner_group_exporter/outliner_group_exporter.js +++ b/plugins/outliner_group_exporter/outliner_group_exporter.js @@ -2,7 +2,6 @@ var separator; var actionExportGroup; var originalExportFunction; - var originalGroupOpenContext; BBPlugin.register('outliner_group_exporter', { title: 'Group Exporter', author: 'MrCrayfish', @@ -24,7 +23,10 @@ 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 + 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 @@ -73,26 +75,10 @@ originalExportFunction.call(this); resetCubes(restrict); }; - - // Patch the context menu to include export options. Have to do this lazily - let patchedMenu = false; - originalGroupOpenContext = Group.prototype.showContextMenu; - Group.prototype.showContextMenu = function(event) { - if(!patchedMenu) { - MenuBar.menus.file.structure.forEach(menu => { - if(menu.id === 'export') { - actionExportGroup.children = menu.children.slice(0); - } - }); - patchedMenu = true; - } - originalGroupOpenContext.call(this, event); - } }, onunload() { // Clean up Codec.prototype.export = originalExportFunction; - Group.prototype.showContextMenu = originalGroupOpenContext; Group.prototype.menu.removeAction(separator); Group.prototype.menu.removeAction(actionExportGroup); actionExportGroup.delete(); From fa5752527e41fecfec4552c6e45e3bcce8510cd0 Mon Sep 17 00:00:00 2001 From: MrCrayfish <4958241+MrCrayfish@users.noreply.github.com> Date: Wed, 29 May 2024 17:12:01 +0930 Subject: [PATCH 5/6] Remove ellipsis from translation --- plugins/outliner_group_exporter/outliner_group_exporter.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/outliner_group_exporter/outliner_group_exporter.js b/plugins/outliner_group_exporter/outliner_group_exporter.js index 2f1e37bd..1ec03018 100644 --- a/plugins/outliner_group_exporter/outliner_group_exporter.js +++ b/plugins/outliner_group_exporter/outliner_group_exporter.js @@ -14,7 +14,7 @@ onload() { // Add translations window.Language.addTranslations('en', { - 'action.export_outliner_group': "Export..." + 'action.export_outliner_group': "Export" }); // Setup action and separator From 5ee235557c61c40e78da75b2d6552100b607916b Mon Sep 17 00:00:00 2001 From: JannisX11 Date: Thu, 30 May 2024 22:33:14 +0200 Subject: [PATCH 6/6] Outliner Group Exporter: Make export action not global --- .../outliner_group_exporter.js | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/plugins/outliner_group_exporter/outliner_group_exporter.js b/plugins/outliner_group_exporter/outliner_group_exporter.js index 1ec03018..d995dd1e 100644 --- a/plugins/outliner_group_exporter/outliner_group_exporter.js +++ b/plugins/outliner_group_exporter/outliner_group_exporter.js @@ -12,14 +12,11 @@ min_version: '4.10.1', variant: 'both', onload() { - // Add translations - window.Language.addTranslations('en', { - 'action.export_outliner_group': "Export" - }); - // Setup action and separator separator = new MenuSeparator('export'); - actionExportGroup = new Action('export_outliner_group', { + 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) @@ -27,7 +24,7 @@ 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); @@ -70,7 +67,7 @@ originalExportFunction = Codec.prototype.export; Codec.prototype.export = async function () { // Check if the menu is open. Is this okay for web/mobile app? - let restrict = actionExportGroup.menu_node.classList.contains("opened"); + let restrict = Group.prototype.menu == Menu.open; restrictCubes(restrict); originalExportFunction.call(this); resetCubes(restrict); @@ -80,8 +77,7 @@ // Clean up Codec.prototype.export = originalExportFunction; Group.prototype.menu.removeAction(separator); - Group.prototype.menu.removeAction(actionExportGroup); - actionExportGroup.delete(); + Group.prototype.menu.removeAction('export_outliner_group'); } }); })() \ No newline at end of file