LOTAsset.m 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. //
  2. // LOTAsset.m
  3. // Pods
  4. //
  5. // Created by Brandon Withrow on 2/16/17.
  6. //
  7. //
  8. #import "LOTAsset.h"
  9. #import "LOTLayer.h"
  10. #import "LOTLayerGroup.h"
  11. #import "LOTAssetGroup.h"
  12. @implementation LOTAsset
  13. - (instancetype)initWithJSON:(NSDictionary *)jsonDictionary
  14. withAssetGroup:(LOTAssetGroup * _Nullable)assetGroup
  15. withAssetBundle:(NSBundle *_Nonnull)bundle
  16. withFramerate:(NSNumber *)framerate {
  17. self = [super init];
  18. if (self) {
  19. _assetBundle = bundle;
  20. [self _mapFromJSON:jsonDictionary
  21. withAssetGroup:assetGroup
  22. withFramerate:framerate];
  23. }
  24. return self;
  25. }
  26. - (void)_mapFromJSON:(NSDictionary *)jsonDictionary
  27. withAssetGroup:(LOTAssetGroup * _Nullable)assetGroup
  28. withFramerate:(NSNumber *)framerate {
  29. _referenceID = [jsonDictionary[@"id"] copy];
  30. if (jsonDictionary[@"w"]) {
  31. _assetWidth = [jsonDictionary[@"w"] copy];
  32. }
  33. if (jsonDictionary[@"h"]) {
  34. _assetHeight = [jsonDictionary[@"h"] copy];
  35. }
  36. if (jsonDictionary[@"u"]) {
  37. _imageDirectory = [jsonDictionary[@"u"] copy];
  38. }
  39. if (jsonDictionary[@"p"]) {
  40. _imageName = [jsonDictionary[@"p"] copy];
  41. }
  42. NSArray *layersJSON = jsonDictionary[@"layers"];
  43. if (layersJSON) {
  44. _layerGroup = [[LOTLayerGroup alloc] initWithLayerJSON:layersJSON
  45. withAssetGroup:assetGroup
  46. withFramerate:framerate];
  47. }
  48. }
  49. @end