Permalink
Browse files

Implemented launching save states from context menu.

  • Loading branch information...
1 parent 1fd51a1 commit 2240d56b8ce150f6f7c29e0c3c79b988151a6582 @cyco cyco committed Mar 18, 2012
@@ -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.");
@@ -29,8 +29,8 @@
@class OEGameViewController;
@class OEDBRom;
@class OEDBGame;
+@class OEDBSaveState;
@class OECorePlugin;
-
@interface OEGameDocument : NSDocument
- (id)initWithRom:(OEDBRom *)rom;
@@ -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;
@@ -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];
@@ -28,6 +28,7 @@
@class OEDBRom;
@class OEDBGame;
+@class OEDBSaveState;
@class OEGameView;
@protocol OEGameCoreHelper;
@@ -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;
@@ -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];
@@ -35,7 +35,7 @@
@class OELibrarySplitView;
@class OEROMImporter;
@class FullscreenWindow;
-@class OEDBGame, OEDBRom;
+@class OEDBGame, OEDBRom, OEDBSaveState;
@protocol OELibraryControllerDelegate;
@@ -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
@@ -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
@@ -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

0 comments on commit 2240d56

Please sign in to comment.