Skip to content

Instantly share code, notes, and snippets.

@mortenson
Last active September 28, 2020 11:37
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mortenson/3fbd1dd79c22c947e012f41b88b15f7c to your computer and use it in GitHub Desktop.
Save mortenson/3fbd1dd79c22c947e012f41b88b15f7c to your computer and use it in GitHub Desktop.
Watch mode for a game I'm working on
#! /bin/bash
function processSprite {
file=$1
echo "Creating sprite sheet for $file..."
filename=$(basename $file .aseprite)
aseprite -b "$file" --sheet "assets/$filename-Sheet.png" > /dev/null
}
function processTilemap {
echo "Creating tilemap..."
tiled --export-map assets_src/tilemap.tmx assets/tilemap.json
}
if [[ "$1" =~ ".aseprite" ]]; then
processSprite $1
exit
fi
if [[ "$1" =~ ".tmx" ]]; then
processTilemap
exit
fi
ASEPRITE=$(find assets_src -name '*.aseprite')
for file in $ASEPRITE; do
processSprite $file
done
processTilemap
#! /bin/bash
# To open in sticky mode: STICKY=1 ./watch.sh
# Wait for our game window to open.
function waitForOpen {
while true
do
windows=$(wmctrl -l)
if [[ "$windows" =~ "SRPG" ]];
then
return
fi
done
}
function openGame {
# Remember the current window ID.
activeWindow=$(xdotool getactivewindow)
# Only reprocess what just changed.
if [[ "$1" =~ ".go" || "$1" == "" ]]; then
echo "Recompiling..."
go build main.go
else
./scripts/assets.sh "$1"
fi
# Start game in background and get its PID.
./main &
PID=$!
if [ "$STICKY" = "1" ]; then
waitForOpen
# Ensure original window has focus.
wmctrl -a $activeWindow -i
# Sticky the game in the bottom right hand of the screen.
wmctrl -F -r SRPG -e 0,1280,840,640,360
wmctrl -F -r SRPG -b add,above
wmctrl -a $activeWindow -i
fi
}
openGame
trap 'kill $PID' 2
while out=$(inotifywait --format '%w%f' -e modify,create -r assets_src pkg); do
# This occurs when a file was deleted post-operation (as a swap).
if [[ "$out" =~ "#" ]]; then
continue
fi
echo "File changed: $out"
kill $PID
openGame $out
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment