Files
fanyin-ios/Pods/SVGAPlayer/Source/SVGAVideoSpriteEntity.m

75 lines
2.9 KiB
Mathematica
Raw Permalink Normal View History

2025-08-12 14:27:12 +08:00
//
// SVGAVideoSpriteEntity.m
// SVGAPlayer
//
// Created by on 2017/2/20.
// Copyright © 2017 UED Center. All rights reserved.
//
#import "SVGAVideoSpriteEntity.h"
#import "SVGAVideoSpriteFrameEntity.h"
#import "SVGABitmapLayer.h"
#import "SVGAContentLayer.h"
#import "SVGAVectorLayer.h"
#import "Svga.pbobjc.h"
@implementation SVGAVideoSpriteEntity
- (instancetype)initWithJSONObject:(NSDictionary *)JSONObject {
self = [super init];
if (self) {
if ([JSONObject isKindOfClass:[NSDictionary class]]) {
NSString *imageKey = JSONObject[@"imageKey"];
NSString *matteKey = JSONObject[@"matteKey"];
NSArray<NSDictionary *> *JSONFrames = JSONObject[@"frames"];
if ([imageKey isKindOfClass:[NSString class]] && [JSONFrames isKindOfClass:[NSArray class]]) {
NSMutableArray<SVGAVideoSpriteFrameEntity *> *frames = [[NSMutableArray alloc] init];
[JSONFrames enumerateObjectsUsingBlock:^(NSDictionary * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
if ([obj isKindOfClass:[NSDictionary class]]) {
[frames addObject:[[SVGAVideoSpriteFrameEntity alloc] initWithJSONObject:obj]];
}
}];
_imageKey = imageKey;
_frames = frames;
_matteKey = matteKey;
}
}
}
return self;
}
- (instancetype)initWithProtoObject:(SVGAProtoSpriteEntity *)protoObject {
self = [super init];
if (self) {
if ([protoObject isKindOfClass:[SVGAProtoSpriteEntity class]]) {
NSString *imageKey = protoObject.imageKey;
NSString *matteKey = protoObject.matteKey;
NSArray<NSDictionary *> *protoFrames = [protoObject.framesArray copy];
if ([imageKey isKindOfClass:[NSString class]] && [protoFrames isKindOfClass:[NSArray class]]) {
NSMutableArray<SVGAVideoSpriteFrameEntity *> *frames = [[NSMutableArray alloc] init];
[protoFrames enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
if ([obj isKindOfClass:[SVGAProtoFrameEntity class]]) {
[frames addObject:[[SVGAVideoSpriteFrameEntity alloc] initWithProtoObject:obj]];
}
}];
_imageKey = imageKey;
_frames = frames;
_matteKey = matteKey;
}
}
}
return self;
}
- (SVGAContentLayer *)requestLayerWithBitmap:(UIImage *)bitmap {
SVGAContentLayer *layer = [[SVGAContentLayer alloc] initWithFrames:self.frames];
if (bitmap != nil) {
layer.bitmapLayer = [[SVGABitmapLayer alloc] initWithFrames:self.frames];
layer.bitmapLayer.contents = (__bridge id _Nullable)([bitmap CGImage]);
}
layer.vectorLayer = [[SVGAVectorLayer alloc] initWithFrames:self.frames];
return layer;
}
@end