Skip to content

Commit

Permalink
Adding custom function blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
afska committed Feb 6, 2019
1 parent f859078 commit 0e042cd
Show file tree
Hide file tree
Showing 4 changed files with 121 additions and 2 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"dependencies": {
"polymer": "Polymer/polymer#^1.4.0",
"blockly-package": "0.0.15",
"proceds-blockly": "Program-AR/proceds-blockly#^0.1.13"
"proceds-blockly": "Program-AR/proceds-blockly#^0.2.0"
},
"devDependencies": {
"iron-component-page": "PolymerElements/iron-component-page#^1.0.0",
Expand Down
1 change: 0 additions & 1 deletion gs-element-blockly.html
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ <h2>Hello gs-element-blockly</h2>
<script src="../blockly-package/es.js"></script>
<script src="../proceds-blockly/proceds-blockly-original.js"></script>
<script src="../proceds-blockly/proceds-blockly.js"></script>
<script>initProcedsBlockly("Statement");</script>
<script src="js/gobstones-blocks.js"></script>
<script src="js/gobstones-language-generator.js"></script>
<script src="js/block-aliases.js"></script>
Expand Down
114 changes: 114 additions & 0 deletions js/gobstones-blocks.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,119 @@
/* global Blockly */

// Initialize proceds-blockly creating new custom functions
initProcedsBlockly("Statement", (makeProcedureInit, makeUpdateParams, makeProcedureDomToMutation, makeProcedureCustomMenu) => {
Blockly.Blocks['DefinicionDeFuncionDeclarativa'] = {
init: makeProcedureInit(
true, true, true,
"algo",
"Definir que",
Blockly.Msg.PROCEDURES_DEFRETURN_COMMENT,
Blockly.Msg.PROCEDURES_DEFRETURN_TOOLTIP,
Blockly.Msg.PROCEDURES_DEFRETURN_HELPURL,
"es igual a"
),
setStatements_: Blockly.Blocks['procedures_defreturn'].setStatements_,
updateParams_: makeUpdateParams(),
mutationToDom: Blockly.Blocks['procedures_defreturn'].mutationToDom,
domToMutation: makeProcedureDomToMutation(),
decompose: Blockly.Blocks['procedures_defreturn'].decompose,
compose: Blockly.Blocks['procedures_defreturn'].compose,
getProcedureDef: Blockly.Blocks['procedures_defreturn'].getProcedureDef,
getVars: Blockly.Blocks['procedures_defreturn'].getVars,
renameVar: Blockly.Blocks['procedures_defreturn'].renameVar,
customContextMenu: makeProcedureCustomMenu(true),
callType_: 'procedures_callreturndeclarative'
};

Blockly.Blocks['procedures_callreturndeclarative'] = {
init: Blockly.Blocks['procedures_callreturn'].init,
getProcedureCall: Blockly.Blocks['procedures_callreturn'].getProcedureCall,
renameProcedure: Blockly.Blocks['procedures_callreturn'].renameProcedure,
setProcedureParameters_: Blockly.Blocks['procedures_callreturn'].setProcedureParameters_,
updateShape_: Blockly.Blocks['procedures_callreturn'].updateShape_,
mutationToDom: Blockly.Blocks['procedures_callreturn'].mutationToDom,
domToMutation: Blockly.Blocks['procedures_callreturn'].domToMutation,
renameVar: Blockly.Blocks['procedures_callreturn'].renameVar,
onchange: Blockly.Blocks['procedures_callreturn'].onchange,
customContextMenu: Blockly.Blocks['procedures_callreturn'].customContextMenu,
defType_: 'DefinicionDeFuncionDeclarativa'
};

Blockly.Blocks['DefinicionDeFuncionSimpleConParametrosDeclarativa'] = {
init: makeProcedureInit(
true, false, true,
"algo",
"Definir que",
Blockly.Msg.PROCEDURES_DEFRETURN_COMMENT,
Blockly.Msg.PROCEDURES_DEFRETURN_TOOLTIP,
Blockly.Msg.PROCEDURES_DEFRETURN_HELPURL,
"es igual a"
),
setStatements_: Blockly.Blocks['procedures_defreturn'].setStatements_,
updateParams_: makeUpdateParams(),
mutationToDom: Blockly.Blocks['procedures_defreturn'].mutationToDom,
domToMutation: makeProcedureDomToMutation(),
decompose: Blockly.Blocks['procedures_defreturn'].decompose,
compose: Blockly.Blocks['procedures_defreturn'].compose,
getProcedureDef: Blockly.Blocks['procedures_defreturn'].getProcedureDef,
getVars: Blockly.Blocks['procedures_defreturn'].getVars,
renameVar: Blockly.Blocks['procedures_defreturn'].renameVar,
customContextMenu: makeProcedureCustomMenu(true),
callType_: 'procedures_callreturndeclarativesimplewithparams'
};

Blockly.Blocks['procedures_callreturndeclarativesimplewithparams'] = {
init: Blockly.Blocks['procedures_callreturn'].init,
getProcedureCall: Blockly.Blocks['procedures_callreturn'].getProcedureCall,
renameProcedure: Blockly.Blocks['procedures_callreturn'].renameProcedure,
setProcedureParameters_: Blockly.Blocks['procedures_callreturn'].setProcedureParameters_,
updateShape_: Blockly.Blocks['procedures_callreturn'].updateShape_,
mutationToDom: Blockly.Blocks['procedures_callreturn'].mutationToDom,
domToMutation: Blockly.Blocks['procedures_callreturn'].domToMutation,
renameVar: Blockly.Blocks['procedures_callreturn'].renameVar,
onchange: Blockly.Blocks['procedures_callreturn'].onchange,
customContextMenu: Blockly.Blocks['procedures_callreturn'].customContextMenu,
defType_: 'DefinicionDeFuncionSimpleConParametrosDeclarativa'
};

Blockly.Blocks['DefinicionDeFuncionSimpleDeclarativa'] = {
init: makeProcedureInit(
true, false, false,
"algo",
"Definir que",
Blockly.Msg.PROCEDURES_DEFRETURN_COMMENT,
Blockly.Msg.PROCEDURES_DEFRETURN_TOOLTIP,
Blockly.Msg.PROCEDURES_DEFRETURN_HELPURL,
"es igual a"
),
setStatements_: Blockly.Blocks['procedures_defreturn'].setStatements_,
updateParams_: makeUpdateParams(),
mutationToDom: Blockly.Blocks['procedures_defreturn'].mutationToDom,
domToMutation: makeProcedureDomToMutation(),
decompose: Blockly.Blocks['procedures_defreturn'].decompose,
compose: Blockly.Blocks['procedures_defreturn'].compose,
getProcedureDef: Blockly.Blocks['procedures_defreturn'].getProcedureDef,
getVars: Blockly.Blocks['procedures_defreturn'].getVars,
renameVar: Blockly.Blocks['procedures_defreturn'].renameVar,
customContextMenu: makeProcedureCustomMenu(false),
callType_: 'procedures_callreturndeclarativesimple'
};

Blockly.Blocks['procedures_callreturndeclarativesimple'] = {
init: Blockly.Blocks['procedures_callreturn'].init,
getProcedureCall: Blockly.Blocks['procedures_callreturn'].getProcedureCall,
renameProcedure: Blockly.Blocks['procedures_callreturn'].renameProcedure,
setProcedureParameters_: Blockly.Blocks['procedures_callreturn'].setProcedureParameters_,
updateShape_: Blockly.Blocks['procedures_callreturn'].updateShape_,
mutationToDom: Blockly.Blocks['procedures_callreturn'].mutationToDom,
domToMutation: Blockly.Blocks['procedures_callreturn'].domToMutation,
renameVar: Blockly.Blocks['procedures_callreturn'].renameVar,
onchange: Blockly.Blocks['procedures_callreturn'].onchange,
customContextMenu: Blockly.Blocks['procedures_callreturn'].customContextMenu,
defType_: 'DefinicionDeFuncionSimpleDeclarativa'
};
});

Blockly.CUSTOM_COLORS = {"globalHsvSaturation":0.45,"globalHsvValue":0.65,"primitiveCommand":"#1d3c99","assignation":"#051d66","controlStructure":"#0f2b80","literalExpression":"#1d992c","primitiveExpression":"#1d992c","operator":"#0f801c","program":"#8d1bb3","interactiveProgram":"#6e158c","interactiveBinding":"#a11fcc","procedure":"#935ba6","function":"#745380","primitiveProcedure":"#2e4fb3","primitiveFunction":"#2eb33e","procedure_call":"#355bcc","function_call":"#35cc47","variable":"#056610","parameter":"#056610","complete":"#ff0000","H":{"commands":225,"expressions":127,"definitions":285},"S":{"assignation":95,"variable":95,"parameter":95,"primitiveCommand":81,"literalExpression":81,"primitiveExpression":81,"controlStructure":88,"operator":88,"procedure_call":74,"function_call":74,"primitiveProcedure":74,"primitiveFunction":74,"program":85,"interactiveProgram":85,"interactiveBinding":85,"procedure":45,"function":35,"complete":99},"V":{"assignation":40,"variable":40,"parameter":40,"primitiveCommand":60,"literalExpression":60,"primitiveExpression":60,"controlStructure":50,"operator":50,"procedure_call":80,"function_call":80,"primitiveProcedure":70,"primitiveFunction":70,"program":70,"interactiveProgram":55,"interactiveBinding":80,"procedure":65,"function":50,"complete":99}};
Blockly.AVAILABLE_ICONS = ["bool-false.svg","bool-true.svg","clean.png","color-azul.svg","color-negro.svg","color-rojo.svg","color-verde.svg","direccion-este.svg","direccion-norte.svg","direccion-oeste.svg","direccion-sur.svg","hand.png","minus.png","plus.png"];
const EMPTY_GIF = "data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==";
Expand Down
6 changes: 6 additions & 0 deletions js/gobstones-language-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,9 @@ Blockly.GobstonesLanguage.procedures_defreturn = function (block) {
Blockly.GobstonesLanguage.procedures_defnoreturnnoparams = Blockly.GobstonesLanguage.procedures_defnoreturn;
Blockly.GobstonesLanguage.procedures_defreturnsimplewithparams = Blockly.GobstonesLanguage.procedures_defreturn;
Blockly.GobstonesLanguage.procedures_defreturnsimple = Blockly.GobstonesLanguage.procedures_defreturn;
Blockly.GobstonesLanguage.DefinicionDeFuncionDeclarativa = Blockly.GobstonesLanguage.procedures_defreturn;
Blockly.GobstonesLanguage.DefinicionDeFuncionSimpleConParametrosDeclarativa = Blockly.GobstonesLanguage.procedures_defreturn;
Blockly.GobstonesLanguage.DefinicionDeFuncionSimpleDeclarativa = Blockly.GobstonesLanguage.procedures_defreturn;

var procedureCall = function(block, capitalizeFirst, newLine) {
var procName = formatCallName(block.getFieldValue('NAME'),capitalizeFirst);
Expand All @@ -590,6 +593,9 @@ Blockly.GobstonesLanguage.procedures_callreturn = function (block) {
Blockly.GobstonesLanguage.procedures_callnoreturnnoparams = Blockly.GobstonesLanguage.procedures_callnoreturn;
Blockly.GobstonesLanguage.procedures_callreturnsimplewithparams = Blockly.GobstonesLanguage.procedures_callreturn;
Blockly.GobstonesLanguage.procedures_callreturnsimple = Blockly.GobstonesLanguage.procedures_callreturn;
Blockly.GobstonesLanguage.procedures_callreturndeclarative = Blockly.GobstonesLanguage.procedures_callreturn;
Blockly.GobstonesLanguage.procedures_callreturndeclarativesimplewithparams = Blockly.GobstonesLanguage.procedures_callreturn;
Blockly.GobstonesLanguage.procedures_callreturndeclarativesimple = Blockly.GobstonesLanguage.procedures_callreturn;

Blockly.GobstonesLanguage.variables_get = function (block) {
var code = formatCallName(block.getFieldValue('VAR'),false,Blockly.VARIABLE_CATEGORY_NAME);
Expand Down

0 comments on commit 0e042cd

Please sign in to comment.