Re: LÖVELINESS a LÖVE Chrome Extension
Posted: Wed Sep 25, 2013 7:52 pm
Slight bug: lg.supported 'npot' returns false but LÖVELINESS can display npot images.
Actually, yes! I was going to add a demo of this, but haven't gotten around to it. To do it, add something like this to your HTML:Plu wrote:This is probably going to be a "no", but is there any way to run something like LÖVELINESS inside of a webpage instead of as a full browser tab?
I mean like opening it in a html-element and running it there.
Code: Select all
<div id="listener">
<script>
document.getElementById('listener').addEventListener('load',
function() { document.embeds[0].postMessage('run'); }, true);
</script>
<embed type="application/x-love-game" love_src="url/of/your/game.love" width="800" height="600">
</div>
Code: Select all
if (navigator.mimeTypes['application/x-love-game']) {
// the user has LÖVELINESS installed
} else {
// the user doesn't have loveliness installed, display an error, remove the embed, etc.
}
Awesome! Thanks, it works great. (As long as the .love file is on the same domain as the .html page, I'm guessing? It didn't work when I opened the file from my local machine with the .love on the web)binji wrote:Actually, yes! I was going to add a demo of this, but haven't gotten around to it. To do it, add something like this to your HTML:Plu wrote:This is probably going to be a "no", but is there any way to run something like LÖVELINESS inside of a webpage instead of as a full browser tab?
I mean like opening it in a html-element and running it there.
Hm, this makes me wonder. Can the plugin send messages that the game generates back to javascript? So that the love application can communicate with the rest of the website? And can javascript send additional messages to the plugin that end up in the game?A little explanation of the JavaScript: it is necessary to notify the plugin when it should run. It unfortunately does not run automatically. Instead, the code waits for the module to load, then posts the message "run" to it.
Good question. Basically, LÖVELINESS can be loaded three ways:Robin wrote:Why is that source attribute named love_src instead of src?
Code: Select all
1. <embed type="application/x-nacl" src="love_release.nmf" love_src="...">
2. <embed type="application/x-love-game" src="...">
3. <embed type="application/x-love-game" love_src="...">
Yeah, AFAIK that won't ever work on Chrome. You can't reference file:// resources from a normal web page, and you can't reference file:// resources from other file:// resources.Plu wrote:Awesome! Thanks, it works great. (As long as the .love file is on the same domain as the .html page, I'm guessing? It didn't work when I opened the file from my local machine with the .love on the web)
Yes, it's possible. There would need to be a new function in lua to do it, obviously, and I'm not too keen on extending the LÖVE API. BTW, there are some messages that the plugin already sends to the page that may be useful. You can listen for them like this:Plu wrote:Can the plugin send messages that the game generates back to javascript? So that the love application can communicate with the rest of the website? And can javascript send additional messages to the plugin that end up in the game?
Code: Select all
document.getElementById('listener').addEventListener('message', function(event) {
// event.data is a string:
// setWindow:<width>,<height> -> the plugin is asking to change the size of the embed
// download:<downloaded>,<max> -> the plugin is telling how much of the .love file is downloaded, in bytes
// OK -> the plugin has finished downloading the .love file
// bye -> the .love game has ended, remove the embed element or reload it, etc.
// requestFileSystem -> the .love game is trying to write to persistent storage, but needs JavaScript to OK it.
}, true);