diff options
| -rw-r--r-- | AUTHORS | 1 | ||||
| -rw-r--r-- | Makefile | 1 | ||||
| -rw-r--r-- | data_src/ui/ui.png | bin | 0 -> 13101 bytes | |||
| -rw-r--r-- | src/js_bridge.js | 45 | ||||
| -rw-r--r-- | src/main.lua | 5 |
5 files changed, 31 insertions, 21 deletions
@@ -0,0 +1 @@ +opengameart.org user Buch @@ -51,6 +51,7 @@ $(test_moon) : spec/%.lua : src/%.moon $(MOONC) -p $< > $@ $(built_js) : data/%.lua : src/%.js + npx jshint $< echo "return [=====[" > $@ cat $< >> $@ echo "]=====]" >> $@ diff --git a/data_src/ui/ui.png b/data_src/ui/ui.png Binary files differnew file mode 100644 index 0000000..6b3eafc --- /dev/null +++ b/data_src/ui/ui.png diff --git a/src/js_bridge.js b/src/js_bridge.js index a9c8873..46065cb 100644 --- a/src/js_bridge.js +++ b/src/js_bridge.js @@ -1,24 +1,31 @@ var s = document.createElement('script'); -var PEER = {}; s.setAttribute('src','https://unpkg.com/peerjs@1.5.2/dist/peerjs.min.js'); document.body.appendChild(s); function genRanHex(size) { - return Array.apply(null,Array(size)).map(() => Math.floor(Math.random() * 16).toString(16)).join(''); + return Array.apply(null,Array(size)).map(function(){ + Math.floor(Math.random() * 16).toString(16); + }).join(''); + } -PEER.event_queue = {}; -PEER.peers = {}; -PEER.message_queue = {}; -PEER.create = function(name, options) { - var peer = new Peer(name, options); - PEER.peers[name] = peer; -}; -/* -PEER["on"] = function(name, e, message) { - PEER.peers[name].on(e, function(data) { - PEER.message_queue.push({"message":message, "data":data}) - } -} -PEER["connect"] = function(name, id, options) { - PEER.peers[name].connect(id, options) -} -*/ +window.PEER = { + event_queue: {}, + peers: {}, + message_queue: {}, + create: function(name, options) { + var peer = new Peer(name, options); + PEER.peers[name] = peer; + }, + on: function(name, e, message) { + PEER.peers[name].on(e, function(data) { + PEER.message_queue.push({"message":message, "data":{ + "call": "on", + "peer": name, + "e": e, + "data": data + }}); + }); + }, + connect: function(name, id, options) { + PEER.peers[name].connect(id, options); + }, +}; diff --git a/src/main.lua b/src/main.lua index 176cddc..8c8461a 100644 --- a/src/main.lua +++ b/src/main.lua @@ -4,11 +4,12 @@ print("Hello, world!") am.eval_js("console.log('Hello, js!')") local win = am.window{ - title = "Hi", + title = "ggj25", width = 1280, height = 720, clear_color = vec4(0.8, 0.8, 0.3, 1) } print("about to pcall") -local a,b = pcall(am.eval_js, require("js_bridge")) +am.eval_js(require("js_bridge")) +--local a,b = pcall(am.eval_js, require("js_bridge")) print("done with pcall", a,b) |
