| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288 |
- //
- // MOGiftInfo.m
- //
- // Created by SuperCabbage on 2023/11/24
- // Copyright (c) 2023 __MyCompanyName__. All rights reserved.
- //
- #import "MOGiftInfo.h"
- #import "MOEffect.h"
- #import "MOGiftCornerMark.h"
- #import "MOStripe.h"
- #import "MOBlindboxLottery.h"
- NSString *const kMOGiftInfoEffect = @"effect";
- NSString *const kMOGiftInfoGiftPath = @"giftPath";
- NSString *const kMOGiftInfoId = @"id";
- NSString *const kMOGiftInfoLuckyGift = @"luckyGift";
- NSString *const kMOGiftInfoGiftSource = @"giftSource";
- NSString *const kMOGiftInfoGiftName = @"giftName";
- NSString *const kMOGiftInfoDiamond = @"diamond";
- NSString *const kMOGiftInfoGiftCode = @"giftCode";
- //NSString *const kMOGiftInfoAnimation = @"animation";
- NSString *const kMOGiftInfoGiftCornerMark = @"cornerMark";
- NSString *const kMOGiftInfoEffectType = @"effectType";
- NSString *const kMOGiftInfoSkin = @"skin";
- NSString *const kMOGiftInfoSkins = @"skins";
- NSString *const kMOGiftInfoDiyGiftNumberMax = @"diyGiftNumberMax";
- NSString *const kMOGiftInfoValueLevel = @"valueLevel";
- NSString *const kMOGiftInfoStripe = @"stripe";
- NSString *const kMOGiftInfoBlindBoxGift = @"blindBoxGift";
- NSString *const kMOGiftInfoAntiDrillCritGift = @"antiDrillCritGift";
- @interface MOGiftInfo ()
- - (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict;
- @end
- @implementation MOGiftInfo
- @synthesize effect = _effect;
- @synthesize giftPath = _giftPath;
- @synthesize id = _id;
- @synthesize luckyGift = _luckyGift;
- @synthesize giftSource = _giftSource;
- @synthesize giftName = _giftName;
- @synthesize diamond = _diamond;
- @synthesize giftCode = _giftCode;
- //@synthesize animation = _animation;
- @synthesize giftCornerMark = _giftCornerMark;
- @synthesize effectType = _effectType;
- @synthesize skin = _skin;
- @synthesize skins = _skins;
- @synthesize diyGiftNumberMax = _diyGiftNumberMax;
- @synthesize valueLevel = _valueLevel;
- @synthesize stripe = _stripe;
- @synthesize blindBoxGift = _blindBoxGift;
- @synthesize antiDrillCritGift = _antiDrillCritGift;
- + (instancetype)modelObjectWithDictionary:(NSDictionary *)dict {
- return [[self alloc] initWithDictionary:dict];
- }
- - (instancetype)initWithDictionary:(NSDictionary *)dict {
- self = [super init];
-
- // This check serves to make sure that a non-NSDictionary object
- // passed into the model class doesn't break the parsing.
- if (self && [dict isKindOfClass:[NSDictionary class]]) {
- self.effect = [MOEffect modelObjectWithDictionary:[dict objectForKey:kMOGiftInfoEffect]];
- self.giftPath = [self objectOrNilForKey:kMOGiftInfoGiftPath fromDictionary:dict];
- self.id = [self objectOrNilForKey:kMOGiftInfoId fromDictionary:dict];
- self.luckyGift = [[self objectOrNilForKey:kMOGiftInfoLuckyGift fromDictionary:dict] boolValue];
- self.giftSource = [self objectOrNilForKey:kMOGiftInfoGiftSource fromDictionary:dict];
- self.giftName = [self objectOrNilForKey:kMOGiftInfoGiftName fromDictionary:dict];
- self.diamond = [[self objectOrNilForKey:kMOGiftInfoDiamond fromDictionary:dict] doubleValue];
- self.giftCode = [[self objectOrNilForKey:kMOGiftInfoGiftCode fromDictionary:dict] doubleValue];
-
- // self.animation = [[self objectOrNilForKey:kMOGiftInfoAnimation fromDictionary:dict] boolValue];
- self.giftCornerMark = [MOGiftCornerMark modelObjectWithDictionary:[dict objectForKey:kMOGiftInfoGiftCornerMark]];
- self.effectType = [[self objectOrNilForKey:kMOGiftInfoEffectType fromDictionary:dict] doubleValue];
-
- self.skin = [MOEffect modelObjectWithDictionary:[dict objectForKey:kMOGiftInfoSkin]];
-
- self.blindBoxGift = [[self objectOrNilForKey:kMOGiftInfoBlindBoxGift fromDictionary:dict] boolValue];
-
- self.antiDrillCritGift = [[self objectOrNilForKey:kMOGiftInfoAntiDrillCritGift fromDictionary:dict] boolValue];
-
- NSObject *receivedMOGiftlist = [dict objectForKey:kMOGiftInfoSkins];
- NSMutableArray *parsedMOGiftlist = [NSMutableArray array];
-
- if ([receivedMOGiftlist isKindOfClass:[NSArray class]]) {
- for (NSDictionary *item in (NSArray *)receivedMOGiftlist) {
- if ([item isKindOfClass:[NSDictionary class]]) {
- [parsedMOGiftlist addObject:[MOEffect modelObjectWithDictionary:item]];
- }
- }
- } else if ([receivedMOGiftlist isKindOfClass:[NSDictionary class]]) {
- [parsedMOGiftlist addObject:[MOEffect modelObjectWithDictionary:(NSDictionary *)receivedMOGiftlist]];
- }
- self.skins = [NSArray arrayWithArray:parsedMOGiftlist];
- self.diyGiftNumberMax = [[self objectOrNilForKey:kMOGiftInfoDiyGiftNumberMax fromDictionary:dict] doubleValue];
- self.valueLevel = [[self objectOrNilForKey:kMOGiftInfoValueLevel fromDictionary:dict] doubleValue];
- self.stripe = [MOStripe modelObjectWithDictionary:[dict objectForKey:kMOGiftInfoStripe]];
-
- if(self.giftPath.length == 0){
- self.giftPath = self.skin.path;
- }
-
- if(self.giftName.length == 0){
- self.giftName = self.skin.name;
- }
-
- if(self.giftCode == 0){
- self.giftCode = self.skin.code;
- }
-
- if(self.giftSource.length == 0){
- self.giftSource = self.skin.source;
- }
-
- if(self.effectType == 0){
- if(self.skin){
- self.effectType = self.skin.effectType;
- }
- }
- }
-
- return self;
-
- }
- - (NSDictionary *)dictionaryRepresentation {
- NSMutableDictionary *mutableDict = [NSMutableDictionary dictionary];
- [mutableDict setValue:[self.effect dictionaryRepresentation] forKey:kMOGiftInfoEffect];
- [mutableDict setValue:self.giftPath forKey:kMOGiftInfoGiftPath];
- [mutableDict setValue:self.id forKey:kMOGiftInfoId];
- [mutableDict setValue:[NSNumber numberWithBool:self.luckyGift] forKey:kMOGiftInfoLuckyGift];
- [mutableDict setValue:self.giftSource forKey:kMOGiftInfoGiftSource];
- [mutableDict setValue:self.giftName forKey:kMOGiftInfoGiftName];
- [mutableDict setValue:[NSNumber numberWithDouble:self.diamond] forKey:kMOGiftInfoDiamond];
- [mutableDict setValue:[NSNumber numberWithDouble:self.giftCode] forKey:kMOGiftInfoGiftCode];
-
- // [mutableDict setValue:[NSNumber numberWithBool:self.animation] forKey:kMOGiftInfoAnimation];
- [mutableDict setValue:[self.giftCornerMark dictionaryRepresentation] forKey:kMOGiftInfoGiftCornerMark];
- [mutableDict setValue:[NSNumber numberWithDouble:self.effectType] forKey:kMOGiftInfoEffectType];
-
- [mutableDict setValue:[self.skin dictionaryRepresentation] forKey:kMOGiftInfoSkin];
-
- [mutableDict setValue:[NSNumber numberWithBool:self.blindBoxGift] forKey:kMOGiftInfoBlindBoxGift];
- [mutableDict setValue:[NSNumber numberWithBool:self.antiDrillCritGift] forKey:kMOGiftInfoAntiDrillCritGift];
-
- NSMutableArray *tempArrayForGiftlist = [NSMutableArray array];
-
- for (NSObject *subArrayObject in self.skins) {
- if ([subArrayObject respondsToSelector:@selector(dictionaryRepresentation)]) {
- // This class is a model object
- [tempArrayForGiftlist addObject:[subArrayObject performSelector:@selector(dictionaryRepresentation)]];
- } else {
- // Generic object
- [tempArrayForGiftlist addObject:subArrayObject];
- }
- }
- [mutableDict setValue:[NSArray arrayWithArray:tempArrayForGiftlist] forKey:kMOGiftInfoSkins];
-
- [mutableDict setValue:[NSNumber numberWithDouble:self.diyGiftNumberMax] forKey:kMOGiftInfoDiyGiftNumberMax];
- [mutableDict setValue:[NSNumber numberWithDouble:self.valueLevel] forKey:kMOGiftInfoValueLevel];
- [mutableDict setValue:[self.stripe dictionaryRepresentation] forKey:kMOGiftInfoStripe];
- return [NSDictionary dictionaryWithDictionary:mutableDict];
- }
- - (NSString *)description {
- return [NSString stringWithFormat:@"%@", [self dictionaryRepresentation]];
- }
- #pragma mark - Helper Method
- - (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict {
- id object = [dict objectForKey:aKey];
- return [object isEqual:[NSNull null]] ? nil : object;
- }
- #pragma mark - NSCoding Methods
- - (id)initWithCoder:(NSCoder *)aDecoder {
- self = [super init];
- self.effect = [aDecoder decodeObjectForKey:kMOGiftInfoEffect];
- self.giftPath = [aDecoder decodeObjectForKey:kMOGiftInfoGiftPath];
- self.id = [aDecoder decodeObjectForKey:kMOGiftInfoId];
- self.luckyGift = [aDecoder decodeBoolForKey:kMOGiftInfoLuckyGift];
- self.giftSource = [aDecoder decodeObjectForKey:kMOGiftInfoGiftSource];
- self.giftName = [aDecoder decodeObjectForKey:kMOGiftInfoGiftName];
- self.diamond = [aDecoder decodeDoubleForKey:kMOGiftInfoDiamond];
- self.giftCode = [aDecoder decodeDoubleForKey:kMOGiftInfoGiftCode];
-
- // self.animation = [aDecoder decodeBoolForKey:kMOGiftInfoAnimation];
- self.giftCornerMark = [aDecoder decodeObjectForKey:kMOGiftInfoGiftCornerMark];
- self.effectType = [aDecoder decodeDoubleForKey:kMOGiftInfoEffectType];
-
- self.skin = [aDecoder decodeObjectForKey:kMOGiftInfoSkin];
- self.skins = [aDecoder decodeObjectForKey:kMOGiftInfoSkins];
- self.diyGiftNumberMax = [aDecoder decodeDoubleForKey:kMOGiftInfoDiyGiftNumberMax];
- self.valueLevel = [aDecoder decodeDoubleForKey:kMOGiftInfoValueLevel];
- self.stripe = [aDecoder decodeObjectForKey:kMOGiftInfoStripe];
-
- self.blindBoxGift = [aDecoder decodeBoolForKey:kMOGiftInfoBlindBoxGift];
- self.antiDrillCritGift = [aDecoder decodeBoolForKey:kMOGiftInfoAntiDrillCritGift];
-
- return self;
- }
- - (void)encodeWithCoder:(NSCoder *)aCoder
- {
- [aCoder encodeObject:_effect forKey:kMOGiftInfoEffect];
- [aCoder encodeObject:_giftPath forKey:kMOGiftInfoGiftPath];
- [aCoder encodeObject:_id forKey:kMOGiftInfoId];
- [aCoder encodeBool:_luckyGift forKey:kMOGiftInfoLuckyGift];
- [aCoder encodeObject:_giftSource forKey:kMOGiftInfoGiftSource];
- [aCoder encodeObject:_giftName forKey:kMOGiftInfoGiftName];
- [aCoder encodeDouble:_diamond forKey:kMOGiftInfoDiamond];
- [aCoder encodeDouble:_giftCode forKey:kMOGiftInfoGiftCode];
-
- // [aCoder encodeBool:_animation forKey:kMOGiftInfoAnimation];
- [aCoder encodeObject:_giftCornerMark forKey:kMOGiftInfoGiftCornerMark];
- [aCoder encodeDouble:_effectType forKey:kMOGiftInfoEffectType];
-
- [aCoder encodeObject:_skin forKey:kMOGiftInfoSkin];
- [aCoder encodeObject:_skins forKey:kMOGiftInfoSkins];
- [aCoder encodeDouble:_diyGiftNumberMax forKey:kMOGiftInfoDiyGiftNumberMax];
- [aCoder encodeDouble:_valueLevel forKey:kMOGiftInfoValueLevel];
- [aCoder encodeObject:_stripe forKey:kMOGiftInfoStripe];
-
- [aCoder encodeBool:_blindBoxGift forKey:kMOGiftInfoBlindBoxGift];
- [aCoder encodeBool:_antiDrillCritGift forKey:kMOGiftInfoAntiDrillCritGift];
- }
- - (id)copyWithZone:(NSZone *)zone {
- MOGiftInfo *copy = [[MOGiftInfo alloc] init];
-
-
-
- if (copy) {
- copy.effect = [self.effect copyWithZone:zone];
- copy.giftPath = [self.giftPath copyWithZone:zone];
- copy.id = [self.id copyWithZone:zone];
- copy.luckyGift = self.luckyGift;
- copy.giftSource = [self.giftSource copyWithZone:zone];
- copy.giftName = [self.giftName copyWithZone:zone];
- copy.diamond = self.diamond;
- copy.giftCode = self.giftCode;
- // copy.animation = self.animation;
- copy.giftCornerMark = [self.giftCornerMark copyWithZone:zone];
- copy.effectType = self.effectType;
-
- copy.skin = [self.skin copyWithZone:zone];
- copy.skins = [self.skins copyWithZone:zone];
- copy.diyGiftNumberMax = self.diyGiftNumberMax;
- copy.valueLevel = self.valueLevel;
- copy.stripe = [self.stripe copyWithZone:zone];
-
- copy.selectSkin = [self.selectSkin copyWithZone:zone];
-
- copy.blindBoxGift = self.blindBoxGift;
- copy.antiDrillCritGift = self.antiDrillCritGift;
- }
-
- return copy;
- }
- - (BOOL)isEqual:(id)object {
- if (self == object) return YES;
- if (![object isKindOfClass:[self class]]) return NO;
-
- MOGiftInfo *other = (MOGiftInfo *)object;
- return self.id == other.id;
- }
- @end
|