<commit_before>'use strict';

Blockly.Blocks['move_van'] = {
  // Block for moving forward
  init: function() {
    this.setColour(160);
    this.appendDummyInput()
        .appendField('Move forward');
    this.setPreviousStatement(true);
    this.setNextStatement(true);
    this.setTooltip('Move the van forwards');
  }
};

Blockly.JavaScript['move_van'] = function(block) {
    // Generate JavaScript for moving forward
    return 'BlocklyTest.moveForward();\n';
};

Blockly.Blocks['turn_van'] = {
  // Block for turning left or right.
  init: function() {
    var DIRECTIONS =
        [['Turn left', 'moveLeft'],
         ['Turn right', 'moveRight']];
    // Append arrows to direction messages.
    DIRECTIONS[0][0] += ' \u21BB';
    DIRECTIONS[1][0] += ' \u21BA';
    this.setColour(160);
    this.appendDummyInput()
        .appendField(new Blockly.FieldDropdown(DIRECTIONS), 'DIR');
    this.setPreviousStatement(true);
    this.setNextStatement(true);
    this.setTooltip('Turn the van');
  }
};

Blockly.JavaScript['turn_van'] = function(block) {
    // Generate JavaScript for turning left or right.
    return 'BlocklyTest.' + block.getFieldValue('DIR') + '()\n';
};

var BlocklyTest = {};

BlocklyTest.init = function() {
    Blockly.inject(document.getElementById('blockly'),
        {path: '/static/game/js/blockly/', toolbox: document.getElementById('toolbox')});
} ;

window.addEventListener('load', BlocklyTest.init);

BlocklyTest.queue = [];

BlocklyTest.execute = function() {
    BlocklyTest.queue = [];

    var code = Blockly.JavaScript.workspaceToCode();
    try {
        eval(code);
    } catch (e) {
        // Null is thrown for infinite loop.
        // Otherwise, abnormal termination is a user error.
        if (e !== Infinity) {
            alert(e);
        }
    }
  
    resetVan();
    window.setTimeout(BlocklyTest.animate, 100);  
};

BlocklyTest.animate = function() {
    var instruction = BlocklyTest.queue.shift();
    if (!instruction) {
        return;
    }
    switch (instruction) {
        case FORWARD:
            moveForward(BlocklyTest.animate);
            break;

        case TURN_LEFT:
            moveLeft(BlocklyTest.animate);
            break;

        case TURN_RIGHT:
            moveRight(BlocklyTest.animate);
            break;
    } 
};

BlocklyTest.addInstruction = function(instruction) {
    BlocklyTest.queue.push(instruction);
};

BlocklyTest.moveForward = function() {
    BlocklyTest.addInstruction(FORWARD);
};

BlocklyTest.moveLeft = function() {
    BlocklyTest.addInstruction(TURN_LEFT);
};

BlocklyTest.moveRight = function() {
    BlocklyTest.addInstruction(TURN_RIGHT);
};
<commit_msg>Added Start block to Blockly code<commit_after>'use strict';

Blockly.Blocks['start'] = {
    // Beginning block - identifies the start of the program
    init: function() {
        this.setColour(50);
        this.appendDummyInput()
            .appendField('Start');
        this.setNextStatement(true);
        this.setTooltip('The beginning of the program');
        this.setDeletable(false);
    }
};

Blockly.Blocks['move_van'] = {
  // Block for moving forward
  init: function() {
    this.setColour(160);
    this.appendDummyInput()
        .appendField('Move forward');
    this.setPreviousStatement(true);
    this.setNextStatement(true);
    this.setTooltip('Move the van forwards');
  }
};

Blockly.JavaScript['move_van'] = function(block) {
    // Generate JavaScript for moving forward
    return 'BlocklyTest.moveForward();\n';
};

Blockly.Blocks['turn_van'] = {
  // Block for turning left or right.
  init: function() {
    var DIRECTIONS =
        [['Turn left', 'moveLeft'],
         ['Turn right', 'moveRight']];
    // Append arrows to direction messages.
    DIRECTIONS[0][0] += ' \u21BB';
    DIRECTIONS[1][0] += ' \u21BA';
    this.setColour(160);
    this.appendDummyInput()
        .appendField(new Blockly.FieldDropdown(DIRECTIONS), 'DIR');
    this.setPreviousStatement(true);
    this.setNextStatement(true);
    this.setTooltip('Turn the van');
  }
};

Blockly.JavaScript['turn_van'] = function(block) {
    // Generate JavaScript for turning left or right.
    return 'BlocklyTest.' + block.getFieldValue('DIR') + '()\n';
};

var BlocklyTest = {};

BlocklyTest.init = function() {
    Blockly.inject(document.getElementById('blockly'),
        {path: '/static/game/js/blockly/', toolbox: document.getElementById('toolbox')});

    var startBlock = Blockly.Block.obtain(Blockly.mainWorkspace, 'start');
    startBlock.initSvg();
    startBlock.render();
} ;

window.addEventListener('load', BlocklyTest.init);

BlocklyTest.queue = [];

BlocklyTest.execute = function() {
    BlocklyTest.queue = [];

    var code = Blockly.JavaScript.workspaceToCode();
    try {
        eval(code);
    } catch (e) {
        // Null is thrown for infinite loop.
        // Otherwise, abnormal termination is a user error.
        if (e !== Infinity) {
            alert(e);
        }
    }
  
    resetVan();
    window.setTimeout(BlocklyTest.animate, 100);  
};

BlocklyTest.animate = function() {
    var instruction = BlocklyTest.queue.shift();
    if (!instruction) {
        return;
    }
    switch (instruction) {
        case FORWARD:
            moveForward(BlocklyTest.animate);
            break;

        case TURN_LEFT:
            moveLeft(BlocklyTest.animate);
            break;

        case TURN_RIGHT:
            moveRight(BlocklyTest.animate);
            break;
    } 
};

BlocklyTest.addInstruction = function(instruction) {
    BlocklyTest.queue.push(instruction);
};

BlocklyTest.moveForward = function() {
    BlocklyTest.addInstruction(FORWARD);
};

BlocklyTest.moveLeft = function() {
    BlocklyTest.addInstruction(TURN_LEFT);
};

BlocklyTest.moveRight = function() {
    BlocklyTest.addInstruction(TURN_RIGHT);
};

{'fraction_non_alphanumeric': 0.141091658084449, 'fraction_numerical': 0.006179196704428424, 'mean_word_length': 2.942489851150203, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6701034', 'n_tokens_mistral': 1816, 'n_tokens_neox': 1783, 'n_words': 338}