2024-12-28 15:41:56 +08:00
|
|
|
//
|
|
|
|
// RoomResourceManager.m
|
|
|
|
// YuMi
|
|
|
|
//
|
|
|
|
// Created by P on 2024/12/25.
|
|
|
|
//
|
|
|
|
|
|
|
|
#import "RoomResourceManager.h"
|
|
|
|
|
|
|
|
#import <SVGA.h>
|
|
|
|
#import "SDWebImageManager.h"
|
|
|
|
#import "RoomLevelInfoModel.h"
|
|
|
|
|
|
|
|
@interface RoomResourceManager()
|
|
|
|
|
|
|
|
@property (nonatomic, strong) NSOperationQueue *svgaParseOperationQueue;
|
|
|
|
|
|
|
|
@property(nonatomic, copy) NSArray *roomMicInfos;
|
2025-02-28 19:04:09 +08:00
|
|
|
@property(nonatomic, copy) NSDictionary *giftPanelNums;
|
2024-12-28 15:41:56 +08:00
|
|
|
@property(nonatomic, strong) NSMutableDictionary<NSString *, RoomMicInfoModel *> *micSkins;
|
|
|
|
@property(nonatomic, strong) NSMutableDictionary<NSString *, UIImage *> *micBossSkins;
|
|
|
|
@property(nonatomic, strong) NSMutableDictionary<NSString *, UIImage *> *micNormalSkins;
|
|
|
|
@property(nonatomic, strong) NSMutableDictionary<NSString *, UIImage *> *micBossLockSkins;
|
|
|
|
@property(nonatomic, strong) NSMutableDictionary<NSString *, UIImage *> *micNormalLockSkins;
|
|
|
|
@property(nonatomic, strong) NSMutableDictionary<NSString *, SVGAVideoEntity *> *micEffectVideoItems;
|
|
|
|
|
|
|
|
@property(nonatomic, assign) NSInteger currentSkinID;
|
|
|
|
@property(nonatomic, assign) NSInteger currentEffectID;
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation RoomResourceManager
|
|
|
|
|
|
|
|
+ (instancetype)sharedManager {
|
|
|
|
static RoomResourceManager *sharedManager = nil;
|
|
|
|
static dispatch_once_t onceToken;
|
|
|
|
dispatch_once(&onceToken, ^{
|
|
|
|
sharedManager = [[self alloc] init];
|
|
|
|
// 初始化操作队列
|
|
|
|
sharedManager.svgaParseOperationQueue = [[NSOperationQueue alloc] init];
|
|
|
|
sharedManager.svgaParseOperationQueue.maxConcurrentOperationCount = 1; // 串行执行
|
|
|
|
|
|
|
|
sharedManager.micSkins = [NSMutableDictionary dictionary];
|
|
|
|
sharedManager.micEffectVideoItems = [NSMutableDictionary dictionary];
|
|
|
|
sharedManager.micBossSkins = [NSMutableDictionary dictionary];
|
|
|
|
sharedManager.micNormalSkins = [NSMutableDictionary dictionary];
|
|
|
|
sharedManager.micBossLockSkins = [NSMutableDictionary dictionary];
|
|
|
|
sharedManager.micNormalLockSkins = [NSMutableDictionary dictionary];
|
|
|
|
});
|
|
|
|
return sharedManager;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)cacheAPIData:(id)data {
|
|
|
|
if (!data) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if ([data isKindOfClass:[NSDictionary class]] ) {
|
|
|
|
NSArray *array = data[@"roomMicDressList"];
|
2025-02-28 19:04:09 +08:00
|
|
|
self.giftPanelNums = data[@"roomGiftPanelNums"];
|
2024-12-28 15:41:56 +08:00
|
|
|
self.roomMicInfos = [RoomMicInfoModel modelsWithArray:array];
|
|
|
|
for (RoomMicInfoModel *micInfo in self.roomMicInfos) {
|
|
|
|
switch (micInfo.dressType) {
|
|
|
|
case MicResourceType_Skin: {
|
|
|
|
[self preloadNormalSkin:micInfo.bossMicUrl forID:micInfo.id isForLock:NO isForBoss:YES];
|
|
|
|
[self preloadNormalSkin:micInfo.normalMicUrl forID:micInfo.id isForLock:NO isForBoss:NO];
|
|
|
|
[self preloadNormalSkin:micInfo.bossMicLockUrl forID:micInfo.id isForLock:YES isForBoss:YES];
|
|
|
|
[self preloadNormalSkin:micInfo.normalMicLockUrl forID:micInfo.id isForLock:YES isForBoss:NO];
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case MicResourceType_Effect: {
|
|
|
|
@kWeakify(self);
|
|
|
|
NSBlockOperation *preloadOperation = [NSBlockOperation blockOperationWithBlock:^{
|
|
|
|
@kStrongify(self);
|
|
|
|
SVGAParser *p = [[SVGAParser alloc] init];
|
|
|
|
@kWeakify(self);
|
|
|
|
[p parseWithURL:[NSURL URLWithString:micInfo.normalMicUrl] completionBlock:^(SVGAVideoEntity * _Nullable videoItem) {
|
|
|
|
@kStrongify(self);
|
|
|
|
[self.micEffectVideoItems setObject:videoItem forKey:micInfo.id];
|
|
|
|
} failureBlock:nil];
|
|
|
|
}];
|
|
|
|
#if DEBUG
|
|
|
|
preloadOperation.completionBlock = ^{
|
|
|
|
NSLog(@"Preload SVGA Task completed for URL: %@", micInfo.normalMicUrl);
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
[self.svgaParseOperationQueue addOperation:preloadOperation];
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)preloadNormalSkin:(NSString *)url
|
|
|
|
forID:(NSString *)skinID
|
|
|
|
isForLock:(BOOL)isForLock
|
|
|
|
isForBoss:(BOOL)isForBoss {
|
|
|
|
@kWeakify(self);
|
|
|
|
NSBlockOperation *preloadOperation = [NSBlockOperation blockOperationWithBlock:^{
|
|
|
|
// SVGAParser *p = [[SVGAParser alloc] init];
|
|
|
|
@kStrongify(self);
|
|
|
|
@kWeakify(self);
|
|
|
|
[[SDWebImageManager sharedManager] loadImageWithURL:[NSURL URLWithString:url]
|
|
|
|
options:SDWebImageRetryFailed | SDWebImageHighPriority | SDWebImageHighPriority
|
|
|
|
progress:nil
|
|
|
|
completed:^(UIImage * _Nullable image, NSData * _Nullable data, NSError * _Nullable error, SDImageCacheType cacheType, BOOL finished, NSURL * _Nullable imageURL) {
|
|
|
|
if (image) {
|
|
|
|
@kStrongify(self);
|
|
|
|
if (isForLock) {
|
|
|
|
if (isForBoss) {
|
|
|
|
[self.micBossLockSkins setObject:image forKey:skinID];
|
|
|
|
} else {
|
|
|
|
[self.micNormalLockSkins setObject:image forKey:skinID];
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (isForBoss) {
|
|
|
|
[self.micBossSkins setObject:image forKey:skinID];
|
|
|
|
} else {
|
|
|
|
[self.micNormalSkins setObject:image forKey:skinID];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}];
|
|
|
|
}];
|
|
|
|
#if DEBUG
|
|
|
|
preloadOperation.completionBlock = ^{
|
|
|
|
NSLog(@"Preload Image Task completed for URL: %@", url);
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
[self.svgaParseOperationQueue addOperation:preloadOperation];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *)loadMicNormalSkin:(NSString *)skinID isForLock:(BOOL)isLock {
|
|
|
|
RoomMicInfoModel *micInfo = [self.micSkins objectForKey:skinID];
|
|
|
|
if (micInfo) {
|
|
|
|
return isLock ? micInfo.normalMicLockUrl : micInfo.normalMicUrl;
|
|
|
|
}
|
|
|
|
return @"";
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *)loadMicBossSkin:(NSString *)skinID isForLock:(BOOL)isLock {
|
|
|
|
RoomMicInfoModel *micInfo = [self.micSkins objectForKey:skinID];
|
|
|
|
if (micInfo) {
|
|
|
|
return isLock ? micInfo.bossMicLockUrl : micInfo.bossMicUrl;
|
|
|
|
}
|
|
|
|
return @"";
|
|
|
|
}
|
|
|
|
|
|
|
|
- (SVGAVideoEntity *)loadMicSVGAVideo:(NSString *)effectID {
|
|
|
|
SVGAVideoEntity *entity = [self.micEffectVideoItems objectForKey:effectID];
|
|
|
|
return entity;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)updateCurrentSkinID:(NSInteger )skinID effectID:(NSInteger)effectID {
|
|
|
|
self.currentSkinID = skinID;
|
|
|
|
self.currentEffectID = effectID;
|
|
|
|
}
|
|
|
|
|
|
|
|
//- (NSString *)loadMicNormalSkinForLock:(BOOL)isLock {
|
|
|
|
// return [self loadMicNormalSkin:@(self.currentSkinID).stringValue
|
|
|
|
// isForLock:isLock];
|
|
|
|
//}
|
|
|
|
//
|
|
|
|
//- (NSString *)loadMicBossSkinForLock:(BOOL)isLock {
|
|
|
|
// return [self loadMicBossSkin:@(self.currentSkinID).stringValue
|
|
|
|
// isForLock:isLock];
|
|
|
|
//}
|
|
|
|
|
|
|
|
- (UIImage *)loadMicBossSkinForLock:(BOOL)isLock {
|
|
|
|
if (isLock) {
|
|
|
|
return [self.micBossLockSkins objectForKey:@(self.currentSkinID).stringValue];
|
|
|
|
} else {
|
2025-01-07 20:07:54 +08:00
|
|
|
if (self.currentSkinID == 0) {
|
|
|
|
return kImage(@"room_boss_mic");
|
|
|
|
}
|
2024-12-28 15:41:56 +08:00
|
|
|
return [self.micBossSkins objectForKey:@(self.currentSkinID).stringValue];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (UIImage *)loadMicNormalSKinForLock:(BOOL)isLock {
|
|
|
|
if (isLock) {
|
|
|
|
return [self.micNormalLockSkins objectForKey:@(self.currentSkinID).stringValue];
|
|
|
|
} else {
|
|
|
|
return [self.micNormalSkins objectForKey:@(self.currentSkinID).stringValue];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (SVGAVideoEntity *)loadMicEffect {
|
|
|
|
return [self loadMicSVGAVideo:@(self.currentEffectID).stringValue];
|
|
|
|
}
|
|
|
|
|
2025-02-28 19:04:09 +08:00
|
|
|
- (NSString *)loadGiftPanelNum:(NSInteger)pID {
|
|
|
|
return [self.giftPanelNums objectForKey:@(pID).stringValue];
|
|
|
|
}
|
|
|
|
|
2024-12-28 15:41:56 +08:00
|
|
|
@end
|
|
|
|
|