Love.js - A Direct Emscripten Port

Discuss any ports of LÖVE to different platforms.
User avatar
ivan
Party member
Posts: 1911
Joined: Fri Mar 07, 2008 1:39 pm
Contact:

Re: Love.js - A Direct Emscripten Port

Post by ivan »

Hey, thank you so much for the feedback. I managed to get all of my games to show their titlescreen and the menus work too.
However love.filesystem.read() just hangs the entire script.
I though about writing an alternative using "io." but the asset being loaded is located in my ".love" file.
I suppose wrapping the asset as a string in a ".lua" script and using "require" could work but that's not ideal.
Any tips on working around this?
BTW is there any way of detecting that the code is running from love.js? Something like love's getOS function?
This could be useful so that I can adjust my love files to work across platforms without making special builds just for love.js.

PS. I've also noticed that love.system.openURL doesn't work.
Really appreciate all the help, and hoping to see love.js become more stable in the future.
Attachments
arena.love
updated and trimmed to ~10mb
(10.17 MiB) Downloaded 275 times
User avatar
Stifu
Party member
Posts: 106
Joined: Mon Mar 14, 2016 9:53 am
Contact:

Re: Love.js - A Direct Emscripten Port

Post by Stifu »

ivan wrote: Tue Sep 15, 2020 9:08 am BTW is there any way of detecting that the code is running from love.js? Something like love's getOS function?
Yep!
Davidobot wrote: Sat Sep 12, 2020 3:08 pm love.system.getOS returns Web in-browser. ;)
Zabuyaki, our upcoming beat 'em up: https://www.zabuyaki.com
User avatar
Davidobot
Party member
Posts: 1226
Joined: Sat Mar 31, 2012 5:18 am
Location: Oxford, UK
Contact:

Re: Love.js - A Direct Emscripten Port

Post by Davidobot »

ivan wrote: Tue Sep 15, 2020 9:08 am Hey, thank you so much for the feedback. I managed to get all of my games to show their titlescreen and the menus work too.
However love.filesystem.read() just hangs the entire script.
I though about writing an alternative using "io." but the asset being loaded is located in my ".love" file.
I suppose wrapping the asset as a string in a ".lua" script and using "require" could work but that's not ideal.
Any tips on working around this?
I noticed that you don't have the shader folder in the .love you uploaded?
ivan wrote: Tue Sep 15, 2020 9:08 am PS. I've also noticed that love.system.openURL doesn't work.
Interesting, I'll look into that. What browser are you on? There is specific code that is meant to make openURL work in-browser. Are you trying to open a website or a local file?

More notes:
- love.window.showMessageBox(title, message, buttons, "info", false) -> message boxes with multiple buttons aren't supported
- Reading from inside the .love works fine. I think if you start the filepath with a / it works all the time (you start with a / sometimes, but not always)
- The love.js:9 exception thrown: TypeError: Cannot read property 'length' of undefined,TypeError: Cannot read property 'length' of undefined error is due to sound, I think. I think it is because the sound file aren't read in fully yet. So you might want to check whether they were properly init-ed before you try to play them or do something with them.

Image
I did actually make it run a couple of times, which is why I think it's an audio loading problem.
PM me on here or elsewhere if you'd like to discuss porting your game to Nintendo Switch via mazette!
personal page and a raycaster
User avatar
ivan
Party member
Posts: 1911
Joined: Fri Mar 07, 2008 1:39 pm
Contact:

Re: Love.js - A Direct Emscripten Port

Post by ivan »

