X-Git-Url: https://git.yukkurigames.com/?p=enjoyable.git;a=blobdiff_plain;f=TargetMouseMove.m;h=52f241a0640952f8c16ea49276eea9c4c7a9e1e8;hp=aa503069441645295ebe4bf9551a485eaa646735;hb=62aa5b73be6ec1e499e6b155cd0e7687c338cbaa;hpb=51d43664909060e85c943c4d63cc3cff307ceb1d diff --git a/TargetMouseMove.m b/TargetMouseMove.m index aa50306..52f241a 100644 --- a/TargetMouseMove.m +++ b/TargetMouseMove.m @@ -8,39 +8,54 @@ #import "TargetMouseMove.h" -@implementation TargetMouseMove +#import "JoystickController.h" + +@implementation TargetMouseMove { + int sign; +} -(BOOL) isContinuous { - return true; + return YES; } -@synthesize dir; ++ (NSString *)serializationCode { + return @"mmove"; +} --(NSString*) stringify { - return [[NSString alloc] initWithFormat: @"mmove~%d", dir]; +- (NSDictionary *)serialize { + return @{ @"type": @"mmove", @"axis": @(_axis) }; } -+(TargetMouseMove*) unstringifyImpl: (NSArray*) comps { - NSParameterAssert([comps count] == 2); - TargetMouseMove* target = [[TargetMouseMove alloc] init]; - [target setDir: [comps[1] integerValue]]; ++ (Target *)targetDeserialize:(NSDictionary *)serialization + withConfigs:(NSArray *)configs { + TargetMouseMove *target = [[TargetMouseMove alloc] init]; + target.axis = [serialization[@"axis"] intValue]; return target; } - (BOOL)update:(JoystickController *)jc { - //printf("Dir %d inputValue %f\n", [self dir], [self inputValue]); - if (fabs(self.magnitude) < 0.01) + if (fabsf(self.magnitude) < 0.01) { + sign = 0; return NO; // dead zone + } + + // If the action crossed over High/Low, this target is done. + if (!sign) + sign = self.magnitude < 0 ? -1 : 1; + else if (sign / self.magnitude < 0) { + sign = 0; + return NO; + } NSRect screenRect = [[NSScreen mainScreen] frame]; - NSInteger height = screenRect.size.height; + CGFloat height = screenRect.size.height; // TODO - float speed = 4.0; + float speed = 4.f; if ([jc frontWindowOnly]) - speed = 12.0; - float dx = 0.0, dy = 0.0; - if ([self dir] == 0) + speed = 12.f; + float dx = 0.f, dy = 0.f; + if (_axis == 0) dx = self.magnitude * speed; else dy = self.magnitude * speed; @@ -53,8 +68,8 @@ CGPointMake(mouseLoc.x, height - mouseLoc.y), 0); CGEventSetType(move, kCGEventMouseMoved); - CGEventSetIntegerValueField(move, kCGMouseEventDeltaX, dx); - CGEventSetIntegerValueField(move, kCGMouseEventDeltaY, dy); + CGEventSetIntegerValueField(move, kCGMouseEventDeltaX, (int)dx); + CGEventSetIntegerValueField(move, kCGMouseEventDeltaY, (int)dy); if ([jc frontWindowOnly]) { ProcessSerialNumber psn; @@ -66,7 +81,7 @@ } CFRelease(move); - return dx || dy; + return YES; } @end