Last active
September 28, 2020 11:37
-
-
Save mortenson/3fbd1dd79c22c947e012f41b88b15f7c to your computer and use it in GitHub Desktop.
Watch mode for a game I'm working on
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /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