Loot
Ok, so I sat down and wrote up a list of goals I want to accomplish with my RPG inventory project. Basically, I want an easy way to add items found in-game and keep track of certain information including quantity, price, when and where they were found, where they are being kept, and I would like to have a decent way of sorting/searching these items. I decided to go with a tag system, which seems to be popular these days, and I can see why as it is pretty flexible. With goals jotted down, I started on the database design.
I knew it would need an items table with columns for name, found on, found at, quantity, and price; and I also decided to have a locations table for keeping track of where items are stored/carried. All other information about an item is done through tagging. So, an item can be tagged as weapon, magic, unidentified, etc. I also decided that it would be great for the application to remember previous entries, so that I don’t have to fill out every little detail for each and every mundane item I come across. So, it also needs a templates table with columns for name, price, and tags.
With the database layout hashed out, I started making the app. First of all, of course, was to get Ruby on Rails and MySQL running. Thanks to InstantRails that was pretty easy. Next, I created a new rails project, named Loot (aren’t I clever?), setup a database and edited the database.yml config file. The third step was to generate the scaffold for the Items and Locations controllers and the Tag model and then tie them together with a little rails magic, called has_many, belongs_to and a cool plugin called acts_as_taggable. So, with just a couple of lines of code and a few edits on some templates, I had a working prototype. I can now add, edit, delete, and view items and locations, with a dropdown list for location being generated from the locations I have created.
Wow! That was fast. All in all, it took about 30 minutes to get that far, but getting all of that running in PHP would have required a lot more time and work. What’s left is to make the Template controller and model, write some code to populate the item fields with data from a chosen template, write a little code for sorting, write some code to search tags (which are all indexed in a table by the acts_as_taggable plugin), and then make it pretty and add some bells and whistles, like drag’n'drop to change locations and inline editing, all of which can be done with rails shortcuts. So far, I love it.
