{"action":"created","comment":{"url":"https://api.github.com/repos/bforma/robo-racer/pulls/comments/32730403","id":32730403,"diff_hunk":"@@ -0,0 +1,131 @@\n+RoboRacer.GameEventListener = Class.extend(\n+  initialize: (gameRepository) ->\n+    @gameRepository = gameRepository\n+\n+  handleEvents: (events) ->\n+    startedAt = new Date\n+    _(events).forEach ((event) ->\n+      @handleEvent event\n+    ).bind(this)\n+    endedAt = new Date\n+    duration = endedAt - startedAt\n+    console.log \"Replayed %d events in %d ms\", events.length, duration\n+\n+  handleEvent: (event) ->\n+    eventMethodName = @methodName(event.payload_type)\n+    eventMethod = @[eventMethodName]\n+    if typeof eventMethod == \"function\"\n+      console.log \"Handle '\" + event.payload_type + \"'\"\n+      eventMethod.call this, event.payload\n+    else\n+      console.warn \"Cannot handle event with payload_type '\" + event.payload_type + \"'\"\n+\n+  methodName: (payload_type) ->\n+    \"on\" + payload_type\n+\n+  onGameCreatedEvent: (payload) ->\n+    @gameRepository.add new (RoboRacer.Models.Game)(payload)\n+\n+  onPlayerJoinedGameEvent: (payload) ->\n+    game = @gameRepository.find(payload.id)\n+    game.get(\"players\").add _id: payload.player_id\n+\n+  onPlayerLeftGameEvent: (payload) ->\n+    game = @gameRepository.find(payload.id)\n+    players = game.get(\"players\")\n+    player = players.findWhere(_id: payload.player_id)\n+    players.remove player\n+\n+  onGameStartedEvent: (payload) ->\n+    game = @gameRepository.find(payload.id)\n+    game.set \"state\", payload.state\n+    game.get(\"board\").set \"tiles\", new (RoboRacer.Collections.Tiles)(_.map(payload.tiles, (tile, _) ->\n+      tile\n+    ))\n+\n+  onSpawnPlacedEvent: (payload) ->\n+    game = @gameRepository.find(payload.id)\n+    game.get(\"board\").get(\"spawns\").add new (RoboRacer.Models.Spawn)(\n+      player_id: payload.player_id\n+      x: payload.spawn.x\n+      y: payload.spawn.y\n+      facing: payload.spawn.facing)\n+\n+  onGoalPlacedEvent: (payload) ->\n+    game = @gameRepository.find(payload.id)\n+    game.get(\"board\").get(\"checkpoints\").add new (RoboRacer.Models.Checkpoint)(payload.goal)\n+\n+  onRobotSpawnedEvent: (payload) ->\n+    game = @gameRepository.find(payload.id)\n+    game.get(\"board\").get(\"robots\").add new (RoboRacer.Models.Robot)(\n+      player_id: payload.player_id\n+      x: payload.robot.x\n+      y: payload.robot.y\n+      facing: payload.robot.facing)\n+\n+  onGameRoundStartedEvent: (payload) ->\n+    game = @gameRepository.find(payload.id)\n+    game.set \"round_number\", payload.game_round.number\n+    _(payload.hands).forEach (instructionCards, playerId) ->\n+      player = game.get(\"players\").findWhere(_id: playerId)\n+      player.get(\"hand\").set instructionCards\n+\n+    _(payload.programs).forEach (instructionCards, playerId) ->\n+      player = game.get(\"players\").findWhere(_id: playerId)\n+      player.set \"committedProgram\", false\n+      player.get(\"program\").forEach (register, index) ->\n+        register.set \"instruction_card\", instructionCards[index]\n+\n+      player.get(\"revealedRegisters\").reset()\n+\n+\n+  onInstructionCardDealtEvent: (payload) ->\n+    game = @gameRepository.find(payload.id)\n+    player = game.get(\"players\").findWhere(_id: payload.player_id)\n+    player.get(\"hand\").add new (RoboRacer.Models.InstructionCard)(payload.instruction_card)","path":"app/assets/javascripts/game_event_listener.coffee","position":85,"original_position":85,"commit_id":"d5d81d4c45834ff03fef4570541c45bfe3188fcd","original_commit_id":"d5d81d4c45834ff03fef4570541c45bfe3188fcd","user":{"login":"houndci","id":6697940,"avatar_url":"https://avatars.githubusercontent.com/u/6697940?v=3","gravatar_id":"","url":"https://api.github.com/users/houndci","html_url":"https://github.com/houndci","followers_url":"https://api.github.com/users/houndci/followers","following_url":"https://api.github.com/users/houndci/following{/other_user}","gists_url":"https://api.github.com/users/houndci/gists{/gist_id}","starred_url":"https://api.github.com/users/houndci/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/houndci/subscriptions","organizations_url":"https://api.github.com/users/houndci/orgs","repos_url":"https://api.github.com/users/houndci/repos","events_url":"https://api.github.com/users/houndci/events{/privacy}","received_events_url":"https://api.github.com/users/houndci/received_events","type":"User","site_admin":false},"body":"Line exceeds maximum allowed length","created_at":"2015-06-18T13:43:19Z","updated_at":"2015-06-18T13:43:19Z","html_url":"https://github.com/bforma/robo-racer/pull/7#discussion_r32730403","pull_request_url":"https://api.github.com/repos/bforma/robo-racer/pulls/7","_links":{"self":{"href":"https://api.github.com/repos/bforma/robo-racer/pulls/comments/32730403"},"html":{"href":"https://github.com/bforma/robo-racer/pull/7#discussion_r32730403"},"pull_request":{"href":"https://api.github.com/repos/bforma/robo-racer/pulls/7"}}},"pull_request":{"url":"https://api.github.com/repos/bforma/robo-racer/pulls/7","id":38007673,"html_url":"https://github.com/bforma/robo-racer/pull/7","diff_url":"https://github.com/bforma/robo-racer/pull/7.diff","patch_url":"https://github.com/bforma/robo-racer/pull/7.patch","issue_url":"https://api.github.com/repos/bforma/robo-racer/issues/7","number":7,"state":"open","locked":false,"title":"Feature/humanly replay round","user":{"login":"bforma","id":1178544,"avatar_url":"https://avatars.githubusercontent.com/u/1178544?v=3","gravatar_id":"","url":"https://api.github.com/users/bforma","html_url":"https://github.com/bforma","followers_url":"https://api.github.com/users/bforma/followers","following_url":"https://api.github.com/users/bforma/following{/other_user}","gists_url":"https://api.github.com/users/bforma/gists{/gist_id}","starred_url":"https://api.github.com/users/bforma/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bforma/subscriptions","organizations_url":"https://api.github.com/users/bforma/orgs","repos_url":"https://api.github.com/users/bforma/repos","events_url":"https://api.github.com/users/bforma/events{/privacy}","received_events_url":"https://api.github.com/users/bforma/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-06-18T13:42:48Z","updated_at":"2015-06-18T13:43:19Z","closed_at":null,"merged_at":null,"merge_commit_sha":"562e3945e3c3d8e0e5ae7974bd8334f72a8b1854","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/bforma/robo-racer/pulls/7/commits","review_comments_url":"https://api.github.com/repos/bforma/robo-racer/pulls/7/comments","review_comment_url":"https://api.github.com/repos/bforma/robo-racer/pulls/comments{/number}","comments_url":"https://api.github.com/repos/bforma/robo-racer/issues/7/comments","statuses_url":"https://api.github.com/repos/bforma/robo-racer/statuses/d5d81d4c45834ff03fef4570541c45bfe3188fcd","head":{"label":"bforma:feature/humanly-replay-round","ref":"feature/humanly-replay-round","sha":"d5d81d4c45834ff03fef4570541c45bfe3188fcd","user":{"login":"bforma","id":1178544,"avatar_url":"https://avatars.githubusercontent.com/u/1178544?v=3","gravatar_id":"","url":"https://api.github.com/users/bforma","html_url":"https://github.com/bforma","followers_url":"https://api.github.com/users/bforma/followers","following_url":"https://api.github.com/users/bforma/following{/other_user}","gists_url":"https://api.github.com/users/bforma/gists{/gist_id}","starred_url":"https://api.github.com/users/bforma/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bforma/subscriptions","organizations_url":"https://api.github.com/users/bforma/orgs","repos_url":"https://api.github.com/users/bforma/repos","events_url":"https://api.github.com/users/bforma/events{/privacy}","received_events_url":"https://api.github.com/users/bforma/received_events","type":"User","site_admin":false},"repo":{"id":20587556,"name":"robo-racer","full_name":"bforma/robo-racer","owner":{"login":"bforma","id":1178544,"avatar_url":"https://avatars.githubusercontent.com/u/1178544?v=3","gravatar_id":"","url":"https://api.github.com/users/bforma","html_url":"https://github.com/bforma","followers_url":"https://api.github.com/users/bforma/followers","following_url":"https://api.github.com/users/bforma/following{/other_user}","gists_url":"https://api.github.com/users/bforma/gists{/gist_id}","starred_url":"https://api.github.com/users/bforma/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bforma/subscriptions","organizations_url":"https://api.github.com/users/bforma/orgs","repos_url":"https://api.github.com/users/bforma/repos","events_url":"https://api.github.com/users/bforma/events{/privacy}","received_events_url":"https://api.github.com/users/bforma/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/bforma/robo-racer","description":"","fork":false,"url":"https://api.github.com/repos/bforma/robo-racer","forks_url":"https://api.github.com/repos/bforma/robo-racer/forks","keys_url":"https://api.github.com/repos/bforma/robo-racer/keys{/key_id}","collaborators_url":"https://api.github.com/repos/bforma/robo-racer/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/bforma/robo-racer/teams","hooks_url":"https://api.github.com/repos/bforma/robo-racer/hooks","issue_events_url":"https://api.github.com/repos/bforma/robo-racer/issues/events{/number}","events_url":"https://api.github.com/repos/bforma/robo-racer/events","assignees_url":"https://api.github.com/repos/bforma/robo-racer/assignees{/user}","branches_url":"https://api.github.com/repos/bforma/robo-racer/branches{/branch}","tags_url":"https://api.github.com/repos/bforma/robo-racer/tags","blobs_url":"https://api.github.com/repos/bforma/robo-racer/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/bforma/robo-racer/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/bforma/robo-racer/git/refs{/sha}","trees_url":"https://api.github.com/repos/bforma/robo-racer/git/trees{/sha}","statuses_url":"https://api.github.com/repos/bforma/robo-racer/statuses/{sha}","languages_url":"https://api.github.com/repos/bforma/robo-racer/languages","stargazers_url":"https://api.github.com/repos/bforma/robo-racer/stargazers","contributors_url":"https://api.github.com/repos/bforma/robo-racer/contributors","subscribers_url":"https://api.github.com/repos/bforma/robo-racer/subscribers","subscription_url":"https://api.github.com/repos/bforma/robo-racer/subscription","commits_url":"https://api.github.com/repos/bforma/robo-racer/commits{/sha}","git_commits_url":"https://api.github.com/repos/bforma/robo-racer/git/commits{/sha}","comments_url":"https://api.github.com/repos/bforma/robo-racer/comments{/number}","issue_comment_url":"https://api.github.com/repos/bforma/robo-racer/issues/comments{/number}","contents_url":"https://api.github.com/repos/bforma/robo-racer/contents/{+path}","compare_url":"https://api.github.com/repos/bforma/robo-racer/compare/{base}...{head}","merges_url":"https://api.github.com/repos/bforma/robo-racer/merges","archive_url":"https://api.github.com/repos/bforma/robo-racer/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/bforma/robo-racer/downloads","issues_url":"https://api.github.com/repos/bforma/robo-racer/issues{/number}","pulls_url":"https://api.github.com/repos/bforma/robo-racer/pulls{/number}","milestones_url":"https://api.github.com/repos/bforma/robo-racer/milestones{/number}","notifications_url":"https://api.github.com/repos/bforma/robo-racer/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/bforma/robo-racer/labels{/name}","releases_url":"https://api.github.com/repos/bforma/robo-racer/releases{/id}","created_at":"2014-06-07T06:56:39Z","updated_at":"2015-04-18T09:07:51Z","pushed_at":"2015-06-18T13:42:49Z","git_url":"git://github.com/bforma/robo-racer.git","ssh_url":"git@github.com:bforma/robo-racer.git","clone_url":"https://github.com/bforma/robo-racer.git","svn_url":"https://github.com/bforma/robo-racer","homepage":null,"size":2168,"stargazers_count":0,"watchers_count":0,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"base":{"label":"bforma:master","ref":"master","sha":"969f0e099fc6262ec36b208c25aa2b930003c50a","user":{"login":"bforma","id":1178544,"avatar_url":"https://avatars.githubusercontent.com/u/1178544?v=3","gravatar_id":"","url":"https://api.github.com/users/bforma","html_url":"https://github.com/bforma","followers_url":"https://api.github.com/users/bforma/followers","following_url":"https://api.github.com/users/bforma/following{/other_user}","gists_url":"https://api.github.com/users/bforma/gists{/gist_id}","starred_url":"https://api.github.com/users/bforma/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bforma/subscriptions","organizations_url":"https://api.github.com/users/bforma/orgs","repos_url":"https://api.github.com/users/bforma/repos","events_url":"https://api.github.com/users/bforma/events{/privacy}","received_events_url":"https://api.github.com/users/bforma/received_events","type":"User","site_admin":false},"repo":{"id":20587556,"name":"robo-racer","full_name":"bforma/robo-racer","owner":{"login":"bforma","id":1178544,"avatar_url":"https://avatars.githubusercontent.com/u/1178544?v=3","gravatar_id":"","url":"https://api.github.com/users/bforma","html_url":"https://github.com/bforma","followers_url":"https://api.github.com/users/bforma/followers","following_url":"https://api.github.com/users/bforma/following{/other_user}","gists_url":"https://api.github.com/users/bforma/gists{/gist_id}","starred_url":"https://api.github.com/users/bforma/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bforma/subscriptions","organizations_url":"https://api.github.com/users/bforma/orgs","repos_url":"https://api.github.com/users/bforma/repos","events_url":"https://api.github.com/users/bforma/events{/privacy}","received_events_url":"https://api.github.com/users/bforma/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/bforma/robo-racer","description":"","fork":false,"url":"https://api.github.com/repos/bforma/robo-racer","forks_url":"https://api.github.com/repos/bforma/robo-racer/forks","keys_url":"https://api.github.com/repos/bforma/robo-racer/keys{/key_id}","collaborators_url":"https://api.github.com/repos/bforma/robo-racer/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/bforma/robo-racer/teams","hooks_url":"https://api.github.com/repos/bforma/robo-racer/hooks","issue_events_url":"https://api.github.com/repos/bforma/robo-racer/issues/events{/number}","events_url":"https://api.github.com/repos/bforma/robo-racer/events","assignees_url":"https://api.github.com/repos/bforma/robo-racer/assignees{/user}","branches_url":"https://api.github.com/repos/bforma/robo-racer/branches{/branch}","tags_url":"https://api.github.com/repos/bforma/robo-racer/tags","blobs_url":"https://api.github.com/repos/bforma/robo-racer/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/bforma/robo-racer/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/bforma/robo-racer/git/refs{/sha}","trees_url":"https://api.github.com/repos/bforma/robo-racer/git/trees{/sha}","statuses_url":"https://api.github.com/repos/bforma/robo-racer/statuses/{sha}","languages_url":"https://api.github.com/repos/bforma/robo-racer/languages","stargazers_url":"https://api.github.com/repos/bforma/robo-racer/stargazers","contributors_url":"https://api.github.com/repos/bforma/robo-racer/contributors","subscribers_url":"https://api.github.com/repos/bforma/robo-racer/subscribers","subscription_url":"https://api.github.com/repos/bforma/robo-racer/subscription","commits_url":"https://api.github.com/repos/bforma/robo-racer/commits{/sha}","git_commits_url":"https://api.github.com/repos/bforma/robo-racer/git/commits{/sha}","comments_url":"https://api.github.com/repos/bforma/robo-racer/comments{/number}","issue_comment_url":"https://api.github.com/repos/bforma/robo-racer/issues/comments{/number}","contents_url":"https://api.github.com/repos/bforma/robo-racer/contents/{+path}","compare_url":"https://api.github.com/repos/bforma/robo-racer/compare/{base}...{head}","merges_url":"https://api.github.com/repos/bforma/robo-racer/merges","archive_url":"https://api.github.com/repos/bforma/robo-racer/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/bforma/robo-racer/downloads","issues_url":"https://api.github.com/repos/bforma/robo-racer/issues{/number}","pulls_url":"https://api.github.com/repos/bforma/robo-racer/pulls{/number}","milestones_url":"https://api.github.com/repos/bforma/robo-racer/milestones{/number}","notifications_url":"https://api.github.com/repos/bforma/robo-racer/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/bforma/robo-racer/labels{/name}","releases_url":"https://api.github.com/repos/bforma/robo-racer/releases{/id}","created_at":"2014-06-07T06:56:39Z","updated_at":"2015-04-18T09:07:51Z","pushed_at":"2015-06-18T13:42:49Z","git_url":"git://github.com/bforma/robo-racer.git","ssh_url":"git@github.com:bforma/robo-racer.git","clone_url":"https://github.com/bforma/robo-racer.git","svn_url":"https://github.com/bforma/robo-racer","homepage":null,"size":2168,"stargazers_count":0,"watchers_count":0,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/bforma/robo-racer/pulls/7"},"html":{"href":"https://github.com/bforma/robo-racer/pull/7"},"issue":{"href":"https://api.github.com/repos/bforma/robo-racer/issues/7"},"comments":{"href":"https://api.github.com/repos/bforma/robo-racer/issues/7/comments"},"review_comments":{"href":"https://api.github.com/repos/bforma/robo-racer/pulls/7/comments"},"review_comment":{"href":"https://api.github.com/repos/bforma/robo-racer/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/bforma/robo-racer/pulls/7/commits"},"statuses":{"href":"https://api.github.com/repos/bforma/robo-racer/statuses/d5d81d4c45834ff03fef4570541c45bfe3188fcd"}}}}