Skip to content

Commit

Permalink
0.2.1: inprove block identify system
Browse files Browse the repository at this point in the history
  • Loading branch information
ColinTree committed Mar 24, 2018
1 parent e9b0ae3 commit d0fed74
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
27 changes: 15 additions & 12 deletions assets/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ var TEXT_DO = 'do';
var TEXT_CALL = 'call';
var TEXT_SET = 'set';

// will be increased automatically by getBlock(json)
var blockIndex = 0;
var blockId = 'block0';

require(['gitbook', 'jQuery'], function(gitbook, $) {

gitbook.events.bind("start", function(e, config) {
Expand All @@ -28,11 +32,10 @@ require(['gitbook', 'jQuery'], function(gitbook, $) {
var name = block['name'];
var arg = block['arg'] || [];
var output = block['output']===true;
var divId = 'method_'+name;

$(this).attr('id', divId).show();
$(this).attr('id', blockId).show();

Blockly.Blocks['dynamicCreated_'+divId] = {
Blockly.Blocks['dynamicCreated_'+blockId] = {
init: function() {
this.appendDummyInput().appendField(TEXT_CALL).appendField(new Blockly.FieldDropdown([[ComponentName, 'OPTIONNAME']]), 'COMPONENT_SELECTOR').appendField('.'+name);
for (var i=0; i<arg.length; i++) {
Expand All @@ -51,7 +54,7 @@ require(['gitbook', 'jQuery'], function(gitbook, $) {
}
};

newBlockAndWorkspace(divId).moveBy(output?8:0, 0);
newBlockAndWorkspace(blockId).moveBy(output?8:0, 0);
});

// EVENT
Expand All @@ -60,11 +63,10 @@ require(['gitbook', 'jQuery'], function(gitbook, $) {

var name = block['name'];
var arg = block['arg'] || [];
var divId = 'event_'+name;

$(this).attr('id', divId).show();
$(this).attr('id', blockId).show();

Blockly.Blocks['dynamicCreated_'+divId] = {
Blockly.Blocks['dynamicCreated_'+blockId] = {
init: function() {
this.appendDummyInput('').appendField(TEXT_WHEN).appendField(new Blockly.FieldDropdown([[ComponentName, 'OPTIONNAME']]), "COMPONENT_SELECTOR").appendField('.' + name);
if (arg.length > 0) {
Expand All @@ -83,7 +85,7 @@ require(['gitbook', 'jQuery'], function(gitbook, $) {
}
};

newBlockAndWorkspace(divId);
newBlockAndWorkspace(blockId);
});

// PROPERTY
Expand All @@ -95,11 +97,10 @@ require(['gitbook', 'jQuery'], function(gitbook, $) {
if (getter !== true && getter !== false) {
getter = true;
}
var divId = 'property_'+(getter?'getter':'setter')+'_'+name;

$(this).attr('id', divId).show();
$(this).attr('id', blockId).show();

Blockly.Blocks['dynamicCreated_'+divId] = {
Blockly.Blocks['dynamicCreated_'+blockId] = {
init: function() {
var input;
if (getter) {
Expand All @@ -119,7 +120,7 @@ require(['gitbook', 'jQuery'], function(gitbook, $) {
}
};

newBlockAndWorkspace(divId).moveBy((getter?8:0), 0);
newBlockAndWorkspace(blockId).moveBy((getter?8:0), 0);
});
});
});
Expand All @@ -130,6 +131,8 @@ require(['gitbook', 'jQuery'], function(gitbook, $) {
* @returns object or null
*/
function getBlock(json) {
blockIndex++;
blockId = 'block' + blockIndex;
var blockData = JSON.parse(json);
if (typeof(blockData) != "object") {
console.error("block info is not a json object");
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,5 @@
"type": "git",
"url": "git+https://github.com/ColinTree/gitbook-plugin-ai2-blocks.git"
},
"version": "0.1.1"
"version": "0.2.1"
}

0 comments on commit d0fed74

Please sign in to comment.