2017-02-07 15:14:48 -08:00

71 lines
2.6 KiB
Objective-C

//
// LOTShape.m
// LottieAnimator
//
// Created by Brandon Withrow on 12/14/15.
// Copyright © 2015 Brandon Withrow. All rights reserved.
//
#import "LOTShapeGroup.h"
#import "LOTShapeFill.h"
#import "LOTShapePath.h"
#import "LOTShapeCircle.h"
#import "LOTShapeStroke.h"
#import "LOTShapeTransform.h"
#import "LOTShapeRectangle.h"
#import "LOTShapeTrimPath.h"
@implementation LOTShapeGroup
- (instancetype)initWithJSON:(NSDictionary *)jsonDictionary frameRate:(NSNumber *)frameRate compBounds:(CGRect)compBounds {
self = [super init];
if (self) {
[self _mapFromJSON:jsonDictionary frameRate:frameRate compBounds:compBounds];
}
return self;
}
- (void)_mapFromJSON:(NSDictionary *)jsonDictionary frameRate:(NSNumber *)frameRate compBounds:(CGRect)compBounds {
NSArray *itemsJSON = jsonDictionary[@"it"];
NSMutableArray *items = [NSMutableArray array];
for (NSDictionary *itemJSON in itemsJSON) {
id newItem = [LOTShapeGroup shapeItemWithJSON:itemJSON frameRate:frameRate compBounds:compBounds];
if (newItem) {
[items addObject:newItem];
}
}
_items = items;
}
+ (id)shapeItemWithJSON:(NSDictionary *)itemJSON frameRate:(NSNumber *)frameRate compBounds:(CGRect)compBounds {
NSString *type = itemJSON[@"ty"];
if ([type isEqualToString:@"gr"]) {
LOTShapeGroup *group = [[LOTShapeGroup alloc] initWithJSON:itemJSON frameRate:frameRate compBounds:compBounds];
return group;
} else if ([type isEqualToString:@"st"]) {
LOTShapeStroke *stroke = [[LOTShapeStroke alloc] initWithJSON:itemJSON frameRate:frameRate];
return stroke;
} else if ([type isEqualToString:@"fl"]) {
LOTShapeFill *fill = [[LOTShapeFill alloc] initWithJSON:itemJSON frameRate:frameRate];
return fill;
} else if ([type isEqualToString:@"tr"]) {
LOTShapeTransform *transform = [[LOTShapeTransform alloc] initWithJSON:itemJSON frameRate:frameRate compBounds:compBounds];
return transform;
} else if ([type isEqualToString:@"sh"]) {
LOTShapePath *path = [[LOTShapePath alloc] initWithJSON:itemJSON frameRate:frameRate];
return path;
} else if ([type isEqualToString:@"el"]) {
LOTShapeCircle *circle = [[LOTShapeCircle alloc] initWithJSON:itemJSON frameRate:frameRate];
return circle;
} else if ([type isEqualToString:@"rc"]) {
LOTShapeRectangle *rectangle = [[LOTShapeRectangle alloc] initWithJSON:itemJSON frameRate:frameRate];
return rectangle;
} else if ([type isEqualToString:@"tm"]) {
LOTShapeTrimPath *trim = [[LOTShapeTrimPath alloc] initWithJSON:itemJSON frameRate:frameRate];
return trim;
}
return nil;
}
@end