Oolite 1.91.0.7645-241119-222d325
Loading...
Searching...
No Matches
OOEntityInspectorExtensions.m
Go to the documentation of this file.
1/*
2
3OOEntityInspectorExtensions.m
4
5
6Oolite Debug Bundle
7
8Copyright © 2007-2013 Jens Ayton
9
10Permission is hereby granted, free of charge, to any person obtaining a copy
11of this software and associated documentation files (the “Software”), to deal
12in the Software without restriction, including without limitation the rights
13to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14copies of the Software, and to permit persons to whom the Software is
15furnished to do so, subject to the following conditions:
16
17The above copyright notice and this permission notice shall be included in all
18copies or substantial portions of the Software.
19
20THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26SOFTWARE.
27
28*/
29
31#import "OOConstToString.h"
32#import "PlayerEntity.h"
33#import "OODebugInspector.h"
34
35
36@implementation NSObject (OOInspectorExtensions)
37
38- (NSString *) inspDescription
39{
40 NSString *desc = [self shortDescriptionComponents];
41 if (desc == nil) return [self className];
42 else return [NSString stringWithFormat:@"%@ %@", [self className], desc];
43}
44
45
46- (NSString *) inspBasicIdentityLine
47{
48 return [self inspDescription];
49}
50
51
53{
54 return NO;
55}
56
57
58- (NSString *) inspSecondaryIdentityLine
59{
60 return nil;
61}
62
64{
65 return NO;
66}
67
68
69- (void) inspBecomeTarget
70{
71
72}
73
74
75// Callable via JS Entity.inspect()
76- (void) inspect
77{
78 if ([self conformsToProtocol:@protocol(OOWeakReferenceSupport)])
79 {
80 [[OODebugInspector inspectorForObject:(id <OOWeakReferenceSupport>)self] bringToFront];
81 }
82}
83
84@end
85
86
87@implementation Entity (OOEntityInspectorExtensions)
88
89- (NSString *) inspDescription
90{
91 return [NSString stringWithFormat:@"%@ ID %u", [self class], [self universalID]];
92}
93
94
95- (NSString *) inspBasicIdentityLine
96{
97 OOUniversalID myID = [self universalID];
98
99 if (myID != NO_TARGET)
100 {
101 return [NSString stringWithFormat:@"%@ ID %u", [self class], myID];
102 }
103 else
104 {
105 return [self className];
106 }
107}
108
109
110- (NSString *) inspScanClassLine
111{
112 return OOStringFromScanClass([self scanClass]);
113}
114
115
116- (NSString *) inspStatusLine
117{
118 return OOStringFromEntityStatus([self status]);
119}
120
121
122- (NSString *) inspRetainCountLine
123{
124 return [NSString stringWithFormat:@"%lu", [self retainCount]];
125}
126
127
128- (NSString *) inspPositionLine
129{
130 HPVector v = [self position];
131 return [NSString stringWithFormat:@"%.0f, %.0f, %.0f", v.x, v.y, v.z];
132}
133
134
135- (NSString *) inspVelocityLine
136{
137 Vector v = [self velocity];
138 return [NSString stringWithFormat:@"%.1f, %.1f, %.1f (%.1f)", v.x, v.y, v.z, magnitude(v)];
139}
140
141
142- (NSString *) inspOrientationLine
143{
144 Quaternion q = [self orientation];
145 return [NSString stringWithFormat:@"%.3f (%.3f, %.3f, %.3f)", q.w, q.x, q.y, q.z];
146}
147
148
149- (NSString *) inspEnergyLine
150{
151 return [NSString stringWithFormat:@"%i/%i", (int)[self energy], (int)[self maxEnergy]];
152}
153
154
155- (NSString *) inspOwnerLine
156{
157 if ([self owner] == self) return @"Self";
158 return [[self owner] inspDescription];
159}
160
161
162- (NSString *) inspTargetLine
163{
164 return nil;
165}
166
167@end
168
169
170@implementation ShipEntity (OOEntityInspectorExtensions)
171
172- (BOOL) inspHasSecondaryIdentityLine
173{
174 return YES;
175}
176
177
178- (NSString *) inspSecondaryIdentityLine
179{
180 return [self displayName];
181}
182
183
184- (NSString *) inspDescription
185{
186 return [NSString stringWithFormat:@"%@ ID %u", [self displayName], [self universalID]];
187}
188
189
190- (NSString *) inspTargetLine
191{
192 return [[self primaryTarget] inspDescription];
193}
194
195
196- (BOOL) inspCanBecomeTarget
197{
198 return ![self isSubEntity];
199}
200
201
202- (void) inspBecomeTarget
203{
204 if ([self inspCanBecomeTarget]) [[PlayerEntity sharedPlayer] addTarget:self];
205}
206
207@end
208
209
210@implementation PlayerEntity (OOEntityInspectorExtensions)
211
212- (NSString *) inspSecondaryIdentityLine
213{
214 return [NSString stringWithFormat:NSLocalizedStringFromTableInBundle(@"\"%@\", %@", nil, [NSBundle bundleForClass:[self class]], @""), [self commanderName], [self displayName]];
215}
216
217
218- (BOOL) inspCanBecomeTarget
219{
220 return NO;
221}
222
223
224- (NSString *) inspDescription
225{
226 return @"Player";
227}
228
229@end
NSString * OOStringFromScanClass(OOScanClass scanClass) CONST_FUNC
NSString * OOStringFromEntityStatus(OOEntityStatus status) CONST_FUNC
return nil
uint16_t OOUniversalID
Definition OOTypes.h:189
@ NO_TARGET
Definition OOTypes.h:194
id inspectorForObject:(id< OOWeakReferenceSupport > object)
NSString * commanderName()
void addTarget:(Entity *targetEntity)
PlayerEntity * sharedPlayer()
NSString * displayName
Definition ShipEntity.h:330