Skip to content

Commit c7336db

Browse files
committed
Merge and promote initial fly-thru of this extension from the rpi400 so I can edit on a sturdier machine
1 parent 324656f commit c7336db

12 files changed

Lines changed: 441 additions & 0 deletions

File tree

.envrc

Lines changed: 273 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,273 @@
1+
source <(direnv stdlib)
2+
3+
export WORKSPACE_EXT_ROOT_PATH="$HOME/@Dev/MakecodeArcade/@Extensions/@Daddy/"
4+
export REPOS_ROOT_PATH="$HOME/@Dev/MakecodeArcade/@Extensions/@Daddy/@Repos/"
5+
export WORKSPACE_PATH="$HOME/@Dev/MakecodeArcade/@Extensions/@Daddy/switchcase/"
6+
export REPO_PATH="$HOME/@Dev/MakecodeArcade/@Extensions/@Daddy/@Repos/makecode-ext-switchcase/"
7+
8+
export EDITOR="code"
9+
10+
export REPO_REMOTE_URL="https://github.com/seriussoft/makecode-ext-switchcase.git"
11+
export REPO_BRANCH_DEV="dev"
12+
export REPO_BRANCH_DEV_LOCAL="dev-local-rpi400"
13+
14+
#
15+
# Functions
16+
#
17+
18+
# TODO: Create a localized shortcut for copyWSToRepo() and copyRepoToWS() that doesn't need any arguments
19+
20+
# Copy over code FROM workspace-directory [--ws] TO local-repo-directory [--repo]
21+
copyWSToRepo() {
22+
23+
use_default_dirs_if_empty=0
24+
use_default_dirs_only=0
25+
same_directories_provided=0
26+
run_simulation_without_sideeffects=0
27+
28+
while [[ $# -gt 0 ]]; do
29+
case "$1" in
30+
--help|-help|-h)
31+
#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"
32+
# FULL MANPAGES/Documentation on how to use this function and its flags properly printed to screen with the following function call...
33+
showHelp_copyWSandRepo "copyWSToRepo"
34+
return
35+
;;
36+
--ws|-ws|-w)
37+
workspace_dir="$2"
38+
shift 2
39+
;;
40+
--repo|-repo|-r)
41+
repo_dir="$2"
42+
shift 2
43+
;;
44+
--default|-default|-d)
45+
use_default_dirs_if_empty=1
46+
shift
47+
;;
48+
--ignoreargs|-ignoreargs|-i)
49+
use_default_dirs_only=1
50+
shift
51+
;;
52+
--same|-same|-s)
53+
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..."
54+
same_directories_provided=1
55+
run_simulation_without_sideeffects=1
56+
;;
57+
*)
58+
# invalid flag or argument; let's just shift the args[] and move on
59+
shift
60+
;;
61+
esac
62+
done
63+
64+
# indicates how many (0, 1, or 2) of the two directories are empty BEFORE all other flags are checked
65+
empty_count_prework=0
66+
# indicates how many (0, 1, or 2) of the two directories are empty AFTER all flags are checked
67+
empty_count_postwork=0
68+
# indicates no value was provided for ws if value > 0
69+
ws_empty=0
70+
# indicates no value was provided for repo if value > 0
71+
repo_empty=0
72+
# indicates EITHER --default OR --ignoreargs if value > 0
73+
using_defaults=0
74+
75+
# indicate that any or non of the default flags (--default or --ignoreargs) were provided
76+
if [ $use_default_dirs_if_empty -gt 0 ] || [ $use_default_dirs_only -gt 0 ]; then
77+
using_defaults=1
78+
fi
79+
80+
# if BOTH directories are empty, run through logic checks so we can determine whether to simulate, run, or error out...
81+
if [ -z "$workspace_dir" ] && [ -z "$repo_dir" ]; then
82+
empty_count_prework=2
83+
ws_empty=1
84+
repo_empty=1
85+
# if NOT using_defaults, then empty_count_postwork is 2, just like $empty_count_prework, else 0
86+
if [ $using_defaults -lt 1 ]; then
87+
empty_count_postwork=2
88+
fi
89+
# if ONLY $workspace_dir is empty, run through logic checks so we can determine whether to simulate, run, or error out...
90+
elif [ -z "$workspace_dir" ]; then
91+
empty_count_prework=1
92+
ws_empty=1
93+
# if NOT using_defaults, then empty_count_postwork is 1, just like $empty_count_prework, else 0
94+
if [ $using_defaults -lt 1 ]; then
95+
empty_count_postwork=1
96+
fi
97+
# if ONLY $repo_dir is empty, run through logic checks so we can determine whether to simulate, run, or error out...
98+
elif [ -z "$repo_dir" ]; then
99+
# just the $repo_dir is empty, but we need to check if either of the default flag are checked
100+
empty_count_prework=1
101+
repo_empty=1
102+
# if NOT using_defaults, then empty_count_postwork is 1, just like $empty_count_prework, else 0
103+
if [ $using_defaults -lt 1 ]; then
104+
empty_count_postwork=1
105+
fi
106+
else
107+
# all values are provided, no more logic needs to be run so far...
108+
echo ""
109+
fi
110+
111+
# assign the default value if no value is provided and you supplied the default flag: [-d|--default|-default]
112+
if [ $use_default_dirs_if_empty -gt 0 ]; then
113+
workspace_dir=${workspace_dir:-$WORKSPACE_PATH}
114+
repo_dir=${repo_dir:-$REPO_PATH}
115+
fi
116+
117+
# overrides all situations, except [--same|-same|-s], so it needs to be after $use_default_dirs_if_empty - this depends on [-i|--ignoreargs|-ignoreargs]
118+
if [ $use_default_dirs_only -gt 0 ]; then
119+
workspace_dir=$WORKSPACE_PATH
120+
repo_dir=$REPO_PATH
121+
fi
122+
123+
# lets run a simulation of what WOULD have been executed had we NOT provided the --same|-same|-s flag
124+
if [ $run_simulation_without_sideeffects -gt 0 ]; then
125+
# need to finish out the logic for the following variables:
126+
# 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
127+
# 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
128+
# 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...
129+
# 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...
130+
# 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...
131+
132+
# 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...
133+
echo "cp -a \"${workspace_dir}/.\" \"$repo_dir/\""
134+
# not an error, so return like normal to prevent confusion surrounding
135+
return
136+
fi
137+
138+
# backup to keep from odd behavior or wonky/confusing error messages
139+
if [ -z "$workspace_dir" ] || [ -z "$repo_dir" ]; then
140+
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."
141+
return 1
142+
fi
143+
144+
cp -a "${workspace_dir}/." "$repo_dir/"
145+
}
146+
147+
# TODO: Once copyWSToRepo is completed, copy code over to this method and update the simulation, error, and cp execution code and save.
148+
# Copy over code FROM local-repo-directory [--repo] TO workspace-directory --ws
149+
copyRepoToWS() {
150+
151+
while [[ $# -gt 0 ]]; do
152+
case "$1" in
153+
--help|-help|-h)
154+
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"
155+
return
156+
;;
157+
--ws|-ws|-w)
158+
workspace_dir="$2"
159+
shift 2
160+
;;
161+
--repo|-repo|-r)
162+
repo_dir="$2"
163+
shift 2
164+
;;
165+
esac
166+
done
167+
168+
169+
cp -a "${repo_dir}/." "${workspace_dir}/"
170+
}
171+
172+
173+
# 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"`
174+
gitpush() {
175+
git add .
176+
git commit -m "$1"
177+
git push
178+
}
179+
180+
# > git clone https://github.com/seriussoft/makecode-ext-switchcase.git
181+
# > cd makecode-ext-switchcase
182+
#
183+
# > git checkout dev
184+
# > git add .
185+
# > git commit -m "Merge and promote current code from rpi400"
186+
# > git push origin dev-local-rpi400
187+
188+
# Perform the traditional git-checkout
189+
gitcheck() {
190+
191+
repo=""
192+
repo_given=false
193+
branch_remote=""
194+
branch_remote_given=false
195+
branch_local=""
196+
branch_local_given=false
197+
198+
while [[ $# -gt 0 ]]; do
199+
case $1 in
200+
-help|--help|-h)
201+
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"
202+
return
203+
;;
204+
-repo|--repo|-r)
205+
repo="$2"
206+
shift 2
207+
;;
208+
-branch|--branch|-b)
209+
branch_remote="$2"
210+
shift 2
211+
;;
212+
-local|--localbranch|-l)
213+
branch_local="$2"
214+
shift 2
215+
;;
216+
esac
217+
done
218+
219+
if [ -z "$branch_remote" ]; then
220+
echo "ERROR: Missing Remote Branch"
221+
fi
222+
223+
if [ -z "$branch_local" ]; then
224+
echo "ERROR: Missing Local Branch"
225+
fi
226+
227+
if [ -z "$repo" ]; then
228+
echo "ERROR: Missing Repo"
229+
fi
230+
231+
git checkout -b "${repo}"
232+
233+
}
234+
235+
236+
237+
# you need to provide the name of the function (either 'copyWSToRepo' or 'copyRepoToWS')
238+
showHelp_copyWSandRepo() {
239+
$funcName=$1
240+
if [ -z $funcName ]; then
241+
echo "ERROR: Cannot provide the correct output without a proper function name added as an argument after your function call to showFunc_copyWSandRepo"
242+
fi
243+
244+
# 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"
245+
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"
246+
247+
printf "%-25s %s\n" "--help|-help|-h" "Show help and exit safely"
248+
printf "%-25s %s\n" "--ws|-ws|-w {workspace-dir}" "Workspace directory \(required unless --default or --ignoreargs\)"
249+
printf "%-25s %s\n" "--repo|-repo|-r {local-repo-dir}" "Local repo directory \(required unless --default or --ignoreargs\)"
250+
printf "%-25s %s\n" "--default|-default|-d" "Use default values if missing/empty"
251+
printf "%-25s %s\n" "--ignoreargs|-ignoreargs|-i" "Always use default values, ignore other args"
252+
printf "%-25s %s\n" "--same|-same|-s" "Skip copy if workspace and repo are the same"
253+
254+
echo -e "\nSYNTAX & DETAILS:\n"
255+
256+
printf "%-25s %s\n\n" "--help|-help|-h" \
257+
"Stops execution safely and returns help information specific to this function call and its flags."
258+
259+
printf "%-25s %s\n\n" "--ws|-ws|-w {workspace-dir}" \
260+
"Specifies your workspace directory. Required unless --default or --ignoreargs is used. If not provided or empty, the function errors."
261+
262+
printf "%-25s %s\n\n" "--repo|-repo|-r {local-repo-dir}" \
263+
"Specifies your local repo directory. Required unless --default or --ignoreargs is used. If not provided or empty, the function errors."
264+
265+
printf "%-25s %s\n\n" "--default|-default|-d" \
266+
"Uses default values for missing or empty directory arguments. Does not override provided values unless they are empty."
267+
268+
printf "%-25s %s\n\n" "--ignoreargs|-ignoreargs|-i" \
269+
"Forces use of default values, ignoring any other directory arguments. Overrides --default."
270+
271+
printf "%-25s %s\n\n" "--same|-same|-s" \
272+
"Skips the copy operation if workspace and repo are the same. Overrides other directory flags."
273+
}

