//
//  Target.m
//  Enjoy
//
//  Created by Sam McCall on 5/05/09.
//

#import "Target.h"

#import "TargetKeyboard.h"
#import "TargetConfig.h"
#import "TargetMouseMove.h"
#import "TargetMouseBtn.h"
#import "TargetMouseScroll.h"
#import "TargetToggleMouseScope.h"

@implementation Target {
    BOOL running;
}

+ (NSString *)serializationCode {
    [self doesNotRecognizeSelector:_cmd];
    return nil;
}

- (NSDictionary *)serialize {
    [self doesNotRecognizeSelector:_cmd];
    return nil;    
}

+ (Target *)targetDeserialize:(NSDictionary *)serialization
                  withConfigs:(NSArray *)configs {
    // Don't crash loading old configs (but don't load them either).
    if (![serialization isKindOfClass:[NSDictionary class]])
        return nil;
    NSString *type = serialization[@"type"];
    for (Class cls in @[[TargetKeyboard class],
                        [TargetConfig class],
                        [TargetMouseMove class],
                        [TargetMouseBtn class],
                        [TargetMouseScroll class],
                        [TargetToggleMouseScope class]
         ]) {
        if ([type isEqualToString:[cls serializationCode]])
            return [cls targetDeserialize:serialization withConfigs:configs];
    }
    
    return nil;
}

- (void)trigger {
}

- (void)untrigger {
}

- (BOOL)update:(JoystickController *)jc {
    return NO;
}

- (BOOL)isContinuous {
    return NO;
}

- (BOOL)running {
    return running;
}

- (void)setRunning:(BOOL)newRunning {
    if (running != newRunning) {
        running = newRunning;
        if (running)
            [self trigger];
        else
            [self untrigger];
    }
}


@end
