X-Git-Url: https://git.yukkurigames.com/?p=enjoyable.git;a=blobdiff_plain;f=TargetMouseScroll.m;h=4d6f409a97d2804765f74109447c2c3642837763;hp=a1cca9c94d926816c95e8106f5c25cc7345f0bd7;hb=320e3065d251e11370e571df5705675937b76521;hpb=61f8cdec21ab083b29c22aa11fda54d6005666ca diff --git a/TargetMouseScroll.m b/TargetMouseScroll.m index a1cca9c..4d6f409 100644 --- a/TargetMouseScroll.m +++ b/TargetMouseScroll.m @@ -10,24 +10,27 @@ @implementation TargetMouseScroll -@synthesize howMuch; +@synthesize amount; --(NSString*) stringify { - return [[NSString alloc] initWithFormat: @"mscroll~%d", howMuch]; ++ (NSString *)serializationCode { + return @"mscroll"; } -+(TargetMouseScroll*) unstringifyImpl: (NSArray*) comps { - NSParameterAssert([comps count] == 2); - TargetMouseScroll* target = [[TargetMouseScroll alloc] init]; - [target setHowMuch: [[comps objectAtIndex:1] integerValue]]; - return target; +- (NSDictionary *)serialize { + return @{ @"type": @"mscroll", @"amount": @(self.amount) }; } --(void) trigger: (JoystickController *)jc { ++ (Target *)targetDeserialize:(NSDictionary *)serialization + withConfigs:(NSArray *)configs { + TargetMouseScroll *target = [[TargetMouseScroll alloc] init]; + target.amount = [serialization[@"amount"] intValue]; + return target; +} +-(void) trigger { CGEventRef scroll = CGEventCreateScrollWheelEvent(NULL, kCGScrollEventUnitLine, 1, - [self howMuch]); + self.amount); CGEventPost(kCGHIDEventTap, scroll); CFRelease(scroll); }