| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208 |
- //
- // MOEffect.m
- //
- // Created by SuperCabbage on 2023/11/24
- // Copyright (c) 2023 __MyCompanyName__. All rights reserved.
- //
- #import "MOEffect.h"
- #import "MOAttributes.h"
- NSString *const kMOEffectPath = @"path";
- NSString *const kMOEffectCode = @"code";
- NSString *const kMOEffectSource = @"source";
- NSString *const kMOEffectName = @"name";
- NSString *const kMOEffectDuration = @"duration";
- NSString *const kMOEffectId = @"id";
- NSString *const kMOEffectEffectType = @"effectType";
- NSString *const kMOEffectAnimation = @"animation";
- NSString *const kMOEffectImage = @"image";
- NSString *const kMOEffectResFile = @"resFile";
- NSString *const kMOEffectEffectFile = @"effectFile";
- NSString *const kMOEffectLock = @"lock";
- NSString *const kMOEffectAttributes = @"attributes";
- @interface MOEffect ()
- - (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict;
- @end
- @implementation MOEffect
- @synthesize path = _path;
- @synthesize code = _code;
- @synthesize source = _source;
- @synthesize name = _name;
- @synthesize duration = _duration;
- @synthesize id = _id;
- @synthesize effectType = _effectType;
- @synthesize animation = _animation;
- @synthesize image = _image;
- @synthesize resFile = _resFile;
- @synthesize effectFile = _effectFile;
- @synthesize lock = _lock;
- @synthesize attributes = _attributes;
- + (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.path = [self objectOrNilForKey:kMOEffectPath fromDictionary:dict];
- self.code = [[self objectOrNilForKey:kMOEffectCode fromDictionary:dict] doubleValue];
- self.source = [self objectOrNilForKey:kMOEffectSource fromDictionary:dict];
- self.name = [self objectOrNilForKey:kMOEffectName fromDictionary:dict];
- self.duration = [[self objectOrNilForKey:kMOEffectDuration fromDictionary:dict] doubleValue];
- self.id = [self objectOrNilForKey:kMOEffectId fromDictionary:dict];
- self.effectType = [[self objectOrNilForKey:kMOEffectEffectType fromDictionary:dict] doubleValue];
-
- self.animation = [[self objectOrNilForKey:kMOEffectAnimation fromDictionary:dict] boolValue];
- self.image = [self objectOrNilForKey:kMOEffectImage fromDictionary:dict];
- self.resFile = [self objectOrNilForKey:kMOEffectResFile fromDictionary:dict];
-
- self.effectFile = [self objectOrNilForKey:kMOEffectEffectFile fromDictionary:dict];
-
- self.lock = [[self objectOrNilForKey:kMOEffectLock fromDictionary:dict] boolValue];
-
- self.attributes = [MOAttributes modelObjectWithDictionary:[dict objectForKey:kMOEffectAttributes]];
- }
-
- return self;
-
- }
- - (NSDictionary *)dictionaryRepresentation {
- NSMutableDictionary *mutableDict = [NSMutableDictionary dictionary];
- [mutableDict setValue:self.path forKey:kMOEffectPath];
- [mutableDict setValue:[NSNumber numberWithDouble:self.code] forKey:kMOEffectCode];
- [mutableDict setValue:self.source forKey:kMOEffectSource];
- [mutableDict setValue:self.name forKey:kMOEffectName];
- [mutableDict setValue:[NSNumber numberWithDouble:self.duration] forKey:kMOEffectDuration];
-
- [mutableDict setValue:self.id forKey:kMOEffectId];
- [mutableDict setValue:[NSNumber numberWithDouble:self.effectType] forKey:kMOEffectEffectType];
-
- [mutableDict setValue:[NSNumber numberWithBool:self.animation] forKey:kMOEffectAnimation];
- [mutableDict setValue:self.image forKey:kMOEffectImage];
- [mutableDict setValue:self.resFile forKey:kMOEffectResFile];
-
- [mutableDict setValue:self.effectFile forKey:kMOEffectEffectFile];
-
- [mutableDict setValue:[NSNumber numberWithBool:self.lock] forKey:kMOEffectLock];
-
- [mutableDict setValue:[self.attributes dictionaryRepresentation] forKey:kMOEffectAttributes];
- 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.path = [aDecoder decodeObjectForKey:kMOEffectPath];
- self.code = [aDecoder decodeDoubleForKey:kMOEffectCode];
- self.source = [aDecoder decodeObjectForKey:kMOEffectSource];
- self.name = [aDecoder decodeObjectForKey:kMOEffectName];
- self.duration = [aDecoder decodeDoubleForKey:kMOEffectDuration];
-
- self.id = [aDecoder decodeObjectForKey:kMOEffectId];
- self.effectType = [aDecoder decodeDoubleForKey:kMOEffectEffectType];
-
- self.animation = [aDecoder decodeBoolForKey:kMOEffectAnimation];
- self.image = [aDecoder decodeObjectForKey:kMOEffectImage];
- self.resFile = [aDecoder decodeObjectForKey:kMOEffectResFile];
-
- self.effectFile = [aDecoder decodeObjectForKey:kMOEffectEffectFile];
-
- self.lock = [aDecoder decodeBoolForKey:kMOEffectLock];
-
- self.attributes = [aDecoder decodeObjectForKey:kMOEffectAttributes];
-
- return self;
- }
- - (void)encodeWithCoder:(NSCoder *)aCoder
- {
- [aCoder encodeObject:_path forKey:kMOEffectPath];
- [aCoder encodeDouble:_code forKey:kMOEffectCode];
- [aCoder encodeObject:_source forKey:kMOEffectSource];
- [aCoder encodeObject:_name forKey:kMOEffectName];
- [aCoder encodeDouble:_duration forKey:kMOEffectDuration];
-
- [aCoder encodeObject:_id forKey:kMOEffectId];
- [aCoder encodeDouble:_effectType forKey:kMOEffectEffectType];
-
- [aCoder encodeBool:_animation forKey:kMOEffectAnimation];
- [aCoder encodeObject:_image forKey:kMOEffectImage];
- [aCoder encodeObject:_resFile forKey:kMOEffectResFile];
-
- [aCoder encodeObject:_effectFile forKey:kMOEffectEffectFile];
-
- [aCoder encodeBool:_lock forKey:kMOEffectLock];
-
- [aCoder encodeObject:_attributes forKey:kMOEffectAttributes];
- }
- - (id)copyWithZone:(NSZone *)zone {
- MOEffect *copy = [[MOEffect alloc] init];
-
-
-
- if (copy) {
- copy.path = [self.path copyWithZone:zone];
- copy.code = self.code;
- copy.source = [self.source copyWithZone:zone];
- copy.name = [self.name copyWithZone:zone];
- copy.duration = self.duration;
-
- copy.id = [self.id copyWithZone:zone];
- copy.effectType = self.effectType;
-
- copy.animation = self.animation;
- copy.image = [self.image copyWithZone:zone];
- copy.resFile = [self.resFile copyWithZone:zone];
-
- copy.effectFile = [self.effectFile copyWithZone:zone];
-
- copy.lock = self.lock;
-
- copy.attributes = [self.attributes copyWithZone:zone];
- }
-
- return copy;
- }
- @end
|