Skip to content

prototype snap integration with CPO #462

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Aug 22, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Use new onload callback to load program blocks immediately after snap…
… loads
  • Loading branch information
pcardune committed Feb 12, 2023
commit 0dc6f7c0cc229b4c562e1eb05dab39e2fa16d566
24 changes: 10 additions & 14 deletions src/web/blocks.html
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,7 @@ <h2>Announcements</h2>
.attr("height", 300)
.attr("style", "position: absolute; z-index:8900; border: 1px solid black;");
$("#main").prepend(canvas);
var localStorageKey = "snap-blocks-draft"
var ide = new IDE_Morph({
path: 'js/snap',
load: 'js/transpile.xml',
Expand All @@ -513,7 +514,14 @@ <h2>Announcements</h2>
noImports: true,
noOwnBlocks: true,
noRingify: true,
noUserSettings: true
noUserSettings: true,
onload: () => {
// load saved draft from local storage into snap ide
const draft = localStorage.getItem(localStorageKey);
if (draft != null) {
ide.currentSprite.synchScriptsFrom(draft);
}
}
});
var loop = () => {
requestAnimationFrame(loop);
Expand All @@ -522,21 +530,9 @@ <h2>Announcements</h2>
world = new WorldMorph(document.getElementById('world'), false);
ide.openIn(world);
ide.addMessageListener('update', txt => {
console.log(txt);
CPO.editor.cm.setValue(txt);
localStorage.setItem("snap-blocks-draft", ide.currentSprite.scriptsOnlyXML());
localStorage.setItem(localStorageKey, ide.currentSprite.scriptsOnlyXML());
});

// load saved draft from local storage into snap ide
const draft = localStorage.getItem("snap-blocks-draft");
if (draft != null) {
setTimeout(() => {
// TODO: figure out how to tell when the IDE is ready
// to have scripts loaded. Waiting an arbitrary amount
// of time is error prone.
ide.currentSprite.synchScriptsFrom(draft);
}, 500);
}
requestAnimationFrame(loop);
</script>

Expand Down
2 changes: 1 addition & 1 deletion src/web/js/snap