Big rename part 2: 'config' etc. to 'mapping.
[enjoyable.git] / TargetToggleMouseScope.m
index 55357e5..0413b73 100644 (file)
@@ -3,26 +3,34 @@
 //  Enjoy
 //
 //  Created by Yifeng Huang on 7/28/12.
-//  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
 //
 
 #import "TargetToggleMouseScope.h"
 
+#import "ApplicationController.h"
+#import "NJInputController.h"
+
 @implementation TargetToggleMouseScope
 
--(NSString*) stringify {
-       return [[NSString alloc] initWithFormat: @"mtoggle"];
++ (NSString *)serializationCode {
+    return @"mtoggle";
 }
 
-+(TargetToggleMouseScope*) unstringifyImpl: (NSArray*) comps {
-       NSParameterAssert([comps count] == 1);
-       TargetToggleMouseScope* target = [[TargetToggleMouseScope alloc] init];
-       return target;
+- (NSDictionary *)serialize {
+    return @{ @"type": @"mtoggle" };
 }
 
--(void) trigger: (JoystickController *)jc {
-    [jc setFrontWindowOnly: ![jc frontWindowOnly]];
-    printf("Front window only: %d\n", [jc frontWindowOnly]);
++ (Target *)targetDeserialize:(NSDictionary *)serialization
+                  withMappings:(NSArray *)mappings {
+       TargetToggleMouseScope *target = [[TargetToggleMouseScope alloc] init];
+       return target;
+}
+- (void)trigger {
+    // FIXME: It's hacky to get at the controller this way, but it's
+    // also hacky to pass it. Shouldn't need to do either.
+    ApplicationController *ac = NSApplication.sharedApplication.delegate;
+    NJInputController *jc = ac.inputController;
+    jc.frontWindowOnly = !jc.frontWindowOnly;
 }
 
 @end