.github/workflows/makecode.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
name: MakeCode Build
2+
on:
3+
push:
4+
workflow_dispatch:
5+
6+
jobs:
7+
build:
8+
runs-on: ubuntu-latest
9+
steps:
10+
- uses: actions/checkout@v3
11+
with:
12+
submodules: recursive
13+
- run: npx makecode

.gitignore

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# MakeCode
2+
built
3+
node_modules
4+
yotta_modules
5+
yotta_targets
6+
pxt_modules
7+
.pxt
8+
_site
9+
*.db
10+
*.tgz
11+
.header.json
12+
.simstate.json

.prettierrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"arrowParens":"avoid","semi":false,"tabWidth":4}

.vscode/extensions.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"recommendations": [
3+
"ms-edu.pxt-vscode-web"
4+
]
5+
}

.vscode/settings.json

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"editor.formatOnType": true,
3+
"files.autoSave": "afterDelay",
4+
"files.watcherExclude": {
5+
"**/.git/objects/**": true,
6+
"**/built/**": true,
7+
"**/node_modules/**": true,
8+
"**/yotta_modules/**": true,
9+
"**/yotta_targets": true,
10+
"**/pxt_modules/**": true,
11+
"**/.pxt/**": true
12+
},
13+
"files.associations": {
14+
"*.blocks": "html",
15+
"*.jres": "json"
16+
},
17+
"search.exclude": {
18+
"**/built": true,
19+
"**/node_modules": true,
20+
"**/yotta_modules": true,
21+
"**/yotta_targets": true,
22+
"**/pxt_modules": true,
23+
"**/.pxt": true
24+
},
25+
"files.exclude": {
26+
"**/pxt_modules": true,
27+
"**/.pxt": true,
28+
"**/mkc.json": true
29+
}
30+
}

