
#import "HighScoreEditor.h"
#import "EditingHSController.h"

@implementation HighScoreEditor

- init
{
	connected = NO;
	return self;
}

- connectToggle:sender
{
	if (connected) [self disconnect:sender];
	else [self connect:sender];
	return self;
}

- disconnect:sender
{
	[highScoreController setLocalScores:YES];
	connected = NO;
	[connectWindow setTitle:[stringTable
			valueForStringKey:"DisconnectedTitle"]];
	[connectButton setTitle:[stringTable valueForStringKey:"Connect"]];
	return self;
}

- connect:sender
{
	[highScoreController setServerHost:[serverNameText stringValue]];
	[highScoreController setGameName:[gameNameText stringValue]];
	[highScoreController setLocalScores:NO];
	[highScoreController readHighScores];
	[highScoreController displayHighScores:self];
	connected = ![highScoreController localScores];
	if (!connected) return self;
	[connectWindow setTitle:[stringTable
			valueForStringKey:"ConnectedTitle"]];
	[connectButton setTitle:[stringTable valueForStringKey:"Disconnect"]];
	return self;
}

- appDidInit:sender
{
	return self;
}

- appWillTerminate:sender
{
	// don't leave open connections hanging around; shut down cleanly.
	if (connected) [self disconnect:self];
	return self;
}


@end
