mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-08-08 08:31:13 +00:00
61 lines
1.6 KiB
Objective-C
61 lines
1.6 KiB
Objective-C
//
|
|
// LOTScene.m
|
|
// LottieAnimator
|
|
//
|
|
// Created by Brandon Withrow on 12/14/15.
|
|
// Copyright © 2015 Brandon Withrow. All rights reserved.
|
|
//
|
|
|
|
#import "LOTComposition.h"
|
|
#import "LOTLayer.h"
|
|
|
|
@implementation LOTComposition {
|
|
NSDictionary *_modelMap;
|
|
}
|
|
|
|
- (instancetype)initWithJSON:(NSDictionary *)jsonDictionary {
|
|
self = [super init];
|
|
if (self) {
|
|
[self _mapFromJSON:jsonDictionary];
|
|
}
|
|
return self;
|
|
}
|
|
|
|
- (void)_mapFromJSON:(NSDictionary *)jsonDictionary {
|
|
NSNumber *width = jsonDictionary[@"w"];
|
|
NSNumber *height = jsonDictionary[@"h"];
|
|
if (width && height) {
|
|
CGRect bounds = CGRectMake(0, 0, width.floatValue, height.floatValue);
|
|
_compBounds = bounds;
|
|
}
|
|
|
|
_startFrame = [jsonDictionary[@"ip"] copy];
|
|
_endFrame = [jsonDictionary[@"op"] copy];
|
|
_framerate = [jsonDictionary[@"fr"] copy];
|
|
|
|
if (_startFrame && _endFrame && _framerate) {
|
|
NSInteger frameDuration = _endFrame.integerValue - _startFrame.integerValue;
|
|
NSTimeInterval timeDuration = frameDuration / _framerate.floatValue;
|
|
_timeDuration = timeDuration;
|
|
}
|
|
|
|
NSArray *layersJSON = jsonDictionary[@"layers"];
|
|
NSMutableArray *layers = [NSMutableArray array];
|
|
NSMutableDictionary *modelMap = [NSMutableDictionary dictionary];
|
|
|
|
for (NSDictionary *layerJSON in layersJSON) {
|
|
LOTLayer *layer = [[LOTLayer alloc] initWithJSON:layerJSON fromComposition:self];
|
|
[layers addObject:layer];
|
|
modelMap[layer.layerID] = layer;
|
|
}
|
|
|
|
_modelMap = modelMap;
|
|
_layers = layers;
|
|
}
|
|
|
|
- (LOTLayer *)layerModelForID:(NSNumber *)layerID {
|
|
return _modelMap[layerID];
|
|
}
|
|
|
|
@end
|