diff --git a/README.md b/README.md
index 78dd842..effb49b 100644
--- a/README.md
+++ b/README.md
@@ -1,57 +1,93 @@
# scratch-poppy
-### Scratch-poppy is a Scratch 3 extension for Poppy robots
+Scratch-poppy is a Scratch 3 extension for [Poppy robots](https://github.com/poppy-project).
-## Getting started
+## :inbox_tray: Installation
-### Scratch VM and Scratch GUI installation
-
-This requires you to have **Git** and **Node.js** installed.
-First, you will have to clone **scratch-vm** and **scratch-gui** and to link both. For this, open a Command Prompt or Terminal in your development environment and follow the next steps:
-
- git clone https://github.com/LLK/scratch-gui
- git clone https://github.com/LLK/scratch-vm
- cd scratch-vm
- curl -sL https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh -o install_nvm.sh
- bash install_nvm.sh
- source ~/.profile
- rm install_nvm.sh
- nvm install 10.21.0
- nvm use 10.21.0
- npm install
- npm link
- cd ../scratch-gui
- npm install
- npm link scratch-vm
-
-
-### Scratch Poppy installation
-
-Now, you can clone this repository in the same development environment. For the installation you just have to execute the following lines to copy folders and some extension's additions at the right place:
-
- git clone https://github.com/poppy-project/scratch-poppy
- cd scratch-poppy
- bash install.sh
+### :page_facing_up: Scripted installation
+Requirements : [git](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git "sudo apt install git-all"), [node](https://nodejs.org/en/download/package-manager/ "sudo apt install nodejs"), [zip](https://linux.die.net/man/1/zip "sudo apt install zip"),
+#### Install scratch files & poppy's extension
+We need [scratch-vm](https://github.com/LLK/scratch-vm "GitHub scratch-vm repository") and [scratch-gui](https://github.com/LLK/scratch-gui "GitHub scratch-gui repository") repositories to create our application, we download and install them with **install-scratch-files.sh** script. Then, we install our Poppy extension with **install-extension.sh** script.
+```bash
+bash install-scratch-files.sh
+bash install-extension.sh
+```
-### Launching and editing
+#### Exporting application
+To use scratch with Poppy without having to use node on the raspberry, we export static files we just built as an archive. The archive will be uploaded as a release of poppy-scratch repository, and can be downloaded if the user wants to use Scratch.
+```bash
+bash export-scratch.sh
+```
-Now it is possible to launch scratch in the repository **scratch-gui** with:
-
- cd scratch-gui
- npm start
+### :keyboard: Manual installation
-Then go to http://localhost:8601/ in your web browser.
-Select the **Poppy extension** in the extension menu (with the button at the bottom left corner).
+#### Scratch VM and Scratch GUI installation
-If you want to edit blocks, the code are now situated at this path: `scratch-vm/src/extensions/scratch3_poppy/index.js`. You can find more informations to create a block here: https://github.com/LLK/scratch-vm/blob/develop/docs/extensions.md
-
-### TODO:
-
-* To implement the button "sequentially" and "play senquentially". These buttons allow to play different actions, for the first one, and moves, for the second, one after the other.
-
-* To implement the "wait" option in the "setMotorsGoTo" button to wait until a motor reaches its position before moving a second motor.
-
-* To add the different lists ("all motors", "all motors position", "all recorded moves" ...) directly in scratch (in the index.js file or in the scratch project)
-
-See the `Advanced.sb3` scratch project to see the last two points.
\ No newline at end of file
+First, you will have to clone **scratch-vm** and **scratch-gui** and to link both. For this, open a Command Prompt or Terminal in your development environment and follow the next steps:
+```bash
+git clone https://github.com/LLK/scratch-gui
+git clone https://github.com/LLK/scratch-vm
+cd scratch-vm
+curl -sL https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh -o install_nvm.sh
+bash install_nvm.sh
+source ~/.profile
+rm install_nvm.sh
+export NVM_DIR="$HOME/.nvm"
+[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # loads nvm without reopening a terminal
+nvm install 10.21.0
+nvm use 10.21.0
+npm install
+npm link
+cd ../scratch-gui
+npm install
+npm link scratch-vm
+```
+
+Then you will need to install Poppy's extension in Scratch files. In **scratch-poppy** run:
+```bash
+bash install-extension.sh
+```
+
+#### Building application
+To build the application, go to **scratch-gui** folder and run :
+```bash
+sudo npm run build
+```
+
+#### Exporting application
+To use scratch with Poppy without having to use node on the raspberry, we export static files we just built as an archive. The archive will be uploaded as a release of poppy-scratch repository, and can be downloaded if the user wants to use Scratch.
+To export the application as a zip archive, we need to rename the build folder as **scratch-application** in **scratch-gui**.
+```bash
+mv build scratch-application
+```
+Then zip it:
+```bash
+zip -r scratch-application.zip scratch-application
+```
+
+## :memo: Edit Poppy's Extension
+
+You can add more blocks by modifying **scratch_vm_files/scratch3_poppy** files.
+You can find information to create a block here: https://github.com/LLK/scratch-vm/blob/develop/docs/extensions.md
+
+To see and test your blocks run the script install_extension.sh and then go to **scratch-gui** folder. You can either:
+- run a server that will auto reload Scratch server each time you run the install_extension.sh script.
+For this, run:
+ ```bash
+ sudo npm start
+ ```
+ Then go to http://localhost:8601/ in your web browser.
+ Make sure to install the **Poppy extension** in the extension menu (button in the bottom left corner).
+
+
+- build the static files and open index.html with your browser. You will have to run those steps each time you run install_extention.sh script.
+ ```bash
+ sudo npm run build
+ cd build
+ firefox index.html # Or google-chrome, chromium-browser, ...
+ ```
+
+## :scroll: Todo
+
+* Implement the button "sequentially" and "play sequentially". These buttons allow playing different actions, for the first one, and moves, for the second, one after the other.
diff --git a/SB3/Advanced.sb3 b/SB3/Advanced.sb3
deleted file mode 100644
index f7ebd02..0000000
Binary files a/SB3/Advanced.sb3 and /dev/null differ
diff --git a/SB3/Draw.sb3 b/SB3/Draw.sb3
deleted file mode 100644
index 33f3bce..0000000
Binary files a/SB3/Draw.sb3 and /dev/null differ
diff --git a/SB3/For.sb3 b/SB3/For.sb3
deleted file mode 100644
index 600b8c1..0000000
Binary files a/SB3/For.sb3 and /dev/null differ
diff --git a/export-scratch.sh b/export-scratch.sh
new file mode 100755
index 0000000..08139c1
--- /dev/null
+++ b/export-scratch.sh
@@ -0,0 +1,32 @@
+#!/bin/bash
+
+#################################################################
+# Script Name : Export Scratch
+# Description : Builds the scratch application with the
+# Poppy extension and exports it as a zip archive.
+#################################################################
+
+ITALIC="\033[3m"
+GREEN="\033[92m"
+YELLOW="\033[93m"
+CLEAR="\033[0m"
+
+installation_folder=".."
+archive_name="scratch-application"
+
+# building application
+echo -e "${YELLOW}Building Scratch application (needs permissions)${CLEAR}"
+cd "$installation_folder/scratch-gui" || exit 2
+sudo npm run build
+echo -e "${GREEN}Build done!${CLEAR}\n"
+
+# renaming folder
+echo -ne "${YELLOW}Renaming ${ITALIC}build${CLEAR}${YELLOW} folder to ${ITALIC}${archive_name}${CLEAR}..."
+mv build $archive_name
+echo -e "${GREEN}Done!${CLEAR}\n"
+
+# zipping folder
+echo -e "${YELLOW}Zipping built application to ${ITALIC}${archive_name}.zip${CLEAR}..."
+cd - || exit 2
+zip -r "$archive_name.zip" "$installation_folder/scratch-gui/$archive_name"
+echo -e "${GREEN}Application successfully zipped!${CLEAR}\n"
diff --git a/install-extension.sh b/install-extension.sh
new file mode 100755
index 0000000..3584dc0
--- /dev/null
+++ b/install-extension.sh
@@ -0,0 +1,70 @@
+#!/bin/bash
+
+##############################################################
+# Script Name : Install Extension
+# Description : Installs the Poppy Extension to Scratch files
+##############################################################
+
+ITALIC="\033[3m"
+GREEN="\033[92m"
+YELLOW="\033[93m"
+CLEAR="\033[0m"
+
+installation_folder=".."
+
+##############################################################
+# Function add_require()
+# Adds a require line to a js file, if line does not already exist.
+# It first scans the 'file' for 'search' arg. If 'search' is not found,
+# it replaces 'where' arg by 'replace' arg.
+#
+# ARGUMENTS:
+# $1: search = line(s) to add, to check if it already exists
+# $2: where = where to put it ?
+# $3: replace = where "+" search
+# $4: file
+#
+# OUTPUTS:
+# Some echos of the progress of the script
+##############################################################
+
+add_require () {
+ echo -e "Adding a require to ${ITALIC}$4${CLEAR}"
+ if grep -q "$1" "$4"
+ then
+ # code if found
+ echo -e "${GREEN}Require already satisfied!${CLEAR}"
+ else
+ # code if not found
+ echo -e "${YELLOW}Require not satisfied!${CLEAR}"
+ sed -i "s/$2/$3/" "$4"
+ echo -e "${GREEN}Require has been added!${CLEAR}"
+ fi
+}
+
+
+find="poppy: () => require('..\/extensions\/scratch3_poppy'),"
+where="boost: () => require('..\/extensions\/scratch3_boost'),"
+replace="$where\n $find"
+file="$installation_folder/scratch-vm/src/extension-support/extension-manager.js"
+add_require "$find" "$where" "$replace" "$file"
+
+
+find="import poppyInsetIconURL from '.\/poppy\/poppy-small.png';"
+where="import boostConnectionTipIconURL from '.\/boost\/boost-button-illustration.svg';"
+replace="$where\n\nimport poppyIconURL from '.\/poppy\/poppy.png';\n$find"
+file="$installation_folder/scratch-gui/src/lib/libraries/extensions/index.jsx"
+add_require "$find" "$where" "$replace" "$file"
+
+find='extensionId: "poppy",'
+where="export default \["
+replace='export default [\n {\n name: "Poppy",\n extensionId: "poppy",\n collaborator: "Poppy-Station",\n iconURL: poppyIconURL,\n insetIconURL: poppyInsetIconURL,\n description: (\n \n ),\n featured: true,\n disabled: false,\n internetConnectionRequired: true,\n bluetoothRequired: false,\n },'
+file="$installation_folder/scratch-gui/src/lib/libraries/extensions/index.jsx"
+add_require "$find" "$where" "$replace" "$file"
+
+echo -e "\nCopying Poppy extension code to ${ITALIC}scratch-vm${CLEAR}... \c"
+cp -r ./scratch_vm_files/scratch3_poppy $installation_folder/scratch-vm/src/extensions
+echo -e "${GREEN}DONE!${CLEAR}"
+echo -e "Copying Poppy images to ${ITALIC}scratch-gui${CLEAR}... \c"
+cp -r ./scratch_gui_files/poppy $installation_folder/scratch-gui/src/lib/libraries/extensions
+echo -e "${GREEN}DONE!${CLEAR}"
diff --git a/install-scratch-files.sh b/install-scratch-files.sh
new file mode 100755
index 0000000..13e06a6
--- /dev/null
+++ b/install-scratch-files.sh
@@ -0,0 +1,132 @@
+#!/bin/bash
+
+##############################################################
+# Script Name : Install Scratch Files
+# Description : Clones the Scratch-VM and Scratch-GUI
+# repositories to the parent folder, if they do
+# not already exist. The script also takes care
+# of the installation of the different repos.
+##############################################################
+
+ITALIC="\033[3m"
+GREEN="\033[92m"
+YELLOW="\033[93m"
+CLEAR="\033[0m"
+
+installation_folder=".."
+
+
+##############################################################
+# Function clone_repository()
+# Clones a github repository in a given folder if the repo is
+# not already cloned.
+#
+# ARGUMENTS:
+# $1: repo link
+# $2: folder
+#
+# OUTPUTS:
+# Some echos of the progress of the script
+##############################################################
+
+clone_repository() {
+ repo_name=$(basename -s .git "$1")
+ echo -e "Cloning ${ITALIC}${YELLOW}$repo_name${CLEAR}"
+
+ if [ -d "$2/$repo_name" ]; then
+ # code if found
+ echo -e "${GREEN}Repository already installed!${CLEAR}\n"
+ else
+ # code if not found
+ echo -e "${YELLOW}Repository not installed!${CLEAR}"
+ git clone "$1" "$2/$repo_name"
+ echo -e "${GREEN}Repository has been installed!${CLEAR}\n"
+ fi
+}
+
+# Cloning vm & gui repos
+# if VM:
+# if GUI:
+# nothing to do, exit script
+# else:
+# install GUI
+# else:
+# if GUI
+# install VM
+# else:
+# install VM & GUI
+
+if [ -d "$installation_folder/scratch-vm" ]
+then
+ if [ -d "$installation_folder/scratch-gui" ]
+ then
+ echo -e "${GREEN}Nothing to do${CLEAR}"
+ echo -e "Script found scratch-vm & scratch-gui repositories in ${installation_folder}/ folder."
+ echo -e "If you have not installed these folders using the Poppy script, you have three choices to continue the installation:"
+ echo -e "- Delete the existing folders to get a fresh start and then re-run this script (install-scratch-files)."
+ echo -e "- Change the installation folder to reclone the Scratch folders elsewhere"
+ echo -e "- Install the folders by hand, following the steps described in the README, in the manual installation section."
+ exit 0
+ else
+ echo -e "${YELLOW}> Installing GUI${CLEAR}"
+ clone_repository "https://github.com/LLK/scratch-gui.git" $installation_folder
+ fi
+else
+ if [ -d "$installation_folder/scratch-gui" ]
+ then
+ echo -e "${YELLOW}> Installing VM${CLEAR}"
+ clone_repository "https://github.com/LLK/scratch-vm.git" $installation_folder
+ else
+ echo -e "${YELLOW}> Installing VM & GUI${CLEAR}"
+ clone_repository "https://github.com/LLK/scratch-vm.git" $installation_folder
+ clone_repository "https://github.com/LLK/scratch-gui.git" $installation_folder
+ fi
+fi
+echo -e "\n${GREEN}All repositories are downloaded!${CLEAR}\n"
+
+
+# Installing nvm
+echo -e "${YELLOW}Installing nvm...${CLEAR}"
+cd "$installation_folder/scratch-vm" || exit 2
+curl -sL https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh -o install_nvm.sh
+bash install_nvm.sh
+source ~/.profile
+rm install_nvm.sh
+export NVM_DIR="$HOME/.nvm"
+[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
+nvm install 10.21.0
+nvm use 10.21.0
+echo -e "${GREEN}NVM installed!${CLEAR}\n"
+
+
+# Installing scratch-vm node modules
+echo -e "${YELLOW}Installing scratch-vm node modules...${CLEAR}"
+npm install
+echo -e "${GREEN}scratch-vm node modules installed!${CLEAR}\n"
+
+
+# Linking scratch-vm
+echo -e "${YELLOW}Linking scratch-vm...${CLEAR}"
+npm link
+echo -e "${GREEN}scratch-vm linked!${CLEAR}\n"
+
+
+# Changing directory to scratch-gui
+cd ../scratch-gui || exit 2
+
+
+# Installing scratch-gui node modules
+echo -e "${YELLOW}Installing scratch-gui node modules...${CLEAR}"
+npm install
+echo -e "${GREEN}scratch-gui node modules installed!${CLEAR}\n"
+
+
+# Installing scratch-vm node modules
+echo -e "${YELLOW}Linking scratch-gui to scratch-vm...${CLEAR}"
+npm link scratch-vm
+echo -e "${GREEN}scratch-gui linked to scratch-vm!${CLEAR}\n"
+
+
+# Success message
+echo -e "${GREEN}Installation of scratch files complete!${CLEAR}"
+
diff --git a/install.sh b/install.sh
deleted file mode 100755
index 088b0a7..0000000
--- a/install.sh
+++ /dev/null
@@ -1,57 +0,0 @@
-#!/bin/bash
-
-ITALIC="\033[3m"
-GREEN="\033[92m"
-YELLOW="\033[93m"
-CLEAR="\033[0m"
-
-############################################################
-# Adds a require line to a js file,
-# if line does not already exist.
-#
-# ARGUMENTS:
-# $1: search = line to add, to check if it already exists
-# $2: where = where to put it ?
-# $3: replace = where "+" search
-# $4: file
-#
-# OUTPUTS:
-# Some echos of the progress of the script
-############################################################
-
-add_require () {
- echo -e "Adding a require to ${ITALIC}$4${CLEAR}"
- if grep -q "$1" $4
- then
- # code if found
- echo -e "${GREEN}Require already satisfied!${CLEAR}"
- else
- # code if not found
- echo -e "${YELLOW}Require not satisfied!${CLEAR}"
- sed -i "s/$2/$3/" $4
- echo -e "${GREEN}Require has been added!${CLEAR}"
- fi
-}
-
-
-find="poppy: () => require('..\/extensions\/scratch3_poppy'),"
-where="boost: () => require('..\/extensions\/scratch3_boost'),"
-replace="$where\n $find"
-file="../scratch-vm/src/extension-support/extension-manager.js"
-add_require "$find" "$where" "$replace" "$file"
-
-
-find="import poppyInsetIconURL from '.\/poppy\/poppy-small.png';"
-where="import boostConnectionTipIconURL from '.\/boost\/boost-button-illustration.svg';"
-replace="$where\n\nimport poppyIconURL from '.\/poppy\/poppy.png';\n$find"
-file="../scratch-gui/src/lib/libraries/extensions/index.jsx"
-add_require "$find" "$where" "$replace" "$file"
-
-find="extensionId: 'poppy',"
-where="helpLink: 'https:\/\/scratch.mit.edu\/wedo'"
-replace='$where\n },\n {\n name: "Poppy",\n extensionId: "poppy",\n collaborator: "rrandriamana",\n iconURL: poppyIconURL,\n insetIconURL: poppyInsetIconURL,\n description: (\n \n ),\n featured: true,\n disabled: false,\n internetConnectionRequired: true,\n bluetoothRequired: false,'
-file="../scratch-gui/src/lib/libraries/extensions/index.jsx"
-add_require "$find" "$where" "$replace" "$file"
-
-cp -r ./scratch_vm_files/scratch3_poppy ../scratch-vm/src/extensions
-cp -r ./scratch_gui_files/poppy ../scratch-gui/src/lib/libraries/extensions
diff --git a/scratch_raspoppy_files/install-raspoppy.sh b/scratch_raspoppy_files/install-raspoppy.sh
deleted file mode 100644
index 8548300..0000000
--- a/scratch_raspoppy_files/install-raspoppy.sh
+++ /dev/null
@@ -1,16 +0,0 @@
-#!/bin/bash
-
-search="boost: () => require('..\/extensions\/scratch3_boost'),"
-replace="boost: () => require('..\/extensions\/scratch3_boost'),\n poppy: () => require('..\/extensions\/scratch3_poppy'),"
-sed -i "s/$search/$replace/" ~/dev/snap/scratch-vm/src/extension-support/extension-manager.js
-
-search1="import boostConnectionTipIconURL from '.\/boost\/boost-button-illustration.svg';"
-replace1="import boostConnectionTipIconURL from '.\/boost\/boost-button-illustration.svg';\n\nimport poppyIconURL from '.\/poppy\/poppy.png';\nimport poppyInsetIconURL from '.\/poppy\/poppy-small.png';"
-sed -i "s/$search1/$replace1/" ~/dev/snap/scratch-gui/src/lib/libraries/extensions/index.jsx
-
-search2="helpLink: 'https:\/\/scratch.mit.edu\/wedo'"
-replace2="helpLink: 'https:\/\/scratch.mit.edu\/wedo'\n },\n {\n name: 'Poppy',\n extensionId: 'poppy',\n collaborator: 'rrandriamana',\n iconURL: poppyIconURL,\n insetIconURL: poppyInsetIconURL,\n description: (\n \n ),\n featured: true,\n disabled: false,\n internetConnectionRequired: true,\n bluetoothRequired: false,"
-sed -i "s/$search2/$replace2/" ~/dev/snap/scratch-gui/src/lib/libraries/extensions/index.jsx
-
-cp -r ~/dev/snap/scratch-poppy/scratch_vm_files/scratch3_poppy ~/dev/snap/scratch-vm/src/extensions
-cp -r ~/dev/snap/scratch-poppy/scratch_gui_files/poppy ~/dev/snap/scratch-gui/src/lib/libraries/extensions
diff --git a/scratch_raspoppy_files/start.sh b/scratch_raspoppy_files/start.sh
deleted file mode 100644
index 61ee45c..0000000
--- a/scratch_raspoppy_files/start.sh
+++ /dev/null
@@ -1,4 +0,0 @@
-#!/bin/bash
-
-cd ~/dev/snap/scratch-gui
-./node_modules/webpack-dev-server/bin/webpack-dev-server.js --host 0.0.0.0 --disable-host-check
\ No newline at end of file
diff --git a/scratch_vm_files/scratch3_poppy/index.js b/scratch_vm_files/scratch3_poppy/index.js
index 4e21470..3879183 100644
--- a/scratch_vm_files/scratch3_poppy/index.js
+++ b/scratch_vm_files/scratch3_poppy/index.js
@@ -374,7 +374,7 @@ class Scratch3Poppy {
arguments: {
TEXT: {
type: ArgumentType.STRING,
- defaultValue: ' '
+ defaultValue: 'My custom alert'
}
}
}
@@ -494,14 +494,10 @@ class Scratch3Poppy {
}
+ // TODO: (Antoine) Implement QR code reader
detectMarker(args) {
let argText = args.TEXT.toString();
- let url = this._robotUrl + '/detect/' + argText;
- axios.get(url)
- .then(resp => resp.data)
- .catch(() => {
- return 'Error with the connection';
- });
+ return "Block is not implemented yet."
}
/**
@@ -679,7 +675,10 @@ class Scratch3Poppy {
}
}
- // Todo : popup
+ /**
+ * Gives a custom alert to the user
+ * @param args custom message is stored in args.TEXT
+ */
popup(args) {
let argText = args.TEXT.toString();
return alert(argText);
@@ -782,14 +781,10 @@ class Scratch3Poppy {
}
}
-
+ // Todo : initRobot
initRobot(args) {
let argText = args.TEXT.toString();
- let url = 'http://poppy.local/api/' + argText;
- axios.get(url)
- .catch(() => {
- return 'Error with parameter.';
- });
+ return 'Block not implemented yet';
}
deleteRecord(args) {
diff --git a/uninstall.sh b/uninstall.sh
new file mode 100644
index 0000000..601ab8b
--- /dev/null
+++ b/uninstall.sh
@@ -0,0 +1,22 @@
+#!/bin/bash
+
+##############################################################
+# Script Name : Uninstall Scratch Files
+# Description : Removes scratch-vm and scratch-gui from your
+# installation folder. It can be used to make a
+# clean reinstallation of scratch-poppy.
+##############################################################
+
+GREEN="\033[92m"
+CLEAR="\033[0m"
+
+read -p "Do you want to delete all scratch repositories ? (y/n) " -n 1 -r
+echo # (optional) move to a new line
+if [[ $REPLY =~ ^[Yy]$ ]]
+then
+ echo -ne "removing scratch-vm scratch-gui folders..."
+ # Change installation path here. No installation_folder variable is used, just to make sure you never run a command
+ # like sudo rm -rf / unintentionally...
+ rm -rvf ../scratch-vm ../scratch-gui
+ echo -e " ${GREEN}Done!${CLEAR}"
+fi