Skip to content

Commit

Permalink
Implemented launching save states from context menu.
Browse files Browse the repository at this point in the history
  • Loading branch information
cyco committed Mar 18, 2012
1 parent 1fd51a1 commit 2240d56
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 8 deletions.
5 changes: 0 additions & 5 deletions OpenEmu/OECollectionViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -630,11 +630,6 @@ - (void)deleteSaveState:(id)stateItem
[state remove];
}

- (void)startSelectedGameWithSaveState:(id)stateItem
{
NSLog(@"startSelectedGameWithSaveState: Not implemented yet.");
}

- (void)renameSelectedGame:(id)sender
{
NSLog(@"renameSelectedGame: Not implemented yet.");
Expand Down
5 changes: 3 additions & 2 deletions OpenEmu/OEGameDocument.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
@class OEGameViewController;
@class OEDBRom;
@class OEDBGame;
@class OEDBSaveState;
@class OECorePlugin;

@interface OEGameDocument : NSDocument

- (id)initWithRom:(OEDBRom *)rom;
Expand All @@ -41,7 +41,8 @@
- (id)initWithGame:(OEDBGame *)game core:(OECorePlugin*)core;
- (id)initWithGame:(OEDBGame *)game error:(NSError **)outError;
- (id)initWithGame:(OEDBGame *)game core:(OECorePlugin*)core error:(NSError **)outError;

- (id)initWithSaveState:(OEDBSaveState *)state;
- (id)initWithSaveState:(OEDBSaveState *)state error:(NSError **)outError;
@property(readonly, strong) OEGameViewController *gameViewController;

- (void)showInSeparateWindow:(id)sender;
Expand Down
21 changes: 21 additions & 0 deletions OpenEmu/OEGameDocument.m
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,27 @@ - (id)initWithGame:(OEDBGame *)game core:(OECorePlugin*)core error:(NSError **)o
return self;
}

- (id)initWithSaveState:(OEDBSaveState *)state
{
return [self initWithSaveState:state error:nil];
}

- (id)initWithSaveState:(OEDBSaveState *)state error:(NSError **)outError
{
if((self = [self init]))
{
gameViewController = [[OEGameViewController alloc] initWithSaveState:state error:outError];
if(gameViewController == nil)
{
[self close];
return nil;
}

[gameViewController setDocument:self];
}
return self;
}

- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self name:NSApplicationWillTerminateNotification object:NSApp];
Expand Down
4 changes: 4 additions & 0 deletions OpenEmu/OEGameViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

@class OEDBRom;
@class OEDBGame;
@class OEDBSaveState;

@class OEGameView;
@protocol OEGameCoreHelper;
Expand Down Expand Up @@ -72,6 +73,9 @@
- (id)initWithGame:(OEDBGame *)game error:(NSError **)outError;
- (id)initWithGame:(OEDBGame *)game core:(OECorePlugin*)core error:(NSError **)outError;

- (id)initWithSaveState:(OEDBSaveState *)state;
- (id)initWithSaveState:(OEDBSaveState *)state error:(NSError **)outError;

@property (strong) OEHUDControlsBarWindow *controlsWindow;

@property(weak) id<OEGameViewControllerDelegate> delegate;
Expand Down
21 changes: 21 additions & 0 deletions OpenEmu/OEGameViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,27 @@ - (id)initWithGame:(OEDBGame *)game core:(OECorePlugin*)core error:(NSError **)o
return [self initWithRom:[OEGameViewController OE_choseRomFromGame:game] core:core error:outError];
}


- (id)initWithSaveState:(OEDBSaveState *)state
{
return [self initWithSaveState:state error:nil];
}


- (id)initWithSaveState:(OEDBSaveState *)state error:(NSError **)outError
{
OEDBRom *rom = [state rom];
NSString *coreIdentifier = [state coreIdentifier];
OECorePlugin *core = [OECorePlugin corePluginWithBundleIdentifier:coreIdentifier];
id gameViewController = [self initWithRom:rom core:core error:outError];
if(gameViewController)
{
[self loadSaveState:state];
}

return self;
}

- (void)dealloc
{
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
Expand Down
3 changes: 2 additions & 1 deletion OpenEmu/OELibraryController.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
@class OELibrarySplitView;
@class OEROMImporter;
@class FullscreenWindow;
@class OEDBGame, OEDBRom;
@class OEDBGame, OEDBRom, OEDBSaveState;

@protocol OELibraryControllerDelegate;

Expand Down Expand Up @@ -113,4 +113,5 @@
@optional
- (void)libraryController:(OELibraryController *)sender didSelectGame:(OEDBGame *)aGame;
- (void)libraryController:(OELibraryController *)sender didSelectRom:(OEDBRom *)aGame;
- (void)libraryController:(OELibraryController *)sender didSelectSaveState:(OEDBSaveState *)aSaveState;
@end
10 changes: 10 additions & 0 deletions OpenEmu/OELibraryController.m
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,16 @@ - (IBAction)startGame:(id)sender
[[self delegate] libraryController:self didSelectGame:selectedGame];
}

- (void)startSelectedGameWithSaveState:(id)stateItem
{
OEDBSaveState *saveState = [stateItem representedObject];

NSAssert(saveState != nil, @"Attempt to start a save state without valid item");

if([[self delegate] respondsToSelector:@selector(libraryController:didSelectGame:)])
[[self delegate] libraryController:self didSelectSaveState:saveState];
}

#pragma mark -
#pragma mark Spotlight Importing

Expand Down
16 changes: 16 additions & 0 deletions OpenEmu/OEMainWindowController.m
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,22 @@ - (void)libraryController:(OELibraryController *)sender didSelectGame:(OEDBGame
[self openGameDocument:gameDocument];
}


- (void)libraryController:(OELibraryController *)sender didSelectSaveState:(OEDBSaveState *)aSaveState
{
NSError *error = nil;
OEGameDocument *gameDocument = [[OEGameDocument alloc] initWithSaveState:aSaveState error:&error];

if(gameDocument == nil)
{
if(error!=nil)
[NSApp presentError:error];
return;
}

[[NSDocumentController sharedDocumentController] addDocument:gameDocument];
[self openGameDocument:gameDocument];
}
#pragma mark -
#pragma mark NSWindow delegate

Expand Down

0 comments on commit 2240d56

Please sign in to comment.