{"author_name":"Thecoolestnerdguy","cat":"LD #26","comments":[{"author_name":"","time":"April 22, 2013 7:09 am","epoch":1366632540,"text":"JSON (JavaScript Object Notation) is the answer to your question","spam":"N"},{"author_name":"","time":"April 22, 2013 7:13 am","epoch":1366632780,"text":"Another idea popped up in my head just now: strip the HTMLImage elements and only conserve the image path. Any element of the DOM tends to screw up JSON.","spam":"N"}],"epoch":1366631340,"likes":1,"metadata":{"p_key":"46948","p_author":"Thecoolestnerdguy","p_authorkey":"506310","p_urlkey":"82611","p_title":"Stringy madness","p_cat":"LD #26","p_event":"LD26","p_time":"1366631340","p_likes":"1","p_comments":"2","p_status":"UPD5","us_key":"506310","us_name":"Thecoolestnerdguy","us_username":"Thecoolestnerdguy","event_start":"1366934400","event_key":"16","event_name":"LD26"},"text":"<p>So, I&#8217;m making a veeery basic level editor in html5 for LD.<\/p>\n <p>&#8220;Ok, what&#8217;s the matter&#8221;, you could ask. Well, as you know, level editors &#8220;generally&#8221; needs to actually save the levels.<\/p>\n <p>I tried some solutions and the localStorage API seemed to be \u00a0a easy win, except for one thing: it just works with strings!<\/p>\n <p>My level editor saves all the objects on the level in a gigantic array. I just needed to save that array, but how?<\/p>\n <p>Four steps:<\/p>\n <p>&nbsp;<\/p>\n <ol>\n <li><span style=\"line-height: 13px\">Convert every property in every object in the array to a string and save them in temporary objects in a temporary array.<\/span><\/li>\n <li>Convert every object on the temporary array to strings.<\/li>\n <li>Convert the array populated with strings into a string.<\/li>\n <li>Save the gigantic string on localStorage.<\/li>\n <\/ol>\n <p>&nbsp;<\/p>\n <p>&#8220;Well, why not use JSON.stringify with the array&#8221; you may also ask. Well, because I was getting some &#8220;circular structure&#8221; errors, and I had no patience to figure out what was causing it.<\/p>\n <p>&#8220;And why this is so mad&#8221; you may finally ask. Well, because a level (with only two tiles) looks something like this:<\/p>\n <p>&nbsp;<\/p>\n <p>[&#8220;{\\&#8221;x\\&#8221;:\\&#8221;240\\&#8221;,\\&#8221;y\\&#8221;:\\&#8221;192\\&#8221;,\\&#8221;cell\\&#8221;:\\&#8221;0,0\\&#8221;,\\&#8221;image\\&#8221;:\\&#8221;[object HTMLImageElement]\\&#8221;,\\&#8221;imgsrc\\&#8221;:\\&#8221;spritesheet.png\\&#8221;,\\&#8221;densidade\\&#8221;:\\&#8221;0\\&#8221;,\\&#8221;friccao\\&#8221;:\\&#8221;0\\&#8221;,\\&#8221;<\/p>\n <p>elasticidade\\&#8221;:\\&#8221;0\\&#8221;,\\&#8221;tipo\\&#8221;:\\&#8221;static\\&#8221;,\\&#8221;collisiongroup\\&#8221;:\\&#8221;solid\\&#8221;,\\&#8221;forma\\&#8221;:\\&#8221;Quadrada\\&#8221;}&#8221;,&#8221;{\\&#8221;x\\&#8221;:\\&#8221;272\\&#8221;,\\&#8221;y\\&#8221;:\\&#8221;192\\&#8221;,\\&#8221;cell\\&#8221;:\\&#8221;0,0\\&#8221;,\\&#8221;image\\&#8221;:\\&#8221;[object HTMLImageElement]\\&#8221;,\\&#8221;imgsrc\\&#8221;:\\&#8221;spritesheet.png\\&#8221;,\\&#8221;densidade\\&#8221;:\\&#8221;0\\&#8221;,\\&#8221;friccao\\&#8221;:\\&#8221;0\\&#8221;,<\/p>\n <p>\\&#8221;elasticidade\\&#8221;:\\&#8221;0\\&#8221;,\\&#8221;tipo\\&#8221;:\\&#8221;static\\&#8221;,\\&#8221;collisiongroup\\&#8221;:\\&#8221;solid\\&#8221;,\\&#8221;forma\\&#8221;:\\&#8221;Quadrada\\&#8221;}&#8221;]<\/p>\n <p>&nbsp;<\/p>\n <p>Well, there must be a more elegant way to do this&#8230;<\/p>\n <p>&nbsp;<\/p>\n <p>Potatoes FTW!<\/p>","time":"April 22nd, 2013 6:49 am","title":"Stringy madness"}