{"action":"created","comment":{"url":"https://api.github.com/repos/SplatJS/splat-ecs/pulls/comments/55470715","id":55470715,"diff_hunk":"@@ -0,0 +1,135 @@\n+\"use strict\";\n+\n+/** <p>Import an orthogonal tilemap from\n+ * <a href=\"http://www.mapeditor.org/\" target=\"_blank\">Tiled: Map Editor</a> and draw on the screen.</p>\n+ * <h5>To Do</h5>\n+ * <ul>\n+ * <li><b>Image Layer</b></li>\n+ * <li><b>Ellipse and Polygon Objects</b></li>\n+ * </ul>\n+ * @module Import From Tiled\n+ */\n+\n+/** @function ImportTilemap\n+ * @param {Object} file JSON file exported from Tiled. This should be required in a scene enter\n+ * script and passed to the function.\n+ * @param {EntityPool} entities EntityPool from game.entities\n+ */\n+function ImportTilemap(file, entities) { // eslint-disable-line no-unused-vars\n+\n+\tvar tile, image, image_index, tile_pos, cols, tileset, tileset_index = 0;\n+\tvar layer, object, entity, object_properties = {};\n+\n+\tfor (var i = 0; i < file.layers.length; i++) {\n+\t\tlayer = file.layers[i];\n+\n+\t\t// Render Tile Layers\n+\t\tif (layer.type == \"tilelayer\") {\n+\t\t\tfor (j = 0; j < layer.data.length; j++) {\n+\n+\t\t\t\t// Select tileset index based on firstgid and image index\n+\t\t\t\t// Set image index minus firstgid for positioning math\n+\t\t\t\tfor (var k = 0; k < file.tilesets.length; k++) {\n+\t\t\t\t\tif (layer.data[j] >= file.tilesets[k].firstgid) {\n+\t\t\t\t\t\ttileset_index = k;\n+\t\t\t\t\t}\n+\t\t\t\t}\n+\t\t\t\tcols = file.tilesets[tileset_index].imagewidth / file.tilesets[tileset_index].tilewidth;\n+\t\t\t\timage_index = layer.data[j] - file.tilesets[tileset_index].firstgid;\n+\t\t\t\ttileset = file.tilesets[tileset_index];\n+\n+\t\t\t\tif (image_index >= 0) {\n+\n+\t\t\t\t\t// Create tile and get properties\n+\t\t\t\t\ttile = entities.create();\n+\t\t\t\t\tentities.set(tile, \"name\", \"tile\");\n+\t\t\t\t\tentities.set(tile, \"tile\", true);\n+\t\t\t\t\tentities.set(tile, \"image\", { \"name\": \"\" });\n+\t\t\t\t\tentities.set(tile, \"position\", { \"x\": 0, \"y\": 0 });\n+\t\t\t\t\tentities.set(tile, \"size\", { \"width\": tileset.tileheight, \"height\": tileset.tilewidth });\n+\t\t\t\t\timage = entities.get(tile, \"image\");\n+\t\t\t\t\ttile_pos = entities.get(tile, \"position\");\n+\n+\t\t\t\t\t// Position based on index\n+\t\t\t\t\ttile_pos.x = (j % file.width) * file.tilewidth;\n+\t\t\t\t\ttile_pos.y = Math.floor(j / file.width) * file.tileheight;\n+\n+\t\t\t\t\t// Character position z: 1 so anything without background true will layer over player\n+\t\t\t\t\ttile_pos.z = (layer.properties.Background == \"True\") ? -1 : 2;\n+\n+\t\t\t\t\t// Select which \"tile\" of the tileset image to render\n+\t\t\t\t\timage.name = tileset.image;\n+\t\t\t\t\timage.sourceWidth = tileset.tilewidth;\n+\t\t\t\t\timage.sourceHeight = tileset.tileheight;\n+\t\t\t\t\timage.destinationWidth = tileset.tilewidth;\n+\t\t\t\t\timage.destinationHeight = tileset.tileheight;\n+\t\t\t\t\timage.sourceX = (image_index % cols) * tileset.tilewidth + ((image_index % cols) * tileset.spacing) + tileset.margin;\n+\t\t\t\t\tif(tileset.tileheight == tileset.imageheight) {\n+\t\t\t\t\t\timage.sourceY = 0;\n+\t\t\t\t\t} else {\n+\t\t\t\t\t\timage.sourceY = Math.floor(image_index / cols) * tileset.tileheight + (Math.floor(image_index / cols) * tileset.spacing) + tileset.margin;\n+\t\t\t\t\t}\n+\n+\t\t\t\t}\n+\t\t\t}\n+\t\t}\n+\n+\t\t/**\n+\t\t * @member {Entity} Object Entities\n+\t\t * <p>Create Entity with size and position components</p>\n+\t\t * <p><b>Collidable</b>: True or False <br />Add collision component to entity.\n+\t\t * Currently collisions are handled as a simulation system in the project.</p>\n+\t\t * <p><b>Spawn</b>: True or False <br />Creates an entity with a \"spawn\" boolean\n+\t\t * component allowing you to use <code>game.entities.find(\"spawn\");</code> to find the spawn point for this map.</p>\n+\t\t * <br />All other properties end up in a \"tiledProperties\" component to be handled on a per-game basis.\n+\t\t */\n+\t\t// Loop object layer for collisions and spawn point\n+\t\tif (layer.type == \"objectgroup\") {\n+\t\t\tfor (var j = 0; j < layer.objects.length; j++) {\n+\t\t\t\tobject = layer.objects[j];\n+\t\t\t\tobject_properties = {};\n+\t\t\t\tentity = entities.create();\n+\t\t\t\tentities.set(entity, \"size\", { \"width\": object.width, \"height\": object.height });\n+\t\t\t\tentities.set(entity, \"position\", { \"x\": object.x, \"y\": object.y });\n+\t\t\t\tentities.set(entity, \"collisions\", []);\n+\t\t\t\tObject.keys(object.properties).forEach(function(key) {","path":"lib/import-from-tiled.js","position":95,"original_position":95,"commit_id":"44913054d171095811259823f4fdd8d8b43cc1aa","original_commit_id":"44913054d171095811259823f4fdd8d8b43cc1aa","user":{"login":"ericlathrop","id":530891,"avatar_url":"https://avatars.githubusercontent.com/u/530891?v=3","gravatar_id":"","url":"https://api.github.com/users/ericlathrop","html_url":"https://github.com/ericlathrop","followers_url":"https://api.github.com/users/ericlathrop/followers","following_url":"https://api.github.com/users/ericlathrop/following{/other_user}","gists_url":"https://api.github.com/users/ericlathrop/gists{/gist_id}","starred_url":"https://api.github.com/users/ericlathrop/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ericlathrop/subscriptions","organizations_url":"https://api.github.com/users/ericlathrop/orgs","repos_url":"https://api.github.com/users/ericlathrop/repos","events_url":"https://api.github.com/users/ericlathrop/events{/privacy}","received_events_url":"https://api.github.com/users/ericlathrop/received_events","type":"User","site_admin":false},"body":"Extract this anonymous function into a named function `coerceData(value)`.","created_at":"2016-03-09T04:25:50Z","updated_at":"2016-03-09T04:25:50Z","html_url":"https://github.com/SplatJS/splat-ecs/pull/33#discussion_r55470715","pull_request_url":"https://api.github.com/repos/SplatJS/splat-ecs/pulls/33","_links":{"self":{"href":"https://api.github.com/repos/SplatJS/splat-ecs/pulls/comments/55470715"},"html":{"href":"https://github.com/SplatJS/splat-ecs/pull/33#discussion_r55470715"},"pull_request":{"href":"https://api.github.com/repos/SplatJS/splat-ecs/pulls/33"}}},"pull_request":{"url":"https://api.github.com/repos/SplatJS/splat-ecs/pulls/33","id":61826634,"html_url":"https://github.com/SplatJS/splat-ecs/pull/33","diff_url":"https://github.com/SplatJS/splat-ecs/pull/33.diff","patch_url":"https://github.com/SplatJS/splat-ecs/pull/33.patch","issue_url":"https://api.github.com/repos/SplatJS/splat-ecs/issues/33","number":33,"state":"open","locked":false,"title":"Basic tilemap importer. Missing some components and other tweaks ","user":{"login":"CaldwellYSR","id":1413992,"avatar_url":"https://avatars.githubusercontent.com/u/1413992?v=3","gravatar_id":"","url":"https://api.github.com/users/CaldwellYSR","html_url":"https://github.com/CaldwellYSR","followers_url":"https://api.github.com/users/CaldwellYSR/followers","following_url":"https://api.github.com/users/CaldwellYSR/following{/other_user}","gists_url":"https://api.github.com/users/CaldwellYSR/gists{/gist_id}","starred_url":"https://api.github.com/users/CaldwellYSR/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/CaldwellYSR/subscriptions","organizations_url":"https://api.github.com/users/CaldwellYSR/orgs","repos_url":"https://api.github.com/users/CaldwellYSR/repos","events_url":"https://api.github.com/users/CaldwellYSR/events{/privacy}","received_events_url":"https://api.github.com/users/CaldwellYSR/received_events","type":"User","site_admin":false},"body":"Don't merge this","created_at":"2016-03-05T22:38:14Z","updated_at":"2016-03-09T04:25:50Z","closed_at":null,"merged_at":null,"merge_commit_sha":"c9dba10f42d0e033cf84a02e2be23bfa0f2d9e12","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/SplatJS/splat-ecs/pulls/33/commits","review_comments_url":"https://api.github.com/repos/SplatJS/splat-ecs/pulls/33/comments","review_comment_url":"https://api.github.com/repos/SplatJS/splat-ecs/pulls/comments{/number}","comments_url":"https://api.github.com/repos/SplatJS/splat-ecs/issues/33/comments","statuses_url":"https://api.github.com/repos/SplatJS/splat-ecs/statuses/44913054d171095811259823f4fdd8d8b43cc1aa","head":{"label":"CaldwellYSR:tiled_support","ref":"tiled_support","sha":"44913054d171095811259823f4fdd8d8b43cc1aa","user":{"login":"CaldwellYSR","id":1413992,"avatar_url":"https://avatars.githubusercontent.com/u/1413992?v=3","gravatar_id":"","url":"https://api.github.com/users/CaldwellYSR","html_url":"https://github.com/CaldwellYSR","followers_url":"https://api.github.com/users/CaldwellYSR/followers","following_url":"https://api.github.com/users/CaldwellYSR/following{/other_user}","gists_url":"https://api.github.com/users/CaldwellYSR/gists{/gist_id}","starred_url":"https://api.github.com/users/CaldwellYSR/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/CaldwellYSR/subscriptions","organizations_url":"https://api.github.com/users/CaldwellYSR/orgs","repos_url":"https://api.github.com/users/CaldwellYSR/repos","events_url":"https://api.github.com/users/CaldwellYSR/events{/privacy}","received_events_url":"https://api.github.com/users/CaldwellYSR/received_events","type":"User","site_admin":false},"repo":{"id":52753137,"name":"splat-ecs","full_name":"CaldwellYSR/splat-ecs","owner":{"login":"CaldwellYSR","id":1413992,"avatar_url":"https://avatars.githubusercontent.com/u/1413992?v=3","gravatar_id":"","url":"https://api.github.com/users/CaldwellYSR","html_url":"https://github.com/CaldwellYSR","followers_url":"https://api.github.com/users/CaldwellYSR/followers","following_url":"https://api.github.com/users/CaldwellYSR/following{/other_user}","gists_url":"https://api.github.com/users/CaldwellYSR/gists{/gist_id}","starred_url":"https://api.github.com/users/CaldwellYSR/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/CaldwellYSR/subscriptions","organizations_url":"https://api.github.com/users/CaldwellYSR/orgs","repos_url":"https://api.github.com/users/CaldwellYSR/repos","events_url":"https://api.github.com/users/CaldwellYSR/events{/privacy}","received_events_url":"https://api.github.com/users/CaldwellYSR/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/CaldwellYSR/splat-ecs","description":"","fork":true,"url":"https://api.github.com/repos/CaldwellYSR/splat-ecs","forks_url":"https://api.github.com/repos/CaldwellYSR/splat-ecs/forks","keys_url":"https://api.github.com/repos/CaldwellYSR/splat-ecs/keys{/key_id}","collaborators_url":"https://api.github.com/repos/CaldwellYSR/splat-ecs/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/CaldwellYSR/splat-ecs/teams","hooks_url":"https://api.github.com/repos/CaldwellYSR/splat-ecs/hooks","issue_events_url":"https://api.github.com/repos/CaldwellYSR/splat-ecs/issues/events{/number}","events_url":"https://api.github.com/repos/CaldwellYSR/splat-ecs/events","assignees_url":"https://api.github.com/repos/CaldwellYSR/splat-ecs/assignees{/user}","branches_url":"https://api.github.com/repos/CaldwellYSR/splat-ecs/branches{/branch}","tags_url":"https://api.github.com/repos/CaldwellYSR/splat-ecs/tags","blobs_url":"https://api.github.com/repos/CaldwellYSR/splat-ecs/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/CaldwellYSR/splat-ecs/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/CaldwellYSR/splat-ecs/git/refs{/sha}","trees_url":"https://api.github.com/repos/CaldwellYSR/splat-ecs/git/trees{/sha}","statuses_url":"https://api.github.com/repos/CaldwellYSR/splat-ecs/statuses/{sha}","languages_url":"https://api.github.com/repos/CaldwellYSR/splat-ecs/languages","stargazers_url":"https://api.github.com/repos/CaldwellYSR/splat-ecs/stargazers","contributors_url":"https://api.github.com/repos/CaldwellYSR/splat-ecs/contributors","subscribers_url":"https://api.github.com/repos/CaldwellYSR/splat-ecs/subscribers","subscription_url":"https://api.github.com/repos/CaldwellYSR/splat-ecs/subscription","commits_url":"https://api.github.com/repos/CaldwellYSR/splat-ecs/commits{/sha}","git_commits_url":"https://api.github.com/repos/CaldwellYSR/splat-ecs/git/commits{/sha}","comments_url":"https://api.github.com/repos/CaldwellYSR/splat-ecs/comments{/number}","issue_comment_url":"https://api.github.com/repos/CaldwellYSR/splat-ecs/issues/comments{/number}","contents_url":"https://api.github.com/repos/CaldwellYSR/splat-ecs/contents/{+path}","compare_url":"https://api.github.com/repos/CaldwellYSR/splat-ecs/compare/{base}...{head}","merges_url":"https://api.github.com/repos/CaldwellYSR/splat-ecs/merges","archive_url":"https://api.github.com/repos/CaldwellYSR/splat-ecs/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/CaldwellYSR/splat-ecs/downloads","issues_url":"https://api.github.com/repos/CaldwellYSR/splat-ecs/issues{/number}","pulls_url":"https://api.github.com/repos/CaldwellYSR/splat-ecs/pulls{/number}","milestones_url":"https://api.github.com/repos/CaldwellYSR/splat-ecs/milestones{/number}","notifications_url":"https://api.github.com/repos/CaldwellYSR/splat-ecs/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/CaldwellYSR/splat-ecs/labels{/name}","releases_url":"https://api.github.com/repos/CaldwellYSR/splat-ecs/releases{/id}","deployments_url":"https://api.github.com/repos/CaldwellYSR/splat-ecs/deployments","created_at":"2016-02-29T00:45:49Z","updated_at":"2016-02-29T00:45:50Z","pushed_at":"2016-03-08T22:50:26Z","git_url":"git://github.com/CaldwellYSR/splat-ecs.git","ssh_url":"git@github.com:CaldwellYSR/splat-ecs.git","clone_url":"https://github.com/CaldwellYSR/splat-ecs.git","svn_url":"https://github.com/CaldwellYSR/splat-ecs","homepage":null,"size":399,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"SplatJS:master","ref":"master","sha":"9fe3895894775604c00600a5cdf6cd0f946172be","user":{"login":"SplatJS","id":7811315,"avatar_url":"https://avatars.githubusercontent.com/u/7811315?v=3","gravatar_id":"","url":"https://api.github.com/users/SplatJS","html_url":"https://github.com/SplatJS","followers_url":"https://api.github.com/users/SplatJS/followers","following_url":"https://api.github.com/users/SplatJS/following{/other_user}","gists_url":"https://api.github.com/users/SplatJS/gists{/gist_id}","starred_url":"https://api.github.com/users/SplatJS/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SplatJS/subscriptions","organizations_url":"https://api.github.com/users/SplatJS/orgs","repos_url":"https://api.github.com/users/SplatJS/repos","events_url":"https://api.github.com/users/SplatJS/events{/privacy}","received_events_url":"https://api.github.com/users/SplatJS/received_events","type":"Organization","site_admin":false},"repo":{"id":46762138,"name":"splat-ecs","full_name":"SplatJS/splat-ecs","owner":{"login":"SplatJS","id":7811315,"avatar_url":"https://avatars.githubusercontent.com/u/7811315?v=3","gravatar_id":"","url":"https://api.github.com/users/SplatJS","html_url":"https://github.com/SplatJS","followers_url":"https://api.github.com/users/SplatJS/followers","following_url":"https://api.github.com/users/SplatJS/following{/other_user}","gists_url":"https://api.github.com/users/SplatJS/gists{/gist_id}","starred_url":"https://api.github.com/users/SplatJS/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SplatJS/subscriptions","organizations_url":"https://api.github.com/users/SplatJS/orgs","repos_url":"https://api.github.com/users/SplatJS/repos","events_url":"https://api.github.com/users/SplatJS/events{/privacy}","received_events_url":"https://api.github.com/users/SplatJS/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/SplatJS/splat-ecs","description":"","fork":false,"url":"https://api.github.com/repos/SplatJS/splat-ecs","forks_url":"https://api.github.com/repos/SplatJS/splat-ecs/forks","keys_url":"https://api.github.com/repos/SplatJS/splat-ecs/keys{/key_id}","collaborators_url":"https://api.github.com/repos/SplatJS/splat-ecs/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/SplatJS/splat-ecs/teams","hooks_url":"https://api.github.com/repos/SplatJS/splat-ecs/hooks","issue_events_url":"https://api.github.com/repos/SplatJS/splat-ecs/issues/events{/number}","events_url":"https://api.github.com/repos/SplatJS/splat-ecs/events","assignees_url":"https://api.github.com/repos/SplatJS/splat-ecs/assignees{/user}","branches_url":"https://api.github.com/repos/SplatJS/splat-ecs/branches{/branch}","tags_url":"https://api.github.com/repos/SplatJS/splat-ecs/tags","blobs_url":"https://api.github.com/repos/SplatJS/splat-ecs/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/SplatJS/splat-ecs/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/SplatJS/splat-ecs/git/refs{/sha}","trees_url":"https://api.github.com/repos/SplatJS/splat-ecs/git/trees{/sha}","statuses_url":"https://api.github.com/repos/SplatJS/splat-ecs/statuses/{sha}","languages_url":"https://api.github.com/repos/SplatJS/splat-ecs/languages","stargazers_url":"https://api.github.com/repos/SplatJS/splat-ecs/stargazers","contributors_url":"https://api.github.com/repos/SplatJS/splat-ecs/contributors","subscribers_url":"https://api.github.com/repos/SplatJS/splat-ecs/subscribers","subscription_url":"https://api.github.com/repos/SplatJS/splat-ecs/subscription","commits_url":"https://api.github.com/repos/SplatJS/splat-ecs/commits{/sha}","git_commits_url":"https://api.github.com/repos/SplatJS/splat-ecs/git/commits{/sha}","comments_url":"https://api.github.com/repos/SplatJS/splat-ecs/comments{/number}","issue_comment_url":"https://api.github.com/repos/SplatJS/splat-ecs/issues/comments{/number}","contents_url":"https://api.github.com/repos/SplatJS/splat-ecs/contents/{+path}","compare_url":"https://api.github.com/repos/SplatJS/splat-ecs/compare/{base}...{head}","merges_url":"https://api.github.com/repos/SplatJS/splat-ecs/merges","archive_url":"https://api.github.com/repos/SplatJS/splat-ecs/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/SplatJS/splat-ecs/downloads","issues_url":"https://api.github.com/repos/SplatJS/splat-ecs/issues{/number}","pulls_url":"https://api.github.com/repos/SplatJS/splat-ecs/pulls{/number}","milestones_url":"https://api.github.com/repos/SplatJS/splat-ecs/milestones{/number}","notifications_url":"https://api.github.com/repos/SplatJS/splat-ecs/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/SplatJS/splat-ecs/labels{/name}","releases_url":"https://api.github.com/repos/SplatJS/splat-ecs/releases{/id}","deployments_url":"https://api.github.com/repos/SplatJS/splat-ecs/deployments","created_at":"2015-11-24T02:36:09Z","updated_at":"2016-02-21T17:41:47Z","pushed_at":"2016-03-09T03:52:47Z","git_url":"git://github.com/SplatJS/splat-ecs.git","ssh_url":"git@github.com:SplatJS/splat-ecs.git","clone_url":"https://github.com/SplatJS/splat-ecs.git","svn_url":"https://github.com/SplatJS/splat-ecs","homepage":null,"size":426,"stargazers_count":3,"watchers_count":3,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":4,"mirror_url":null,"open_issues_count":17,"forks":4,"open_issues":17,"watchers":3,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/SplatJS/splat-ecs/pulls/33"},"html":{"href":"https://github.com/SplatJS/splat-ecs/pull/33"},"issue":{"href":"https://api.github.com/repos/SplatJS/splat-ecs/issues/33"},"comments":{"href":"https://api.github.com/repos/SplatJS/splat-ecs/issues/33/comments"},"review_comments":{"href":"https://api.github.com/repos/SplatJS/splat-ecs/pulls/33/comments"},"review_comment":{"href":"https://api.github.com/repos/SplatJS/splat-ecs/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/SplatJS/splat-ecs/pulls/33/commits"},"statuses":{"href":"https://api.github.com/repos/SplatJS/splat-ecs/statuses/44913054d171095811259823f4fdd8d8b43cc1aa"}}}}