gobstones-blockly 0.17.0 → 0.18.0

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: c2068974de8a97b4a7873a2e18fd99811d6e13e7f9a387739f02b44aba8468f2
4
- data.tar.gz: 4616a462fa78fdf3ec572a232007e438c4a749f7c5478382c4c773d7e2f31c0a
3
+ metadata.gz: feb2595a317dc38ed739f495938f3cc7fe2d635cec35dbcf81e2cebdd8def04d
4
+ data.tar.gz: 1ac9279dbfaeed5723d6d769b79c006078b9b676ed0a82aebd722ef2bc6fd614
5
5
  SHA512:
6
- metadata.gz: f6eaf3699011663c610228fb139e38032bd484b352c0a842a58651f8b1574f2d7bcf2f93650f5223ba4785bca01a139cc688fd5bbfded809ab7aa95552fd4707
7
- data.tar.gz: 15f33263b6be825c896b070f4748d5b88c3d3589e8a2d9ba247beb06169bfdefe3cfd0af61bf5f73e2a5256b1f2b00d47e2c98fac31cf43394e47d0a05b1a5ba
6
+ metadata.gz: 62da51f613fc533c1c968558099f7e987972ab9c98a5c1543b1b0a719a48c1be990d6b7303d1799565e164d098a4971531c77eb064f30d02c092957f07e2f8fd
7
+ data.tar.gz: 34dbc8bf8b7ab184170a2a3de93685d27fc49a3e2d42d01866999292e11f19b7bea009728af7a658210e89ae53e07cbe5fa902e5c3a1bf7486206b548111f823
@@ -5071,6 +5071,20 @@ Blockly.GobstonesLanguage.addPragma = function(block, str){
5071
5071
  // Gobstones pragma BEGIN_REGION should avoid char 'at' ( @ )
5072
5072
  Blockly.utils.genUid.soup_ = Blockly.utils.genUid.soup_.replace(/@/g,"a");
5073
5073
 
5074
+ function getCustomTeacherDropdownValue(block) {
5075
+ try {
5076
+ const inputs = block.inputList;
5077
+ const lastInput = inputs[inputs.length - 1];
5078
+ const fields = lastInput.fieldRow;
5079
+ const lastField = fields[fields.length - 1];
5080
+
5081
+ if (lastField.name === 'custom_teacher_dropdown')
5082
+ return lastField.getValue();
5083
+ } catch(e) { // TODO: Sacar esto
5084
+ return null;
5085
+ }
5086
+ }
5087
+
5074
5088
  /**
5075
5089
  * Retorna la función que representa la llamada a un procedimiento o funcion F(arg1, arg2, ...)
5076
5090
  * Importante: los arg son input values, no fields.
@@ -5080,8 +5094,13 @@ function callGenerator(name, args = [], newLine, order) {
5080
5094
  var code = name + '(';
5081
5095
  var sep = '';
5082
5096
  args.forEach(function (arg) {
5083
- code += sep + Blockly.GobstonesLanguage.valueToCode(block, arg,
5084
- Blockly.GobstonesLanguage.ORDER_NONE);
5097
+ const value = getCustomTeacherDropdownValue(block) || Blockly.GobstonesLanguage.valueToCode(
5098
+ block,
5099
+ arg,
5100
+ Blockly.GobstonesLanguage.ORDER_NONE
5101
+ );
5102
+
5103
+ code += sep + value;
5085
5104
  sep = ', ';
5086
5105
  });
5087
5106
  code += newLine ? ')\n' : ')';
@@ -6118,6 +6137,17 @@ Blockly.ErrorInforming.CssContent = [
6118
6137
  return name.split("_");
6119
6138
  },
6120
6139
 
6140
+ _getDropdownOptions(definition) {
6141
+ const attributes = definition.attributes;
6142
+
6143
+ const dropdown = definition.attributes && definition.attributes.block_dropdown;
6144
+ const dropdownOptions = dropdown && dropdown.match(/\("\w+" *, *'[^']*'\)/g);
6145
+ return dropdownOptions && dropdownOptions.map((option) => {
6146
+ const parts = option.match(/^\("(\w+)" *, *'([^']*)'\)$/);
6147
+ return [parts[1], parts[2]];
6148
+ });
6149
+ },
6150
+
6121
6151
  /**
6122
6152
  * Define un bloque a partir de una definicion tipo Poner_En_
6123
6153
  */
@@ -6125,6 +6155,7 @@ Blockly.ErrorInforming.CssContent = [
6125
6155
  const name = this._getPrimitiveName(definition);
6126
6156
  const customName = definition.attributes && definition.attributes.block_name;
6127
6157
  const icon = definition.attributes && definition.attributes.block_icon;
6158
+ const dropdownOptions = this._getDropdownOptions(definition);
6128
6159
 
6129
6160
  const finalName = customName || name;
6130
6161
  const parts = (customName ? this._getParts : this._getPartsByConvention.bind(this, true))
@@ -6145,11 +6176,24 @@ Blockly.ErrorInforming.CssContent = [
6145
6176
  ));
6146
6177
  }
