forked from fyhuang/enjoy2
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTargetConfig.m
executable file
·60 lines (49 loc) · 1.69 KB
/
TargetConfig.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
//
// TargetConfig.m
// Enjoy
//
// Created by Sam McCall on 6/05/09.
//
#import "TargetConfig.h"
@implementation TargetConfig
@synthesize config, onpress, myJsaKey;
-(id) init {
if(self=[super init]) {
configsController=[[[NSApplication sharedApplication] delegate] configsController];
}
return self;
}
-(NSString*) stringify {
return [[NSString alloc] initWithFormat: @"cfg~%@~%d", [config name],onpress];
}
+(TargetConfig*) unstringifyImpl: (NSArray*) comps withConfigList: (NSArray*) configs {
NSParameterAssert([comps count] > 1);
NSString* name = [comps objectAtIndex: 1];
TargetConfig* target = [[TargetConfig alloc] init];
for(int i=0; i<[configs count]; i++){
//NSLog(@"Config %@ equal to %@",[[configs objectAtIndex:i] name],name);
if([[[configs objectAtIndex:i] name] isEqualToString:name]) {
[target setConfig: [configs objectAtIndex:i]];
if([comps count]>2)[target setOnpress: (int)[[comps objectAtIndex:2] integerValue]];
else [target setOnpress: 0];
return target;
}
}
NSLog(@"Warning: couldn't find matching config to restore from: %@",name);
return NULL;
}
-(void) trigger: (JoystickController *)jc {
//NSLog(@"TC trigg op:%d config:%@",onpress,[config name]);
if(onpress==0){
[configsController activateConfig:config forApplication: NULL];
[[config getTargetForActionFromKey:myJsaKey] setRunning:YES];
}
}
-(void) untrigger: (JoystickController *)jc {
//NSLog(@"TC untrg op:%d config:%@",onpress,[config name]);
if(onpress==1){
[configsController activateConfig:config forApplication: NULL];
[[config getTargetForActionFromKey:myJsaKey] setRunning:NO];
}
}
@end