Love-js updated to set love file size for web.

This commit is contained in:
Alexander Griffith 2021-09-24 16:45:14 -04:00
parent ea38605427
commit 0b2faf372b
3 changed files with 18 additions and 8 deletions

View file

@ -3,7 +3,7 @@ help="love-js.sh: \n\
For the full project please see https://github.com/Davidobot/love.js \n\
\n\
usage: \n\
./love-js.sh [directory-name] [project-name] [version] \n\
./love-js.sh [directory-name] [project-name] [version] [cache]\n\
\n\
eg: \n\
./love-js.sh ../../releases/ project 0.1.0 \n\
@ -21,7 +21,6 @@ fi
release_dir=$1
name=$2
version=$3
## confirm that $release_dir/$name-$version.love exists
if [ ! -f $release_dir/$name-$version.love ]; then
echo "love file not found!"
@ -33,9 +32,12 @@ release="compat"
canvas_colour="62, 50, 100"
page_colour=$canvas_colour
text_colour="223, 7, 114"
initial_memory=0 #$(du -b $release_dir/$name-$version.love | awk '{print $1}')
initial_memory=0
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
# echo $title " " $canvas_colour " " $text_colour " " $initial_memory
call_dir=$(pwd)
@ -55,7 +57,8 @@ cat src/love.css | \
$name-$version/theme/love.css
cat src/game.js | \
sed "s/{{{metadata}}}/{\"package_uuid\":\"2fd99e56-5455-45dd-86dd-7af724874d65\",\"remote_package_size\":4506139,\"files\":[{\"filename\":\"\/game.love\",\"crunched\":0,\"start\":0,\"end\":4506139,\"audio\":false}]}/" > \
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}]}/" > \
$name-$version/game.js
cp src/consolewrapper.js $name-$version

View file

@ -1,5 +1,7 @@
var Module;
var CACHEMODULE = {{{cachemodule}}};
if (typeof Module === 'undefined') Module = eval('(function() { try { return Module || {} } catch(e) { return {} } })()');
if (!Module.expectedDataFileDownloads) {
@ -250,20 +252,25 @@ Module.expectedDataFileDownloads++;
openDatabase(
function(db) {
checkCachedPackage(db, PACKAGE_PATH + PACKAGE_NAME,
function(useCached) {
function(useCached) {
Module.preloadResults[PACKAGE_NAME] = {fromCache: useCached};
if (useCached) {
if (useCached && CACHEMODULE) {
console.info('loading ' + PACKAGE_NAME + ' from cache');
fetchCachedPackage(db, PACKAGE_PATH + PACKAGE_NAME, processPackageData, preloadFallback);
} else {
console.info('loading ' + PACKAGE_NAME + ' from remote');
fetchRemotePackage(REMOTE_PACKAGE_NAME, REMOTE_PACKAGE_SIZE,
function(packageData) {
if(CACHEMODULE){
cacheRemotePackage(db, PACKAGE_PATH + PACKAGE_NAME, packageData, {uuid:PACKAGE_UUID}, processPackageData,
function(error) {
console.error(error);
processPackageData(packageData);
});
});}
else {
processPackageData(packageData);
}
}
, preloadFallback);
}

View file

@ -43,7 +43,7 @@ releases/$(NAME)-$(VERSION)-win.zip: $(LOVEFILE)
mv releases/$(NAME)-win32.zip $@
releases/$(NAME)-$(VERSION)-web.zip: $(LOVEFILE)
cd releases && ../buildtools/love-js/love-js.sh $(PWD)/releases $(NAME) $(VERSION)
cd releases && ../buildtools/love-js/love-js.sh $(PWD)/releases $(NAME) $(VERSION) false
linux: releases/$(NAME)-$(VERSION)-x86_64.AppImage
mac: releases/$(NAME)-$(VERSION)-macos.zip