Skip to content
This repository
Browse code

Implemented launching save states from context menu.

  • Loading branch information...
commit 2240d56b8ce150f6f7c29e0c3c79b988151a6582 1 parent 1fd51a1
Christoph Leimbrock authored March 18, 2012
5  OpenEmu/OECollectionViewController.m
@@ -630,11 +630,6 @@ - (void)deleteSaveState:(id)stateItem
630 630
         [state remove];
631 631
 }
632 632
 
633  
-- (void)startSelectedGameWithSaveState:(id)stateItem
634  
-{
635  
-    NSLog(@"startSelectedGameWithSaveState: Not implemented yet.");
636  
-}
637  
-
638 633
 - (void)renameSelectedGame:(id)sender
639 634
 {
640 635
     NSLog(@"renameSelectedGame: Not implemented yet.");
5  OpenEmu/OEGameDocument.h
@@ -29,8 +29,8 @@
29 29
 @class OEGameViewController;
30 30
 @class OEDBRom;
31 31
 @class OEDBGame;
  32
+@class OEDBSaveState;
32 33
 @class OECorePlugin;
33  
-
34 34
 @interface OEGameDocument : NSDocument
35 35
 
36 36
 - (id)initWithRom:(OEDBRom *)rom;
@@ -41,7 +41,8 @@
41 41
 - (id)initWithGame:(OEDBGame *)game core:(OECorePlugin*)core;
42 42
 - (id)initWithGame:(OEDBGame *)game error:(NSError **)outError;
43 43
 - (id)initWithGame:(OEDBGame *)game core:(OECorePlugin*)core error:(NSError **)outError;
44  
-
  44
+- (id)initWithSaveState:(OEDBSaveState *)state;
  45
+- (id)initWithSaveState:(OEDBSaveState *)state error:(NSError **)outError;
45 46
 @property(readonly, strong) OEGameViewController *gameViewController;
46 47
 
47 48
 - (void)showInSeparateWindow:(id)sender;
21  OpenEmu/OEGameDocument.m
@@ -152,6 +152,27 @@ - (id)initWithGame:(OEDBGame *)game core:(OECorePlugin*)core error:(NSError **)o
152 152
     return self;
153 153
 }
154 154
 
  155
+- (id)initWithSaveState:(OEDBSaveState *)state
  156
+{
  157
+    return [self initWithSaveState:state error:nil];
  158
+}
  159
+
  160
+- (id)initWithSaveState:(OEDBSaveState *)state error:(NSError **)outError
  161
+{
  162
+    if((self = [self init]))
  163
+    {
  164
+        gameViewController = [[OEGameViewController alloc] initWithSaveState:state error:outError];
  165
+        if(gameViewController == nil)
  166
+        {
  167
+            [self close];
  168
+            return nil;
  169
+        }
  170
+        
  171
+        [gameViewController setDocument:self];
  172
+    }
  173
+    return self;
  174
+}
  175
+
155 176
 - (void)dealloc
156 177
 {
157 178
     [[NSNotificationCenter defaultCenter] removeObserver:self name:NSApplicationWillTerminateNotification object:NSApp];
4  OpenEmu/OEGameViewController.h
@@ -28,6 +28,7 @@
28 28
 
29 29
 @class OEDBRom;
30 30
 @class OEDBGame;
  31
+@class OEDBSaveState;
31 32
 
32 33
 @class OEGameView;
33 34
 @protocol OEGameCoreHelper;
@@ -72,6 +73,9 @@
72 73
 - (id)initWithGame:(OEDBGame *)game error:(NSError **)outError;
73 74
 - (id)initWithGame:(OEDBGame *)game core:(OECorePlugin*)core error:(NSError **)outError;
74 75
 
  76
+- (id)initWithSaveState:(OEDBSaveState *)state;
  77
+- (id)initWithSaveState:(OEDBSaveState *)state error:(NSError **)outError;
  78
+
75 79
 @property (strong) OEHUDControlsBarWindow *controlsWindow;
76 80
 
77 81
 @property(weak)   id<OEGameViewControllerDelegate> delegate;
21  OpenEmu/OEGameViewController.m
@@ -149,6 +149,27 @@ - (id)initWithGame:(OEDBGame *)game core:(OECorePlugin*)core error:(NSError **)o
149 149
     return [self initWithRom:[OEGameViewController OE_choseRomFromGame:game] core:core error:outError];
150 150
 }
