/***
|''Name:''|DiceRollMacro |
|''Description:''|Inline dice roll macro. |
|''Version:''|0.1 |
|''Date:''|2008.08.18 |
|''Source:''|http://www.draugrheim.net/rpgwiki/rpgwiki.html |
|''Status''|stable |
|''Author:''|[[Martin Andersen|mailto:draugen@draugrheim.net]] |
|''Contributors''|[[Devon Jones|http://www.legolas.org/gmwiki/dev/gmwikidev.html]] |
|''Type:''|plugin |
|''License:''|GPL |
|''CoreVersion:''|2.4 |

!Description
Provides a <<roll>> macro that allows for inline dice rolls.
!Usage
{{{<<roll [Dice Expression] [Label]>>}}}
!!Parameters
!!!Dice Expression
The dice expression can be in 3 forms:
* {{{<<roll 1d20>>}}}; {{{<<roll 2d8+5>>}}}; {{{<<roll (1d20-2d6)+3d4>>}}}
* {{{<<roll +5>>}}} The number is added to a rolled D20.  Used for skill checks, attack rolls etc. in the D20 system.
* {{{<<roll DC15>>}}} 1d20 is rolled against the DC. The result is how much it succeeded or missed by.
!!!Label
An optional label for the roll button.  Defaults to the dice expression.
!Notes
Multiple expressions in parenthesies on the same level (e.g. (3d6+1d3)+3d4+(1d12+12)
!!Examples
{{{<<roll 1d20 "roll a D20">>}}}
<<roll 1d20 "roll a D20">>
{{{<<roll 1dF>>}}}
<<roll 1dF>>
{{{<<roll (1d6)dF>>}}}
<<roll (1d6)dF>>
!Revision history
!!v0.1 - 2008-08-18
Initial release.

!Code
***/
//{{{
if(!version.extensions.roll) {
	version.extensions.roll = {
		installed:true
	};
	version.extensions.roll = {
		major: 0,
		minor: 1,
		revision: 0,
		date: new Date(2008, 8, 18)
	};
	config.macros.roll = {};
	config.macros.roll.onClick = function(e) {
		var e = e || event;
		var target = e.target || e.srcElement;
		parseExp = new DiceRollParser(this.title);
		//log roll result to messageArea
		clearMessage();
		displayMessage("Rolled " + parseExp.exp + ": " + parseExp.toString());
		var resultbox = this.parentNode.lastChild;
		resultbox.innerHTML = parseExp.result;
	};
	config.macros.roll.handler = function(place,macroName,params) {
		// param 0: dice expression
		// param 1: optional text label
		var dicestring = params[0];
		var title = params[1] ? params[1] : dicestring;
		
		var rollwrapper = createTiddlyElement(place, "span", null, "rollwrapper");
		createTiddlyButton(rollwrapper,title,dicestring,this.onClick,"rollbutton");
		rollwrapper.appendChild(document.createTextNode(" "));
		var resultbox = createTiddlyElement(rollwrapper, "span", null, "rollresult");
	};

} //# end of 'install only once'
//}}}