#import "QuickRollController.h"
#import "dice.h"

@implementation QuickRollController

- init
{
  return [super initWithWindowNibName:@"quickroll"];
}

- (IBAction)rollDice:(id)sender
{
  int tag = [sender tag];
  int i = [sender tag];
  int c = [dice numberOfRows];

  for (i = 0; i < c; i++) {
    // If the user edited one of the fields, then just change that field.
    // If they pressed the button (tag == -1) change everything.
    if (i != tag && tag != -1) continue;
    
    NSTextField *die = [dice cellAtRow:i column:0];
    NSTextField *res = [results cellAtRow:i column:0];
    NSAttributedString *diceroll = [[die stringValue] interpretDiceValuesWithRepeatPattern:nil
                                                                           savingPatternTo:nil];
    [res setAttributedStringValue:diceroll];
  }
}

@end
