From 0b2faf372b2809b8a110252d361ca5b6b2bef624 Mon Sep 17 00:00:00 2001 From: Alexander Griffith Date: Fri, 24 Sep 2021 16:45:14 -0400 Subject: [PATCH] Love-js updated to set love file size for web. --- buildtools/love-js/love-js.sh | 11 +++++++---- buildtools/love-js/src/game.js | 13 ++++++++++--- makefile | 2 +- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/buildtools/love-js/love-js.sh b/buildtools/love-js/love-js.sh index 5a12efe..7eb37df 100755 --- a/buildtools/love-js/love-js.sh +++ b/buildtools/love-js/love-js.sh @@ -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 diff --git a/buildtools/love-js/src/game.js b/buildtools/love-js/src/game.js index ca20533..9459ee0 100644 --- a/buildtools/love-js/src/game.js +++ b/buildtools/love-js/src/game.js @@ -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); } diff --git a/makefile b/makefile index 8329918..82f2513 100644 --- a/makefile +++ b/makefile @@ -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