diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..d494858 --- /dev/null +++ b/.envrc @@ -0,0 +1,273 @@ +source <(direnv stdlib) + +export WORKSPACE_EXT_ROOT_PATH="$HOME/@Dev/MakecodeArcade/@Extensions/@Daddy/" +export REPOS_ROOT_PATH="$HOME/@Dev/MakecodeArcade/@Extensions/@Daddy/@Repos/" +export WORKSPACE_PATH="$HOME/@Dev/MakecodeArcade/@Extensions/@Daddy/switchcase/" +export REPO_PATH="$HOME/@Dev/MakecodeArcade/@Extensions/@Daddy/@Repos/makecode-ext-switchcase/" + +export EDITOR="code" + +export REPO_REMOTE_URL="https://github.com/seriussoft/makecode-ext-switchcase.git" +export REPO_BRANCH_DEV="dev" +export REPO_BRANCH_DEV_LOCAL="dev-local-rpi400" + +# +# Functions +# + +# TODO: Create a localized shortcut for copyWSToRepo() and copyRepoToWS() that doesn't need any arguments + +# Copy over code FROM workspace-directory [--ws] TO local-repo-directory [--repo] +copyWSToRepo() { + + use_default_dirs_if_empty=0 + use_default_dirs_only=0 + same_directories_provided=0 + run_simulation_without_sideeffects=0 + + while [[ $# -gt 0 ]]; do + case "$1" in + --help|-help|-h) + #echo "copyWSToRepo [--ws|-ws|w] {workspace_directory} [--repo|-repo|-r] {local_repo_directory} [--default|-default|-d] (will use the default values found int $WORKSPACE_DIR and $LOCAL_REPO_DIR) [--help|-help|-h] # Help flag forces an exit without running any of the script" + # FULL MANPAGES/Documentation on how to use this function and its flags properly printed to screen with the following function call... + showHelp_copyWSandRepo "copyWSToRepo" + return + ;; + --ws|-ws|-w) + workspace_dir="$2" + shift 2 + ;; + --repo|-repo|-r) + repo_dir="$2" + shift 2 + ;; + --default|-default|-d) + use_default_dirs_if_empty=1 + shift + ;; + --ignoreargs|-ignoreargs|-i) + use_default_dirs_only=1 + shift + ;; + --same|-same|-s) + echo "Because you provided the --same flag (or derivative variant), no destructive or side-effect-producing code will be run. Instead, you will see what WOULD have run had you provided both directories and appropriate flags --ws && --repo..." + same_directories_provided=1 + run_simulation_without_sideeffects=1 + ;; + *) + # invalid flag or argument; let's just shift the args[] and move on + shift + ;; + esac + done + + # indicates how many (0, 1, or 2) of the two directories are empty BEFORE all other flags are checked + empty_count_prework=0 + # indicates how many (0, 1, or 2) of the two directories are empty AFTER all flags are checked + empty_count_postwork=0 + # indicates no value was provided for ws if value > 0 + ws_empty=0 + # indicates no value was provided for repo if value > 0 + repo_empty=0 + # indicates EITHER --default OR --ignoreargs if value > 0 + using_defaults=0 + + # indicate that any or non of the default flags (--default or --ignoreargs) were provided + if [ $use_default_dirs_if_empty -gt 0 ] || [ $use_default_dirs_only -gt 0 ]; then + using_defaults=1 + fi + + # if BOTH directories are empty, run through logic checks so we can determine whether to simulate, run, or error out... + if [ -z "$workspace_dir" ] && [ -z "$repo_dir" ]; then + empty_count_prework=2 + ws_empty=1 + repo_empty=1 + # if NOT using_defaults, then empty_count_postwork is 2, just like $empty_count_prework, else 0 + if [ $using_defaults -lt 1 ]; then + empty_count_postwork=2 + fi + # if ONLY $workspace_dir is empty, run through logic checks so we can determine whether to simulate, run, or error out... + elif [ -z "$workspace_dir" ]; then + empty_count_prework=1 + ws_empty=1 + # if NOT using_defaults, then empty_count_postwork is 1, just like $empty_count_prework, else 0 + if [ $using_defaults -lt 1 ]; then + empty_count_postwork=1 + fi + # if ONLY $repo_dir is empty, run through logic checks so we can determine whether to simulate, run, or error out... + elif [ -z "$repo_dir" ]; then + # just the $repo_dir is empty, but we need to check if either of the default flag are checked + empty_count_prework=1 + repo_empty=1 + # if NOT using_defaults, then empty_count_postwork is 1, just like $empty_count_prework, else 0 + if [ $using_defaults -lt 1 ]; then + empty_count_postwork=1 + fi + else + # all values are provided, no more logic needs to be run so far... + echo "" + fi + + # assign the default value if no value is provided and you supplied the default flag: [-d|--default|-default] + if [ $use_default_dirs_if_empty -gt 0 ]; then + workspace_dir=${workspace_dir:-$WORKSPACE_PATH} + repo_dir=${repo_dir:-$REPO_PATH} + fi + + # overrides all situations, except [--same|-same|-s], so it needs to be after $use_default_dirs_if_empty - this depends on [-i|--ignoreargs|-ignoreargs] + if [ $use_default_dirs_only -gt 0 ]; then + workspace_dir=$WORKSPACE_PATH + repo_dir=$REPO_PATH + fi + + # lets run a simulation of what WOULD have been executed had we NOT provided the --same|-same|-s flag + if [ $run_simulation_without_sideeffects -gt 0 ]; then + # need to finish out the logic for the following variables: + # TODO: Handle logic for $empty_count_prework - this may have originally been intended for custom logic within $use_default_dirs_if_empty or $use_default_dirs_only + # TODO: Handle logic for $empty_count_postwork - this may have originally been intended for custom logic with the error handler, and the $using_defaults variable + # TODO: Handle logic for $ws_empty - this was intended for governing which of the directories took priority and which one to NOT default a value to from the directories... + # TODO: Handle logic for $repo_empty - see the entry for $ws_empty; this is a pair with $ws_empty so far as HOW the logic works... + # TODO: Handle logic for $using_defaults - related to the $empty_count_prework and $empty_count_postwork entries above and the logic related to the $use_default_dirs_if_empty and $use_default_dirs_only variables... + + # print out the call that would have run if the [--same|-same|-s] flag was NOT enabled. This is as far as the simulation can go today... + echo "cp -a \"${workspace_dir}/.\" \"$repo_dir/\"" + # not an error, so return like normal to prevent confusion surrounding + return + fi + + # backup to keep from odd behavior or wonky/confusing error messages + if [ -z "$workspace_dir" ] || [ -z "$repo_dir" ]; then + echo -e "Error: workspace_directory and local_repo_directory MUST be specified. \nIf you want to use the default directories for this project, then you need to use the [-d|--default|-default] flag or the [-i|--ignoreargs|-ignoreargs] flag AND to assign them to the proper local shared variables at the top of our '.envrc' file and activate it with 'direnv allow'. \nFor more information, use the '-h' flag when running this function." + return 1 + fi + + cp -a "${workspace_dir}/." "$repo_dir/" +} + +# TODO: Once copyWSToRepo is completed, copy code over to this method and update the simulation, error, and cp execution code and save. +# Copy over code FROM local-repo-directory [--repo] TO workspace-directory --ws +copyRepoToWS() { + + while [[ $# -gt 0 ]]; do + case "$1" in + --help|-help|-h) + echo "copyRepoToWS [--ws|-ws|w] {workspace_directory} [--repo|-repo|-r] {local_repo_directory} [--help|-help|-h] # Help flag forces an exit without running any of the script" + return + ;; + --ws|-ws|-w) + workspace_dir="$2" + shift 2 + ;; + --repo|-repo|-r) + repo_dir="$2" + shift 2 + ;; + esac + done + + + cp -a "${repo_dir}/." "${workspace_dir}/" +} + + +# Perform the traditional git-add-*, git-commit-with-msg and git-push. $1 will auto pull the text you provide in `gitpush "This is my commit message"` +gitpush() { + git add . + git commit -m "$1" + git push +} + +# > git clone https://github.com/seriussoft/makecode-ext-switchcase.git +# > cd makecode-ext-switchcase +# +# > git checkout dev +# > git add . +# > git commit -m "Merge and promote current code from rpi400" +# > git push origin dev-local-rpi400 + +# Perform the traditional git-checkout +gitcheck() { + + repo="" + repo_given=false + branch_remote="" + branch_remote_given=false + branch_local="" + branch_local_given=false + + while [[ $# -gt 0 ]]; do + case $1 in + -help|--help|-h) + echo "gitcheck [--repo|-repo|-r] {repo_url} [--branch|-branch|-b] {remote_branch to check out and default local_branch if no local_branch is supplied} [--localbranch|-localbranch|-l] {local_branch to use with checked out repository} [--help|-help|-h] # Help flag forces an exit without running any of the script" + return + ;; + -repo|--repo|-r) + repo="$2" + shift 2 + ;; + -branch|--branch|-b) + branch_remote="$2" + shift 2 + ;; + -local|--localbranch|-l) + branch_local="$2" + shift 2 + ;; + esac + done + + if [ -z "$branch_remote" ]; then + echo "ERROR: Missing Remote Branch" + fi + + if [ -z "$branch_local" ]; then + echo "ERROR: Missing Local Branch" + fi + + if [ -z "$repo" ]; then + echo "ERROR: Missing Repo" + fi + + git checkout -b "${repo}" + +} + + + +# you need to provide the name of the function (either 'copyWSToRepo' or 'copyRepoToWS') +showHelp_copyWSandRepo() { + $funcName=$1 + if [ -z $funcName ]; then + echo "ERROR: Cannot provide the correct output without a proper function name added as an argument after your function call to showFunc_copyWSandRepo" + fi + + # echo -e "copyWSToRepo [--help|-help|-h] [--ws|-ws|-w] {workspace_dir} [--repo|-repo|-r] {local_repo_dir} [--default|-default|-d] [--ignoreargs|-ignoreargs|-i] [--same|-same|-s]\n" + echo -e "$funcName [--help|-help|-h] [--ws|-ws|-w] {workspace_dir} [--repo|-repo|-r] {local_repo_dir} [--default|-default|-d] [--ignoreargs|-ignoreargs|-i] [--same|-same|-s]\n" + + printf "%-25s %s\n" "--help|-help|-h" "Show help and exit safely" + printf "%-25s %s\n" "--ws|-ws|-w {workspace-dir}" "Workspace directory \(required unless --default or --ignoreargs\)" + printf "%-25s %s\n" "--repo|-repo|-r {local-repo-dir}" "Local repo directory \(required unless --default or --ignoreargs\)" + printf "%-25s %s\n" "--default|-default|-d" "Use default values if missing/empty" + printf "%-25s %s\n" "--ignoreargs|-ignoreargs|-i" "Always use default values, ignore other args" + printf "%-25s %s\n" "--same|-same|-s" "Skip copy if workspace and repo are the same" + + echo -e "\nSYNTAX & DETAILS:\n" + + printf "%-25s %s\n\n" "--help|-help|-h" \ + "Stops execution safely and returns help information specific to this function call and its flags." + + printf "%-25s %s\n\n" "--ws|-ws|-w {workspace-dir}" \ + "Specifies your workspace directory. Required unless --default or --ignoreargs is used. If not provided or empty, the function errors." + + printf "%-25s %s\n\n" "--repo|-repo|-r {local-repo-dir}" \ + "Specifies your local repo directory. Required unless --default or --ignoreargs is used. If not provided or empty, the function errors." + + printf "%-25s %s\n\n" "--default|-default|-d" \ + "Uses default values for missing or empty directory arguments. Does not override provided values unless they are empty." + + printf "%-25s %s\n\n" "--ignoreargs|-ignoreargs|-i" \ + "Forces use of default values, ignoring any other directory arguments. Overrides --default." + + printf "%-25s %s\n\n" "--same|-same|-s" \ + "Skips the copy operation if workspace and repo are the same. Overrides other directory flags." +} diff --git a/.github/workflows/makecode.yml b/.github/workflows/makecode.yml new file mode 100644 index 0000000..9497b8f --- /dev/null +++ b/.github/workflows/makecode.yml @@ -0,0 +1,13 @@ +name: MakeCode Build +on: + push: + workflow_dispatch: + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + with: + submodules: recursive + - run: npx makecode diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..cfccae1 --- /dev/null +++ b/.gitignore @@ -0,0 +1,12 @@ +# MakeCode +built +node_modules +yotta_modules +yotta_targets +pxt_modules +.pxt +_site +*.db +*.tgz +.header.json +.simstate.json \ No newline at end of file diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 0000000..292912b --- /dev/null +++ b/.prettierrc @@ -0,0 +1 @@ +{"arrowParens":"avoid","semi":false,"tabWidth":4} \ No newline at end of file diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 0000000..416fdc8 --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,5 @@ +{ + "recommendations": [ + "ms-edu.pxt-vscode-web" + ] +} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..c7a2e80 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,30 @@ +{ + "editor.formatOnType": true, + "files.autoSave": "afterDelay", + "files.watcherExclude": { + "**/.git/objects/**": true, + "**/built/**": true, + "**/node_modules/**": true, + "**/yotta_modules/**": true, + "**/yotta_targets": true, + "**/pxt_modules/**": true, + "**/.pxt/**": true + }, + "files.associations": { + "*.blocks": "html", + "*.jres": "json" + }, + "search.exclude": { + "**/built": true, + "**/node_modules": true, + "**/yotta_modules": true, + "**/yotta_targets": true, + "**/pxt_modules": true, + "**/.pxt": true + }, + "files.exclude": { + "**/pxt_modules": true, + "**/.pxt": true, + "**/mkc.json": true + } +} \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..e69de29 diff --git a/case.ts b/case.ts new file mode 100644 index 0000000..82d2690 --- /dev/null +++ b/case.ts @@ -0,0 +1,19 @@ + + + +namespace switchCase { + + /** + * Case Block Container + */ + //% block="case $match" + //% blockId=switchcase_case_block + //% group="Control" + //% weight=90 + //% draggableParameters + //% draggableStatement=true + export function caseBlock(match: any): void { + //Placeholder for CodeGen + } + +} \ No newline at end of file diff --git a/main.ts b/main.ts new file mode 100644 index 0000000..3a4b3c7 --- /dev/null +++ b/main.ts @@ -0,0 +1,24 @@ +/** + * This is the main file for your project. + * + * Create images, tilemaps, animations, and songs using the + * asset explorer in VS Code. You can reference those assets + * using the tagged templates on the assets namespace: + * + * assets.image`myImageName` + * assets.tilemap`myTilemapName` + * assets.tile`myTileName` + * assets.animation`myAnimationName` + * assets.song`mySongName` + * + * New to MakeCode Arcade? Try creating a new project using one + * of the templates to learn about Sprites, Tilemaps, Animations, + * and more! Or check out the reference docs here: + * + * https://arcade.makecode.com/reference + */ + +game.onUpdate(() => { + // Code in this function will run once per frame. MakeCode + // Arcade games run at 30 FPS +}); diff --git a/mkc.json b/mkc.json new file mode 100644 index 0000000..4e64c44 --- /dev/null +++ b/mkc.json @@ -0,0 +1,4 @@ +{ + "targetWebsite": "https://arcade.makecode.com/", + "links": {} +} \ No newline at end of file diff --git a/pxt.json b/pxt.json new file mode 100644 index 0000000..7b683b4 --- /dev/null +++ b/pxt.json @@ -0,0 +1,18 @@ +{ + "name": "SwitchCase" + , "version": "0.0.0" + , "description": "Adds a switch-case block for MakeCode Arcade" + , "files": [ + "main.ts" + , "switch.ts" + , "case.ts" + ], + " public": true + , "supportedTargets": [ + "arcade" + ] + , "dependencies": { + "device": "*" + } + , "testDependencies": {} +} \ No newline at end of file diff --git a/switch.ts b/switch.ts new file mode 100644 index 0000000..bc38a3e --- /dev/null +++ b/switch.ts @@ -0,0 +1,48 @@ + + + +namespace switchCase { + + /** + * Switch Block Container + */ + //% block="switch $value" + //% blockId=switchcase_switch_block + //% group="Control" + //% weight=100 + //% draggableParameters + export function switchBlock(value: any): void { + //this is jut a container; actual logic is in codegen + //Placeholder for CodeGen + } + + /** + * Case Block Container + */ + /********************** + //% block="case $match" + //% blockId=switchcase_case_block + //% group="Control" + //% weight=90 + //% draggableParameters + //% draggableStatement=true + export function caseBlock(match: any): void { + //Placeholder for CodeGen + } + *********************/ + + /** + * Default-Case Block Container + */ + //% block="default case" + //% blockId=switchcase_default_case_block + //% group="Control" + //% weight=80 + //% draggableStatement=true + export function defaultCaseBlock(): void { + //Placeholder for CodeGen + } + + +} + diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..1f12644 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,15 @@ +{ + "compilerOptions": { + "target": "ES5", + "noImplicitAny": true, + "outDir": "built", + "rootDir": "." + }, + "include": [ + "**/*.ts" + ], + "exclude": [ + "built/**", + "pxt_modules/**/*test.ts" + ] +} \ No newline at end of file