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

feat: add chameleon test block #2193

Merged
merged 1 commit into from
Feb 6, 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
61 changes: 61 additions & 0 deletions plugins/block-test/src/chameleon.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/**
* @license
* Copyright 2024 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
'use strict';

/**
* @fileoverview Blocks that have both a previous connection and an output
* connection while they are being dragged.
*/

import * as Blockly from 'blockly/core';

Blockly.Blocks['test_chameleon'] = {
hasOutput: true,
hasPrevious: true,

init: function () {
this.appendDummyInput().appendField('chameleon');
this.setColour(120);
this.updateShape();
},

onchange: function (e) {
if (e.type === Blockly.Events.BLOCK_DRAG) {
console.log('got drag event');
this.hasPrevious =
!this.outputConnection || !this.outputConnection.targetBlock();
this.hasOutput = !this.getPreviousBlock();
this.updateShape();
}
},

updateShape: function () {
this.setPreviousStatement(this.hasPrevious);
this.setOutput(this.hasOutput);
},
};

/**
* The Chameleon Category.
*/
export const category = {
kind: 'CATEGORY',
name: 'Chameleon',
contents: [
{
kind: 'BLOCK',
type: 'test_chameleon',
},
],
};

/**
* Initialize this toolbox category.
* @param {!Blockly.WorkspaceSvg} workspace The Blockly workspace.
*/
export function onInit(workspace) {
// NOP
}
6 changes: 6 additions & 0 deletions plugins/block-test/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ import * as Blockly from 'blockly/core';

import {category as alignCategory, onInit as initAlign} from './align';
import {category as basicCategory, onInit as initBasic} from './basic';
import {
category as chameleonCategory,
onInit as initChameleon,
} from './chameleon';
import {
category as connectionsCategory,
onInit as initConnections,
Expand All @@ -34,6 +38,7 @@ export const toolboxTestBlocks = {
contents: [
alignCategory,
basicCategory,
chameleonCategory,
connectionsCategory,
dragCategory,
fieldsCategory,
Expand All @@ -50,6 +55,7 @@ export const toolboxTestBlocks = {
export function toolboxTestBlocksInit(workspace) {
initAlign(workspace);
initBasic(workspace);
initChameleon(workspace);
initConnections(workspace);
initDrag(workspace);
initFields(workspace);
Expand Down
Loading