LOTLayerGroup.m 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. //
  2. // LOTLayerGroup.m
  3. // Pods
  4. //
  5. // Created by Brandon Withrow on 2/16/17.
  6. //
  7. //
  8. #import "LOTLayerGroup.h"
  9. #import "LOTLayer.h"
  10. #import "LOTAssetGroup.h"
  11. @implementation LOTLayerGroup {
  12. NSDictionary *_modelMap;
  13. NSDictionary *_referenceIDMap;
  14. }
  15. - (instancetype)initWithLayerJSON:(NSArray *)layersJSON
  16. withAssetGroup:(LOTAssetGroup * _Nullable)assetGroup
  17. withFramerate:(NSNumber *)framerate {
  18. self = [super init];
  19. if (self) {
  20. [self _mapFromJSON:layersJSON withAssetGroup:assetGroup withFramerate:framerate];
  21. }
  22. return self;
  23. }
  24. - (void)_mapFromJSON:(NSArray *)layersJSON
  25. withAssetGroup:(LOTAssetGroup * _Nullable)assetGroup
  26. withFramerate:(NSNumber *)framerate {
  27. NSMutableArray *layers = [NSMutableArray array];
  28. NSMutableDictionary *modelMap = [NSMutableDictionary dictionary];
  29. NSMutableDictionary *referenceMap = [NSMutableDictionary dictionary];
  30. for (NSDictionary *layerJSON in layersJSON) {
  31. LOTLayer *layer = [[LOTLayer alloc] initWithJSON:layerJSON
  32. withAssetGroup:assetGroup
  33. withFramerate:framerate];
  34. [layers addObject:layer];
  35. modelMap[layer.layerID] = layer;
  36. if (layer.referenceID) {
  37. referenceMap[layer.referenceID] = layer;
  38. }
  39. }
  40. _referenceIDMap = referenceMap;
  41. _modelMap = modelMap;
  42. _layers = layers;
  43. }
  44. - (LOTLayer *)layerModelForID:(NSNumber *)layerID {
  45. return _modelMap[layerID];
  46. }
  47. - (LOTLayer *)layerForReferenceID:(NSString *)referenceID {
  48. return _referenceIDMap[referenceID];
  49. }
  50. @end