6147
6178
 
6148
- for(var i in parts) {
6149
- if(i == (parts.length - 1)) {
6150
- this.appendDummyInput().appendField(parts[i]);
6151
- }
6152
- else {
6179
+ for (var i in parts) {
6180
+ if (i == (parts.length - 1)) {
6181
+ this.appendDummyInput().appendField(parts[i]);
6182
+
6183
+ if (dropdownOptions) {
6184
+ this.removeInput('arg1');
6185
+ this.jsonInit({
6186
+ message0: parts[i - 1] + " %1",
6187
+ args0: [
6188
+ {
6189
+ type: 'field_dropdown',
6190
+ name: "custom_teacher_dropdown",
6191
+ options: dropdownOptions
6192
+ }
6193
+ ]
6194
+ });
6195
+ }
6196
+ } else {
6153
6197
  this.appendValueInput('arg' + argsIndex).appendField(parts[i]);
6154
6198
  argsIndex++;
6155
6199
  }
@@ -6185,6 +6229,7 @@ Blockly.ErrorInforming.CssContent = [
6185
6229
  const name = this._getPrimitiveName(definition);
6186
6230
  const customName = definition.attributes && definition.attributes.block_name;
6187
6231
  const icon = definition.attributes && definition.attributes.block_icon;
6232
+ const dropdownOptions = this._getDropdownOptions(definition);
6188
6233
 
6189
6234
  const finalName = customName || name;
6190
6235
  const parts = (customName ? this._getParts : this._getPartsByConvention.bind(this, false))
@@ -6205,11 +6250,24 @@ Blockly.ErrorInforming.CssContent = [
6205
6250
  ));
6206
6251
  }
6207
6252
 
6208
- for(var i in parts) {
6209
- if(i == (parts.length - 1)) {
6253
+ for (var i in parts) {
6254
+ if (i == (parts.length - 1)) {
6210
6255
  this.appendDummyInput().appendField(parts[i]);
6211
- }
6212
- else {
6256
+
6257
+ if (dropdownOptions) {
6258
+ this.removeInput('arg1');
6259
+ this.jsonInit({
6260
+ message0: parts[i - 1] + " %1",
6261
+ args0: [
6262
+ {
6263
+ type: 'field_dropdown',
6264
+ name: "custom_teacher_dropdown",
6265
+ options: dropdownOptions
6266
+ }
6267
+ ]
6268
+ });
6269
+ }
6270
+ } else {
6213
6271
  this.appendValueInput('arg' + argsIndex).appendField(parts[i]);
6214
6272
  argsIndex++;
6215
6273
  }
@@ -1,5 +1,5 @@
1
1
  module Gobstones
2
2
  module Blockly
3
- VERSION = "0.17.0"
3
+ VERSION = "0.18.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gobstones-blockly
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.17.0
4
+ version: 0.18.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rodrigo Alfonso
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-06-25 00:00:00.000000000 Z
11
+ date: 2018-06-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler