-
Notifications
You must be signed in to change notification settings - Fork 8
/
BFScene.m
64 lines (50 loc) · 1.68 KB
/
BFScene.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
//
// BFScene.m
// Briefs
//
// Created by Rob Rhyne on 7/17/09.
// Copyright Digital Arch Design, 2009. See LICENSE file for details.
//
#import "BFScene.h"
#import "BFActor.h"
@implementation BFScene
@synthesize bg, actors, name;
- (id)init:(NSString*)nameOfScene withDictionary:(NSDictionary*)dict
{
if (self = [super init]) {
self.bg = [dict valueForKey:@"img"];
self.name = nameOfScene;
// Load actors
NSArray *actor_dicts = [dict valueForKey:@"actors"];
NSMutableArray *actors_tree = [NSMutableArray arrayWithCapacity:[actor_dicts count]];
for (NSDictionary *dictionary in actor_dicts) {
BFActor *actor = [[[BFActor alloc] init:[dictionary valueForKey:@"name"] withDictionary:dictionary] autorelease];
[actors_tree addObject:actor];
}
self.actors = actors_tree;
}
return self;
}
- (void)dealloc
{
[name release];
[actors release];
[bg release];
[super dealloc];
}
- (NSDictionary *)copyAsDictionary
{
NSArray *keys = [NSArray arrayWithObjects:@"img", @"name", @"actors", nil];
// Serialize actors
NSMutableArray *serializedActors = [NSMutableArray arrayWithCapacity:[[self actors] count]];
for (BFActor *actor in [self actors]) {
NSDictionary *actorAsDictionary = [actor copyAsDictionary];
[serializedActors addObject:actorAsDictionary];
//[actor release];
[actorAsDictionary release];
}
NSArray *values = [NSArray arrayWithObjects:[self bg], [self name], serializedActors, nil];
NSDictionary *dict = [[NSDictionary dictionaryWithObjects:values forKeys:keys] retain];
return dict;
}
@end