Update zelos rendering playground so that screenshots reflect state of the workspace (#3491)

This commit is contained in:
Sam El-Husseini
2019-12-09 08:33:00 -08:00
committed by GitHub
parent 7d24276721
commit 7baa192d59
2 changed files with 45 additions and 25 deletions

View File

@@ -37,17 +37,28 @@
}
});
try {
Blockly.Xml.domToWorkspace(Blockly.Xml.textToDom(xml), workspace);
var topBlock = workspace.getTopBlocks()[0];
workspaceToSvg_(workspace, function (datauri) {
window.parent.postMessage({
type: 'svg',
from: 'pxtblockly',
text: datauri
}, '*');
});
} catch { }
Blockly.Xml.domToWorkspace(Blockly.Xml.textToDom(xml), workspace);
function postChange() {
try {
var topBlock = workspace.getTopBlocks()[0];
workspaceToSvg_(workspace, function (datauri) {
window.parent.postMessage({
type: 'svg',
from: 'pxtblockly',
text: datauri
}, '*');
});
} catch { }
}
workspace.addChangeListener(function(e) {
if (e.type != 'ui') {
postChange();
}
});
postChange();
});
</script>
</body>

View File

@@ -32,7 +32,6 @@
<script>
goog.require('Blockly.blockRendering.Debug');
goog.require('Blockly.zelos.Renderer');
goog.require('Blockly.zelos.Themes.Classic');
// Blockly.blockRendering.startDebugger();
// This stub is a workaround in order to load pxt-blockly blocks, as they
@@ -62,7 +61,6 @@
drag: true,
wheel: false,
},
theme: Blockly.zelos.Themes.Classic,
zoom: {
wheel: true,
startScale: 2,
@@ -73,19 +71,30 @@
constants.FIELD_TEXT_FONTWEIGHT = 'bold';
constants.FIELD_TEXT_FONTFAMILY = 'Helvetica Neue';
try {
Blockly.Xml.domToWorkspace(Blockly.Xml.textToDom(xml), workspace);
var topBlock = workspace.getTopBlocks()[0];
workspaceToSvg_(workspace, function (datauri) {
window.parent.postMessage({
type: 'svg',
from: 'zelos',
text: datauri
}, '*');
}, document.getElementById('blocklycss').innerText);
} catch (err) {
console.error(err);
Blockly.Xml.domToWorkspace(Blockly.Xml.textToDom(xml), workspace);
function postChange() {
try {
var topBlock = workspace.getTopBlocks()[0];
workspaceToSvg_(workspace, function (datauri) {
window.parent.postMessage({
type: 'svg',
from: 'zelos',
text: datauri
}, '*');
}, document.getElementById('blocklycss').innerText);
} catch (err) {
console.error(err);
}
}
workspace.addChangeListener(function(e) {
if (e.type != 'ui') {
postChange();
}
});
postChange();
});
</script>
</body>