Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
LucasHT22 committed Mar 19, 2023
2 parents 5aa1182 + e21dd50 commit 59f8244
Show file tree
Hide file tree
Showing 5 changed files with 113 additions and 9 deletions.
79 changes: 79 additions & 0 deletions bin/lint-sprig
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#!/usr/bin/env bash
# lint-sprig
#
# Do some sanity checks on the sprig games.

metadata=games/metadata.json

if [[ "$1" == "-h" ]] || [[ "$1" == "--help" ]]; then
echo "Usage: $0 [games/<name>.js ...]" >&2;
cat <<EOF >&2
Perform sanity check on sprig games. Ensures js files in games directory are
represented in metadata file. Checks name for invalid characters. Suggests a
record to add to metadata if not present, pulling title and author from
javascript file. Checks for associated image file.
Does not read metadata to determine if it references files not present.
EOF
exit 2;
fi

if [[ $# -eq 0 ]]; then
files=$(echo games/*.js);
else
files="$@";
fi


err=0
for game in $files; do
name=$(basename "$game" .js);
if [[ ! "$name" =~ ^[a-zA-Z0-9_\-]+$ ]]; then
echo "warning: Unexpected character in file name '$game'." >&2;
err=1;
fi

if ! grep -c "$name" $metadata > /dev/null; then
echo "warning: '$name' for $game not present in $metadata." >&2;
if ! grep '@title' $game >&-; then
echo "error: no @title in $game";
title="$name";
else
title=$(grep '@title' $game | awk '{ print $2 }');
fi
if ! grep '@author' $game >&-; then
echo "error: no @author in $game";
author="N/A";
else
author=$(grep '@author' $game | awk '{ print $2 }');
fi
img="games/img/$name.png";
if [[ ! -f "$img" ]]; then
echo "warning: no '$img' image found for $game." >&2;
img="";
err=1;
fi
date=$(date +%Y-%m-%d);
echo "Suggested fix: add this record to $metadata." >&2;
cat <<EOF >&2
{
"filename": "$name.js",
"title": "$title",
"author": "$author",
"img": "$img",
"tags": [],
"addedOn": "$date"
},
EOF
err=1
fi

# img="games/img/$name.png"
# if [[ ! -f "$img" ]]; then
# echo "warning: expect image '$img' for $game." >&2;
# err=1
# fi
done

exit $err
28 changes: 26 additions & 2 deletions games/metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -2344,11 +2344,35 @@
"addedOn": "2023-03-14"
},
{
"filename": "MusicalTiles",
"title": "MusicalTiles",
"filename": "MagicalTiles",
"title": "MagicalTiles",
"author": "Shreeya Rani",
"img": "",
"tags": [],
"addedOn": "2023-03-14"
},
{
"filename": "Alien_Attack",
"title": "Alien_Attack",
"author": "whatware",
"img": "Alien_Attack",
"tags": [],
"addedOn": "2023-03-15"
},
{
"filename": "ElfSokoban",
"title": "ElfSokoban",
"author": "Markonije",
"img": "",
"tags": [],
"addedOn": "2023-03-15"
},
{
"filename": "It_Is_Coming_Out!",
"title": "It_Is_Coming_Out!",
"author": "N/A",
"img": "It_Is_Coming_Out!",
"tags": [],
"addedOn": "2023-03-15"
}
]
6 changes: 3 additions & 3 deletions src/components/codemirror.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,18 @@ export default function CodeMirror(props: CodeMirrorProps) {
if (!parent.current) throw new Error('Oh golly! The editor parent ref is null')
let lastCode: string = props.initialCode ?? ''
const editor = new EditorView({
state: createEditorState(() => {
state: createEditorState(props.initialCode ? props.initialCode : '', () => {
if (editor.state.doc.toString() === lastCode) return
lastCode = editor.state.doc.toString()
onCodeChangeRef.current?.()
}, () => onRunShortcutRef.current?.()),
parent: parent.current
})
if (props.initialCode) editor.dispatch({ changes: { from: 0, insert: props.initialCode } })

props.onEditorView?.(editor)
}, [])

return (
<div class={`${styles.container} ${props.class ?? ''}`} ref={parent} />
)
}
}
5 changes: 3 additions & 2 deletions src/lib/codemirror/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ import { effect, signal } from '@preact/signals'
import { h, render } from 'preact'
import SearchBox from '../../components/search-box'

export function createEditorState(onUpdate = () => {}, onRunShortcut = () => {}): EditorState {
export function createEditorState(initialCode: string, onUpdate = () => {}, onRunShortcut = () => {}): EditorState {
return EditorState.create({
doc: initialCode,
extensions: [
lineNumbers(),
highlightActiveLineGutter(),
Expand Down Expand Up @@ -93,4 +94,4 @@ export function createEditorState(onUpdate = () => {}, onRunShortcut = () => {})
widgets
]
})
}
}
4 changes: 2 additions & 2 deletions src/pages/gallery/index.astro
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ games
<div class='info-split'>
<div class='search-container'>
<p>
The best way to learn is by making things that you care about and sharing them with other people. Check out games by other Hack Clubbers and hack on them in the Sprig editor!
We currently have {games.length} games made my Hack Clubbers. Click on any to play in the browser and hack on the code in our editor!
</p>

<div class='search-controls'>
Expand All @@ -224,7 +224,7 @@ games
</div>

<div class='join-container'>
<p>Have a Sprig game to share with the community? Join the fun and get your very own Sprig console.</p>
<p>Add your finished game to the Gallery and get your very own Sprig console!</p>
<a href='/get'><Button accent>Add your game</Button></a>
</div>
</div>
Expand Down

0 comments on commit 59f8244

Please sign in to comment.