#!/bin/bash

option=$1

upload(){
    cargo build -p $option --release && cp ./target/arduboy/release/lib$option.a ./arduboy-rust/Wrapper-Project/lib/libgame.a && cd arduboy-rust/Wrapper-Project/ && pio run -v -t upload && cp ./.pio/build/arduboy/firmware.hex ./build/$option.hex && pio run -t clean && rm lib/libgame.a && cd ../../
}

if [ -z "$option" ]
then
    cargo build -p game --release && cp ./target/arduboy/release/libgame.a ./arduboy-rust/Wrapper-Project/lib/libgame.a && cd arduboy-rust/Wrapper-Project/ && pio run -v -t upload && cp ./.pio/build/arduboy/firmware.hex ./build/game.hex && pio run -t clean && rm lib/libgame.a && cd ../../
elif [ "$option" = "doc" ] 
then
    cargo doc -p arduboy-rust && rm -r ./docs/doc/ && cp -r ./target/arduboy/doc ./docs/
elif [ "$option" = "snake" ] 
then
    upload
elif [ "$option" = "pong" ] 
then
    upload
elif [ "$option" = "drboy" ] 
then
    upload
elif [ "$option" = "rustacean" ] 
then
    upload
elif [ "$option" = "tone" ] 
then
    upload
elif [ "$option" = "eeprom" ] 
then
    upload
elif [ "$option" = "eeprom-byte" ] 
then
    cargo build -p eeprom-byte --release && cp ./target/arduboy/release/libeeprom_byte.a ./arduboy-rust/Wrapper-Project/lib/libgame.a && cd arduboy-rust/Wrapper-Project/ && pio run -v -t upload && cp ./.pio/build/arduboy/firmware.hex ./build/eeprom-byte.hex && pio run -t clean && rm lib/libgame.a && cd ../../
elif [ "$option" = "progmem" ] 
then
    upload
elif [ "$option" = "demo2" ] 
then
    upload
elif [ "$option" = "demo3" ] 
then
    upload
elif [ "$option" = "demo4" ] 
then
    upload
elif [ "$option" = "demo5" ] 
then
    upload
elif [ "$option" = "demo6" ] 
then
    upload
else
    echo Usage: for uploading your game \|./run.sh
    echo Usage: for uploading an example game \| ./run.sh \<Example Game\>
fi
