mumuki-gobstones-blockly 0.36.0 → 0.37.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2c4fe28a4dc5acc14accd6bd628d2815cd4fca7616c08c3fa38ceb2563d20bbf
4
- data.tar.gz: aab4223fc681de33312f26af435249098a86669de164c855d673ca767efae47e
3
+ metadata.gz: 88547c393fcedd81919aec55517f88961c02ba806ba3ba4fb5aec363e4ebdc99
4
+ data.tar.gz: 725ad912f884ea0b4108118dbc8c32ddf4ec498f29cdad27f8d3e8ead22d3942
5
5
  SHA512:
6
- metadata.gz: 18e5903a764239637a66a2d87d44f2d855491048b0851a01417822d4f028487efdd3af6e8d6db37bc54c367d0111b4b282094eaa3df8b7804306c569f3d59aef
7
- data.tar.gz: c8df246a95f84a23ccbe4b54183f31a1c9bd7cafd573ff2d91e8b34eb105d00180e82aa839679befa36c4260179d82330cf0a496c329df25b1188cc2560babd1
6
+ metadata.gz: a2f7af4813edc25b9af1ad6f95ec9f2b2456004034d94b0ac69b61fc3ff3ab5232e2ba84c7e1e67af97c65fd08695ed6e3da88c7c0ec4e78d723e5676be8fda4
7
+ data.tar.gz: 01b7593d0cb27480b2af418ea7b11ddaa27e333eb8404655693ba7799dc3771efaf120973c920a59f66821f726af8b57b20f03b290188789abc02626d9f31c3d
@@ -4085,6 +4085,21 @@ window.initProcedsBlockly = function(customStatementType, initialize = () => {})
4085
4085
  </script>
4086
4086
  <script>/* global initProcedsBlockly */
4087
4087
 
4088
+ Blockly.displayMode = 'text';
4089
+
4090
+ Blockly.displayModes = {
4091
+ text: {
4092
+ iconSize: 16,
4093
+ showText: true
4094
+ },
4095
+ iconic: {
4096
+ iconSize: 32,
4097
+ showText: false
4098
+ },
4099
+ };
4100
+
4101
+ Blockly.currentDisplayMode = () => Blockly.displayModes[Blockly.displayMode];
4102
+
4088
4103
  // Initialize proceds-blockly creating new custom functions
