Beefed up love-js.sh
This commit is contained in:
parent
e6a28ab7c0
commit
1f2b086ede
|
@ -1,72 +1,205 @@
|
||||||
help="love-js.sh: \n\
|
#!/bin/bash
|
||||||
A tool for asembling love.js projects without relying on npm / node. \n\
|
|
||||||
|
help="love-js.sh: \n
|
||||||
|
A tool for assembling love.js projects without relying on npm / node. \n\
|
||||||
For the full project please see https://github.com/Davidobot/love.js \n\
|
For the full project please see https://github.com/Davidobot/love.js \n\
|
||||||
\n\
|
\n\
|
||||||
usage: \n\
|
usage: \n\
|
||||||
./love-js.sh [directory-name] [project-name] [version] [cache]\n\
|
./love-js.sh [love-file] [project-name] [opts]\n\
|
||||||
\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
|
||||||
eg: \n\
|
eg: \n\
|
||||||
./love-js.sh ../../releases/ project 0.1.0 \n\
|
|
||||||
./tools/love-js/love-js.sh releases project 0.1.0\n\
|
|
||||||
\n\
|
|
||||||
"
|
|
||||||
|
|
||||||
if [ "$#" -lt "3" ]
|
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" ]
|
||||||
then
|
then
|
||||||
echo "ERROR! love-js.sh expects three arguments."
|
echo "ERROR! love-js.sh expects at least two arguments."
|
||||||
echo -e $help
|
echo -e $help
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
release_dir=$1
|
love_file=$1
|
||||||
name=$2
|
name=$2
|
||||||
version=$3
|
|
||||||
## confirm that $release_dir/$name-$version.love exists
|
## confirm that $release_dir/$name-$version.love exists
|
||||||
if [ ! -f $release_dir/$name-$version.love ]; then
|
if [ ! -f $love_file ]; then
|
||||||
echo "love file not found!"
|
echo "love file not found!"
|
||||||
echo $release_dir/$name-$version.love
|
echo $love_file
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
release="compat"
|
if [ -f /proc/sys/kernel/random/uuid ]; then
|
||||||
canvas_colour="62, 50, 100"
|
uuid=$(cat /proc/sys/kernel/random/uuid)
|
||||||
page_colour=$canvas_colour
|
else
|
||||||
text_colour="223, 7, 114"
|
uuid="2fd99e56-5455-45dd-86dd-7af724874d65"
|
||||||
initial_memory=0
|
fi
|
||||||
module_size=$(du -b $release_dir/$name-$version.love | awk '{print $1}')
|
|
||||||
title=$(echo $name-$version | sed -r 's/\<./\U&/g' | sed -r 's/-/\ /g')
|
|
||||||
cachemodule=$4
|
|
||||||
|
|
||||||
echo $release_dir $name $version $cachemodule
|
author="";
|
||||||
# echo $title " " $canvas_colour " " $text_colour " " $initial_memory
|
run=false;
|
||||||
|
debug=false;
|
||||||
|
gethelp=false;
|
||||||
|
width=800
|
||||||
|
height=600
|
||||||
|
release="compat"
|
||||||
|
canvas_colour="54,69,79"
|
||||||
|
page_colour=$canvas_colour
|
||||||
|
text_colour="240,234,214"
|
||||||
|
initial_memory=0
|
||||||
|
module_size=$(du -b $love_file | awk '{print $1}')
|
||||||
|
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#*=}"
|
||||||
|
;;
|
||||||
|
-c=*|--text-colour=*)
|
||||||
|
text_colour="${i#*=}"
|
||||||
|
;;
|
||||||
|
-t=*|--canvas-colour=*)
|
||||||
|
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
|
||||||
|
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
call_dir=$(pwd)
|
call_dir=$(pwd)
|
||||||
cd "$(dirname "$0")"
|
root="$(dirname "$0")"
|
||||||
|
|
||||||
mkdir -p $name-$version && mkdir -p $name-$version/theme
|
build(){
|
||||||
|
rm -fr $file_name
|
||||||
|
mkdir -p $file_name && mkdir -p $file_name/theme
|
||||||
|
|
||||||
cat src/index.html | \
|
cat $root/src/index.html | \
|
||||||
sed "s/{{title}}/${title}/g" | \
|
sed "s/{{title}}/${title}/g" | \
|
||||||
sed "s/{{initial-memory}}/${initial_memory}/g" | \
|
sed "s/{{version}}/${version}/g" | \
|
||||||
sed "s/{{canvas-colour}}/${canvas_colour}/g" | \
|
sed "s/{{author}}/${author}/g" | \
|
||||||
sed "s/{{text-colour}}/${text_colour}/g" > \
|
sed "s/{{width}}/${width}/g" | \
|
||||||
$name-$version/index.html
|
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 src/love.css | \
|
cat $root/src/love.css | \
|
||||||
sed "s/{{page-colour}}/${page_colour}/g" > \
|
sed "s/{{page-colour}}/${page_colour}/g" > \
|
||||||
$name-$version/theme/love.css
|
$file_name/theme/love.css
|
||||||
|
|
||||||
cat src/game.js | \
|
cat $root/src/game.js | \
|
||||||
sed "s/{{{cachemodule}}}/${cachemodule}/g" | \
|
sed "s/{{{cachemodule}}}/${cachemodule}/g" | \
|
||||||
sed "s/{{{metadata}}}/{\"package_uuid\":\"2fd99e56-5455-45dd-86dd-7af724874d65\",\"remote_package_size\":$module_size,\"files\":[{\"filename\":\"\/game.love\",\"crunched\":0,\"start\":0,\"end\":$module_size,\"audio\":false}]}/" > \
|
sed "s/{{{metadata}}}/{\"package_uuid\":\"${uuid}\",\"remote_package_size\":$module_size,\"files\":[{\"filename\":\"\/game.love\",\"crunched\":0,\"start\":0,\"end\":$module_size,\"audio\":false}]}/" > \
|
||||||
$name-$version/game.js
|
$file_name/game.js
|
||||||
|
cp $root/src/consolewrapper.js $file_name
|
||||||
|
cp $love_file $file_name/game.love
|
||||||
|
cp $root/src/$release/love.js $file_name
|
||||||
|
cp $root/src/$release/love.wasm $file_name
|
||||||
|
cp $root/src/release/love.worker.js $file_name
|
||||||
|
}
|
||||||
|
|
||||||
cp src/consolewrapper.js $name-$version
|
clean(){
|
||||||
# cp src/game.js $name-$version
|
rm -rf $file_name
|
||||||
cp $release_dir/$name-$version.love $name-$version/game.love
|
}
|
||||||
cp src/$release/love.js $name-$version
|
|
||||||
cp src/$release/love.wasm $name-$version
|
release (){
|
||||||
cp src/release/love.worker.js $name-$version
|
rm -fr $file_name
|
||||||
zip -r -q tmp $name-$version
|
build
|
||||||
mv tmp.zip $call_dir/$name-$version-web.zip
|
debug
|
||||||
rm -rf $name-$version
|
zip -r -q tmp $file_name
|
||||||
|
rm -f $file_name.zip
|
||||||
|
mv tmp.zip $file_name.zip
|
||||||
|
clean
|
||||||
|
}
|
||||||
|
|
||||||
|
run (){
|
||||||
|
debug
|
||||||
|
build
|
||||||
|
cd $file_name
|
||||||
|
python2.7 -m SimpleHTTPServer
|
||||||
|
}
|
||||||
|
|
||||||
|
if [ $gethelp = true ]
|
||||||
|
then
|
||||||
|
echo -e $help
|
||||||
|
elif [ $run = false ]
|
||||||
|
then
|
||||||
|
release
|
||||||
|
else
|
||||||
|
run
|
||||||
|
fi
|
||||||
|
|
|
@ -12,7 +12,8 @@
|
||||||
<center>
|
<center>
|
||||||
<div>
|
<div>
|
||||||
<canvas id="canvas" oncontextmenu="event.preventDefault()"></canvas>
|
<canvas id="canvas" oncontextmenu="event.preventDefault()"></canvas>
|
||||||
<canvas id="loadingCanvas" oncontextmenu="event.preventDefault()" width="800" height="600"></canvas>
|
<canvas id="loadingCanvas" oncontextmenu="event.preventDefault()"
|
||||||
|
width="{{width}}" height="{{height}}"></canvas>
|
||||||
</div>
|
</div>
|
||||||
</center>
|
</center>
|
||||||
|
|
||||||
|
@ -46,9 +47,17 @@
|
||||||
goFullScreen();
|
goFullScreen();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var loadingContext = document.getElementById('loadingCanvas').getContext('2d');
|
var loadingContext = document.getElementById('loadingCanvas').getContext('2d');
|
||||||
function drawLoadingText(text) {
|
var complete = false;
|
||||||
var canvas = loadingContext.canvas;
|
function drawLoadingText(text, soFar, total) {
|
||||||
|
var canvas = loadingContext.canvas;
|
||||||
|
var ratio = complete ? 1 : 0;
|
||||||
|
if (soFar && total){
|
||||||
|
ratio = soFar / total
|
||||||
|
}
|
||||||
|
if (ratio == 1){
|
||||||
|
complete = true
|
||||||
|
}
|
||||||
//
|
//
|
||||||
loadingContext.fillStyle = "rgb({{canvas-colour}})";
|
loadingContext.fillStyle = "rgb({{canvas-colour}})";
|
||||||
loadingContext.fillRect(0, 0, canvas.scrollWidth, canvas.scrollHeight);
|
loadingContext.fillRect(0, 0, canvas.scrollWidth, canvas.scrollHeight);
|
||||||
|
@ -57,13 +66,39 @@
|
||||||
loadingContext.textAlign = 'center'
|
loadingContext.textAlign = 'center'
|
||||||
//
|
//
|
||||||
loadingContext.fillStyle = "rgb({{text-colour}})";
|
loadingContext.fillStyle = "rgb({{text-colour}})";
|
||||||
loadingContext.fillText(text, canvas.scrollWidth / 2, canvas.scrollHeight / 2);
|
loadingContext.fillText(text, canvas.scrollWidth / 2, (canvas.scrollHeight / 2) - 40);
|
||||||
//
|
//
|
||||||
loadingContext.fillText("{{title}}!", canvas.scrollWidth / 2, canvas.scrollHeight / 4);
|
loadingContext.beginPath();
|
||||||
loadingContext.fillText("Powered By LÖVE.", canvas.scrollWidth / 2, canvas.scrollHeight / 4 * 3);
|
loadingContext.strokeStyle = "rgb({{text-colour}})";
|
||||||
}
|
loadingContext.rect((canvas.scrollWidth / 2) - 200,
|
||||||
|
( canvas.scrollHeight / 2) - 20,
|
||||||
|
400,
|
||||||
|
40
|
||||||
|
|
||||||
window.onload = function () { window.focus(); };
|
|
||||||
|
);
|
||||||
|
loadingContext.stroke();
|
||||||
|
loadingContext.beginPath();
|
||||||
|
loadingContext.rect((canvas.scrollWidth / 2) - 200,
|
||||||
|
( canvas.scrollHeight / 2) - 20,
|
||||||
|
400 * ratio,
|
||||||
|
40
|
||||||
|
|
||||||
|
|
||||||
|
);
|
||||||
|
loadingContext.fill();
|
||||||
|
loadingContext.font = '4em arial';
|
||||||
|
loadingContext.fillText("{{title}}", canvas.scrollWidth / 2, canvas.scrollHeight / 4);
|
||||||
|
loadingContext.font = '2em arial';
|
||||||
|
loadingContext.fillText("{{version}}", canvas.scrollWidth / 2, (canvas.scrollHeight / 4 + 45));
|
||||||
|
loadingContext.font = '1em arial';
|
||||||
|
loadingContext.textAlign = 'left'
|
||||||
|
loadingContext.fillText("Powered By LÖVE", canvas.scrollWidth / 2 - 300, canvas.scrollHeight / 4 * 3);
|
||||||
|
loadingContext.textAlign = 'right'
|
||||||
|
loadingContext.fillText("Game By: {{author}}", canvas.scrollWidth / 2 + 300, canvas.scrollHeight / 4 * 3);
|
||||||
|
}
|
||||||
|
|
||||||
|
window.onload = function () { window.focus(); };
|
||||||
window.onclick = function () { window.focus(); };
|
window.onclick = function () { window.focus(); };
|
||||||
|
|
||||||
window.addEventListener("keydown", function(e) {
|
window.addEventListener("keydown", function(e) {
|
||||||
|
@ -87,9 +122,9 @@
|
||||||
|
|
||||||
return canvas;
|
return canvas;
|
||||||
})(),
|
})(),
|
||||||
setStatus: function(text) {
|
setStatus: function(text, soFar, total) {
|
||||||
if (text) {
|
if (text) {
|
||||||
drawLoadingText(text);
|
drawLoadingText(text, soFar, total);
|
||||||
} else if (Module.remainingDependencies === 0) {
|
} else if (Module.remainingDependencies === 0) {
|
||||||
document.getElementById('loadingCanvas').style.display = 'none';
|
document.getElementById('loadingCanvas').style.display = 'none';
|
||||||
document.getElementById('canvas').style.display = 'block';
|
document.getElementById('canvas').style.display = 'block';
|
||||||
|
@ -100,7 +135,9 @@
|
||||||
monitorRunDependencies: function(left) {
|
monitorRunDependencies: function(left) {
|
||||||
this.remainingDependencies = left;
|
this.remainingDependencies = left;
|
||||||
this.totalDependencies = Math.max(this.totalDependencies, left);
|
this.totalDependencies = Math.max(this.totalDependencies, left);
|
||||||
Module.setStatus(left ? 'Preparing... (' + (this.totalDependencies-left) + '/' + this.totalDependencies + ')' : 'All downloads complete.');
|
Module.setStatus(left ? 'Preparing... (' + (this.totalDependencies-left) + '/' + this.totalDependencies + ')' : 'All downloads complete.',
|
||||||
|
this.totalDependencies-left,
|
||||||
|
this.totalDependencies);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
Module.setStatus('Downloading...');
|
Module.setStatus('Downloading...');
|
||||||
|
|
5
makefile
5
makefile
|
@ -43,13 +43,16 @@ releases/$(NAME)-$(VERSION)-win.zip: $(LOVEFILE)
|
||||||
mv releases/$(NAME)-win32.zip $@
|
mv releases/$(NAME)-win32.zip $@
|
||||||
|
|
||||||
releases/$(NAME)-$(VERSION)-web.zip: $(LOVEFILE)
|
releases/$(NAME)-$(VERSION)-web.zip: $(LOVEFILE)
|
||||||
cd releases && ../buildtools/love-js/love-js.sh $(PWD)/releases $(NAME) $(VERSION) false
|
buildtools/love-js/love-js.sh releases/$(NAME)-$(VERSION).love $(NAME) -v=$(VERSION) -a=$(AUTHOR) -o=releases
|
||||||
|
|
||||||
linux: releases/$(NAME)-$(VERSION)-x86_64.AppImage
|
linux: releases/$(NAME)-$(VERSION)-x86_64.AppImage
|
||||||
mac: releases/$(NAME)-$(VERSION)-macos.zip
|
mac: releases/$(NAME)-$(VERSION)-macos.zip
|
||||||
windows: releases/$(NAME)-$(VERSION)-win.zip
|
windows: releases/$(NAME)-$(VERSION)-win.zip
|
||||||
web: releases/$(NAME)-$(VERSION)-web.zip
|
web: releases/$(NAME)-$(VERSION)-web.zip
|
||||||
|
|
||||||
|
|
||||||
|
runweb: $(LOVEFILE)
|
||||||
|
buildtools/love-js/love-js.sh $(LOVEFILE) $(NAME) -v=$(VERSION) -a=$(AUTHOR) -o=releases -r
|
||||||
# If you release on itch.io, you should install butler:
|
# If you release on itch.io, you should install butler:
|
||||||
# https://itch.io/docs/butler/installing.html
|
# https://itch.io/docs/butler/installing.html
|
||||||
|
|
||||||
|
|
|
@ -3,15 +3,19 @@
|
||||||
(var counter 0)
|
(var counter 0)
|
||||||
(var time 0)
|
(var time 0)
|
||||||
|
|
||||||
|
(love.graphics.setNewFont 30)
|
||||||
|
|
||||||
{:draw (fn draw [message]
|
{:draw (fn draw [message]
|
||||||
(love.graphics.print (: "This window should close in %0.2f seconds"
|
(local (w h _flags) (love.window.getMode))
|
||||||
:format (- 3 time)) 32 16))
|
(love.graphics.printf
|
||||||
|
(: "This window should close in %0.1f seconds"
|
||||||
|
:format (math.max 0 (- 3 time)))
|
||||||
|
0 (- (/ h 2) 15) w :center))
|
||||||
:update (fn update [dt set-mode]
|
:update (fn update [dt set-mode]
|
||||||
(if (< counter 65535)
|
(if (< counter 65535)
|
||||||
(set counter (+ counter 1))
|
(set counter (+ counter 1))
|
||||||
(set counter 0))
|
(set counter 0))
|
||||||
(incf time dt)
|
(incf time dt)
|
||||||
;;(set time (+ time dt))
|
|
||||||
(when (> time 3)
|
(when (> time 3)
|
||||||
(love.event.quit)))
|
(love.event.quit)))
|
||||||
:keypressed (fn keypressed [key set-mode]
|
:keypressed (fn keypressed [key set-mode]
|
||||||
|
|
Loading…
Reference in a new issue