LOTMask.m 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. //
  2. // LOTMask.m
  3. // LottieAnimator
  4. //
  5. // Created by Brandon Withrow on 12/14/15.
  6. // Copyright © 2015 Brandon Withrow. All rights reserved.
  7. //
  8. #import "LOTMask.h"
  9. #import "CGGeometry+LOTAdditions.h"
  10. @implementation LOTMask
  11. - (instancetype)initWithJSON:(NSDictionary *)jsonDictionary {
  12. self = [super init];
  13. if (self) {
  14. [self _mapFromJSON:jsonDictionary];
  15. }
  16. return self;
  17. }
  18. - (void)_mapFromJSON:(NSDictionary *)jsonDictionary {
  19. NSNumber *closed = jsonDictionary[@"cl"];
  20. _closed = closed.boolValue;
  21. NSNumber *inverted = jsonDictionary[@"inv"];
  22. _inverted = inverted.boolValue;
  23. NSString *mode = jsonDictionary[@"mode"];
  24. if ([mode isEqualToString:@"a"]) {
  25. _maskMode = LOTMaskModeAdd;
  26. } else if ([mode isEqualToString:@"s"]) {
  27. _maskMode = LOTMaskModeSubtract;
  28. } else if ([mode isEqualToString:@"i"]) {
  29. _maskMode = LOTMaskModeIntersect;
  30. } else {
  31. _maskMode = LOTMaskModeUnknown;
  32. }
  33. NSDictionary *maskshape = jsonDictionary[@"pt"];
  34. if (maskshape) {
  35. _maskPath = [[LOTKeyframeGroup alloc] initWithData:maskshape];
  36. }
  37. NSDictionary *opacity = jsonDictionary[@"o"];
  38. if (opacity) {
  39. _opacity = [[LOTKeyframeGroup alloc] initWithData:opacity];
  40. [_opacity remapKeyframesWithBlock:^CGFloat(CGFloat inValue) {
  41. return LOT_RemapValue(inValue, 0, 100, 0, 1);
  42. }];
  43. }
  44. NSDictionary *expansion = jsonDictionary[@"x"];
  45. if (expansion) {
  46. _expansion = [[LOTKeyframeGroup alloc] initWithData:expansion];
  47. }
  48. }
  49. @end