-
Notifications
You must be signed in to change notification settings - Fork 8
/
BFSceneManager.m
92 lines (73 loc) · 2.09 KB
/
BFSceneManager.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
//
// BFSceneManager.m
// Briefs
//
// Created by Rob Rhyne on 7/17/09.
// Copyright Digital Arch Design, 2009. See LICENSE file for details.
//
#import "BFSceneManager.h"
@implementation BFSceneManager
@synthesize source, scene_graph, scene_desc;
///////////////////////////////////////////////////////////////////////////////
#pragma mark -
#pragma mark NSObject overrides
- (id)initWithPathToDictionary:(NSString*)path
{
NSDictionary *dict = [NSDictionary dictionaryWithContentsOfFile: path];
return [self initWithDictionary:dict];
}
- (id)initWithDictionary:(NSDictionary *)dict
{
if (self = [super init]) {
NSArray *scenes = [dict valueForKey:@"scenes"];
openingScene = [[dict valueForKey:@"start_scene"] intValue];
self.source = dict;
self.scene_desc = scenes;
currentIndex = openingScene;
NSMutableArray *graph = [NSMutableArray arrayWithCapacity:[self.scene_desc count]];
for (NSDictionary *dictionary in scenes) {
BFScene *scene = [[BFScene alloc] init:[dictionary valueForKey:@"name"] withDictionary:dictionary];
[graph addObject:scene];
[scene release];
}
self.scene_graph = graph;
// memory cleanup
[scenes release];
}
return self;
}
- (void)dealloc
{
[scene_graph release];
[scene_desc release];
[super dealloc];
}
///////////////////////////////////////////////////////////////////////////////
#pragma mark -
#pragma mark Scene Management
- (int)totalNumberOfScenes
{
return [self.scene_desc count];
}
- (BFScene *)openingScene
{
return [self sceneByNumber:openingScene];
}
- (BFScene *)currentScene
{
return [self sceneByNumber:currentIndex];
}
- (BFScene *)sceneByNumber:(int)index
{
currentIndex = index;
BFScene *scene = [self.scene_graph objectAtIndex:index];
if ([self.scene_graph count] >= index || scene != nil) {
return scene;
}
return nil;
}
- (NSDictionary *)copyOfSource:(BOOL)asCompacted withWorkingDirectory:(NSString *)directory
{
return nil;
}
@end