Skip to content

Commit

Permalink
inter-file backpack
Browse files Browse the repository at this point in the history
  • Loading branch information
JosephAbbey committed Nov 1, 2022
1 parent 37bd55d commit bcd299f
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 3 deletions.
1 change: 1 addition & 0 deletions scratch-vhdl-vscode/.vscodeignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ vsc-extension-quickstart.md
**/@types/**
node_modules/**
!node_modules/blockly/blockly.min.js
!node_modules/@blockly/workspace-backpack/dist/index.js
things_to_try.txt
.eslintignore
38 changes: 38 additions & 0 deletions scratch-vhdl-vscode/media/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,41 @@ document.addEventListener('DOMContentLoaded', function () {
});
return new Promise((resolve) => requests[rid++] = resolve);
};
window.addEventListener("message", (message) => message.data.type == "getState" && requests[message.data.id](message.data.value));
const getState = (key, a) => {
vscode.postMessage({
type: "getState",
key,
a,
id: rid
});
return new Promise((resolve) => requests[rid++] = resolve);
};
window.addEventListener("message", (message) => message.data.type == "setState" && requests[message.data.id]());
const setState = (key, value) => {
vscode.postMessage({
type: "setState",
key,
value,
id: rid
});
return new Promise((resolve) => requests[rid++] = resolve);
};

//#region storage_backpack
class StorageBackpack extends Backpack {
open() {
if (!this.isOpenable_()) {
return;
}
getState("bp_contents", []).then((d) => (this.contents_ = d, super.open()));
}
onContentChange_() {
super.onContentChange_();
setState("bp_contents", this.contents_)
}
}
//#endregion

const builtinLibs = {};

Expand Down Expand Up @@ -1036,6 +1071,9 @@ document.addEventListener('DOMContentLoaded', function () {
renderer: "zelos"
});

const bp = new StorageBackpack(ws);
bp.init();

let entity = {};
let libraries = {};
let signals = {};
Expand Down
22 changes: 20 additions & 2 deletions scratch-vhdl-vscode/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions scratch-vhdl-vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
"typescript": "^4.8.4"
},
"dependencies": {
"@blockly/workspace-backpack": "^3.0.2",
"blockly": "^9.0.0"
}
}
35 changes: 35 additions & 0 deletions scratch-vhdl-vscode/src/scratchVHDLEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,17 @@ export class ScratchVHDLEditorProvider
vscode.Uri.joinPath(this._context.extensionUri, 'media', 'main.js')
);

const scriptBlocklyBackpackUri = webview.asWebviewUri(
vscode.Uri.joinPath(
this._context.extensionUri,
'node_modules',
'@blockly',
'workspace-backpack',
'dist',
'index.js'
)
);

const scriptBlocklyUri = webview.asWebviewUri(
vscode.Uri.joinPath(
this._context.extensionUri,
Expand Down Expand Up @@ -477,6 +488,7 @@ export class ScratchVHDLEditorProvider
<div id="root"></div>
<script src="${scriptBlocklyUri}"></script>
<script src="${scriptBlocklyBackpackUri}"></script>
<script src="${scriptUri}"></script>
</body>
</html>`;
Expand Down Expand Up @@ -633,6 +645,29 @@ export class ScratchVHDLEditorProvider
});
return;
}

case 'setState':
this._context.globalState.setKeysForSync([message.key]);
this._context.globalState
.update(message.key, message.value)
.then(() =>
panel.webview.postMessage({
type: 'setState',
id: message.id,
})
);
return;

case 'getState':
panel.webview.postMessage({
type: 'getState',
id: message.id,
value: this._context.globalState.get<any>(
message.key,
message.a
),
});
return;
}
}
}
Expand Down
1 change: 0 additions & 1 deletion scratch-vhdl-vscode/things_to_try.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
https://google.github.io/blockly-samples/examples/backpack-demo/
https://google.github.io/blockly-samples/plugins/typed-variable-modal/test/
https://google.github.io/blockly-samples/plugins/strict-connection-checker/test/
https://google.github.io/blockly-samples/plugins/block-dynamic-connection/test/

0 comments on commit bcd299f

Please sign in to comment.