4089
4104
  initProcedsBlockly("Statement", (makeProcedureInit, makeUpdateParams, makeProcedureDomToMutation, makeProcedureCustomMenu) => {
4090
4105
  Blockly.Blocks['DefinicionDeFuncionDeclarativa'] = {
@@ -4200,7 +4215,7 @@ initProcedsBlockly("Statement", (makeProcedureInit, makeUpdateParams, makeProced
4200
4215
  });
4201
4216
 
4202
4217
  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}};
4203
- 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"];
4218
+ 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", "repeticion-simple.png", "program.png"];
4204
4219
  const EMPTY_GIF = "data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==";
4205
4220
 
4206
4221
  const ATOMICALLY = (action) => {
@@ -4221,7 +4236,8 @@ const getLocalMediaUrl = (block, name) =>
4221
4236
  hasLocalMedia(name)
4222
4237
  ? getOptions(block).localMedia + name + (getOptions(block).localMediaSuffix || "")
4223
4238
  : EMPTY_GIF;
4224
- const getLocalMediaSize = (name) => hasLocalMedia(name) ? 16 : 0;
4239
+ const getLocalMediaSize = (name) =>
4240
+ hasLocalMedia(name) ? Blockly.currentDisplayMode().iconSize : 0;
4225
4241
 
4226
4242
  /**
4227
4243
  * Create the svg representation of a block and render
@@ -4260,24 +4276,32 @@ const triggerRefresh = (block) => {
4260
4276
 
4261
4277
  Blockly.Blocks.Program = {
4262
4278
  init: function () {
4279
+ const icon = 'program.png';
4263
4280
  this.jsonInit({
4264
- "type": "Program",
4265
- "message0": "%1 %2 %3",
4266
- "args0": [
4281
+ type: "Program",
4282
+ message0: "%1 %2 %3",
4283
+ args0: [
4284
+ Blockly.currentDisplayMode().showText
4285
+ ? {
4286
+ type: "field_label",
4287
+ text: "programa",
4288
+ }
4289
+ : {
4290
+ type: "field_image",
4291
+ src: getLocalMediaUrl(this, icon),
4292
+ width: getLocalMediaSize(icon),
4293
+ height: getLocalMediaSize(icon),
4294
+ },
4267
4295
  {
4268
- "type": "field_label",
4269
- "text": "programa"
4296
+ type: "input_dummy",
4270
4297
  },
4271
4298
  {
4272
- "type": "input_dummy"
4299
+ type: "input_statement",
4300
+ name: "program",
4301
+ check: ["Statement"],
4273
4302
  },
4274
- {
4275
- "type": "input_statement",
4276
- "name": "program",
4277
- "check": ["Statement"]
4278
- }
4279
- ]
4280
- })
4303
+ ],
4304
+ });
4281
4305
  this.setColour(Blockly.CUSTOM_COLORS.Program || Blockly.CUSTOM_COLORS.program);
4282
4306
  this.setDeletable(true);
4283
4307
  this.setEditable(true);
@@ -4623,10 +4647,24 @@ Blockly.Blocks.RepeticionSimple = {
4623
4647
  });
4624
4648
 
4625
4649
  this.setColour(Blockly.CUSTOM_COLORS.RepeticionSimple || Blockly.CUSTOM_COLORS.controlStructure);
4626
- this.appendValueInput('count')
4627
- .appendField('repetir');
4628
- this.appendDummyInput()
4629
- .appendField('veces');
4650
+
4651
+ if (Blockly.currentDisplayMode().showText) {
4652
+ this.appendValueInput("count").appendField("repetir");
4653
+ this.appendDummyInput().appendField("veces");
4654
+ } else {
4655
+ const icon = "repeticion-simple.png";
4656
+ const imageField = this.appendDummyInput().appendField(new Blockly.FieldImage(
4657
+ '',
4658
+ getLocalMediaSize(icon),
4659
+ getLocalMediaSize(icon)
4660
+ ));
4661
+ this.appendValueInput("count");
4662
+
4663
+ // El atributo localMedia recién va a estar disponible cuando termine de cargar el toolbox,
4664
+ // por eso la imagen se carga en el evento y no directamente más arriba.
4665
+ this.onchange = () => imageField.fieldRow[0].setValue(getLocalMediaUrl(this, icon));
4666
+ }
4667
+
4630
4668
  this.appendStatementInput('block').setCheck(["Statement"]);
4631
4669
  this.setInputsInline(true);
4632
4670
  }
@@ -5665,6 +5703,45 @@ Blockly.Blocks.procedures_defnoreturn.customContextMenu = function(options) {
5665
5703
  }
5666
5704
  })
5667
5705
  }
5706
+
5707
+ const includeIconMutationMixin = (block) => {
5708
+ const originalMutationToDom = block.mutationToDom;
5709
+ block.mutationToDom = function() {
5710
+ const container = originalMutationToDom.call(this);
5711
+ if (this.$icon) {
5712
+ container.setAttribute("icon", this.$icon);
5713
+ }
5714
+ return container;
5715
+ }
5716
+
5717
+ const originalDomToMutation = block.domToMutation;
5718
+ block.domToMutation = function(xmlElement) {
5719
+ const icon = xmlElement.getAttribute("icon");
5720
+ if (icon) {
5721
+ this.$icon = icon;
5722
+ }
5723
+
5724
+ return originalDomToMutation.call(this, xmlElement);
5725
+ }
5726
+ }
5727
+
5728
+ // Por retrocompatibilidad, agregamos el mixin que parsea el ícono a todas las formas posibles
5729
+ // de definir procedimientos y funciones.
5730
+ const allProceduresAndFunctionsTypes = [
5731
+ "procedures_defnoreturn",
5732
+ "procedures_defnoreturnnoparams",
5733
+ "procedures_defreturn",
5734
+ "procedures_defreturnsimple",
5735
+ "procedures_defreturnsimplewithparams",
5736
+ "DefinicionDeFuncionDeclarativa",
5737
+ "DefinicionDeFuncionSimpleConParametrosDeclarativa",
5738
+ "DefinicionDeFuncionSimpleDeclarativa",
5739
+ ];
5740
+
5741
+ allProceduresAndFunctionsTypes.forEach((blockName) =>
5742
+ includeIconMutationMixin(Blockly.Blocks[blockName])
5743
+ );
5744
+
5668
5745
  const oldProceduresMutationToDom = Blockly.Blocks['procedures_defnoreturn'].mutationToDom;
5669
5746
  Blockly.Blocks.procedures_defnoreturn.mutationToDom = function() {
5670
5747
  const container = oldProceduresMutationToDom.call(this);
@@ -5673,9 +5750,7 @@ Blockly.Blocks.procedures_defnoreturn.mutationToDom = function() {
5673
5750
  }
5674
5751
  const oldProceduresDomToMutation = Blockly.Blocks['procedures_defnoreturn'].domToMutation;
5675
5752
  Blockly.Blocks.procedures_defnoreturn.domToMutation = function(xmlElement) {
5676
- const isAtomic = xmlElement.getAttribute("isatomic");
5677
- this.$isAtomic = isAtomic === "true";
5678
-
5753
+ this.$isAtomic = xmlElement.getAttribute("isatomic") === "true";
5679
5754
  return oldProceduresDomToMutation.call(this, xmlElement);
5680
5755
  }
5681
5756
  </script>
@@ -6250,12 +6325,21 @@ var makeParameterList = function (block) {
6250
6325
  .join(', ');
6251
6326
  };
6252
6327
 
6328
+ const addIconAttributeIfPresent = (block, code) =>
6329
+ block.$icon ? `/*@ATTRIBUTE@block_icon@${block.$icon}@*/\n${code}` : code;
6330
+
6253
6331
  Blockly.GobstonesLanguage.procedures_defnoreturn = function (block) {
6254
6332
  var name = formatCallName(block.getFieldValue('NAME'),true);
6255
6333
  var body = Blockly.GobstonesLanguage.statementToCode(block, 'STACK');
6256
6334
 
6257
- var code = 'procedure ' + name + '(' + makeParameterList(block) + ') {\n' + body + '}\n';
6258
- if (block.$isAtomic) code = "/*@ATTRIBUTE@atomic@*/" + "\n" + code;
6335
+ const baseCode =
6336
+ `procedure ${name}(${makeParameterList(block)}) {
6337
+ ${body}}\n`
6338
+
6339
+ var code = addIconAttributeIfPresent(block, baseCode);
6340
+ if (block.$isAtomic) {
6341
+ code = "/*@ATTRIBUTE@atomic@*/" + "\n" + code;
6342
+ }
6259
6343
 
6260
6344
  code = Blockly.GobstonesLanguage.scrub_(block, code);
6261
6345
  Blockly.GobstonesLanguage.definitions_[name] = code;
@@ -6268,8 +6352,12 @@ Blockly.GobstonesLanguage.procedures_defreturn = function (block) {
6268
6352
  var body = Blockly.GobstonesLanguage.statementToCode(block, 'STACK');
6269
6353
  var returnValue = Blockly.GobstonesLanguage.valueToCode(block, 'RETURN');
6270
6354
 
6271
- var code = 'function ' + name + '(' + makeParameterList(block) + ') {\n' +
6272
- body + ' return (' + returnValue + ')\n}\n';
6355
+ const baseCode =
6356
+ `function ${name}(${makeParameterList(block)}) {
6357
+ ${body} return (${returnValue})
6358
+ }\n`;
6359
+
6360
+ var code = addIconAttributeIfPresent(block, baseCode);
6273
6361
 
6274
6362
  code = Blockly.GobstonesLanguage.scrub_(block, code);
6275
6363
  Blockly.GobstonesLanguage.definitions_[name] = code;
@@ -6970,13 +7058,15 @@ Blockly.ErrorInforming.CssContent = [
6970
7058
  if (icon) {
6971
7059
  this.appendDummyInput().appendField(new Blockly.FieldImage(
6972
7060
  icon,
6973
- 16,
6974
- 16,
7061
+ Blockly.currentDisplayMode().iconSize,
7062
+ Blockly.currentDisplayMode().iconSize,
6975
7063
  finalName
6976
7064
  ));
6977
7065
  }
6978
7066
 
6979
- self._definePrimitiveHolesOrDropdown(this, parts, dropdownOptions);
7067
+ if (Blockly.currentDisplayMode().showText) {
7068
+ self._definePrimitiveHolesOrDropdown(this, parts, dropdownOptions);
7069
+ }
6980
7070
 
6981
7071
  this.setInputsInline(true);
6982
7072
  this.setTooltip(definition.attributes && definition.attributes.tooltip || "");
@@ -7026,13 +7116,15 @@ Blockly.ErrorInforming.CssContent = [
7026
7116
  if (icon) {
7027
7117
  this.appendDummyInput().appendField(new Blockly.FieldImage(
7028
7118
  icon,
7029
- 16,
7030
- 16,
7119
+ Blockly.currentDisplayMode().iconSize,
7120
+ Blockly.currentDisplayMode().iconSize,
7031
7121
  finalName
7032
7122
  ));
7033
7123
  }
7034
7124
 
7035
- self._definePrimitiveHolesOrDropdown(this, parts, dropdownOptions);
7125
+ if (Blockly.currentDisplayMode().showText) {
7126
+ self._definePrimitiveHolesOrDropdown(this, parts, dropdownOptions);
7127
+ }
7036
7128
 
7037
7129
  this.setPreviousStatement(false);
7038
7130
  this.setNextStatement(false);
@@ -7321,6 +7413,12 @@ Blockly.ErrorInforming.CssContent = [
7321
7413
  },
7322
7414
 
7323
7415
  _processCustomCategoryStyles(xml) {
7416
+ // TODO: el querySelector no funciona si no hay categorías, y además este método no tiene sentido en ese contexto.
7417
+ // Habría que revisarlo si más adelante se quieren soportar los separadores en ese contexto.
7418
+ if (!this.showCategories) {
7419
+ return;
7420
+ }
7421
+
7324
7422
  const parsedXml = Blockly.Xml.textToDom(`<xml>${xml}</xml>`);
7325
7423
 
7326
7424
  const forEachNode = (node, action) => {
@@ -1,5 +1,5 @@
1
1
  module Gobstones
2
2
  module Blockly
3
- VERSION = "0.36.0"
3
+ VERSION = "0.37.1"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mumuki-gobstones-blockly
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.36.0
4
+ version: 0.37.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rodrigo Alfonso
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2020-08-12 00:00:00.000000000 Z
12
+ date: 2020-08-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -88,7 +88,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
88
88
  - !ruby/object:Gem::Version
89
89
  version: '0'
90
90
  requirements: []
91
- rubygems_version: 3.0.1
91
+ rubygems_version: 3.0.8
92
92
  signing_key:
93
93
  specification_version: 4
94
94
  summary: Gobstones Blockly