README.md

Whitespace-only changes.

main.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/**
2+
* This is the main file for your project.
3+
*
4+
* Create images, tilemaps, animations, and songs using the
5+
* asset explorer in VS Code. You can reference those assets
6+
* using the tagged templates on the assets namespace:
7+
*
8+
* assets.image`myImageName`
9+
* assets.tilemap`myTilemapName`
10+
* assets.tile`myTileName`
11+
* assets.animation`myAnimationName`
12+
* assets.song`mySongName`
13+
*
14+
* New to MakeCode Arcade? Try creating a new project using one
15+
* of the templates to learn about Sprites, Tilemaps, Animations,
16+
* and more! Or check out the reference docs here:
17+
*
18+
* https://arcade.makecode.com/reference
19+
*/
20+
21+
game.onUpdate(() => {
22+
// Code in this function will run once per frame. MakeCode
23+
// Arcade games run at 30 FPS
24+
});

mkc.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"targetWebsite": "https://arcade.makecode.com/",
3+
"links": {}
4+
}

pxt.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"name": "SwitchCase"
3+
, "version": "0.0.0"
4+
, "description": "Adds a switch-case block for MakeCode Arcade"
5+
, "files": [
6+
"main.ts"
7+
, "switch.ts"
8+
, "case.ts"
9+
],
10+
" public": true
11+
, "supportedTargets": [
12+
"arcade"
13+
]
14+
, "dependencies": {
15+
"device": "*"
16+
}
17+
, "testDependencies": {}
18+
}

0 commit comments

Comments
 (0)