X-Git-Url: https://git.yukkurigames.com/?p=enjoyable.git;a=blobdiff_plain;f=TargetMouseMove.m;h=f75f70bd2d74a3fa92db4fc80da75b47239c67a7;hp=78d9c93198d75d684a13845f3264ce3b9ddc7a2c;hb=44fe6f649589488b367eee7ffff240cecf8669ad;hpb=724979785b445dcba8a9861c2531ae0308bdf40a diff --git a/TargetMouseMove.m b/TargetMouseMove.m index 78d9c93..f75f70b 100644 --- a/TargetMouseMove.m +++ b/TargetMouseMove.m @@ -8,50 +8,59 @@ #import "TargetMouseMove.h" -@implementation TargetMouseMove +#import "JoystickController.h" + +@implementation TargetMouseMove { + int sign; +} -(BOOL) isContinuous { - return true; + return YES; } @synthesize dir; --(NSString*) stringify { - return [[NSString alloc] initWithFormat: @"mmove~%d", dir]; -} - -+(TargetMouseMove*) unstringifyImpl: (NSArray*) comps { - NSParameterAssert([comps count] == 2); - TargetMouseMove* target = [[TargetMouseMove alloc] init]; - [target setDir: [comps[1] integerValue]]; - return target; ++ (NSString *)serializationCode { + return @"mmove"; } --(void) trigger: (JoystickController *)jc { - return; +- (NSDictionary *)serialize { + return @{ @"type": @"mmove", @"dir": @(self.dir) }; } --(void) untrigger: (JoystickController *)jc { - return; ++ (Target *)targetDeserialize:(NSDictionary *)serialization + withConfigs:(NSArray *)configs { + TargetMouseMove *target = [[TargetMouseMove alloc] init]; + target.dir = [serialization[@"dir"] intValue]; + return target; } - (BOOL)update:(JoystickController *)jc { - //printf("Dir %d inputValue %f\n", [self dir], [self inputValue]); - if (fabs([self inputValue]) < 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; // TODO - double speed = 4.0; + float speed = 4.f; if ([jc frontWindowOnly]) - speed = 12.0; - double dx = 0.0, dy = 0.0; - if ([self dir] == 0) - dx = [self inputValue] * speed; + speed = 12.f; + float dx = 0.f, dy = 0.f; + if (self.dir == 0) + dx = self.magnitude * speed; else - dy = [self inputValue] * speed; + dy = self.magnitude * speed; NSPoint mouseLoc = jc.mouseLoc; mouseLoc.x += dx; mouseLoc.y -= dy; @@ -74,7 +83,7 @@ } CFRelease(move); - return dx || dy; + return YES; } @end