Thank you so much for taking a look.
I managed to get two of my games working fully so that's very exciting (still no luck with the one mentioned above).
I will definitely be putting up public demos soon.
love.js is great and I think it should be mentioned on the love2d homepage - that would drive further usage and hopefully more development and commits.
I noticed that you don't have the shader folder in the .love you uploaded?
I removed that folder in order to debug the more essential issues.
Interesting, I'll look into that. What browser are you on?
Chrome 85.0.4183.102 (official build) (64-bit)
There is specific code that is meant to make openURL work in-browser. Are you trying to open a website or a local file?
Yep, trying to open a website (the game's Steam page) when the demo is over.
message boxes with multiple buttons aren't supported
This one is fine, and I believe it's not used in the web version of my games.
I think if you start the filepath with a / it works all the time (you start with a / sometimes, but not always)
Great, I will investigate this further. It does look like love.filesystem.read works in certain cases and fails in others.

One more suggestion - I think the love.js loader should not contain any text.
Instead of "downloading, preparing, powered by, etc..." it's better to just show a simple progress bar.
I am nitpicking here but a progress bar is more obvious and universally understood (furthemore, some games are localized and may not be in English at all).
Also, I will include you in the game credits, please let me know if you'd don't mind being credited as "Davidobot".
Thanks so much!
User avatar
Davidobot
Party member
Posts: 1226
Joined: Sat Mar 31, 2012 5:18 am
Location: Oxford, UK
Contact:

Re: Love.js - A Direct Emscripten Port

Post by Davidobot »

ivan wrote: Wed Sep 16, 2020 10:30 am love.js is great and I think it should be mentioned on the love2d homepage - that would drive further usage and hopefully more development and commits.
I've brought this up with slime73 a few days ago. They said they were happy to bring it to mainline once it is stable.
ivan wrote: Tue Sep 15, 2020 9:08 am PS. I've also noticed that love.system.openURL doesn't work.
I pushed a fix for that just now.
ivan wrote: Wed Sep 16, 2020 10:30 am Great, I will investigate this further. It does look like love.filesystem.read works in certain cases and fails in others.
PS. I've also noticed that love.system.openURL doesn't work.
Would be super to hear if you discover anything!
ivan wrote: Wed Sep 16, 2020 10:30 am One more suggestion - I think the love.js loader should not contain any text.
Instead of "downloading, preparing, powered by, etc..." it's better to just show a simple progress bar.
I am nitpicking here but a progress bar is more obvious and universally understood (furthemore, some games are localized and may not be in English at all).
Hm, I see what you mean. The "loader" can easily be configured. It's just in the index.html file that is generated. For example, if you want, you can edit drawLoadingText and setStatus to make the loading screen black with a white loading bar and no text.
ivan wrote: Wed Sep 16, 2020 10:30 am Also, I will include you in the game credits, please let me know if you'd don't mind being credited as "Davidobot".
Thanks so much!
I only ported Tanner's work to 11.3 :) Not too much hassle. If you'd like to credit me, Davidobot is just fine. If you have links, it'd be nice to link to my website https://davidobot.net/ otherwise just the username is enough :)
PM me on here or elsewhere if you'd like to discuss porting your game to Nintendo Switch via mazette!
personal page and a raycaster
User avatar
ivan
Party member
Posts: 1911
Joined: Fri Mar 07, 2008 1:39 pm
Contact:

Re: Love.js - A Direct Emscripten Port

Post by ivan »

Hey, I finally managed to figure it out.
The following line was causing a crash on my system:

Code: Select all

love.audio.stop()
I have disabled this line specifically for the web version of the game and it seems to run fine now.
Attached is the latest .love file if you want to take a look.

Thanks again for all of the help, I will make sure to credit both you and Tanner for your great work.
And I'll mention love.js on the official issue tracker and hopefully we can bring more attention to this great project.
Cheers!
Attachments
arena.love
Skullmaster's Arena demo for the web
(4.49 MiB) Downloaded 225 times
User avatar
ivan
Party member
Posts: 1911
Joined: Fri Mar 07, 2008 1:39 pm
Contact:

Re: Love.js - A Direct Emscripten Port

Post by ivan »

Nice fix, I can confirm that love.system.openURL works perfectly now.
I managed to get all of my games working and the performance is pretty good.

So far it looks like the major issue is: errors in pcall cause the entire script to fail when used in a coroutine (as mentioned earlier).
Another significant bug is that love.filesystem.read crashes when the file doesn't exist (the same happens with love.filesystem.load).
I think it's certainly possible to circumvent some of these issues by using pure Lua.
For example, there could be a "normalize.lua" script loaded ahead of time that replaces the vanilla "pcall".

Code: Select all

-- normalization fix for lfs.read:
local lfs = love.filesystem
local _read = lfs.read
function lfs.read(fn, ...)
  if lfs.getInfo(fn) ~= nil then
    return _read(fn, ...)
  end
end
Any tips for the "reload the page if screen is blank" bug?
This one is annoying and happens about 1/3 of the time.

Thanks again!

PS. Another minor bug and this one is Lua-related:
string.format("%s", true) raises an error in love.js whereas it does not with Love2D

PSS. Any tips on making love.js embed-able?
Would be awesome if the canvas object can be scaled on responsive pages.
We don't need to resize the game resolution,
just scaling the canvas so the game can be embedded in a section of the window.
User avatar
Davidobot
Party member
Posts: 1226
Joined: Sat Mar 31, 2012 5:18 am
Location: Oxford, UK
Contact:

Re: Love.js - A Direct Emscripten Port

Post by Davidobot »

Noted all the queries as bugs in the GitHub issue tracker!
ivan wrote: Thu Sep 17, 2020 8:29 am PSS. Any tips on making love.js embed-able?
Would be awesome if the canvas object can be scaled on responsive pages.
We don't need to resize the game resolution,
just scaling the canvas so the game can be embedded in a section of the window.
I think if you change the dimensions of the "canvas" element via JS on the page, it should call love.resize in-game.

EDIT:
ivan wrote: Thu Sep 17, 2020 8:29 am Any tips for the "reload the page if screen is blank" bug?
This one is annoying and happens about 1/3 of the time.
I just pushed a new version that prints out the error if the screen is blank. This occurred when an error was thrown by love before the main window was initialised.
PM me on here or elsewhere if you'd like to discuss porting your game to Nintendo Switch via mazette!
personal page and a raycaster
User avatar
ivan
Party member
Posts: 1911
Joined: Fri Mar 07, 2008 1:39 pm
Contact:

Re: Love.js - A Direct Emscripten Port

Post by ivan »

Davidobot wrote: Thu Sep 17, 2020 4:15 pm I think if you change the dimensions of the "canvas" element via JS on the page, it should call love.resize in-game.
I tried adding a function to index.html which resizes the canvas automatically but it didn't quite work:

Code: Select all

window.addEventListener("resize", function(e) {
        var canvas = document.getElementById("canvas");
        canvas.width = window.innerWidth;
        canvas.height = window.innerHeight;
      }, false);
This is not very important although it would be good if we can get love.js running in a "responsive" container that resizes automatically.
It would be good to intercept errors and show something as a fallback.

Other than that love.js works great. Here is one my games running with love.js:
https://2dengine.com/superchains/
I am using non-compatibility mode because the audio seems more stable.

Huge thanks again and keep up the great work!
User avatar
ivan
Party member
Posts: 1911
Joined: Fri Mar 07, 2008 1:39 pm
Contact:

Re: Love.js - A Direct Emscripten Port

Post by ivan »

Found another minor bug: setWrap("repeat", "repeat") doesn't seem to work correctly.
If you look at my previous arena.love build - you can see that the texture "bleeds" and doesn't repeat at all.
The shiny logo effect is supposed to look like this:
Image
I have figured out a way to draw this effect without using quads/setWrap, but it should be noted.
Thanks again!
Post Reply

Who is online

Users browsing this forum: No registered users and 20 guests