151 151
 
  152
+
  153
+- (id)initWithSaveState:(OEDBSaveState *)state
  154
+{
  155
+    return [self initWithSaveState:state error:nil];
  156
+}
  157
+
  158
+
  159
+- (id)initWithSaveState:(OEDBSaveState *)state error:(NSError **)outError
  160
+{
  161
+    OEDBRom         *rom            = [state rom];
  162
+    NSString        *coreIdentifier = [state coreIdentifier];
  163
+    OECorePlugin    *core           = [OECorePlugin corePluginWithBundleIdentifier:coreIdentifier];
  164
+    id gameViewController = [self initWithRom:rom core:core error:outError];
  165
+    if(gameViewController)
  166
+    {
  167
+        [self loadSaveState:state];
  168
+    }
  169
+    
  170
+    return self;    
  171
+}
  172
+
152 173
 - (void)dealloc
153 174
 {
154 175
     NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
3  OpenEmu/OELibraryController.h
@@ -35,7 +35,7 @@
35 35
 @class OELibrarySplitView;
36 36
 @class OEROMImporter;
37 37
 @class FullscreenWindow;
38  
-@class OEDBGame, OEDBRom;
  38
+@class OEDBGame, OEDBRom, OEDBSaveState;
39 39
 
40 40
 @protocol OELibraryControllerDelegate;
41 41
 
@@ -113,4 +113,5 @@
113 113
 @optional
114 114
 - (void)libraryController:(OELibraryController *)sender didSelectGame:(OEDBGame *)aGame;
115 115
 - (void)libraryController:(OELibraryController *)sender didSelectRom:(OEDBRom *)aGame;
  116
+- (void)libraryController:(OELibraryController *)sender didSelectSaveState:(OEDBSaveState *)aSaveState;
116 117
 @end
10  OpenEmu/OELibraryController.m
@@ -366,6 +366,16 @@ - (IBAction)startGame:(id)sender
366 366
         [[self delegate] libraryController:self didSelectGame:selectedGame];
367 367
 }
368 368
 
  369
+- (void)startSelectedGameWithSaveState:(id)stateItem
  370
+{
  371
+    OEDBSaveState *saveState = [stateItem representedObject];
  372
+    
  373
+    NSAssert(saveState != nil, @"Attempt to start a save state without valid item");
  374
+
  375
+    if([[self delegate] respondsToSelector:@selector(libraryController:didSelectGame:)])
  376
+        [[self delegate] libraryController:self didSelectSaveState:saveState];
  377
+}
  378
+
369 379
 #pragma mark -
370 380
 #pragma mark Spotlight Importing
371 381
 
16  OpenEmu/OEMainWindowController.m
@@ -206,6 +206,22 @@ - (void)libraryController:(OELibraryController *)sender didSelectGame:(OEDBGame
206 206
     [self openGameDocument:gameDocument];
207 207
 }
208 208
 
  209
+
  210
+- (void)libraryController:(OELibraryController *)sender didSelectSaveState:(OEDBSaveState *)aSaveState
  211
+{
  212
+    NSError        *error = nil;
  213
+    OEGameDocument *gameDocument = [[OEGameDocument alloc] initWithSaveState:aSaveState error:&error];
  214
+    
  215
+    if(gameDocument == nil)
  216
+    {
  217
+        if(error!=nil)
  218
+            [NSApp presentError:error];
  219
+        return;
  220
+    }
  221
+    
  222
+    [[NSDocumentController sharedDocumentController] addDocument:gameDocument];
  223
+    [self openGameDocument:gameDocument];
  224
+}
209 225
 #pragma mark -
210 226
 #pragma mark NSWindow delegate
211 227
 

0 notes on commit 2240d56

Please sign in to comment.
Something went wrong with that request. Please try again.