prolog-blockly 1.0.15 → 1.0.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/app/assets/htmls/pl-element-blockly.html +43 -900
- data/lib/prolog/blockly/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c9f825a09a92f0844d92a5e727d5125a3f5521c60e49a83e290e201fa1f558b5
|
4
|
+
data.tar.gz: 2c1e420db5c725c8f1942367e378bab7e24ff8aca4ca9d7e267addde6a773740
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 232daaa3bbfb7d3649ac94d628530c4332c360e144ff46a63c7bea4f67d6a9ba121208f2803078c69a40484192f437ac5bb9fc3d35e31c0d85a8a0f8327333fa
|
7
|
+
data.tar.gz: 8305af9ac5b90de74175c7212ced5a74a8e835475cf778d58debe1c80a466cfd3648c2dfc1f0e3a646c477b01f6aaff4e2fe7258e81f23c4b4e9480605d5afbf
|
@@ -4311,18 +4311,12 @@ Blockly.MUMUKI_COLORS = {
|
|
4311
4311
|
green: "#3FAA9D",
|
4312
4312
|
dark_green:"#1F879A"
|
4313
4313
|
};
|
4314
|
-
|
4315
|
-
Blockly.CUSTOM_COLORS.program = Blockly.MUMUKI_COLORS.pink;
|
4316
|
-
Blockly.CUSTOM_COLORS.interactiveProgram = Blockly.MUMUKI_COLORS.pink;
|
4317
|
-
Blockly.CUSTOM_COLORS.interactiveBinding = Blockly.MUMUKI_COLORS.pink;
|
4318
|
-
Blockly.CUSTOM_COLORS.procedure = Blockly.MUMUKI_COLORS.pink;
|
4319
|
-
Blockly.CUSTOM_COLORS.function = Blockly.MUMUKI_COLORS.pink;
|
4320
|
-
Blockly.CUSTOM_COLORS.complete = Blockly.MUMUKI_COLORS.pink;
|
4314
|
+
|
4321
4315
|
// commands
|
4322
4316
|
Blockly.CUSTOM_COLORS.controlStructure = Blockly.MUMUKI_COLORS.yellow;
|
4323
4317
|
Blockly.CUSTOM_COLORS.primitiveCommand = Blockly.MUMUKI_COLORS.yellow;
|
4324
4318
|
Blockly.CUSTOM_COLORS.primitiveProcedure = Blockly.MUMUKI_COLORS.yellow;
|
4325
|
-
Blockly.CUSTOM_COLORS.
|
4319
|
+
Blockly.CUSTOM_COLORS.Fact = Blockly.MUMUKI_COLORS.yellow;
|
4326
4320
|
Blockly.CUSTOM_COLORS.assignation = Blockly.MUMUKI_COLORS.dark_green;
|
4327
4321
|
|
4328
4322
|
// expressions
|
@@ -4332,8 +4326,6 @@ Blockly.CUSTOM_COLORS.primitiveExpression = Blockly.MUMUKI_COLORS.blue;
|
|
4332
4326
|
Blockly.CUSTOM_COLORS.operator = Blockly.MUMUKI_COLORS.blue;
|
4333
4327
|
Blockly.CUSTOM_COLORS.VariableSelector = Blockly.MUMUKI_COLORS.green;
|
4334
4328
|
Blockly.CUSTOM_COLORS.parameter = Blockly.MUMUKI_COLORS.blue;
|
4335
|
-
Blockly.CUSTOM_COLORS.primitiveFunction = Blockly.MUMUKI_COLORS.blue;
|
4336
|
-
Blockly.CUSTOM_COLORS.function_call = Blockly.MUMUKI_COLORS.blue;
|
4337
4329
|
Blockly.CUSTOM_COLORS.Not = Blockly.MUMUKI_COLORS.dark_green;
|
4338
4330
|
Blockly.CUSTOM_COLORS.ForAll = Blockly.MUMUKI_COLORS.dark_green;
|
4339
4331
|
|
@@ -4350,494 +4342,6 @@ Blockly.createBlockSvg = function(workspace, name, f) {
|
|
4350
4342
|
newBlock.render();
|
4351
4343
|
};
|
4352
4344
|
|
4353
|
-
Blockly.Blocks.Program = {
|
4354
|
-
init: function () {
|
4355
|
-
this.jsonInit({
|
4356
|
-
"type": "Program",
|
4357
|
-
"message0": "%1 %2 %3",
|
4358
|
-
"args0": [
|
4359
|
-
{
|
4360
|
-
"type": "field_label",
|
4361
|
-
"text": "programa"
|
4362
|
-
},
|
4363
|
-
{
|
4364
|
-
"type": "input_dummy"
|
4365
|
-
},
|
4366
|
-
{
|
4367
|
-
"type": "input_statement",
|
4368
|
-
"name": "program",
|
4369
|
-
"check": ["Statement"]
|
4370
|
-
}
|
4371
|
-
]
|
4372
|
-
})
|
4373
|
-
this.setColour(Blockly.CUSTOM_COLORS.Program || Blockly.CUSTOM_COLORS.program);
|
4374
|
-
this.setDeletable(true);
|
4375
|
-
this.setEditable(true);
|
4376
|
-
this.setMovable(true);
|
4377
|
-
},
|
4378
|
-
|
4379
|
-
setDisabledAndUpdateTimestamp: function(disabled) {
|
4380
|
-
this.setDisabled(disabled);
|
4381
|
-
if (!disabled) this.$timestamp = Date.now();
|
4382
|
-
},
|
4383
|
-
|
4384
|
-
mutationToDom: function() {
|
4385
|
-
var container = document.createElement("mutation");
|
4386
|
-
container.setAttribute("timestamp", this.$timestamp || Date.now());
|
4387
|
-
return container;
|
4388
|
-
},
|
4389
|
-
|
4390
|
-
domToMutation: function(xmlElement) {
|
4391
|
-
const timestamp = xmlElement.getAttribute("timestamp");
|
4392
|
-
this.$timestamp = timestamp || Date.now();
|
4393
|
-
},
|
4394
|
-
|
4395
|
-
};
|
4396
|
-
|
4397
|
-
Blockly.Blocks.InteractiveProgram = {
|
4398
|
-
init: function () {
|
4399
|
-
this.jsonInit({
|
4400
|
-
"type": "InteractiveProgram",
|
4401
|
-
"message0": "%1 %2 %3",
|
4402
|
-
"args0": [
|
4403
|
-
{
|
4404
|
-
"type": "field_label",
|
4405
|
-
"text": "programa interactivo"
|
4406
|
-
},
|
4407
|
-
{
|
4408
|
-
"type": "input_dummy"
|
4409
|
-
},
|
4410
|
-
{
|
4411
|
-
"type": "input_statement",
|
4412
|
-
"name": "interactiveprogram",
|
4413
|
-
"check": ["InteractiveBinding"]
|
4414
|
-
}
|
4415
|
-
]
|
4416
|
-
});
|
4417
|
-
this.setColour(Blockly.CUSTOM_COLORS.InteractiveProgram || Blockly.CUSTOM_COLORS.interactiveProgram);
|
4418
|
-
this.setDeletable(true);
|
4419
|
-
this.setEditable(true);
|
4420
|
-
this.setMovable(true);
|
4421
|
-
},
|
4422
|
-
|
4423
|
-
customContextMenu: function(options) {
|
4424
|
-
options.unshift({ text: `Agregar timeout`, enabled: !this.$timeout, callback: () => {
|
4425
|
-
let x = '';
|
4426
|
-
while (isNaN(parseInt(x)) || parseInt(x) <= 0)
|
4427
|
-
x = prompt("Ingrese un número en milisegundos");
|
4428
|
-
x = parseInt(x);
|
4429
|
-
|
4430
|
-
this._addTimeout(x);
|
4431
|
-
}});
|
4432
|
-
|
4433
|
-
options.unshift({ text: `Agregar inicialización`, enabled: !this.$init, callback: () => {
|
4434
|
-
this._addInit();
|
4435
|
-
}});
|
4436
|
-
},
|
4437
|
-
|
4438
|
-
setDisabledAndUpdateTimestamp: function(disabled) {
|
4439
|
-
this.setDisabled(disabled);
|
4440
|
-
if (!disabled) this.$timestamp = Date.now();
|
4441
|
-
},
|
4442
|
-
|
4443
|
-
mutationToDom: function() {
|
4444
|
-
var container = document.createElement("mutation");
|
4445
|
-
if (this.$init) container.setAttribute("init", this.$init);
|
4446
|
-
if (this.$timeout) container.setAttribute("timeout", this.$timeout);
|
4447
|
-
|
4448
|
-
container.setAttribute("timestamp", this.$timestamp || Date.now());
|
4449
|
-
return container;
|
4450
|
-
},
|
4451
|
-
|
4452
|
-
domToMutation: function(xmlElement) {
|
4453
|
-
const init = xmlElement.getAttribute("init");
|
4454
|
-
const timeout = xmlElement.getAttribute("timeout");
|
4455
|
-
const timestamp = xmlElement.getAttribute("timestamp");
|
4456
|
-
|
4457
|
-
if (init) this._addInit()
|
4458
|
-
if (timeout) this._addTimeout(parseInt(timeout));
|
4459
|
-
this.$timestamp = timestamp || Date.now();
|
4460
|
-
},
|
4461
|
-
|
4462
|
-
_addInit() {
|
4463
|
-
this.$init = true;
|
4464
|
-
|
4465
|
-
var removeButton = new Blockly.FieldImage(
|
4466
|
-
MINUS,
|
4467
|
-
16,
|
4468
|
-
16,
|
4469
|
-
"Eliminar",
|
4470
|
-
function() {
|
4471
|
-
this.$init = false;
|
4472
|
-
this.removeInput("initlabel");
|
4473
|
-
this.removeInput("init");
|
4474
|
-
this.removeInput("statementsLabel");
|
4475
|
-
}.bind(this)
|
4476
|
-
);
|
4477
|
-
|
4478
|
-
this.appendDummyInput("initlabel").appendField('Al inicializar:').appendField(removeButton);
|
4479
|
-
this.appendStatementInput('init').setCheck(["Statement"]);
|
4480
|
-
this.appendDummyInput("statementsLabel").appendField('Al apretar...');
|
4481
|
-
this.moveInputBefore("init", "interactiveprogram");
|
4482
|
-
this.moveInputBefore("initlabel", "init");
|
4483
|
-
this.moveInputBefore("statementsLabel", "interactiveprogram");
|
4484
|
-
},
|
4485
|
-
|
4486
|
-
_addTimeout(timeout) {
|
4487
|
-
this.$timeout = timeout;
|
4488
|
-
|
4489
|
-
var removeButton = new Blockly.FieldImage(
|
4490
|
-
MINUS,
|
4491
|
-
16,
|
4492
|
-
16,
|
4493
|
-
"Eliminar",
|
4494
|
-
function() {
|
4495
|
-
this.$timeout = undefined;
|
4496
|
-
this.removeInput("timeoutlabel");
|
4497
|
-
this.removeInput("timeout");
|
4498
|
-
}.bind(this)
|
4499
|
-
);
|
4500
|
-
|
4501
|
-
this.appendDummyInput("timeoutlabel").appendField(`Al estar inactivo ${timeout} milisegundos:`).appendField(removeButton);
|
4502
|
-
this.appendStatementInput('timeout').setCheck(["Statement"]);
|
4503
|
-
}
|
4504
|
-
};
|
4505
|
-
|
4506
|
-
// -------------------------------------
|
4507
|
-
// Programa interactivo
|
4508
|
-
// -------------------------------------
|
4509
|
-
|
4510
|
-
const modifiers = [
|
4511
|
-
[ 'SHIFT', 'SHIFT' ],
|
4512
|
-
[ 'CTRL', 'CTRL' ],
|
4513
|
-
[ 'ALT', 'ALT' ]
|
4514
|
-
];
|
4515
|
-
|
4516
|
-
const getModifiersInput = (block) => block.inputList[1];
|
4517
|
-
const getModifierFields = (block) => getModifiersInput(block).fieldRow.slice(2);
|
4518
|
-
const getModifierDropdownFields = (block) => getModifierFields(block).filter(it => it.constructor === Blockly.FieldDropdown);
|
4519
|
-
const getModifierValues = (block) => getModifierDropdownFields(block).map(it => it.getValue());
|
4520
|
-
const getAvailableModifiers = (block) => {
|
4521
|
-
const currentModifiers = getModifierValues(block);
|
4522
|
-
|
4523
|
-
return modifiers.filter(it =>
|
4524
|
-
currentModifiers.indexOf(it[1]) === -1
|
4525
|
-
);
|
4526
|
-
};
|
4527
|
-
const updateModifierMenuGenerators = (block, nameToIgnore) => {
|
4528
|
-
const availableModifiers = getAvailableModifiers(block);
|
4529
|
-
const dropdowns = getModifierDropdownFields(block);
|
4530
|
-
|
4531
|
-
for (var dropdown of dropdowns) {
|
4532
|
-
if (dropdown.name !== nameToIgnore)
|
4533
|
-
dropdown.menuGenerator_ = modifiers.filter(it => {
|
4534
|
-
return it[1] === dropdown.getValue() || availableModifiers.some(availableModifier => availableModifier[1] === it[1])
|
4535
|
-
});
|
4536
|
-
|
4537
|
-
}
|
4538
|
-
}
|
4539
|
-
|
4540
|
-
createInteractiveBinding = (name, keys) => {
|
4541
|
-
return {
|
4542
|
-
init: function () {
|
4543
|
-
this.jsonInit({
|
4544
|
-
message0: "%1 %2 %3 %4",
|
4545
|
-
type: "InteractiveBinding",
|
4546
|
-
previousStatement: "InteractiveBinding",
|
4547
|
-
nextStatement: "InteractiveBinding",
|
4548
|
-
args0: [
|
4549
|
-
{
|
4550
|
-
"type": "field_label",
|
4551
|
-
"text": "Al apretar " + name
|
4552
|
-
},
|
4553
|
-
{ "type": "input_dummy" },
|
4554
|
-
{
|
4555
|
-
"type": "field_label",
|
4556
|
-
"text": "➣"
|
4557
|
-
},
|
4558
|
-
{
|
4559
|
-
type: "field_dropdown",
|
4560
|
-
name: "InteractiveBindingDropdownKey",
|
4561
|
-
options: keys.map(it => [it.name, it.code]),
|
4562
|
-
}
|
4563
|
-
],
|
4564
|
-
colour: Blockly.CUSTOM_COLORS.InteractiveBinding || Blockly.CUSTOM_COLORS.interactiveBinding,
|
4565
|
-
tooltip: "Escoger una entrada",
|
4566
|
-
});
|
4567
|
-
|
4568
|
-
this.appendStatementInput('block').setCheck(["Statement"]);
|
4569
|
-
|
4570
|
-
const self = this;
|
4571
|
-
const input = this.inputList[0];
|
4572
|
-
input.appendField(new Blockly.FieldImage(
|
4573
|
-
PLUS,
|
4574
|
-
16,
|
4575
|
-
16,
|
4576
|
-
"Agregar modificador",
|
4577
|
-
function() {
|
4578
|
-
const modifiersCount = getModifierFields(self).length / 2;
|
4579
|
-
if (modifiersCount >= modifiers.length) return;
|
4580
|
-
|
4581
|
-
self._addModifier();
|
4582
|
-
}
|
4583
|
-
));
|
4584
|
-
input.appendField(new Blockly.FieldImage(
|
4585
|
-
CLEAN,
|
4586
|
-
16,
|
4587
|
-
16,
|
4588
|
-
"Limpiar modificadores",
|
4589
|
-
function() {
|
4590
|
-
self._cleanModifiers();
|
4591
|
-
}
|
4592
|
-
));
|
4593
|
-
},
|
4594
|
-
|
4595
|
-
customContextMenu: function(options) {
|
4596
|
-
const modifiersCount = getModifierFields(this).length / 2;
|
4597
|
-
|
4598
|
-
options.unshift({ text: `Limpiar modificadores`, enabled: modifiersCount > 0, callback: () => {
|
4599
|
-
this._cleanModifiers();
|
4600
|
-
}});
|
4601
|
-
options.unshift({ text: `Agregar modificador`, enabled: modifiersCount < modifiers.length, callback: () => {
|
4602
|
-
this._addModifier();
|
4603
|
-
}});
|
4604
|
-
},
|
4605
|
-
|
4606
|
-
mutationToDom: function() {
|
4607
|
-
var container = document.createElement("mutation");
|
4608
|
-
container.setAttribute("modifierscount", getModifierValues(this).length.toString());
|
4609
|
-
return container;
|
4610
|
-
},
|
4611
|
-
|
4612
|
-
domToMutation: function(xmlElement) {
|
4613
|
-
const $modifiersCount = xmlElement.getAttribute("modifierscount");
|
4614
|
-
if ($modifiersCount) {
|
4615
|
-
const count = parseInt($modifiersCount);
|
4616
|
-
for (var i = 0; i < count; i++)
|
4617
|
-
this._addModifier();
|
4618
|
-
}
|
4619
|
-
|
4620
|
-
setTimeout(() => {
|
4621
|
-
updateModifierMenuGenerators(this);
|
4622
|
-
}, 0);
|
4623
|
-
},
|
4624
|
-
|
4625
|
-
_addModifier() {
|
4626
|
-
const availableModifiers = getAvailableModifiers(this);
|
4627
|
-
|
4628
|
-
const self = this;
|
4629
|
-
const id = getModifierValues(this).length + 1;
|
4630
|
-
const labelName = "l" + id;
|
4631
|
-
const dropdownName = "d" + id;
|
4632
|
-
|
4633
|
-
getModifiersInput(this).appendField("+").appendField(new Blockly.FieldDropdown(availableModifiers, (newValue) => {
|
4634
|
-
setTimeout(() => {
|
4635
|
-
updateModifierMenuGenerators(self, dropdownName)
|
4636
|
-
}, 0);
|
4637
|
-
}));
|
4638
|
-
|
4639
|
-
const addedFields = getModifierFields(this).slice(-2);
|
4640
|
-
addedFields[0].name = labelName;
|
4641
|
-
addedFields[1].name = dropdownName;
|
4642
|
-
|
4643
|
-
updateModifierMenuGenerators(this, dropdownName);
|
4644
|
-
},
|
4645
|
-
|
4646
|
-
_cleanModifiers() {
|
4647
|
-
const fieldsToRemove = getModifierFields(this);
|
4648
|
-
|
4649
|
-
for (var field of fieldsToRemove)
|
4650
|
-
getModifiersInput(this).removeField(field.name);
|
4651
|
-
}
|
4652
|
-
}
|
4653
|
-
};
|
4654
|
-
|
4655
|
-
Blockly.Blocks.InteractiveLetterBinding = createInteractiveBinding("letra", [
|
4656
|
-
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'Ñ', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'
|
4657
|
-
].map(it => ({ code: it, name: it })));
|
4658
|
-
|
4659
|
-
Blockly.Blocks.InteractiveNumberBinding = createInteractiveBinding("número", [
|
4660
|
-
'1', '2', '3', '4', '5', '6', '7', '8', '9', '0'
|
4661
|
-
].map(it => ({ code: it, name: it })));
|
4662
|
-
|
4663
|
-
Blockly.Blocks.InteractiveKeyBinding = createInteractiveBinding("tecla", [
|
4664
|
-
{ code: 'ARROW_LEFT', name: '←' },
|
4665
|
-
{ code: 'ARROW_RIGHT', name: '→' },
|
4666
|
-
{ code: 'ARROW_UP', name: '↑' },
|
4667
|
-
{ code: 'ARROW_DOWN', name: '↓' },
|
4668
|
-
{ code: 'MINUS', name: '-' },
|
4669
|
-
{ code: 'SPACE', name: 'Espacio' },
|
4670
|
-
{ code: 'ENTER', name: 'Enter' },
|
4671
|
-
{ code: 'TAB', name: 'Tab' },
|
4672
|
-
{ code: 'BACKSPACE', name: 'Borrar' },
|
4673
|
-
{ code: 'DELETE', name: 'Suprimir' },
|
4674
|
-
{ code: 'ESCAPE', name: 'Escape' }
|
4675
|
-
]);
|
4676
|
-
|
4677
|
-
// ------------------------------------------------------
|
4678
|
-
// Control de flujo de ejecucion:
|
4679
|
-
// ------------------------------------------------------
|
4680
|
-
|
4681
|
-
Blockly.Blocks.RepeticionSimple = {
|
4682
|
-
init: function () {
|
4683
|
-
this.jsonInit({
|
4684
|
-
type: "Statement",
|
4685
|
-
previousStatement: "Statement",
|
4686
|
-
nextStatement: "Statement",
|
4687
|
-
});
|
4688
|
-
|
4689
|
-
this.setColour(Blockly.CUSTOM_COLORS.RepeticionSimple || Blockly.CUSTOM_COLORS.controlStructure);
|
4690
|
-
this.appendValueInput('count')
|
4691
|
-
.appendField('repetir');
|
4692
|
-
this.appendDummyInput()
|
4693
|
-
.appendField('veces');
|
4694
|
-
this.appendStatementInput('block').setCheck(["Statement"]);
|
4695
|
-
this.setInputsInline(true);
|
4696
|
-
}
|
4697
|
-
};
|
4698
|
-
|
4699
|
-
Blockly.Blocks.RepeticionCondicional = {
|
4700
|
-
init: function () {
|
4701
|
-
this.jsonInit({
|
4702
|
-
type: "Statement",
|
4703
|
-
previousStatement: "Statement",
|
4704
|
-
nextStatement: "Statement",
|
4705
|
-
});
|
4706
|
-
|
4707
|
-
this.setColour(Blockly.CUSTOM_COLORS.RepeticionCondicional || Blockly.CUSTOM_COLORS.controlStructure);
|
4708
|
-
this.appendValueInput('condicion')
|
4709
|
-
.setCheck('Bool')
|
4710
|
-
.appendField('repetir hasta que');
|
4711
|
-
this.appendStatementInput('block').setCheck(["Statement"]);
|
4712
|
-
this.setInputsInline(true);
|
4713
|
-
}
|
4714
|
-
};
|
4715
|
-
|
4716
|
-
Blockly.Blocks.AlternativaSimple = {
|
4717
|
-
init: function () {
|
4718
|
-
this.jsonInit({
|
4719
|
-
type: "Statement",
|
4720
|
-
previousStatement: "Statement",
|
4721
|
-
nextStatement: "Statement",
|
4722
|
-
});
|
4723
|
-
|
4724
|
-
this.setColour(Blockly.CUSTOM_COLORS.AlternativaSimple || Blockly.CUSTOM_COLORS.controlStructure);
|
4725
|
-
this.appendValueInput('condicion')
|
4726
|
-
.appendField(Blockly.Msg["CONTROLS_IF_MSG_IF"]);
|
4727
|
-
this.appendStatementInput('block').setCheck(["Statement"]);
|
4728
|
-
this.setInputsInline(true);
|
4729
|
-
}
|
4730
|
-
};
|
4731
|
-
|
4732
|
-
Blockly.Msg["CONTROLS_IF_MSG_ELSE"] = "si no";
|
4733
|
-
Blockly.Msg["CONTROLS_IF_MSG_ELSEIF"] = "si no, si";
|
4734
|
-
Blockly.Msg["CONTROLS_IF_MSG_IF"] = "si";
|
4735
|
-
Blockly.Msg["CONTROLS_IF_MSG_THEN"] = "";
|
4736
|
-
delete Blockly.Constants.Logic.CONTROLS_IF_MUTATOR_MIXIN.compose;
|
4737
|
-
delete Blockly.Constants.Logic.CONTROLS_IF_MUTATOR_MIXIN.decompose;
|
4738
|
-
Blockly.Constants.Logic.CONTROLS_IF_MUTATOR_MIXIN.updateShape_ = function() {
|
4739
|
-
// Delete everything.
|
4740
|
-
if (this.getInput('block2')) {
|
4741
|
-
this.removeInput('block2');
|
4742
|
-
}
|
4743
|
-
var i = 1;
|
4744
|
-
while (this.getInput('IF' + i)) {
|
4745
|
-
this.removeInput('IF' + i);
|
4746
|
-
this.removeInput('DO' + i);
|
4747
|
-
i++;
|
4748
|
-
}
|
4749
|
-
// Rebuild block.
|
4750
|
-
for (var i = 1; i <= this.elseifCount_; i++) {
|
4751
|
-
this.appendValueInput('IF' + i)
|
4752
|
-
.appendField(Blockly.Msg.CONTROLS_IF_MSG_ELSEIF);
|
4753
|
-
this.appendStatementInput('DO' + i)
|
4754
|
-
.setCheck(["Statement"])
|
4755
|
-
}
|
4756
|
-
if (this.elseCount_) {
|
4757
|
-
this.appendStatementInput('block2')
|
4758
|
-
.setCheck(["Statement"])
|
4759
|
-
.appendField(Blockly.Msg.CONTROLS_IF_MSG_ELSE);
|
4760
|
-
}
|
4761
|
-
};
|
4762
|
-
Blockly.Extensions.registerMutator(
|
4763
|
-
"controls_if_mutator_without_ui",
|
4764
|
-
Blockly.Constants.Logic.CONTROLS_IF_MUTATOR_MIXIN,
|
4765
|
-
null,
|
4766
|
-
[]
|
4767
|
-
);
|
4768
|
-
|
4769
|
-
Blockly.Blocks.AlternativaCompleta = {
|
4770
|
-
init: function () {
|
4771
|
-
this.jsonInit({
|
4772
|
-
"type": "Statement",
|
4773
|
-
"previousStatement": "Statement",
|
4774
|
-
"nextStatement": "Statement",
|
4775
|
-
"message0": "%{BKY_CONTROLS_IF_MSG_IF} %1",
|
4776
|
-
"args0": [
|
4777
|
-
{
|
4778
|
-
"type": "input_value",
|
4779
|
-
"name": "condicion"
|
4780
|
-
}
|
4781
|
-
],
|
4782
|
-
"message1": "%{BKY_CONTROLS_IF_MSG_THEN} %1",
|
4783
|
-
"args1": [
|
4784
|
-
{
|
4785
|
-
"type": "input_statement",
|
4786
|
-
"name": "block1",
|
4787
|
-
"check": ["Statement"]
|
4788
|
-
}
|
4789
|
-
],
|
4790
|
-
"colour": "%{BKY_LOGIC_HUE}",
|
4791
|
-
"helpUrl": "%{BKY_CONTROLS_IF_HELPURL}",
|
4792
|
-
"mutator": "controls_if_mutator_without_ui",
|
4793
|
-
"extensions": ["controls_if_tooltip"]
|
4794
|
-
});
|
4795
|
-
|
4796
|
-
this.setColour(Blockly.CUSTOM_COLORS.AlternativaCompleta || Blockly.CUSTOM_COLORS.controlStructure);
|
4797
|
-
this.setInputsInline(true);
|
4798
|
-
|
4799
|
-
this.elseCount_++;
|
4800
|
-
this.updateShape_();
|
4801
|
-
},
|
4802
|
-
customContextMenu: function(options) {
|
4803
|
-
options.unshift({ text: `Limpiar ramas 'si no, si'`, enabled: true, callback: () => {
|
4804
|
-
this.elseifCount_ = 0;
|
4805
|
-
|
4806
|
-
this.updateShape_();
|
4807
|
-
}});
|
4808
|
-
|
4809
|
-
options.unshift({ text: `Agregar 'si no, si'`, enabled: true, callback: () => {
|
4810
|
-
this.elseifCount_++;
|
4811
|
-
|
4812
|
-
const valueConnections = [null];
|
4813
|
-
const statementConnections = [null];
|
4814
|
-
const elseStatementConnection = this.getInput("block2").connection.targetConnection;
|
4815
|
-
let k;
|
4816
|
-
let input;
|
4817
|
-
|
4818
|
-
k = 1;
|
4819
|
-
while (input = this.getInput("IF" + k)) {
|
4820
|
-
valueConnections.push(input.connection.targetConnection);
|
4821
|
-
k++;
|
4822
|
-
}
|
4823
|
-
|
4824
|
-
k = 1;
|
4825
|
-
while (input = this.getInput("DO" + k)) {
|
4826
|
-
statementConnections.push(input.connection.targetConnection);
|
4827
|
-
k++;
|
4828
|
-
}
|
4829
|
-
|
4830
|
-
this.updateShape_();
|
4831
|
-
|
4832
|
-
// Reconnect any child blocks.
|
4833
|
-
for (var i = 1; i <= this.elseifCount_; i++) {
|
4834
|
-
Blockly.Mutator.reconnect(valueConnections[i], this, 'IF' + i);
|
4835
|
-
Blockly.Mutator.reconnect(statementConnections[i], this, 'DO' + i);
|
4836
|
-
}
|
4837
|
-
Blockly.Mutator.reconnect(elseStatementConnection, this, 'block2');
|
4838
|
-
}});
|
4839
|
-
}
|
4840
|
-
};
|
4841
4345
|
|
4842
4346
|
// ------------------------------------------------------
|
4843
4347
|
// Comandos:
|
@@ -4861,7 +4365,7 @@ Blockly.Blocks.fact1 = {
|
|
4861
4365
|
name: 'PrimerIndividuo'
|
4862
4366
|
}
|
4863
4367
|
],
|
4864
|
-
colour: Blockly.CUSTOM_COLORS.Fact
|
4368
|
+
colour: Blockly.CUSTOM_COLORS.Fact,
|
4865
4369
|
tooltip: 'Es una verdad',
|
4866
4370
|
inputsInline: true
|
4867
4371
|
});
|
@@ -4890,7 +4394,7 @@ Blockly.Blocks.fact2 = {
|
|
4890
4394
|
name: 'SegundoIndividuo'
|
4891
4395
|
}
|
4892
4396
|
],
|
4893
|
-
colour: Blockly.CUSTOM_COLORS.Fact
|
4397
|
+
colour: Blockly.CUSTOM_COLORS.Fact,
|
4894
4398
|
tooltip: 'Es una verdad',
|
4895
4399
|
inputsInline: true
|
4896
4400
|
});
|
@@ -4923,7 +4427,7 @@ Blockly.Blocks.fact3 = {
|
|
4923
4427
|
name: 'TerceraCondicion'
|
4924
4428
|
}
|
4925
4429
|
],
|
4926
|
-
colour: Blockly.CUSTOM_COLORS.Fact
|
4430
|
+
colour: Blockly.CUSTOM_COLORS.Fact,
|
4927
4431
|
tooltip: 'Es una verdad',
|
4928
4432
|
inputsInline: true
|
4929
4433
|
});
|
@@ -4943,7 +4447,7 @@ Blockly.Blocks.not = {
|
|
4943
4447
|
name: 'PrimeraCondicion'
|
4944
4448
|
}
|
4945
4449
|
],
|
4946
|
-
colour: Blockly.CUSTOM_COLORS.Not
|
4450
|
+
colour: Blockly.CUSTOM_COLORS.Not,
|
4947
4451
|
tooltip: 'Niega la condición',
|
4948
4452
|
inputsInline: true
|
4949
4453
|
});
|
@@ -4967,111 +4471,13 @@ Blockly.Blocks.forall = {
|
|
4967
4471
|
name: 'SegundaCondicion'
|
4968
4472
|
}
|
4969
4473
|
],
|
4970
|
-
colour: Blockly.CUSTOM_COLORS.ForAll
|
4474
|
+
colour: Blockly.CUSTOM_COLORS.ForAll,
|
4971
4475
|
tooltip: 'Para todo lo primero, se cumple lo segundo.',
|
4972
4476
|
inputsInline: true
|
4973
4477
|
});
|
4974
4478
|
}
|
4975
4479
|
};
|
4976
4480
|
|
4977
|
-
Blockly.Blocks.Sacar= {
|
4978
|
-
init: function () {
|
4979
|
-
this.jsonInit({
|
4980
|
-
type: "Statement",
|
4981
|
-
previousStatement: "Statement",
|
4982
|
-
nextStatement: "Statement",
|
4983
|
-
message0: 'Sacar %1',
|
4984
|
-
args0: [
|
4985
|
-
{
|
4986
|
-
type: 'input_value',
|
4987
|
-
name: 'COLOR'
|
4988
|
-
}
|
4989
|
-
],
|
4990
|
-
colour: Blockly.CUSTOM_COLORS.Sacar || Blockly.CUSTOM_COLORS.primitiveCommand,
|
4991
|
-
tooltip: 'Sacar color de casillero.',
|
4992
|
-
inputsInline: true
|
4993
|
-
});
|
4994
|
-
}
|
4995
|
-
};
|
4996
|
-
|
4997
|
-
Blockly.Blocks.Mover = {
|
4998
|
-
init: function () {
|
4999
|
-
this.jsonInit({
|
5000
|
-
type: "Statement",
|
5001
|
-
previousStatement: "Statement",
|
5002
|
-
nextStatement: "Statement",
|
5003
|
-
message0: 'Mover %1',
|
5004
|
-
args0: [
|
5005
|
-
{
|
5006
|
-
type: 'input_value',
|
5007
|
-
name: 'DIRECCION'
|
5008
|
-
}
|
5009
|
-
],
|
5010
|
-
colour: Blockly.CUSTOM_COLORS.Mover || Blockly.CUSTOM_COLORS.primitiveCommand,
|
5011
|
-
tooltip: 'Mover en una dirección.',
|
5012
|
-
inputsInline: true
|
5013
|
-
});
|
5014
|
-
}
|
5015
|
-
};
|
5016
|
-
|
5017
|
-
Blockly.Blocks.IrAlBorde = {
|
5018
|
-
init: function () {
|
5019
|
-
this.jsonInit({
|
5020
|
-
type: "Statement",
|
5021
|
-
previousStatement: "Statement",
|
5022
|
-
nextStatement: "Statement",
|
5023
|
-
message0: 'Ir al borde %1',
|
5024
|
-
args0: [
|
5025
|
-
{
|
5026
|
-
type: 'input_value',
|
5027
|
-
name: 'DIRECCION'
|
5028
|
-
}
|
5029
|
-
],
|
5030
|
-
colour: Blockly.CUSTOM_COLORS.IrAlBorde || Blockly.CUSTOM_COLORS.primitiveCommand,
|
5031
|
-
tooltip: 'Ir al borde del tablero.',
|
5032
|
-
inputsInline: true
|
5033
|
-
});
|
5034
|
-
}
|
5035
|
-
};
|
5036
|
-
|
5037
|
-
Blockly.Blocks.VaciarTablero = {
|
5038
|
-
init: function () {
|
5039
|
-
this.jsonInit({
|
5040
|
-
type: "Statement",
|
5041
|
-
previousStatement: "Statement",
|
5042
|
-
nextStatement: "Statement",
|
5043
|
-
message0: 'Vaciar tablero',
|
5044
|
-
colour: Blockly.CUSTOM_COLORS.VaciarTablero || Blockly.CUSTOM_COLORS.primitiveCommand,
|
5045
|
-
tooltip: 'Vaciar el tablero.',
|
5046
|
-
inputsInline: true
|
5047
|
-
});
|
5048
|
-
}
|
5049
|
-
};
|
5050
|
-
|
5051
|
-
Blockly.Blocks.BOOM = {
|
5052
|
-
init: function () {
|
5053
|
-
this.jsonInit({
|
5054
|
-
"type": "Statement",
|
5055
|
-
"previousStatement": "Statement",
|
5056
|
-
"nextStatement": "Statement",
|
5057
|
-
"lastDummyAlign0": "RIGHT",
|
5058
|
-
"message0": "Hacer ¡BOOM! porque: %1 %2",
|
5059
|
-
"args0": [
|
5060
|
-
{
|
5061
|
-
"type": "input_dummy"
|
5062
|
-
},
|
5063
|
-
{
|
5064
|
-
"type": "field_input",
|
5065
|
-
"name": "boomDescription",
|
5066
|
-
"text": "Ingresar motivo..."
|
5067
|
-
}
|
5068
|
-
],
|
5069
|
-
"inputsInline": false,
|
5070
|
-
"colour": Blockly.CUSTOM_COLORS.BOOM || Blockly.CUSTOM_COLORS.primitiveCommand,
|
5071
|
-
"tooltip": "Este comando hace que estalle todo."
|
5072
|
-
});
|
5073
|
-
}
|
5074
|
-
};
|
5075
4481
|
|
5076
4482
|
Blockly.Blocks.makeShadowEventListener = function(event){
|
5077
4483
|
if(event.blockId == this.id && event.newParentId){
|
@@ -5167,94 +4573,7 @@ function createLiteralSelectorBlock(type,values){
|
|
5167
4573
|
|
5168
4574
|
Blockly.Blocks.IndividuoSelector = createLiteralSelectorBlock('Individuo');
|
5169
4575
|
Blockly.Blocks.VariableSelector = createLiteralSelectorBlock('Variable');
|
5170
|
-
Blockly.Blocks.ColorSelector = createLiteralSelectorBlock('Color',['Rojo','Verde','Negro','Azul']);
|
5171
|
-
Blockly.Blocks.DireccionSelector = createLiteralSelectorBlock('Direccion',['Este','Oeste','Norte','Sur']);
|
5172
|
-
Blockly.Blocks.BoolSelector = createLiteralSelectorBlock('Bool',['True','False']);
|
5173
4576
|
|
5174
|
-
function createSingleParameterExpressionBlock(blockText,returnType, colorType = "operator"){
|
5175
|
-
return {
|
5176
|
-
init: function () {
|
5177
|
-
this.jsonInit({
|
5178
|
-
message0: blockText + ' %1',
|
5179
|
-
args0: [
|
5180
|
-
{
|
5181
|
-
type: 'input_value',
|
5182
|
-
name: 'VALUE'
|
5183
|
-
}
|
5184
|
-
],
|
5185
|
-
colour: Blockly.CUSTOM_COLORS[this.type] || Blockly.CUSTOM_COLORS[colorType],
|
5186
|
-
inputsInline: true,
|
5187
|
-
output: returnType
|
5188
|
-
})
|
5189
|
-
}
|
5190
|
-
};
|
5191
|
-
}
|
5192
|
-
|
5193
|
-
Blockly.Blocks.hayBolitas = createSingleParameterExpressionBlock('hay bolitas','Bool', "primitiveExpression");
|
5194
|
-
Blockly.Blocks.puedeMover = createSingleParameterExpressionBlock('puede mover','Bool', "primitiveExpression");
|
5195
|
-
Blockly.Blocks.nroBolitas = createSingleParameterExpressionBlock('numero de bolitas','Number', "primitiveExpression");
|
5196
|
-
|
5197
|
-
// ------------------------------------------------------
|
5198
|
-
// Operaciones:
|
5199
|
-
// ------------------------------------------------------
|
5200
|
-
|
5201
|
-
Blockly.Blocks.OperadorDeComparacion = {
|
5202
|
-
init: function () {
|
5203
|
-
this.jsonInit({
|
5204
|
-
message0: '%1 %2 %3 %4',
|
5205
|
-
args0: [
|
5206
|
-
{
|
5207
|
-
type: 'input_value',
|
5208
|
-
name: 'arg1'
|
5209
|
-
},
|
5210
|
-
{
|
5211
|
-
type: 'field_dropdown',
|
5212
|
-
name: 'RELATION',
|
5213
|
-
options: [['==', '=='], ['/=', '/='], ['<=', '<='], ['<', '<'], ['>=', '>='], ['>', '>']]
|
5214
|
-
},
|
5215
|
-
{
|
5216
|
-
type: 'input_dummy'
|
5217
|
-
},
|
5218
|
-
{
|
5219
|
-
type: 'input_value',
|
5220
|
-
name: 'arg2'
|
5221
|
-
}
|
5222
|
-
],
|
5223
|
-
colour: Blockly.CUSTOM_COLORS.OperadorDeComparacion || Blockly.CUSTOM_COLORS.operator,
|
5224
|
-
inputsInline: false,
|
5225
|
-
output: 'Bool'
|
5226
|
-
});
|
5227
|
-
}
|
5228
|
-
};
|
5229
|
-
|
5230
|
-
Blockly.Blocks.OperadorNumerico = {
|
5231
|
-
init: function () {
|
5232
|
-
this.jsonInit({
|
5233
|
-
message0: '%1 %2 %3 %4',
|
5234
|
-
args0: [
|
5235
|
-
{
|
5236
|
-
type: 'input_value',
|
5237
|
-
name: 'arg1'
|
5238
|
-
},
|
5239
|
-
{
|
5240
|
-
type: 'field_dropdown',
|
5241
|
-
name: 'OPERATOR',
|
5242
|
-
options: [['+', '+'], ['-', '-'], ['*', '*'], ['div', 'div'], ['mod', 'mod'], ['^', '^']]
|
5243
|
-
},
|
5244
|
-
{
|
5245
|
-
type: 'input_dummy'
|
5246
|
-
},
|
5247
|
-
{
|
5248
|
-
type: 'input_value',
|
5249
|
-
name: 'arg2'
|
5250
|
-
}
|
5251
|
-
],
|
5252
|
-
colour: Blockly.CUSTOM_COLORS.OperadorNumerico || Blockly.CUSTOM_COLORS.operator,
|
5253
|
-
inputsInline: false,
|
5254
|
-
output: 'Number'
|
5255
|
-
});
|
5256
|
-
}
|
5257
|
-
};
|
5258
4577
|
|
5259
4578
|
Blockly.Blocks.OperadorLogico = {
|
5260
4579
|
init: function () {
|
@@ -5392,9 +4711,15 @@ Blockly.Blocks.variables_get = {
|
|
5392
4711
|
}
|
5393
4712
|
};
|
5394
4713
|
|
5395
|
-
|
5396
|
-
|
5397
|
-
|
4714
|
+
|
4715
|
+
|
4716
|
+
|
4717
|
+
|
4718
|
+
|
4719
|
+
|
4720
|
+
|
4721
|
+
//Deberiamos immplementar una sanitizacion par ablockly, asi se esta haciendo en gobstone
|
4722
|
+
|
5398
4723
|
|
5399
4724
|
|
5400
4725
|
// Necesario para sanitizar nombres de procedimientos.
|
@@ -5501,6 +4826,13 @@ function uncapitalize(text) {
|
|
5501
4826
|
}
|
5502
4827
|
return text.charAt(0).toLowerCase() + text.substr(1);
|
5503
4828
|
}
|
4829
|
+
|
4830
|
+
function capitalize(text) {
|
4831
|
+
if(!text || typeof text !== "string") {
|
4832
|
+
return '';
|
4833
|
+
}
|
4834
|
+
return text.charAt(0).toUpperCase() + text.substr(1);
|
4835
|
+
}
|
5504
4836
|
/**
|
5505
4837
|
* Retorna la funcion que genera el codigo para un bloque tipo PRED(arg1, arg2, ...)
|
5506
4838
|
*/
|
@@ -5510,7 +4842,7 @@ function factBlockCodeGenerator(procName, args, newLine) {
|
|
5510
4842
|
var sep = '';
|
5511
4843
|
args.forEach(function (arg, index) {
|
5512
4844
|
var childBlock = block.childBlocks_[index]
|
5513
|
-
code += sep + (uncapitalize(childBlock.getFieldValue('Individuo')) || childBlock.getFieldValue('Variable'));
|
4845
|
+
code += sep + (uncapitalize(childBlock.getFieldValue('Individuo')) || capitalize(childBlock.getFieldValue('Variable')));
|
5514
4846
|
sep = ', ';
|
5515
4847
|
});
|
5516
4848
|
code += newLine ? ').\n' : ').';
|
@@ -5545,7 +4877,6 @@ function notBlockCodeGenerator(procName, args, newLine) {
|
|
5545
4877
|
return function (block) {
|
5546
4878
|
var code = "\n" + procName + '(';
|
5547
4879
|
var sep = '';
|
5548
|
-
debugger;
|
5549
4880
|
args.forEach(function (arg) {
|
5550
4881
|
var statementCode = Blockly.PrologLanguage.statementToCode(block, arg, false);
|
5551
4882
|
if(statementCode.split("\n").length > 2) {
|
@@ -5562,30 +4893,7 @@ function notBlockCodeGenerator(procName, args, newLine) {
|
|
5562
4893
|
// return callGenerator(procName, args, true);
|
5563
4894
|
}
|
5564
4895
|
window.forallBlockCodeGenerator = forallBlockCodeGenerator;
|
5565
|
-
/**
|
5566
|
-
* Retorna la funcion que genera el codigo para un bloque tipo function(arg1, arg2, ...)
|
5567
|
-
*/
|
5568
|
-
function functionBlockCodeGenerator(procName, args) {
|
5569
|
-
return callGenerator(procName, args, false, Blockly.PrologLanguage.ORDER_FUNCTION_CALL);
|
5570
|
-
}
|
5571
|
-
window.functionBlockCodeGenerator = functionBlockCodeGenerator;
|
5572
4896
|
|
5573
|
-
/**
|
5574
|
-
* Retorna la funcion que genera el codigo para un bloque tipo Expr(arg1, arg2, ...)
|
5575
|
-
*/
|
5576
|
-
function exprParamsBlockCodeGenerator(expr, args) {
|
5577
|
-
return callGenerator(expr, args, false, Blockly.PrologLanguage.ORDER_FUNCTION_CALL);
|
5578
|
-
}
|
5579
|
-
|
5580
|
-
/**
|
5581
|
-
* Retorna la funcion que genera el codigo para un bloque tipo selector de literales
|
5582
|
-
*/
|
5583
|
-
|
5584
|
-
function literalSelectorBlockCodeGenerator(type) {
|
5585
|
-
return function(block) {
|
5586
|
-
return [block.getFieldValue(type), Blockly.PrologLanguage.ORDER_ATOMIC];
|
5587
|
-
};
|
5588
|
-
}
|
5589
4897
|
|
5590
4898
|
function individuoSelectorBlockCodeGenerator(type) {
|
5591
4899
|
return function(block) {
|
@@ -5801,15 +5109,9 @@ Blockly.PrologLanguage.fact3 = factBlockCodeGenerator('fact', ['PrimerIndividuo'
|
|
5801
5109
|
Blockly.PrologLanguage.forall = forallBlockCodeGenerator('forall', ['PrimeraCondicion', 'SegundaCondicion']);
|
5802
5110
|
Blockly.PrologLanguage.not = notBlockCodeGenerator('not', ['PrimeraCondicion']);
|
5803
5111
|
|
5804
|
-
Blockly.PrologLanguage.ComandoCompletar = b => 'BOOM("El programa todavía no está completo")\n';
|
5805
|
-
Blockly.PrologLanguage.ExpresionCompletar = b => ['boom("El programa todavía no está completo")',Blockly.PrologLanguage.ORDER_FUNCTION_CALL];
|
5806
|
-
Blockly.PrologLanguage.AsociacionDeTeclaCompletar = b => ''
|
5807
5112
|
|
5808
5113
|
Blockly.PrologLanguage.IndividuoSelector = individuoSelectorBlockCodeGenerator('Individuo');
|
5809
5114
|
Blockly.PrologLanguage.VariableSelector = variableSelectorBlockCodeGenerator('Variable');
|
5810
|
-
Blockly.PrologLanguage.ColorSelector = literalSelectorBlockCodeGenerator('Color');
|
5811
|
-
Blockly.PrologLanguage.DireccionSelector = literalSelectorBlockCodeGenerator('Direccion');
|
5812
|
-
Blockly.PrologLanguage.BoolSelector = literalSelectorBlockCodeGenerator('Bool');
|
5813
5115
|
|
5814
5116
|
Blockly.PrologLanguage.OperadorDeComparacion = function (block) {
|
5815
5117
|
var code =
|
@@ -5858,9 +5160,6 @@ Blockly.PrologLanguage.OperadorLogico = function(block) {
|
|
5858
5160
|
return [code, order];
|
5859
5161
|
};
|
5860
5162
|
|
5861
|
-
Blockly.PrologLanguage.siguiente = exprParamsBlockCodeGenerator('siguiente',['VALUE']);
|
5862
|
-
Blockly.PrologLanguage.previo = exprParamsBlockCodeGenerator('previo',['VALUE']);
|
5863
|
-
Blockly.PrologLanguage.opuesto = exprParamsBlockCodeGenerator('opuesto',['VALUE']);
|
5864
5163
|
|
5865
5164
|
Blockly.PrologLanguage.math_number = function (block) {
|
5866
5165
|
// Numeric value.
|
@@ -5874,153 +5173,34 @@ Blockly.PrologLanguage.Program = function (block) {
|
|
5874
5173
|
return codigo;
|
5875
5174
|
};
|
5876
5175
|
|
5877
|
-
Blockly.PrologLanguage.InteractiveProgram = function (block) {
|
5878
|
-
let program = Blockly.PrologLanguage.statementToCode(block, 'interactiveprogram');
|
5879
|
-
|
5880
|
-
let init = '';
|
5881
|
-
if (block.$init)
|
5882
|
-
init = ` INIT -> {\n${Blockly.PrologLanguage.statementToCode(block, 'init')} }\n`;
|
5883
|
-
|
5884
|
-
let timeout = '';
|
5885
|
-
if (block.$timeout)
|
5886
|
-
timeout = ` TIMEOUT(${block.$timeout}) -> {\n${Blockly.PrologLanguage.statementToCode(block, 'timeout')} }\n`;
|
5887
|
-
|
5888
|
-
let codigo = `interactive program {\n${init}${program}${timeout}}\n`;
|
5889
|
-
return codigo;
|
5890
|
-
};
|
5891
|
-
|
5892
|
-
Blockly.PrologLanguage.InteractiveLetterBinding = function (block) {
|
5893
|
-
let key = block.getFieldValue('InteractiveBindingDropdownKey');
|
5894
|
-
|
5895
|
-
const order = ["CTRL", "ALT", "SHIFT"];
|
5896
|
-
const modifier = block.inputList[1]
|
5897
|
-
.fieldRow
|
5898
|
-
.slice(2)
|
5899
|
-
.filter(it => it.constructor === Blockly.FieldDropdown)
|
5900
|
-
.map(it => order.indexOf(it.getValue()))
|
5901
|
-
.sort()
|
5902
|
-
.map(it => order[it])
|
5903
|
-
.join("_");
|
5904
|
-
|
5905
|
-
if (modifier !== "")
|
5906
|
-
key = modifier + "_" + key;
|
5907
|
-
|
5908
|
-
const code = Blockly.PrologLanguage.statementToCode(block, 'block');
|
5909
|
-
|
5910
|
-
return `K_${key} -> {\n${code}}\n`;
|
5911
|
-
};
|
5912
|
-
Blockly.PrologLanguage.InteractiveNumberBinding = Blockly.PrologLanguage.InteractiveLetterBinding;
|
5913
|
-
Blockly.PrologLanguage.InteractiveKeyBinding = Blockly.PrologLanguage.InteractiveLetterBinding;
|
5914
|
-
|
5915
|
-
Blockly.PrologLanguage.RepeticionSimple = function (block) {
|
5916
|
-
let body = Blockly.PrologLanguage.statementToCode(block, 'block');
|
5917
|
-
var count = Blockly.PrologLanguage.valueToCode(block, 'count',
|
5918
|
-
Blockly.PrologLanguage.ORDER_NONE) || '';
|
5919
|
-
|
5920
|
-
let codigo = `repeat(${count}) {\n${body}}\n`;
|
5921
|
-
return codigo;
|
5922
|
-
};
|
5923
|
-
|
5924
|
-
Blockly.PrologLanguage.RepeticionCondicional = function (block) {
|
5925
|
-
let body = Blockly.PrologLanguage.statementToCode(block, 'block');
|
5926
|
-
var condicion = Blockly.PrologLanguage.valueToCode(block, 'condicion',
|
5927
|
-
Blockly.PrologLanguage.ORDER_NONE) || '';
|
5928
|
-
|
5929
|
-
let codigo = `while (not (${condicion})) {\n${body}}\n`;
|
5930
|
-
return codigo;
|
5931
|
-
};
|
5932
|
-
|
5933
|
-
Blockly.PrologLanguage.AlternativaSimple = function (block) {
|
5934
|
-
let body = Blockly.PrologLanguage.statementToCode(block, 'block');
|
5935
|
-
var condicion = Blockly.PrologLanguage.valueToCode(block, 'condicion',
|
5936
|
-
Blockly.PrologLanguage.ORDER_NONE) || '';
|
5937
|
-
|
5938
|
-
let codigo = `if (${condicion}) {\n${body}}\n`;
|
5939
|
-
return codigo;
|
5940
|
-
};
|
5941
|
-
|
5942
|
-
Blockly.PrologLanguage.AlternativaCompleta = function (block) {
|
5943
|
-
const elseIfCount = block.elseifCount_;
|
5944
|
-
let body1 = Blockly.PrologLanguage.statementToCode(block, 'block1');
|
5945
|
-
let body2 = Blockly.PrologLanguage.statementToCode(block, 'block2');
|
5946
|
-
|
5947
|
-
const elseIfBodies = Array.apply(null, Array(elseIfCount))
|
5948
|
-
.map(function (_, i) {
|
5949
|
-
const id = i + 1;
|
5950
|
-
return {
|
5951
|
-
condition: Blockly.PrologLanguage.valueToCode(block, "IF" + id,
|
5952
|
-
Blockly.PrologLanguage.ORDER_NONE),
|
5953
|
-
body: Blockly.PrologLanguage.statementToCode(block, "DO" + id)
|
5954
|
-
};
|
5955
|
-
}).map(function({ condition, body }) {
|
5956
|
-
return ` elseif (${condition}) {\n${body}}`;
|
5957
|
-
}).join("");
|
5958
|
-
|
5959
|
-
var condicion = Blockly.PrologLanguage.valueToCode(block, 'condicion',
|
5960
|
-
Blockly.PrologLanguage.ORDER_NONE) || '';
|
5961
|
-
|
5962
|
-
let codigo = `if (${condicion}) {\n${body1}}${elseIfBodies} else {\n${body2}}\n`;
|
5963
|
-
return codigo;
|
5964
|
-
};
|
5965
|
-
|
5966
|
-
Blockly.PrologLanguage.hayBolitas = exprParamsBlockCodeGenerator('hayBolitas', ['VALUE']);
|
5967
|
-
Blockly.PrologLanguage.nroBolitas = exprParamsBlockCodeGenerator('nroBolitas', ['VALUE']);
|
5968
|
-
Blockly.PrologLanguage.puedeMover = exprParamsBlockCodeGenerator('puedeMover', ['VALUE']);
|
5969
|
-
|
5970
5176
|
var formatCallName = function (name, capitalizeFirst, type = Blockly.PROCEDURE_CATEGORY_NAME) {
|
5971
|
-
|
5972
|
-
|
5973
|
-
|
5177
|
+
if(!name) throw new Error(type + " name is empty");
|
5178
|
+
var safe = Blockly.PrologLanguage.variableDB_.getName(name, type);
|
5179
|
+
return (capitalizeFirst ? safe[0].toUpperCase() : safe[0].toLowerCase()) + safe.slice(1);
|
5974
5180
|
};
|
5975
5181
|
|
5976
5182
|
var makeParameterList = function (block) {
|
5977
|
-
|
5183
|
+
return block.arguments_.join(', ');
|
5978
5184
|
};
|
5979
5185
|
|
5980
5186
|
Blockly.PrologLanguage.procedures_defnoreturn = function (block) {
|
5981
|
-
|
5982
|
-
|
5983
|
-
|
5984
|
-
|
5985
|
-
|
5986
|
-
|
5987
|
-
|
5988
|
-
|
5989
|
-
|
5990
|
-
var code = name + '(' + makeParameterList(block) + ')' + ':- \n' + body_final + '\n';
|
5991
|
-
|
5992
|
-
code = Blockly.PrologLanguage.scrub_(block, code);
|
5993
|
-
Blockly.PrologLanguage.definitions_[procName] = code;
|
5994
|
-
|
5995
|
-
return null;
|
5996
|
-
};
|
5997
|
-
|
5998
|
-
Blockly.PrologLanguage.procedures_defnoreturn_nobody = function (block) {
|
5999
|
-
var name = formatCallName(block.getFieldValue('NAME'),false);
|
6000
|
-
var code = name + '(' + makeParameterList(block) + ').';
|
6001
|
-
code = Blockly.PrologLanguage.scrub_(block, code);
|
6002
|
-
Blockly.PrologLanguage.definitions_[name] = code;
|
6003
|
-
return null;
|
6004
|
-
};
|
6005
|
-
|
6006
|
-
Blockly.PrologLanguage.procedures_defreturn = function (block) {
|
6007
|
-
var name = formatCallName(block.getFieldValue('NAME'),false);
|
6008
|
-
var body = Blockly.PrologLanguage.statementToCode(block, 'STACK');
|
6009
|
-
var returnValue = Blockly.PrologLanguage.valueToCode(block, 'RETURN');
|
5187
|
+
var procName = formatCallName(block.getFieldValue('NAME'),false);
|
5188
|
+
var name = procName;
|
5189
|
+
while(Number(name.slice(-1))) {
|
5190
|
+
name = name.slice(0, -1);
|
5191
|
+
}
|
5192
|
+
var body_lines = Blockly.PrologLanguage.statementToCode(block, 'STACK');
|
5193
|
+
var body2 = body_lines.split("\n").slice(1).join(",\n") + '.';
|
5194
|
+
var body_final = body2.replace(/\.\./g, ".").replace(/\.,/g, ",");
|
6010
5195
|
|
6011
|
-
|
6012
|
-
body + ' return (' + returnValue + ')\n}\n';
|
5196
|
+
var code = name + '(' + makeParameterList(block) + ')' + ':- \n' + body_final + '\n';
|
6013
5197
|
|
6014
|
-
|
6015
|
-
|
5198
|
+
code = Blockly.PrologLanguage.scrub_(block, code);
|
5199
|
+
Blockly.PrologLanguage.definitions_[procName] = code;
|
6016
5200
|
|
6017
|
-
|
5201
|
+
return null;
|
6018
5202
|
};
|
6019
5203
|
|
6020
|
-
Blockly.PrologLanguage.procedures_defnoreturnnoparams = Blockly.PrologLanguage.procedures_defnoreturn;
|
6021
|
-
Blockly.PrologLanguage.procedures_defreturnsimplewithparams = Blockly.PrologLanguage.procedures_defreturn;
|
6022
|
-
Blockly.PrologLanguage.procedures_defreturnsimple = Blockly.PrologLanguage.procedures_defreturn;
|
6023
|
-
|
6024
5204
|
var predicateCall = function(block, capitalizeFirst, newLine) {
|
6025
5205
|
var procName = formatCallName(block.getFieldValue('NAME'),false);
|
6026
5206
|
var args = [];
|
@@ -6032,17 +5212,6 @@ var predicateCall = function(block, capitalizeFirst, newLine) {
|
|
6032
5212
|
return code;
|
6033
5213
|
}
|
6034
5214
|
|
6035
|
-
Blockly.PrologLanguage.procedures_callnoreturn = function (block) {
|
6036
|
-
return predicateCall(block, true, true);
|
6037
|
-
};
|
6038
|
-
Blockly.PrologLanguage.procedures_callreturn = function (block) {
|
6039
|
-
return [predicateCall(block, false), Blockly.PrologLanguage.ORDER_FUNCTION_CALL];
|
6040
|
-
};
|
6041
|
-
|
6042
|
-
Blockly.PrologLanguage.procedures_callnoreturnnoparams = Blockly.PrologLanguage.procedures_callnoreturn;
|
6043
|
-
Blockly.PrologLanguage.procedures_callreturnsimplewithparams = Blockly.PrologLanguage.procedures_callreturn;
|
6044
|
-
Blockly.PrologLanguage.procedures_callreturnsimple = Blockly.PrologLanguage.procedures_callreturn;
|
6045
|
-
|
6046
5215
|
Blockly.PrologLanguage.variables_get = function (block) {
|
6047
5216
|
var code = formatCallName(block.getFieldValue('VAR'),false,Blockly.VARIABLE_CATEGORY_NAME);
|
6048
5217
|
return [code, Blockly.PrologLanguage.ORDER_ATOMIC];
|
@@ -6050,45 +5219,19 @@ Blockly.PrologLanguage.variables_get = function (block) {
|
|
6050
5219
|
|
6051
5220
|
Blockly.PrologLanguage.Asignacion = function(block) {
|
6052
5221
|
var varValue = Blockly.PrologLanguage.valueToCode(block, 'varValue', Blockly.PrologLanguage.ORDER_ASSIGNMENT);
|
6053
|
-
var
|
5222
|
+
var varName = formatCallName(block.getFieldValue('varName'),false,Blockly.VARIABLE_CATEGORY_NAME);
|
5223
|
+
var code = capitalize(varName) +
|
6054
5224
|
' is ' + varValue;
|
6055
5225
|
return "\n" + code;
|
6056
5226
|
};
|
6057
5227
|
</script>
|
6058
5228
|
<script>Blockly.PrologLanguage.blockIDAliases = {
|
6059
|
-
"ComandosPrimitivos": "Comandos primitivos",
|
6060
|
-
"ProcedimientosPrimitivos": "Procedimientos primitivos",
|
6061
|
-
"MisProcedimientos": "Mis procedimientos",
|
6062
|
-
"ExpresionesPrimitivas": "Expresiones primitivas",
|
6063
|
-
"FuncionesPrimitivas": "Funciones primitivas",
|
6064
5229
|
"CategoriaAsignacion":"Asignación",
|
6065
5230
|
"Color":"ColorSelector",
|
6066
5231
|
"Individuo":"IndividuoSelector",
|
6067
5232
|
"Variable":"VariableSelector",
|
6068
|
-
"Direccion":"DireccionSelector",
|
6069
|
-
"Numero":"math_number",
|
6070
|
-
"Booleano":"BoolSelector",
|
6071
|
-
"ExpresionesPrimitivas": "Expresiones primitivas",
|
6072
|
-
"FuncionesPrimitivas": "Funciones primitivas",
|
6073
|
-
"MisFunciones": "Mis funciones",
|
6074
5233
|
"OperadorDeNegacion": "not",
|
6075
|
-
|
6076
|
-
"OperadorPrevio": "previo",
|
6077
|
-
"OperadorOpuesto": "opuesto",
|
6078
|
-
"DefinicionesDeProgramas": "Programas",
|
6079
|
-
"DefinicionDeProgramaComun": "Program",
|
6080
|
-
"DefinicionDeProgramaInteractivo": "InteractiveProgram",
|
6081
|
-
"DefinicionDeAsociacionDeTeclaLetra": "InteractiveLetterBinding",
|
6082
|
-
"DefinicionDeAsociacionDeTeclaNumero": "InteractiveNumberBinding",
|
6083
|
-
"DefinicionDeAsociacionDeTeclaEspecial": "InteractiveKeyBinding",
|
6084
|
-
"DefinicionesDeProcedimientos": "Procedimientos",
|
6085
|
-
"DefinicionDeProcedimientoSimple": "procedures_defnoreturnnoparams",
|
6086
|
-
"DefinicionDeProcedimientoParametrizado": "procedures_defnoreturn",
|
6087
|
-
"DefinicionesDeFunciones": "Funciones",
|
6088
|
-
"DefinicionDeFuncionSimple": "procedures_defreturnsimple",
|
6089
|
-
"DefinicionDeFuncionSimpleParametrizada": "procedures_defreturnsimplewithparams",
|
6090
|
-
"DefinicionDeFuncionParametrizada": "procedures_defreturn"
|
6091
|
-
};
|
5234
|
+
};
|
6092
5235
|
|
6093
5236
|
Blockly.PrologLanguage.aliasForBlockID = function(id){
|
6094
5237
|
return this.blockIDAliases[id] || id;
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: prolog-blockly
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.16
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Agustin Pina
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-11-
|
11
|
+
date: 2018-11-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|