//
//  CampaignDocument.m
//  longspear
//
//  Created by Niko Matsakis on Wed Jun 16 2004.
//  Copyright (c) 2004 __MyCompanyName__. All rights reserved.
//

#import "CampaignDocument.h"
#import "CampaignController.h"
#import "Config.h"

@implementation CampaignDocument

// Some one time initialization:
+ (void) initialize
{
    srand (time (NULL));
    initializeDefaultConfiguration ();
}

- init
{
    if ((self = [super init])) {
        _campaign = [[Campaign alloc] init];
    }
    return self;
}

- (void) dealloc
{
    [_campaign release];
}

- (void) makeWindowControllers
{
    CampaignController *cc = [[[CampaignController alloc] init] autorelease];
    [self addWindowController:cc];
}


- (NSData *) dataRepresentationOfType: (NSString *) aType 
{
    return [NSKeyedArchiver archivedDataWithRootObject:_campaign];  
}

- (BOOL) loadDataRepresentation: (NSData *) docData 
                         ofType: (NSString *) docType 
{
    [_campaign release];
    _campaign = [[NSKeyedUnarchiver unarchiveObjectWithData:docData] retain];
    return YES;
}

- (Campaign*) campaign
{
    return _campaign;
}

@end
