mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2025-03-13 17:04:39 -04:00
Merge pull request #200 from rschamp/render-scope
Scope renderer to instance
This commit is contained in:
commit
9884c583a9
9 changed files with 814 additions and 420 deletions
|
@ -20,6 +20,7 @@
|
|||
},
|
||||
"devDependencies": {
|
||||
"eslint": "2.7.0",
|
||||
"expose-loader": "0.7.1",
|
||||
"highlightjs": "8.7.0",
|
||||
"json-loader": "0.5.4",
|
||||
"scratch-blocks": "git+https://git@github.com/LLK/scratch-blocks.git#develop",
|
||||
|
|
|
@ -21,7 +21,7 @@ var loadProject = function () {
|
|||
|
||||
window.onload = function() {
|
||||
// Lots of global variables to make debugging easier
|
||||
// Instantiate the VM worker.
|
||||
// Instantiate the VM.
|
||||
var vm = new window.VirtualMachine();
|
||||
window.vm = vm;
|
||||
|
||||
|
@ -39,7 +39,9 @@ window.onload = function() {
|
|||
|
||||
// Instantiate the renderer and connect it to the VM.
|
||||
var canvas = document.getElementById('scratch-stage');
|
||||
window.renderer = new window.RenderWebGL(canvas);
|
||||
var renderer = new window.RenderWebGL(canvas);
|
||||
window.renderer = renderer;
|
||||
vm.attachRenderer(renderer);
|
||||
|
||||
// Instantiate scratch-blocks and attach it to the DOM.
|
||||
var toolbox = document.getElementById('toolbox');
|
||||
|
|
|
@ -199,6 +199,14 @@ Runtime.prototype.clearEdgeActivatedValues = function () {
|
|||
this._edgeActivatedHatValues = {};
|
||||
};
|
||||
|
||||
/**
|
||||
* Attach the renderer
|
||||
* @param {!RenderWebGL} renderer The renderer to attach
|
||||
*/
|
||||
Runtime.prototype.attachRenderer = function (renderer) {
|
||||
this.renderer = renderer;
|
||||
};
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
|
@ -573,8 +581,8 @@ Runtime.prototype.getTargetForStage = function () {
|
|||
* Handle an animation frame from the main thread.
|
||||
*/
|
||||
Runtime.prototype.animationFrame = function () {
|
||||
if (self.renderer) {
|
||||
self.renderer.draw();
|
||||
if (this.renderer) {
|
||||
this.renderer.draw();
|
||||
}
|
||||
};
|
||||
|
||||
|
|
13
src/index.js
13
src/index.js
|
@ -162,6 +162,14 @@ VirtualMachine.prototype.createEmptyProject = function () {
|
|||
this.emitWorkspaceUpdate();
|
||||
};
|
||||
|
||||
/**
|
||||
* Set the renderer for the VM/runtime
|
||||
* @param {!RenderWebGL} renderer The renderer to attach
|
||||
*/
|
||||
VirtualMachine.prototype.attachRenderer = function (renderer) {
|
||||
this.runtime.attachRenderer(renderer);
|
||||
};
|
||||
|
||||
/**
|
||||
* Handle a Blockly event for the current editing target.
|
||||
* @param {!Blockly.Event} e Any Blockly event.
|
||||
|
@ -227,8 +235,5 @@ VirtualMachine.prototype.emitWorkspaceUpdate = function () {
|
|||
'xml': this.editingTarget.blocks.toXML()
|
||||
});
|
||||
};
|
||||
/**
|
||||
* Export and bind to `window`
|
||||
*/
|
||||
|
||||
module.exports = VirtualMachine;
|
||||
if (typeof window !== 'undefined') window.VirtualMachine = module.exports;
|
||||
|
|
|
@ -28,8 +28,8 @@ Mouse.prototype.postData = function(data) {
|
|||
};
|
||||
|
||||
Mouse.prototype._activateClickHats = function (x, y) {
|
||||
if (self.renderer) {
|
||||
var drawableID = self.renderer.pick(x, y);
|
||||
if (this.runtime.renderer) {
|
||||
var drawableID = this.runtime.renderer.pick(x, y);
|
||||
for (var i = 0; i < this.runtime.targets.length; i++) {
|
||||
var target = this.runtime.targets[i];
|
||||
if (target.hasOwnProperty('drawableID') &&
|
||||
|
|
|
@ -21,10 +21,8 @@ function Clone(sprite, runtime) {
|
|||
* @type {?RenderWebGLWorker}
|
||||
*/
|
||||
this.renderer = null;
|
||||
// If this is not true, there is no renderer (e.g., running in a test env).
|
||||
if (typeof self !== 'undefined' && self.renderer) {
|
||||
// Pull from `self.renderer`.
|
||||
this.renderer = self.renderer;
|
||||
if (this.runtime) {
|
||||
this.renderer = this.runtime.renderer;
|
||||
}
|
||||
/**
|
||||
* ID of the drawable for this clone returned by the renderer, if rendered.
|
||||
|
|
12
vm.min.js
vendored
12
vm.min.js
vendored
File diff suppressed because one or more lines are too long
|
@ -14,6 +14,9 @@ module.exports = {
|
|||
{
|
||||
test: /\.json$/,
|
||||
loader: 'json-loader'
|
||||
}, {
|
||||
test: require.resolve('./src/index.js'),
|
||||
loader: 'expose?VirtualMachine'
|
||||
}
|
||||
]
|
||||
},
|
||||
|
|
Loading…
Reference in a new issue