This session was an exploration of complex real-world data management issues, and ways to solve them, using D&D as a point of reference for discussion. The presentation was given by Tobby Hagler, Senior Developer at Phase2 Technology at DrupalCamp Atlanta.
Good afternoon, and welcome to Drupal & Dungeons & Dragons I’ll be your dungeon master…
So why are we going to be talking about Dungeons & Dragons at a Drupal Camp? Write this down for your bosses: “This session was an exploration of complex real-world data management issues, and ways to solve them, using D&D as a point of reference for discussion.”
What do they have in common? Where do they intersect? Playing and managing a D&D game, like many other real-world business needs, can be a complex and time-consuming experience. Whether it’s PC sheets, or contract records, or product or sales information…All of these things have unique challenges to managing workflows and how their data is stored.
Managing lots of PCs with paper can get daunting. A character sheet is complex and takes a long time to fill out by hand Each piece of data (like a weapon or a spell) has complex sub-units of data – compound data Finally, there wasn’t anything on drupal.org for D7 to manage D&D Characters… So I scratched my own itch
When I first created the D&D Character module, Drupal 7 had just been released (January 5). I had been using the Features module on new projects already I *REALLY* wanted to know how the Fields API worked
When learning a new language, a few typical milestones… Hello World Start messing with user submitted data (CLI, use STDIN; for PHP, mess with the $_GET superglobal variable) Connect to a database, run queries, etc Eventually comes to creating a D&D character generator
…and so the D&D Character module was born. A suite that includes: D&D Character D&D Fields D&D Character Sheet
So let’s talk about data management in D&D…
So let’s look at the problem we need to solve.
The node is the go-to data bundle* in Drupal. But does it do enough of what we need for PCs? What can we do with standard fields? Race changes certain attributes. Can be multi-class Attributes – do you manage those as individual fields or a single field with 6 multiple values? Weapons alone have many characteristics to field
We can accept multiple values for a single fields, which is useful. This is one-dimensional
Does everyone know what I mean by vertical vs horizontal data depth? Longsword, short sword, gauntlet, mace Longsword +1, short sword +2 vs goblins, regular gauntlet with no powers, MACE OF TERROR! Mace of Terror == Cone of Fear for 60 feet
Remember when I was talking about learning a new language or API with D&D as a common reference point? Learned Fields API to build a series of compound fields in a single night
To store complex, horizontal data, you need compound fields. Sure, the modifier can be derived – ability score divided by 2 (rounded down) minus 5 is the modifier Modifier is an input value and not a derived value in case you want to play Heroic campaign rules.
Fields API has field info, schemas, widgets, and formatters Widgets are the form input – HTML fields Formatters are the output – the templated output of the data
3 steps: Define your Info, Widget, and Formatter This LOOKS like a lot of hooks to learn, but most of them are actually really simple to use.
Hook_field_info tells Drupal about the field. It’s nothing more than a simple array with some meta data. Real simple.
What am I talking about when I say “Field Widget” This is simply a standard Forms API definition of a form to capture data for your user’s data Arrow-Up 4 times to go back to the Ability page
What am I talking about when I say “Field Formatter” This is a rendered form of the field data In this case, theme_table is what we use to display the data. Every field is a new table row.
Even then, field formatters might not be enough. What if you need to generate printer-friendly output?
Output of your complex data is key to good data management In the case of D&D, table-top role-playing uses pencil and paper record keeping There are good iPad apps for characters, but nothing beats paper. NOTHING. 3 rd module in the D&D Character module suite.
It’s one thing (and an important thing) to capture PC data in a filedable way It’s just as important to be able to print a PC record in a way that makes sense on paper
In Drupal, there’s really not much that will generate character sheets Print module and maybe some others will produce PDFs, but these don’t print to exact data record specifications Whether it’s a PC sheet, a product spec sheet, or a tax record, we need something very specific.
In this code sample, we set up page information: The paper size and dimensions Which page in the PDF this is Accepts the node object as an argument
PDF programming for a specific sheet can get complicated as a theme Printing the node data is pretty easy though This code prints the boxes that displays the PC wealth boxes
Node data in a PDF – what does that look like? Each box in the sheet comes from fields in the node
One last thing Drupal is great for D&D… Manage your campaign in Drupal Campaign history, pantheon of gods, Pages for NPCs the players have met, Blog posts of past runs for recapping the story thus far…
Drupal is a CMS. A Campaign Management System.
With the D&D Character module, and blog posts of previous runs, players can update their data, see what they’ve done, even look for clues.
Visit the Agile Approach blog for a good intro to building custom fields using Field API D&D Character module with these submodules API.drupal.org has helpful information – search for field_example module hooks