2022-03-10 12:29:30 -08:00
#!/bin/bash
help = " love-js.sh: \n
A tool for assembling love.js projects without relying on npm / node. \n \
2021-02-01 17:09:15 -08:00
For the full project please see https://github.com/Davidobot/love.js \n \
\n \
usage: \n \
2022-03-10 12:29:30 -08:00
./love-js.sh [ love-file] [ project-name] [ opts] \n \
\n
opts:\n
-v= ( --version= ) Version of the Game. Will be included in file name.\n
-o= ( --output-directory= ) Target directory. Defaults to PWD\n
-t= ( --text-colour= ) Text Colour. Defaults to \" 240,234,214\" \n
-c= ( --canvas-colour= ) Canvas Colour. Defaults to \" 54,69,79\" \n
-a= ( --author= ) Author ( Shows up on loading page) .\n
-w= ( --width= ) Canvas Width ( game width in conf) . Defaults to 800\n
-h= ( --height= ) Canvas Height ( game height in conf) . Defaults to 600\n
-r ( --run) Set flag if you want to run a local copy on port 8000\n
-d ( --debug) Set flag for debug info\n
-h ( --help) Display this text\n
\n
2021-02-01 17:09:15 -08:00
eg: \n \
2022-03-10 12:29:30 -08:00
Pack up sample.love\n
\t ./love-js.sh sample.love sample\n
\t > sample-web.zip\n
\n
Pack up sample.love version 0.1.0\n
\t ./love-js.sh sample-0.1.0.love sample -v= 0.1.0\n
\t > sample-0.1.0-web.zip\n
\n
Pack up sample.love and set the background colour to black\n
\t ./love-js.sh sample-0.1.0.love sample -v= 0.1.0 -c= \" 0,0,0\" \n
\t > sample-0.1.0-web.zip\n
\n
Pack up sample.love and set the author to \" Sample Name\" \n
\t ./love-js.sh sample-0.1.0.love sample -a= \" Sample Name\" \n
\t > sample-web.zip"
if [ " $# " -lt "2" ]
2021-02-01 17:09:15 -08:00
then
2022-03-10 12:29:30 -08:00
echo "ERROR! love-js.sh expects at least two arguments."
2021-02-01 17:09:15 -08:00
echo -e $help
exit 1
fi
2022-03-23 19:41:18 -07:00
# use gdu on macOS, fixes 'invalid option -b' error
if [ " $( uname -s) " = "Darwin" ] ; then
DU_CMD = gdu
else
DU_CMD = du
fi
2022-03-10 12:29:30 -08:00
love_file = $1
2021-02-01 17:09:15 -08:00
name = $2
## confirm that $release_dir/$name-$version.love exists
2022-03-10 12:29:30 -08:00
if [ ! -f $love_file ] ; then
2021-02-01 17:09:15 -08:00
echo "love file not found!"
2022-03-10 12:29:30 -08:00
echo $love_file
2021-02-01 17:09:15 -08:00
exit 1
fi
2022-03-10 12:29:30 -08:00
if [ -f /proc/sys/kernel/random/uuid ] ; then
uuid = $( cat /proc/sys/kernel/random/uuid)
else
uuid = "2fd99e56-5455-45dd-86dd-7af724874d65"
fi
author = "" ;
run = false;
debug = false;
gethelp = false;
width = 800
height = 600
2021-02-01 17:09:15 -08:00
release = "compat"
2022-03-16 17:22:07 -07:00
love_version = "11.4"
2022-03-10 12:29:30 -08:00
canvas_colour = "54,69,79"
text_colour = "240,234,214"
2021-09-24 13:45:14 -07:00
initial_memory = 0
2022-03-23 19:41:18 -07:00
module_size = $( $DU_CMD -b $love_file | awk '{print $1}' )
2022-03-10 12:29:30 -08:00
title = $( echo $name | sed -r 's/\<./\U&/g' | sed -r 's/-/\ /g' )
version = ""
dash_version = ""
output_dir = $( pwd )
cachemodule = "true"
for i in " $@ "
do
case $i in
-v= *| --version= *)
version = " ${ i #*= } "
dash_version = " - ${ i #*= } "
; ;
-o= *| --output-directory= *)
output_dir = " ${ i #*= } "
; ;
-w= *| --width= *)
width = " ${ i #*= } "
; ;
-h= *| --height= *)
height = " ${ i #*= } "
; ;
2022-03-16 17:45:46 -07:00
-t= *| --text-colour= *)
2022-03-10 12:29:30 -08:00
text_colour = " ${ i #*= } "
; ;
2022-03-16 17:45:46 -07:00
-c= *| --canvas-colour= *)
2022-03-10 12:29:30 -08:00
canvas_colour = " ${ i #*= } "
; ;
-a= *| --author= *)
author = " ${ i #*= } "
; ;
-r| --run)
run = true
; ;
-d| --debug)
debug = true
; ;
-h| --help)
gethelp = true
; ;
-n| --no-cache)
cachemodule = "false"
; ;
*)
# unknown option
; ;
esac
done
2022-03-16 17:45:46 -07:00
page_colour = $canvas_colour
2021-02-01 17:09:15 -08:00
2022-03-10 12:29:30 -08:00
file_name = $output_dir /$name $dash_version -web
debug ( ) {
if [ $debug = true ]
then
echo ""
echo "Debug: love-js.sh"
echo " love file: ${ love_file } "
echo " output file: $file_name "
echo " author: $author "
echo " version: $version "
echo " text colour: $text_colour "
echo " canvas colour: $canvas_colour "
echo " canvas size: ${ height } , ${ width } "
echo " run: ${ run } "
echo " use cache: $cachemodule "
fi
}
2021-02-01 17:09:15 -08:00
call_dir = $( pwd )
2022-03-10 12:29:30 -08:00
root = " $( dirname " $0 " ) "
build( ) {
rm -fr $file_name
mkdir -p $file_name && mkdir -p $file_name /theme
cat $root /src/index.html | \
sed " s/{{title}}/ ${ title } /g " | \
sed " s/{{version}}/ ${ version } /g " | \
sed " s/{{author}}/ ${ author } /g " | \
sed " s/{{width}}/ ${ width } /g " | \
sed " s/{{height}}/ ${ height } /g " | \
sed " s/{{initial-memory}}/ ${ initial_memory } /g " | \
sed " s/{{canvas-colour}}/ ${ canvas_colour } /g " | \
sed " s/{{text-colour}}/ ${ text_colour } /g " > \
$file_name /index.html
cat $root /src/love.css | \
sed " s/{{page-colour}}/ ${ page_colour } /g " > \
$file_name /theme/love.css
cat $root /src/game.js | \
sed " s/{{{cachemodule}}}/ ${ cachemodule } /g " | \
sed " s/{{{metadata}}}/{\"package_uuid\":\" ${ uuid } \",\"remote_package_size\": $module_size ,\"files\":[{\"filename\":\"\/game.love\",\"crunched\":0,\"start\":0,\"end\": $module_size ,\"audio\":false}]}/ " > \
$file_name /game.js
2022-03-16 17:22:07 -07:00
cp $root /src/serve.py $file_name
2022-03-10 12:29:30 -08:00
cp $root /src/consolewrapper.js $file_name
cp $love_file $file_name /game.love
2022-03-16 17:22:07 -07:00
cp $root /src/love-$love_version /$release /love.js $file_name
cp $root /src/love-$love_version /$release /love.wasm $file_name
if [ $release = = "release" ] ; then
cp $root /src/release/love.worker.js $file_name
fi
2022-03-10 12:29:30 -08:00
}
clean( ) {
rm -rf $file_name
}
release ( ) {
rm -fr $file_name
build
debug
zip -r -q tmp $file_name
rm -f $file_name .zip
mv tmp.zip $file_name .zip
clean
}
run ( ) {
debug
build
cd $file_name
2022-03-16 17:22:07 -07:00
python serve.py
2022-03-10 12:29:30 -08:00
}
if [ $gethelp = true ]
then
echo -e $help
elif [ $run = false ]
then
release
else
run
fi