From 93cc87a0ce435e4907fa04935f33da5d3560cb0e Mon Sep 17 00:00:00 2001 From: joshualowe1002 Date: Fri, 22 Mar 2024 16:00:43 +0000 Subject: [PATCH] Save/Load blocks --- .../builder/src/data/providers/icon-provider.ts | 6 ++++-- .../builder/src/views/builder/builder-model.ts | 10 ++++++++++ src/tools/builder/src/views/builder/builder.vue | 14 ++++++++++++++ 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/src/tools/builder/src/data/providers/icon-provider.ts b/src/tools/builder/src/data/providers/icon-provider.ts index fcc1faf..ea8c7a5 100644 --- a/src/tools/builder/src/data/providers/icon-provider.ts +++ b/src/tools/builder/src/data/providers/icon-provider.ts @@ -1,5 +1,5 @@ import { library } from "@fortawesome/fontawesome-svg-core"; -import { faPlus, faTimes, faRocket, faChevronDown, faChevronUp, faCheckCircle, faDatabase, faFileUpload, faFile, faArrowsRotate, faImage, faPuzzlePiece, faTrash } from "@fortawesome/free-solid-svg-icons"; +import { faPlus, faTimes, faRocket, faChevronDown, faChevronUp, faCheckCircle, faDatabase, faFileUpload, faFile, faArrowsRotate, faImage, faPuzzlePiece, faTrash, faSave, faUpload } from "@fortawesome/free-solid-svg-icons"; // Import SVG Icons library.add( @@ -15,5 +15,7 @@ library.add( faArrowsRotate, faImage, faPuzzlePiece, - faTrash + faTrash, + faSave, + faUpload ); \ No newline at end of file diff --git a/src/tools/builder/src/views/builder/builder-model.ts b/src/tools/builder/src/views/builder/builder-model.ts index 01b8ca0..3808a0f 100644 --- a/src/tools/builder/src/views/builder/builder-model.ts +++ b/src/tools/builder/src/views/builder/builder-model.ts @@ -209,6 +209,16 @@ export class BuilderModel extends ViewModelBase { }); } + public loadBlocks(): void { + if (localStorage.getItem("blocks")){ + Blockly.serialization.workspaces.load(JSON.parse(localStorage.getItem("blocks") as string), Blockly.getMainWorkspace()) + } + } + + public saveBlocks(): void { + localStorage.setItem("blocks", JSON.stringify(Blockly.serialization.workspaces.save(Blockly.getMainWorkspace()))); + } + /** * The path argument should be relative to the project root and contain the filename. * For example: some/folder/here/file.js diff --git a/src/tools/builder/src/views/builder/builder.vue b/src/tools/builder/src/views/builder/builder.vue index 52599ea..71b8391 100644 --- a/src/tools/builder/src/views/builder/builder.vue +++ b/src/tools/builder/src/views/builder/builder.vue @@ -50,6 +50,20 @@ @click="view.onBuilderTabClicked('media')" /> + + + +