mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2025-03-14 01:09:51 -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": {
|
"devDependencies": {
|
||||||
"eslint": "2.7.0",
|
"eslint": "2.7.0",
|
||||||
|
"expose-loader": "0.7.1",
|
||||||
"highlightjs": "8.7.0",
|
"highlightjs": "8.7.0",
|
||||||
"json-loader": "0.5.4",
|
"json-loader": "0.5.4",
|
||||||
"scratch-blocks": "git+https://git@github.com/LLK/scratch-blocks.git#develop",
|
"scratch-blocks": "git+https://git@github.com/LLK/scratch-blocks.git#develop",
|
||||||
|
|
|
@ -21,7 +21,7 @@ var loadProject = function () {
|
||||||
|
|
||||||
window.onload = function() {
|
window.onload = function() {
|
||||||
// Lots of global variables to make debugging easier
|
// Lots of global variables to make debugging easier
|
||||||
// Instantiate the VM worker.
|
// Instantiate the VM.
|
||||||
var vm = new window.VirtualMachine();
|
var vm = new window.VirtualMachine();
|
||||||
window.vm = vm;
|
window.vm = vm;
|
||||||
|
|
||||||
|
@ -39,7 +39,9 @@ window.onload = function() {
|
||||||
|
|
||||||
// Instantiate the renderer and connect it to the VM.
|
// Instantiate the renderer and connect it to the VM.
|
||||||
var canvas = document.getElementById('scratch-stage');
|
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.
|
// Instantiate scratch-blocks and attach it to the DOM.
|
||||||
var toolbox = document.getElementById('toolbox');
|
var toolbox = document.getElementById('toolbox');
|
||||||
|
|
|
@ -199,6 +199,14 @@ Runtime.prototype.clearEdgeActivatedValues = function () {
|
||||||
this._edgeActivatedHatValues = {};
|
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.
|
* Handle an animation frame from the main thread.
|
||||||
*/
|
*/
|
||||||
Runtime.prototype.animationFrame = function () {
|
Runtime.prototype.animationFrame = function () {
|
||||||
if (self.renderer) {
|
if (this.renderer) {
|
||||||
self.renderer.draw();
|
this.renderer.draw();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
13
src/index.js
13
src/index.js
|
@ -162,6 +162,14 @@ VirtualMachine.prototype.createEmptyProject = function () {
|
||||||
this.emitWorkspaceUpdate();
|
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.
|
* Handle a Blockly event for the current editing target.
|
||||||
* @param {!Blockly.Event} e Any Blockly event.
|
* @param {!Blockly.Event} e Any Blockly event.
|
||||||
|
@ -227,8 +235,5 @@ VirtualMachine.prototype.emitWorkspaceUpdate = function () {
|
||||||
'xml': this.editingTarget.blocks.toXML()
|
'xml': this.editingTarget.blocks.toXML()
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
/**
|
|
||||||
* Export and bind to `window`
|
|
||||||
*/
|
|
||||||
module.exports = VirtualMachine;
|
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) {
|
Mouse.prototype._activateClickHats = function (x, y) {
|
||||||
if (self.renderer) {
|
if (this.runtime.renderer) {
|
||||||
var drawableID = self.renderer.pick(x, y);
|
var drawableID = this.runtime.renderer.pick(x, y);
|
||||||
for (var i = 0; i < this.runtime.targets.length; i++) {
|
for (var i = 0; i < this.runtime.targets.length; i++) {
|
||||||
var target = this.runtime.targets[i];
|
var target = this.runtime.targets[i];
|
||||||
if (target.hasOwnProperty('drawableID') &&
|
if (target.hasOwnProperty('drawableID') &&
|
||||||
|
|
|
@ -21,10 +21,8 @@ function Clone(sprite, runtime) {
|
||||||
* @type {?RenderWebGLWorker}
|
* @type {?RenderWebGLWorker}
|
||||||
*/
|
*/
|
||||||
this.renderer = null;
|
this.renderer = null;
|
||||||
// If this is not true, there is no renderer (e.g., running in a test env).
|
if (this.runtime) {
|
||||||
if (typeof self !== 'undefined' && self.renderer) {
|
this.renderer = this.runtime.renderer;
|
||||||
// Pull from `self.renderer`.
|
|
||||||
this.renderer = self.renderer;
|
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* ID of the drawable for this clone returned by the renderer, if rendered.
|
* 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$/,
|
test: /\.json$/,
|
||||||
loader: 'json-loader'
|
loader: 'json-loader'
|
||||||
|
}, {
|
||||||
|
test: require.resolve('./src/index.js'),
|
||||||
|
loader: 'expose?VirtualMachine'
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in a new issue