scratch-vm/src/index.js

43 lines
1 KiB
JavaScript
Raw Normal View History

2016-04-18 17:20:30 -04:00
var EventEmitter = require('events');
var util = require('util');
var Blocks = require('./engine/blocks');
2016-04-18 17:20:30 -04:00
var Runtime = require('./engine/runtime');
/**
* Handles connections between blocks, stage, and extensions.
*
* @author Andrew Sliwinski <ascii@media.mit.edu>
*/
function VirtualMachine () {
var instance = this;
// Bind event emitter and runtime to VM instance
2016-04-18 18:03:18 -04:00
// @todo Post message (Web Worker) polyfill
2016-04-18 17:20:30 -04:00
EventEmitter.call(instance);
instance.blocks = new Blocks();
instance.runtime = new Runtime(instance.blocks);
2016-04-18 17:20:30 -04:00
/**
* Event listeners for scratch-blocks.
2016-04-18 17:20:30 -04:00
*/
instance.blockListener = (
instance.blocks.generateBlockListener(false, instance.runtime)
);
2016-04-18 17:20:30 -04:00
instance.flyoutBlockListener = (
instance.blocks.generateBlockListener(true, instance.runtime)
);
2016-04-18 17:20:30 -04:00
}
/**
* Inherit from EventEmitter
*/
util.inherits(VirtualMachine, EventEmitter);
/**
* Export and bind to `window`
*/
module.exports = VirtualMachine;
if (typeof window !== 'undefined') window.VirtualMachine = module.exports;