This repository was archived by the owner on Aug 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCCGroupNode.m
More file actions
89 lines (68 loc) · 1.49 KB
/
CCGroupNode.m
File metadata and controls
89 lines (68 loc) · 1.49 KB
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
//
// CCGroupNode.m
// Violet
//
#import "CCGroupNode.h"
#import "CCItemNode.h"
#import "AppDelegate.h"
@implementation CCGroupNode
@dynamic isExpanded;
@dynamic isSpecialGroup;
@dynamic children;
+ (CCGroupNode*)groupNode
{
return [NSEntityDescription insertNewObjectForEntityForName:@"GroupNode" inManagedObjectContext:[AppDelegate defaultManagedObjectContext]];
}
- (void)addChild:(CCNode *)child
{
[self addChild:child atIndex:[[self children] count]];
}
- (void)addChild:(CCNode *)child atIndex:(NSInteger)index
{
[child setParent:self];
NSArray *children = [[self children] sortedArrayUsingDescriptors:[NSArray arrayWithObject:[[[NSSortDescriptor alloc] initWithKey:@"sortIndex" ascending:YES] autorelease]]];
if(index < 1)
{
[child setSortIndex:[NSNumber numberWithInt:0]];
}
else if(index >= [children count])
{
[child setSortIndex:[NSNumber numberWithInteger:[[[children lastObject] sortIndex] integerValue]+1]];
}
else {
[child setSortIndex:[NSNumber numberWithInteger:[[[children objectAtIndex:index-1] sortIndex] integerValue]+1]];
}
[[self children] addObject:child];
}
- (BOOL)isAncestorOfNode:(CCNode *)node
{
CCNode *parent = self;
BOOL isAncestor = NO;
while (parent)
{
if([parent isEqualTo:node])
{
isAncestor = YES;
break;
}
parent = [parent parent];
}
return isAncestor;
}
- (BOOL)isLeaf
{
return NO;
}
- (BOOL)isDeviceNode
{
return NO;
}
- (BOOL)isGroupNode
{
return YES;
}
- (BOOL)isItemNode
{
return NO;
}
@end