blob: 7d360a9241d5238ddfdd431007152e206a358e0f (
plain)
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
|
// SDLAddCommand.m
//
#import "SDLAddCommand.h"
#import "SDLImage.h"
#import "SDLMenuParams.h"
#import "SDLNames.h"
@implementation SDLAddCommand
- (instancetype)init {
if (self = [super initWithName:SDLNameAddCommand]) {
}
return self;
}
- (instancetype)initWithHandler:(SDLRPCNotificationHandler)handler {
self = [self init];
if (!self) {
return nil;
}
_handler = handler;
return self;
}
- (instancetype)initWithId:(UInt32)commandId vrCommands:(NSArray<NSString *> *)vrCommands handler:(SDLRPCNotificationHandler)handler {
return [self initWithId:commandId vrCommands:vrCommands menuName:nil handler:handler];
}
- (instancetype)initWithId:(UInt32)commandId vrCommands:(NSArray<NSString *> *)vrCommands menuName:(NSString *)menuName handler:(SDLRPCNotificationHandler)handler {
self = [self init];
if (!self) {
return nil;
}
self.cmdID = @(commandId);
if (menuName != nil) {
self.menuParams = [[SDLMenuParams alloc] initWithMenuName:menuName];
}
self.vrCommands = [vrCommands mutableCopy];
self.handler = handler;
return self;
}
- (instancetype)initWithId:(UInt32)commandId vrCommands:(NSArray<NSString *> *)vrCommands menuName:(NSString *)menuName parentId:(UInt32)parentId position:(UInt16)position iconValue:(NSString *)iconValue iconType:(SDLImageType)iconType handler:(SDLRPCNotificationHandler)handler {
self = [self initWithId:commandId vrCommands:vrCommands menuName:menuName handler:handler];
if (!self) {
return nil;
}
self.menuParams.parentID = @(parentId);
self.menuParams.position = @(position);
if (iconValue != nil && iconType != nil) {
self.cmdIcon = [[SDLImage alloc] initWithName:iconValue ofType:iconType];
}
return self;
}
- (void)setCmdID:(NSNumber<SDLInt> *)cmdID {
if (cmdID != nil) {
[parameters setObject:cmdID forKey:SDLNameCommandId];
} else {
[parameters removeObjectForKey:SDLNameCommandId];
}
}
- (NSNumber<SDLInt> *)cmdID {
return [parameters objectForKey:SDLNameCommandId];
}
- (void)setMenuParams:(SDLMenuParams *)menuParams {
if (menuParams != nil) {
[parameters setObject:menuParams forKey:SDLNameMenuParams];
} else {
[parameters removeObjectForKey:SDLNameMenuParams];
}
}
- (SDLMenuParams *)menuParams {
NSObject *obj = [parameters objectForKey:SDLNameMenuParams];
if (obj == nil || [obj isKindOfClass:SDLMenuParams.class]) {
return (SDLMenuParams *)obj;
} else {
return [[SDLMenuParams alloc] initWithDictionary:(NSDictionary *)obj];
}
}
- (void)setVrCommands:(NSMutableArray<NSString *> *)vrCommands {
if (vrCommands != nil) {
[parameters setObject:vrCommands forKey:SDLNameVRCommands];
} else {
[parameters removeObjectForKey:SDLNameVRCommands];
}
}
- (NSMutableArray<NSString *> *)vrCommands {
return [parameters objectForKey:SDLNameVRCommands];
}
- (void)setCmdIcon:(SDLImage *)cmdIcon {
if (cmdIcon != nil) {
[parameters setObject:cmdIcon forKey:SDLNameCommandIcon];
} else {
[parameters removeObjectForKey:SDLNameCommandIcon];
}
}
- (SDLImage *)cmdIcon {
NSObject *obj = [parameters objectForKey:SDLNameCommandIcon];
if (obj == nil || [obj isKindOfClass:SDLImage.class]) {
return (SDLImage *)obj;
} else {
return [[SDLImage alloc] initWithDictionary:(NSDictionary *)obj];
}
}
@end
|