
Yet another lovejs player. This player is based onLove 11.5 andEmscription 3.1.68. It outputs a single html file that contains the engine and game you pass in.
You can parameterize the output file by providinglovejs.json in the top level of your .love file
You can customize theHEIGHT andWIDTH of the default html shell using the appropriate tags, or you can provide your own custom html shell.
Note that if you are passing in your own html shell or style sheet those files should be present in your .love file and their paths should be provided bySTYLE_FILE andHTML_FILE.
Currently onlylove115-compat-beta1 is the only available version of love.
Recommendations on further customizable parameters are welcome.
{"TITLE":"Your Game","WIDTH":1280,"HEIGHT":720,"VERSION":"love115-compat-beta1","STYLE_FILE":"/path/to/style.css","HTML_FILE":"/path/to/index.html"}
This bundler extends Love2D to accept incoming signals from the JS environment.
love_send_event(key-string,value-string, value-number) => nil
To create an event"key" with arguments"value" and10 call the following from javascript.
Note the types are fixed, the first two variables must be strings and the last must be a number. This is a limitation of the SDL_UserEvent struct. This may be ameliorated in the future by replacing the event integration with polling.
LoveState['love_send_event']("key","value",10)
On the love2d side you can catch this event using an event handler
functionlove.handlers.key(value,code)print(value)print(code)end
js.call(js-string) => nil
You can usejs.call to execute a js string. No return value is provided. Coupling this withlove_send_event lets you create asynchronous callbacks into the js environment.
Be careful, there are no checks on the string being executed. Errors may crash your game.
-- js is preloaded so it can be required anywherelocaljs=require("js")js.call("console.log(\"hello\");")
js["send-event"](event-name-string) => nil
js["send-event"] sends an event that can be picked up by event listeners attached to the canvas element. No return value is provided. Coupling this withlove_send_event lets you create asynchronous callbacks into the js environment.
-- js is preloaded so it can be required anywherelocaljs=require("js")js["send-event"]("game-start")
functiongameStartEvent(_e){console.log("Game Start!");}LoveState["canvas"].addEventListener("game-start",gameStartEvent);
js["send-custom-json-event"](event-name-string, json-string) => nil
js["send-custom-json-event"] sends an event that can be picked up by event listeners attached to the canvas element. A custom json object will be available under the eventsdetail key. No return value is provided. Coupling this withlove_send_event lets you create asynchronous callbacks into the js environment. You must format the outgoingjson-string as json or there will be an error in the JS environment.
-- js is preloaded so it can be required anywherelocaljs=require("js")-- load your own json librarylocaljson=require("lib.json")localmessage={}message["name"]="Test Name"js["send-custom-json-event"]("game-start",json.encode(message))
functiongameStartEvent(e){console.log(e.detail.name);}LoveState["canvas"].addEventListener("game-start",gameStartEvent);
websocket.supported() => bool
websocket.new(handle-string, address-string) => WS
websocket.deinitalize() => nil
WS:send_utf8_text(utf8text-string) => nil
WS:send_close(code-number,reason-string) => nil
WS:delete() => nil
WS:get_protocol() => string
WS:get_url() => string
WS:get_extensions() => string
WS:get_ready_state() => number
WS:get_ready_state() => number
Incoming websocket events are passed into Love2D via the event system.
There are four events passed in,websocketmessage,websocketopen,websocketerror, andwebsocketclose. Each event passes in a message (string) and a code (number). Write your own handlers to handle these incoming events.
Thehandle string passed towebsockets.new will prepend the name of the four events generated by the websocket system.
-- websocket is preloaded so may be required anywherelocalwebsocket=require("websocket")-- create a new websocket with handle "myhandle-" connected-- to the your localhost port 9000localWS=websocket.new("myhandle-","ws://localhost:9000")love["handlers"]["myhandle-websocketopen"]=function(message)print(message)-- message for websocketopen should always be an empty stringWS.send_utf8_text("connected!!")endlove["handlers"]["myhandle-websocketmessage"]=function(message)print(message)-- incoming message from serverendlove["handlers"]["myhandle-websocketclose"]=function(message)print(message)-- json formatted message to be parsedendlove["handlers"]["myhandle-websocketerror"]=function(message)print(message)-- message from websocketerror is an empty string.end
| Status | In development |
| Category | Tool |
| Platforms | HTML5 |
| Rating | Rated 4.7 out of 5 stars (3 total ratings) |
| Author | Alex ☕🇨🇦 |
| Made with | LÖVE |
| Tags | html5,LÖVE,software |
| Code license | MIT License |
| Asset license | Creative Commons Attribution_ShareAlike v4.0 International |
| Links | Source code |