Skip to content

Commit

Permalink
Add in TogetherJS support
Browse files Browse the repository at this point in the history
  • Loading branch information
ianb committed Dec 5, 2013
1 parent 7a54cb4 commit 696bbf4
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 1 deletion.
4 changes: 4 additions & 0 deletions index.htm
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
<script src="//cdnjs.cloudflare.com/ajax/libs/codemirror/3.20.0/addon/display/placeholder.js"></script>
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/codemirror/3.20.0/codemirror.css">
<script src="cm/logo.js"></script>

<link rel="stylesheet" href="cm/logo.css">

<link rel="stylesheet" href="index.css">
Expand All @@ -29,6 +30,7 @@ <h1>Logo Interpreter</h1>
By <a href="mailto:inexorabletash@gmail.com">Joshua Bell</a>
| <a target="_blank" href="tests.htm">Unit Tests</a>
| <a target="_blank" href="https://github.com/inexorabletash/jslogo">Source</a>
| <button id="start-togetherjs" onclick="TogetherJS()">Collaborate</button>
</p>
</div>

Expand Down Expand Up @@ -114,6 +116,8 @@ <h1>Logo Interpreter</h1>
<script src="logo.js"></script>
<script src="turtle.js"></script>
<script src="index.js"></script>
<!-- TogetherJS Collaboration -->
<script src="https://togetherjs.com/togetherjs-min.js"></script>

<script type="text/javascript">
var _gaq = _gaq || [];
Expand Down
58 changes: 57 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,10 @@ var input = {};
return document.body.classList.contains('multi');
};

function run() {
function run(remote) {
if (remote !== true && window.TogetherJS && window.TogetherJS.running) {
TogetherJS.send({type: "run"});
}
var error = $('#display #error');
error.classList.remove('shown');

Expand All @@ -195,6 +198,8 @@ var input = {};
}, 100);
}

input.run = run;

if ('CodeMirror' in window) {
var BRACKETS = '()[]{}';

Expand Down Expand Up @@ -546,3 +551,54 @@ window.addEventListener('load', function() {
demo(param);
window.addEventListener('hashchange', function(e) { demo(document.location.hash); } );
});

window.TogetherJSConfig ={

hub_on: {
"togetherjs.hello": function () {
var visible = turtle.isturtlevisible();
TogetherJS.send({
type: "init",
image: $("#sandbox").toDataURL("image/png"),
color: turtle.getcolor(),
xy: turtle.getxy(),
heading: turtle.getheading(),
penmode: turtle.getpenmode(),
turtlemode: turtle.getturtlemode(),
width: turtle.getwidth(),
fontsize: turtle.getfontsize(),
visible: visible,
pendown: turtle.down
});
},

"init": function (msg) {
var context = $("#sandbox").getContext("2d");
var image = new Image();
image.src = msg.image;
context.drawImage(image, 0, 0);
turtle.begin();
turtle.penup();
turtle.hideturtle();
turtle.setturtlemode(msg.turtlemode);
turtle.setcolor(msg.color);
turtle.setwidth(msg.width);
turtle.setfontsize(msg.size);
turtle.setposition(msg.xy[0], msg.xy[1]);
turtle.setheading(msg.heading);
turtle.setpenmode(msg.penmode);
if (msg.visible) {
turtle.showturtle();
}
if (msg.pendown) {
turtle.pendown();
}
turtle.end();
},

run: function (msg) {
input.run(true);
}
}

};

0 comments on commit 696bbf4

Please sign in to comment.