{"id":191,"date":"2009-12-06T22:42:48","date_gmt":"2009-12-06T09:42:48","guid":{"rendered":"http:\/\/www.paradicesoftware.com\/blog\/?p=191"},"modified":"2009-12-06T22:42:48","modified_gmt":"2009-12-06T09:42:48","slug":"assets-as-text-files","status":"publish","type":"post","link":"http:\/\/www.paradicesoftware.com\/blog\/2009\/12\/assets-as-text-files\/","title":{"rendered":"Assets as Text Files!"},"content":{"rendered":"<p>OK, this trick is probably universally known, but I&#8217;ve only just discovered it (by the classic programmer method of reinventing it), so on the chance there are others who are unfamiliar with this technique, it&#8217;s worth describing.<\/p>\n<p>Any sufficiently complex game is going to have &#8220;assets&#8221;: data external to the main program that the game depends on to function. This includes &#8220;art assets&#8221; (textures, images, music, etc) as well as more application-specific &#8220;data assets&#8221; which contain data in a format unique to your application (e.g. Icefall has\u00a0&#8220;item types&#8221; of all the different equipment players can find\/buy\/receive).<\/p>\n<p>Handling art assets is relatively easy: you create\/modify them in Photoshop (or equivalent), you save them as PNGs or JPGs, and you&#8217;re done! You might wrap them all up in a custom file format to compress\/encrypt\/streamline them, but that&#8217;s pretty simple and you\u00a0can do that at the very end of development.<\/p>\n<p>Data assets are different. There aren&#8217;t any programs around that can edit &#8220;Icefall item types&#8221; files. I need to write my own &#8220;Item Types Editor&#8221;, which understands this format and can load, modify and save it. This leads to two problems:<\/p>\n<p>1. I have to spend time writing an Editor. (the actual format load\/save code could be shared with Icefall itself, but there&#8217;s all the UI!).<\/p>\n<p>2. If I ever change the &#8220;item types&#8221; format, all the data I&#8217;ve previously created is now in jeopardy. (What I typically do is modify the &#8216;save&#8217; code only, run the editor and\u00a0 load each asset (old-code), and re-save it (new-code), then when that&#8217;s done I can modify the &#8216;load&#8217; code.<\/p>\n<p>Depending on the type of data asset, using Asset Text Files may be superior. I DON&#8217;T mean your game should store all of it&#8217;s data assets in plain text (yuck!).\u00a0Here&#8217;s what I mean:<\/p>\n<p>Whip up a simple\u00a0plaintext\u00a0&#8216;syntax&#8217;\u00a0that stores all of the information you want to include\u00a0in your data asset. Then,\u00a0\u00a0instead of creating an &#8220;Editor&#8221; with bulky UI code, create a command line utility that can parse your plaintext files and spit out your compiled data asset files. If you borrow your main game code for load\/save, all you have to write is the text parser, and that can be as easy as you like: you&#8217;re dictating the syntax it has to interpret.<\/p>\n<p>The BEST part of this system is that it makes changing the format of the assets later on very very easy. Oops, I forgot a field for my item types? No worries. Add the extra field to your text file sources (bringing to bear the full power of your fantastic Programmer Text Editor \/ IDE\u00a0you&#8217;re using &#8211; the programmers&#8217; Photoshop), a quick change to the asset compiler to recognise the new format, and hit execute.<\/p>\n<p>You get other benefits too: you can put &#8216;logic&#8217; into your compiler without having to put it in you main game. (e.g. scale the values, dictate whatever &#8220;optional&#8221; or &#8220;Default&#8221; fields, anything!<\/p>\n<p>It doesn&#8217;t work for everything (e.g. Icefall&#8217;s &#8220;Level Map&#8221; is huge and an Editor really is the right option for that) &#8211; but when it&#8217;s appropriate, I have found it works brilliantly.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>OK, this trick is probably universally known, but I&#8217;ve only just discovered it (by the classic programmer method of reinventing it), so on the chance there are others who are unfamiliar with this technique, it&#8217;s worth describing. Any sufficiently complex game is going to have &#8220;assets&#8221;: data external to the main program that the game<\/p>\n","protected":false},"author":2722,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[18,3],"tags":[76],"class_list":["post-191","post","type-post","status-publish","format-standard","hentry","category-good-coding-guidelines","category-icefall","tag-icefall"],"_links":{"self":[{"href":"http:\/\/www.paradicesoftware.com\/blog\/wp-json\/wp\/v2\/posts\/191","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.paradicesoftware.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.paradicesoftware.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.paradicesoftware.com\/blog\/wp-json\/wp\/v2\/users\/2722"}],"replies":[{"embeddable":true,"href":"http:\/\/www.paradicesoftware.com\/blog\/wp-json\/wp\/v2\/comments?post=191"}],"version-history":[{"count":1,"href":"http:\/\/www.paradicesoftware.com\/blog\/wp-json\/wp\/v2\/posts\/191\/revisions"}],"predecessor-version":[{"id":192,"href":"http:\/\/www.paradicesoftware.com\/blog\/wp-json\/wp\/v2\/posts\/191\/revisions\/192"}],"wp:attachment":[{"href":"http:\/\/www.paradicesoftware.com\/blog\/wp-json\/wp\/v2\/media?parent=191"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.paradicesoftware.com\/blog\/wp-json\/wp\/v2\/categories?post=191"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.paradicesoftware.com\/blog\/wp-json\/wp\/v2\/tags?post=191"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}