Skip to content

Commit

Permalink
Save/Load blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshuaLowe1002 committed Mar 22, 2024
1 parent d8c9a71 commit 93cc87a
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/tools/builder/src/data/providers/icon-provider.ts
Original file line number Diff line number Diff line change
@@ -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(
Expand All @@ -15,5 +15,7 @@ library.add(
faArrowsRotate,
faImage,
faPuzzlePiece,
faTrash
faTrash,
faSave,
faUpload
);
10 changes: 10 additions & 0 deletions src/tools/builder/src/views/builder/builder-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions src/tools/builder/src/views/builder/builder.vue
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,20 @@
@click="view.onBuilderTabClicked('media')"
/>

<ib-button
label="Load"
size="sm"
:icon="['fas', 'upload']"
@click="view.loadBlocks()"
/>

<ib-button
label="Save"
size="sm"
:icon="['fas', 'save']"
@click="view.saveBlocks()"
/>

<ib-button
label="Publish"
size="sm"
Expand Down

0 comments on commit 93cc87a

Please sign in to comment.