Fix names while I still can.
[enjoyable.git] / TargetMouseBtn.m
index e8d77e4..2f56f7e 100644 (file)
 
 @implementation TargetMouseBtn
 
-@synthesize which;
+@synthesize button;
 
--(NSString*) stringify {
-       return [[NSString alloc] initWithFormat: @"mbtn~%u", which];
++ (NSString *)serializationCode {
+    return @"mbtn";
 }
 
-+(TargetMouseBtn*) unstringifyImpl: (NSArray*) comps {
-       NSParameterAssert([comps count] == 2);
-       TargetMouseBtn* target = [[TargetMouseBtn alloc] init];
-       [target setWhich: [comps[1] integerValue]];
+- (NSDictionary *)serialize {
+    return @{ @"type": @"mbtn", @"button": @(self.button) };
+}
+
++ (Target *)targetDeserialize:(NSDictionary *)serialization
+                  withConfigs:(NSArray *)configs {
+       TargetMouseBtn *target = [[TargetMouseBtn alloc] init];
+    target.button = [serialization[@"button"] intValue];
        return target;
 }
 
     NSRect screenRect = [[NSScreen mainScreen] frame];
     NSInteger height = screenRect.size.height;
     NSPoint mouseLoc = [NSEvent mouseLocation];
-    CGEventType eventType = (which == kCGMouseButtonLeft) ? kCGEventLeftMouseDown : kCGEventRightMouseDown;
+    CGEventType eventType = (button == kCGMouseButtonLeft) ? kCGEventLeftMouseDown : kCGEventRightMouseDown;
     CGEventRef click = CGEventCreateMouseEvent(NULL,
                                                eventType,
                                                CGPointMake(mouseLoc.x, height - mouseLoc.y),
-                                               which);
+                                               button);
     CGEventPost(kCGHIDEventTap, click);
     CFRelease(click);
 }
     NSRect screenRect = [[NSScreen mainScreen] frame];
     NSInteger height = screenRect.size.height;
     NSPoint mouseLoc = [NSEvent mouseLocation];
-    CGEventType eventType = (which == kCGMouseButtonLeft) ? kCGEventLeftMouseUp : kCGEventRightMouseUp;
+    CGEventType eventType = (button == kCGMouseButtonLeft) ? kCGEventLeftMouseUp : kCGEventRightMouseUp;
     CGEventRef click = CGEventCreateMouseEvent(NULL,
                                                eventType,
                                                CGPointMake(mouseLoc.x, height - mouseLoc.y),
-                                               which);
+                                               button);
     CGEventPost(kCGHIDEventTap, click);
     CFRelease(click);
 }