Skip to content

Commit

Permalink
Added option to set/remove a comment on blocks
Browse files Browse the repository at this point in the history
Added option to show inputs either horizontally or vertically on blocks
Added option to expand/collapse a block
  • Loading branch information
LennardF1989 committed Nov 14, 2021
1 parent 14fb84d commit 7f332d7
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 5 deletions.
16 changes: 12 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@
This extension adds additional functionality to the BF2042 Portal Rules Editor.

Functionality available:
- Open documentation
- Copy to clipboard
- Paste from clipboard
- Open Documentation
- Copy to Clipboard
- Paste from Clipboard
- Add/Remove Comment
- Show Inputs Vertically/Horizontally
- Expand/Collapse Block

## Usage
The extension is currently being submitted to the Chrome Web Store! In the mean time, you can download and load the extension yourself into Chrome*:
Expand All @@ -15,4 +18,9 @@ The extension is currently being submitted to the Chrome Web Store! In the mean

Done! The extension is now active, simply refresh the BF2042 Portal to see the effects in the Rules Editor.

* Edge should also work, as well as Mozilla.
* Edge should also work, as well as Mozilla.

## Donations
If you appreciate what I'm doing, consider buying me a cup of coffee!

https://paypal.me/lennardf1989
80 changes: 79 additions & 1 deletion src/extensions.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const BF1942PortalExtensions = (function () {
const BF2042PortalExtensions = (function () {
const mouseCoords = {
x: 0,
y: 0
Expand Down Expand Up @@ -78,6 +78,81 @@ const BF1942PortalExtensions = (function () {
};
})();

const toggleComments = (function () {
function displayText(scope) {
return scope.block.getCommentIcon()
? "Remove Comment"
: "Add Comment";
}

function precondition() {
return "enabled";
}

async function callback(scope) {
scope.block.getCommentIcon() ? scope.block.setCommentText(null) : scope.block.setCommentText("");
}

return {
id: "toggleComments",
displayText: displayText,
scopeType: _Blockly.ContextMenuRegistry.ScopeType.BLOCK,
weight: 100,
preconditionFn: precondition,
callback: callback
};
})();

const toggleInputs = (function () {
function displayText(scope) {
return scope.block.getInputsInline()
? "Show Inputs Vertically"
: "Show Inputs Horizontally";
}

function precondition() {
return "enabled";
}

async function callback(scope) {
scope.block.setInputsInline(!scope.block.getInputsInline());
}

return {
id: "toggleInputs",
displayText: displayText,
scopeType: _Blockly.ContextMenuRegistry.ScopeType.BLOCK,
weight: 100,
preconditionFn: precondition,
callback: callback
};
})();

const toggleCollapse = (function () {
function displayText(scope) {
return scope.block.isCollapsed()
? "Expand Block"
: "Collapse Block";
}

function precondition() {
return "enabled";
}

async function callback(scope) {
scope.block.setCollapsed(!scope.block.isCollapsed());
}

return {
id: "toggleCollapse",
displayText: displayText,
scopeType: _Blockly.ContextMenuRegistry.ScopeType.BLOCK,
weight: 100,
preconditionFn: precondition,
callback: callback
};
})();

const openDocumentation = (function () {
const documentationUrl = "https://bf2042.lennardf1989.com";

Expand Down Expand Up @@ -134,6 +209,9 @@ const BF1942PortalExtensions = (function () {
}

function init() {
_Blockly.ContextMenuRegistry.registry.register(toggleComments);
_Blockly.ContextMenuRegistry.registry.register(toggleInputs);
_Blockly.ContextMenuRegistry.registry.register(toggleCollapse);
_Blockly.ContextMenuRegistry.registry.register(copyToClipboard);
_Blockly.ContextMenuRegistry.registry.register(openDocumentation);
_Blockly.ContextMenuRegistry.registry.register(pasteFromClipboard);
Expand Down

0 comments on commit 7f332d7

Please sign in to comment.