projects
/
enjoyable.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Replace hacky target stringification with structured serialization.
[enjoyable.git]
/
TargetMouseMove.m
diff --git
a/TargetMouseMove.m
b/TargetMouseMove.m
index
86dd736
..
8eeae88
100644
(file)
--- a/
TargetMouseMove.m
+++ b/
TargetMouseMove.m
@@
-8,6
+8,8
@@
#import "TargetMouseMove.h"
#import "TargetMouseMove.h"
+#import "JoystickController.h"
+
@implementation TargetMouseMove
-(BOOL) isContinuous {
@implementation TargetMouseMove
-(BOOL) isContinuous {
@@
-16,48
+18,45
@@
@synthesize dir;
@synthesize dir;
-
-(NSString*) stringify
{
-
return [[NSString alloc] initWithFormat: @"mmove~%d", dir]
;
+
+ (NSString *)serializationCode
{
+
return @"mmove"
;
}
}
-+(TargetMouseMove*) unstringifyImpl: (NSArray*) comps {
- NSParameterAssert([comps count] == 2);
- TargetMouseMove* target = [[TargetMouseMove alloc] init];
- [target setDir: [comps[1] integerValue]];
- return target;
+- (NSDictionary *)serialize {
+ return @{ @"type": @"mmove", @"dir": @(self.dir) };
}
}
--(void) trigger: (JoystickController *)jc {
- return;
-}
-
--(void) untrigger: (JoystickController *)jc {
- return;
++ (Target *)targetDeserialize:(NSDictionary *)serialization
+ withConfigs:(NSArray *)configs {
+ TargetMouseMove *target = [[TargetMouseMove alloc] init];
+ target.dir = [serialization[@"dir"] intValue];
+ return target;
}
}
--
(void) update:
(JoystickController *)jc {
+-
(BOOL)update:
(JoystickController *)jc {
//printf("Dir %d inputValue %f\n", [self dir], [self inputValue]);
//printf("Dir %d inputValue %f\n", [self dir], [self inputValue]);
- if (fabs(
[self inputValue]
) < 0.01)
- return; // dead zone
+ if (fabs(
self.magnitude
) < 0.01)
+ return
NO
; // dead zone
NSRect screenRect = [[NSScreen mainScreen] frame];
NSInteger height = screenRect.size.height;
// TODO
NSRect screenRect = [[NSScreen mainScreen] frame];
NSInteger height = screenRect.size.height;
// TODO
-
double
speed = 4.0;
+
float
speed = 4.0;
if ([jc frontWindowOnly])
speed = 12.0;
if ([jc frontWindowOnly])
speed = 12.0;
-
double
dx = 0.0, dy = 0.0;
+
float
dx = 0.0, dy = 0.0;
if ([self dir] == 0)
if ([self dir] == 0)
- dx =
[self inputValue]
* speed;
+ dx =
self.magnitude
* speed;
else
else
- dy = [self inputValue] * speed;
- NSPoint *mouseLoc = &jc->mouseLoc;
- mouseLoc->x += dx;
- mouseLoc->y -= dy;
+ dy = self.magnitude * speed;
+ NSPoint mouseLoc = jc.mouseLoc;
+ mouseLoc.x += dx;
+ mouseLoc.y -= dy;
+ jc.mouseLoc = mouseLoc;
CGEventRef move = CGEventCreateMouseEvent(NULL, kCGEventMouseMoved,
CGEventRef move = CGEventCreateMouseEvent(NULL, kCGEventMouseMoved,
- CGPointMake(mouseLoc
->x, height - mouseLoc->
y),
+ CGPointMake(mouseLoc
.x, height - mouseLoc.
y),
0);
CGEventSetType(move, kCGEventMouseMoved);
CGEventSetIntegerValueField(move, kCGMouseEventDeltaX, dx);
0);
CGEventSetType(move, kCGEventMouseMoved);
CGEventSetIntegerValueField(move, kCGMouseEventDeltaX, dx);
@@
-73,6
+72,7
@@
}
CFRelease(move);
}
CFRelease(move);
+ return dx || dy;
}
@end
}
@end