From b5e74ae246e8ab89a713be2fc77dd775143b0c1f Mon Sep 17 00:00:00 2001 From: Alexander Griffith Date: Mon, 13 Sep 2021 01:15:26 -0400 Subject: [PATCH] Updated makefile and buildtools to work with web --- buildtools/love-js/love-js.sh | 14 ++++--- buildtools/love-js/src/game.js | 7 ++-- buildtools/love-js/src/index.html | 2 +- lib/stdio.lua | 69 +++++++++++++++++++++++++++++++ makefile | 2 +- wrap.fnl | 4 +- 6 files changed, 85 insertions(+), 13 deletions(-) create mode 100644 lib/stdio.lua diff --git a/buildtools/love-js/love-js.sh b/buildtools/love-js/love-js.sh index 04a4123..5a12efe 100755 --- a/buildtools/love-js/love-js.sh +++ b/buildtools/love-js/love-js.sh @@ -30,10 +30,10 @@ if [ ! -f $release_dir/$name-$version.love ]; then fi release="compat" -canvas_colour="197, 204, 184" +canvas_colour="62, 50, 100" page_colour=$canvas_colour -text_colour="102, 96, 146" -initial_memory=$(du -b $release_dir/$name-$version.love | awk '{print $1}') +text_colour="223, 7, 114" +initial_memory=0 #$(du -b $release_dir/$name-$version.love | awk '{print $1}') title=$(echo $name-$version | sed -r 's/\<./\U&/g' | sed -r 's/-/\ /g') # echo $title " " $canvas_colour " " $text_colour " " $initial_memory @@ -54,9 +54,13 @@ cat src/love.css | \ sed "s/{{page-colour}}/${page_colour}/g" > \ $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}]}/" > \ + $name-$version/game.js + cp src/consolewrapper.js $name-$version -cp src/game.js $name-$version -cp $release_dir/$name-$version.love $name-$version/game.data +# cp src/game.js $name-$version +cp $release_dir/$name-$version.love $name-$version/game.love cp src/$release/love.js $name-$version cp src/$release/love.wasm $name-$version cp src/release/love.worker.js $name-$version diff --git a/buildtools/love-js/src/game.js b/buildtools/love-js/src/game.js index 95fd6fd..ca20533 100644 --- a/buildtools/love-js/src/game.js +++ b/buildtools/love-js/src/game.js @@ -1,4 +1,3 @@ - var Module; if (typeof Module === 'undefined') Module = eval('(function() { try { return Module || {} } catch(e) { return {} } })()'); @@ -20,8 +19,8 @@ Module.expectedDataFileDownloads++; } else { throw 'using preloaded data can only be done on a web page or in a web worker'; } - var PACKAGE_NAME = 'game.data'; - var REMOTE_PACKAGE_BASE = 'game.data'; + var PACKAGE_NAME = 'game.love'; + var REMOTE_PACKAGE_BASE = 'game.love'; if (typeof Module['locateFilePackage'] === 'function' && !Module['locateFile']) { Module['locateFile'] = Module['locateFilePackage']; Module.printErr('warning: you defined Module.locateFilePackage, that has been renamed to Module.locateFile (using your locateFilePackage for now)'); @@ -90,7 +89,7 @@ Module.expectedDataFileDownloads++; function assert(check, msg) { if (!check) throw msg + new Error().stack; } - {{{create_file_paths}}} + // {{{create_file_paths}}} function DataRequest(start, end, crunched, audio) { this.start = start; diff --git a/buildtools/love-js/src/index.html b/buildtools/love-js/src/index.html index 8870711..d2d4960 100644 --- a/buildtools/love-js/src/index.html +++ b/buildtools/love-js/src/index.html @@ -74,7 +74,7 @@ }, false); var Module = { - arguments: ["./game.love","web"], + arguments: ["game.love","web"], INITIAL_MEMORY: {{initial-memory}}, printErr: console.error.bind(console), canvas: (function() { diff --git a/lib/stdio.lua b/lib/stdio.lua new file mode 100644 index 0000000..b588d2d --- /dev/null +++ b/lib/stdio.lua @@ -0,0 +1,69 @@ +require("love.event") +local function prompt(cont_3f) + local function _1_() + if cont_3f then + return ".." + else + return ">> " + end + end + io.write(_1_()) + io.flush() + return (io.read() .. "\n") +end +local function looper(event, channel) + do + local _2_ = channel:demand() + if ((_G.type(_2_) == "table") and ((_2_)[1] == "write") and (nil ~= (_2_)[2])) then + local vals = (_2_)[2] + io.write(table.concat(vals, "\9")) + io.write("\n") + elseif ((_G.type(_2_) == "table") and ((_2_)[1] == "read") and (nil ~= (_2_)[2])) then + local cont_3f = (_2_)[2] + love.event.push(event, prompt(cont_3f)) + end + end + return looper(event, channel) +end +do + local _4_, _5_ = ... + if ((nil ~= _4_) and (nil ~= _5_)) then + local event = _4_ + local channel = _5_ + looper(event, channel) + end +end +local function start_repl() + local code = love.filesystem.read("lib/stdio.fnl") + local luac + if code then + luac = love.filesystem.newFileData(fennel.compileString(code), "io") + else + luac = love.filesystem.read("lib/stdio.lua") + end + local thread = love.thread.newThread(luac) + local io_channel = love.thread.newChannel() + local coro = coroutine.create(fennel.repl) + local options + local function _10_(_8_) + local _arg_9_ = _8_ + local stack_size = _arg_9_["stack-size"] + io_channel:push({"read", (0 < stack_size)}) + return coroutine.yield() + end + local function _11_(vals) + return io_channel:push({"write", vals}) + end + local function _12_(errtype, err) + return io_channel:push({"write", {err}}) + end + options = {readChunk = _10_, onValues = _11_, onError = _12_, moduleName = "lib.fennel"} + coroutine.resume(coro, options) + thread:start("eval", io_channel) + local function _13_(input) + return coroutine.resume(coro, input) + end + love.handlers.eval = _13_ + return nil +end +return {start = start_repl} diff --git a/makefile b/makefile index f91f86b..bc03a7e 100644 --- a/makefile +++ b/makefile @@ -32,7 +32,7 @@ love: $(LOVEFILE) # platform-specific distributables -REL=$(PWD)/love-release.sh # https://p.hagelb.org/love-release.sh +REL=$(PWD)/buildtools/love-release.sh # https://p.hagelb.org/love-release.sh FLAGS=-a "$(AUTHOR)" --description $(DESCRIPTION) \ --love $(LOVE_VERSION) --url $(URL) --version $(VERSION) --lovefile $(LOVEFILE) diff --git a/wrap.fnl b/wrap.fnl index 51284ec..59aa98d 100644 --- a/wrap.fnl +++ b/wrap.fnl @@ -14,10 +14,10 @@ (match (pcall mode.activate ...) (false msg) (print mode-name "activate error" msg)))) -(fn love.load [] +(fn love.load [args] (set-mode :mode-intro) (canvas:setFilter "nearest" "nearest") - (repl.start)) + (when (~= :web (. args 1)) (repl.start))) (fn safely [f] (xpcall f #(set-mode :error-mode mode-name $ (fennel.traceback))))