User Tools



adventuregenerator:test_harness_directory_structure

Test Harness Directory Structure

The test harness is structured into several files and directories:

TestHarness/testharness.php

This is the test harness itself.

TestHarness/Generators

This is where the generator classes are stored, both the included examples and the ones that you'll write yourself.

Interfaces

In the TestHarness/Generators directory, there are several interfaces.

iAdventureGenerator.php.inc iEncounterGenerator.php.inc iGenerator.php.inc iMapGenerator.php.inc iOutputGenerator.php.inc iTextGenerator.php.inc

These interfaces define the functions that the generator that you want to write must implement. The only types of generator that are documented at the moment are Dressing and Encounters, which use iTextGenerator and iEncounterGenerator respectively, so those two and the interfaces that they extend are probably the only ones that you need to worry about.

If you're a little confused, don't worry about it. It'll be clear soon, once we get all this exposition out of the way.

Generator Classes

In subdirectories below TestHarness/Generators/, there are several example generator classes included which implement the interfaces mentioned above. You can use these examples as a basis for your own.

TestHarness/Generators/Adventure/ExampleAdventure.php.inc TestHarness/Generators/AdventureName/ExampleAdventureName.php.inc TestHarness/Generators/Dressing/ExampleDressing.php.inc TestHarness/Generators/Encounter/ExampleEncounter.php.inc TestHarness/Generators/Map/ExampleMap.php.inc TestHarness/Generators/Output/ExampleOutput.php.inc

The only ones that are documented at the moment are Dressing and Encounters. Trying to write any other type of generator may be counterproductive at the moment, given the lack of documentation and the fluid nature of the code in those areas.

TestHarness/Data

This is where any static data for your generator needs to be stored. This directory is arranged using the same structure as Generators/. Ie, the class TestHarness/Generators/Adventure/ExampleAdventure.php.inc would store any static data that it needed under TestHarness/Data/Generators/Adventure/ExampleAdventure/

TestHarness/Util

This directory includes some utility headers to make your life easier.

IncludeAll.php.inc

Provides an includeAll($path) function, which will include all .php.inc files in the given directory (but not any subdirectories beneath it). You probably won't need to use this in your own code, but it is used by testharness.php to load all the generator classes.

Dice.php.inc

Convenience functions for tabletop-style die rolling. d($num,$sides) will roll a given number of dice with the given number of sides, ie d(3,6) will rill 3d6 and return a result. Please note that the statistical spread of d(3,6) or rolling 3 actual 6-sided dice is very different than mt_rand(3,18), so please use the d() function whenever possible. Also included are some convenience functions for rolling a given die size, ie d4([$num]) etc.

ImageOutput.php.inc

This function will take a GD image (http://php.net/manual/en/book.image.php) and return an inline base64 encoded PNG <IMG> tag that you can echo. Please note that, for security reasons, the static data files may not be accessable if you link directly to them via HTML (they are at the moment, but I'm going to fix that at some point), so please emit any images that your generator needs to draw as inline base64 encoded PNGs using this function.

You shouldn't need to worry about images for encounter and dressing generators, though.

NOTE: Since it seems that IE doesn't like to play well with base64 encoding, this library is obsolete. We've implemented a timed dynamic image cache instead, and documentation will be forthcoming someday™.

StringEndsWith.php.inc

Simple code, swiped from the www somewhere, that tests to see if the given string ends with the given substring. Mostly used to filename sanity checking, and you shouldn't need to use this in your own code.

NumberToWord.php.inc

Two functions: numberToWord($num), which will take an integer (ie 2) and return a word (ie two). numberToNd($num), which will take an integer (ie 1 or 2 or 3 or 4) and output the equivalent -th form (ie 1st, 2nd, 3rd, 4th).

adventuregenerator/test_harness_directory_structure.txt · Last modified: 2012/02/08 15:22 by leaf