Oolite
Loading...
Searching...
No Matches
OOCheckShipDataPListVerifierStage Class Reference

#include <OOCheckShipDataPListVerifierStage.h>

Inheritance diagram for OOCheckShipDataPListVerifierStage:
Collaboration diagram for OOCheckShipDataPListVerifierStage:

Instance Methods

(NSString *) - name [implementation]
(NSSet *) - dependents [implementation]
(BOOL) - shouldRun [implementation]
(void) - run [implementation]
(void) - verifyShipInfo:withName: [implementation]
(void) - message: [implementation]
(void) - verboseMessage: [implementation]
(void) - getRoles [implementation]
(void) - checkKeys [implementation]
(void) - checkSchema [implementation]
(void) - checkModel [implementation]
(NSSet *) - rolesFromString: [implementation]
(BOOL) - verifier:withPropertyList:named:testProperty:atPath:againstType:error: [implementation]
(BOOL) - verifier:withPropertyList:named:failedForProperty:withError:expectedType: [implementation]
Instance Methods inherited from OOFileHandlingVerifierStage
(NSSet *) - dependencies [implementation]
Instance Methods inherited from OOOXPVerifierStage
(OOOXPVerifier *) - verifier
(BOOL) - completed
(id) - init [implementation]
(void) - dealloc [implementation]
(id) - description [implementation]
(void) - setVerifier: [implementation]
(BOOL) - isDependentOf: [implementation]
(void) - registerDependency: [implementation]
(void) - dependencyRegistrationComplete [implementation]
(BOOL) - canRun [implementation]
(void) - performRun [implementation]
(void) - noteSkipped [implementation]
(NSSet *) - resolvedDependencies [implementation]
(NSSet *) - resolvedDependents [implementation]
(void) - registerDepedent: [implementation]
(void) - dependencyCompleted: [implementation]

Private Attributes

NSDictionary * _shipdataPList
NSSet * _ooliteShipNames
NSSet * _basicKeys
NSSet * _stationKeys
NSSet * _playerKeys
NSSet * _allKeys
OOPListSchemaVerifier * _schemaVerifier
OOAIStateMachineVerifierStage * _aiVerifierStage
NSString * _name
NSDictionary * _info
NSSet * _roles
uint32_t _isStation: 1
uint32_t _isPlayer: 1
uint32_t _isTemplate: 1
uint32_t _havePrintedMessage: 1

Detailed Description

Definition at line 34 of file OOCheckShipDataPListVerifierStage.h.

Method Documentation

◆ checkKeys

- (void) checkKeys
implementation

Provided by category OOCheckShipDataPListVerifierStage(OOPrivate).

Definition at line 249 of file OOCheckShipDataPListVerifierStage.m.

250{
251 NSSet* referenceSet = nil;
252 NSEnumerator* keyEnum = nil;
253 NSString* key = nil;
254
255 if (_isPlayer)
256 referenceSet = _playerKeys;
257 else if (_isStation)
258 referenceSet = _stationKeys;
259 else
260 referenceSet = _basicKeys;
261
262 for (keyEnum = [_info keyEnumerator]; (key = [keyEnum nextObject]);) {
263 if (![referenceSet containsObject:key]) {
264 if ([_allKeys containsObject:key]) {
265 if (!_isTemplate) {
266 // if it's a template, this key might apply to a descendant
267 // as happens in the core files
268 [self message:@"----- WARNING: key \"%@\" does not apply to this category of ship.", key];
269 }
270 } else {
271 [self message:@"----- WARNING: unknown key \"%@\".", key];
272 }
273 }
274 }
275}
return nil

Referenced by OOCheckShipDataPListVerifierStage(OOPrivate)::verifyShipInfo:withName:.

Here is the caller graph for this function:

◆ checkModel

- (void) checkModel
implementation

Provided by category OOCheckShipDataPListVerifierStage(OOPrivate).

Definition at line 282 of file OOCheckShipDataPListVerifierStage.m.

283{
284 id model = nil,
285 materials = nil,
286 shaders = nil;
287
288 model = [_info oo_stringForKey:@"model"];
289 materials = [_info oo_dictionaryForKey:@"materials"];
290 shaders = [_info oo_dictionaryForKey:@"shaders"];
291
292 if (model != nil) {
293 if (![[[self verifier] modelVerifierStage] modelNamed:model
294 usedForEntry:_name
295 inFile:@"shipdata.plist"
296 withMaterials:materials
297 andShaders:shaders]) {
298 [self message:@"----- WARNING: model \"%@\" could not be found in %@ or in Oolite.", model, [[self verifier] oxpDisplayName]];
299 }
300 } else {
301 if ([_info oo_stringForKey:@"like_ship"] == nil) {
302 [self message:@"***** ERROR: ship does not specify model or like_ship."];
303 }
304 }
305}
OOOXPVerifier * verifier()

Referenced by OOCheckShipDataPListVerifierStage(OOPrivate)::verifyShipInfo:withName:.

Here is the caller graph for this function:

◆ checkSchema

- (void) checkSchema
implementation

Provided by category OOCheckShipDataPListVerifierStage(OOPrivate).

Definition at line 277 of file OOCheckShipDataPListVerifierStage.m.

278{
279 [_schemaVerifier verifyPropertyList:_info named:_name];
280}

Referenced by OOCheckShipDataPListVerifierStage(OOPrivate)::verifyShipInfo:withName:.

Here is the caller graph for this function:

◆ dependents

- (NSSet *) dependents
implementation

Reimplemented from OOTextureHandlingStage.

Definition at line 63 of file OOCheckShipDataPListVerifierStage.m.

64{
65 NSMutableSet* result = [[super dependents] mutableCopy];
66 [result addObject:[OOModelVerifierStage nameForReverseDependencyForVerifier:[self verifier]]];
67 [result addObject:[OOAIStateMachineVerifierStage nameForReverseDependencyForVerifier:[self verifier]]];
68 return [result autorelease];
69}
NSString * nameForReverseDependencyForVerifier:(OOOXPVerifier *verifier)
NSString * nameForReverseDependencyForVerifier:(OOOXPVerifier *verifier)

References dependents, OOTextureHandlingStage::dependents, OOAIStateMachineVerifierStage::nameForReverseDependencyForVerifier:, OOModelVerifierStage::nameForReverseDependencyForVerifier:, and OOOXPVerifierStage::verifier.

Referenced by dependents.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getRoles

- (void) getRoles
implementation

Provided by category OOCheckShipDataPListVerifierStage(OOPrivate).

Definition at line 227 of file OOCheckShipDataPListVerifierStage.m.

228{
229 NSString* rolesString = nil;
230
231 rolesString = [_info objectForKey:@"roles"];
232 _roles = [self rolesFromString:rolesString];
233 _isPlayer = [_roles containsObject:@"player"];
234 _isStation = [_info oo_boolForKey:@"is_carrier" defaultValue:NO] ||
235 [_info oo_boolForKey:@"isCarrier"
236 defaultValue:NO]
237 ||
238 [rolesString rangeOfString:@"station"].location != NSNotFound ||
239 [rolesString rangeOfString:@"carrier"].location != NSNotFound;
240 // the is_carrier or isCarrier key will be missed when it was insise a like_ship definition.
241 _isTemplate = [_info oo_boolForKey:@"is_template" defaultValue:NO];
242
243 if (_isPlayer && _isStation) {
244 [self message:@"***** ERROR: ship is both a player ship and a station. Treating as non-station."];
245 _isStation = NO;
246 }
247}

Referenced by OOCheckShipDataPListVerifierStage(OOPrivate)::verifyShipInfo:withName:.

Here is the caller graph for this function:

◆ message:

- (void) message: (NSString*) format
, (...)  
implementation

Provided by category OOCheckShipDataPListVerifierStage(OOPrivate).

Definition at line 194 of file OOCheckShipDataPListVerifierStage.m.

194 :(NSString*)format, ...
195{
196 va_list args;
197
198 if (!_havePrintedMessage) {
199 OOLog(@"verifyOXP.shipData.firstMessage", @"Ship \"%@\":", _name);
200 OOLogIndent();
202 }
203
204 va_start(args, format);
205 OOLogWithFunctionFileAndLineAndArguments(@"verifyOXP.shipData", NULL, NULL, 0, format, args);
206 va_end(args);
207}
void void void OOLogWithFunctionFileAndLineAndArguments(NSString *inMessageClass, const char *inFunction, const char *inFile, unsigned long inLine, NSString *inFormat, va_list inArguments) OO_TAKES_FORMAT_STRING(5
#define OOLog(class, format,...)
Definition OOLogging.h:84
void OOLogIndent(void)
Definition OOLogging.m:345

Referenced by OOCheckShipDataPListVerifierStage(OOPrivate)::checkKeys, OOCheckShipDataPListVerifierStage(OOPrivate)::checkModel, OOCheckShipDataPListVerifierStage(OOPrivate)::getRoles, and OOCheckShipDataPListVerifierStage(OOPrivate)::verifier:withPropertyList:named:failedForProperty:withError:expectedType:.

Here is the caller graph for this function:

◆ name

- (NSString *) name
implementation

Reimplemented from OOOXPVerifierStage.

Definition at line 58 of file OOCheckShipDataPListVerifierStage.m.

59{
60 return kStageName;
61}
static NSString *const kStageName

References kStageName, and name.

Referenced by name.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ rolesFromString:

- (NSSet *) rolesFromString: (NSString*) string
implementation

Provided by category OOCheckShipDataPListVerifierStage(OOPrivate).

Definition at line 308 of file OOCheckShipDataPListVerifierStage.m.

308 :(NSString*)string
309{
310 NSArray* parts = nil;
311 NSMutableSet* result = nil;
312 NSUInteger i, count;
313 NSString* role = nil;
314 NSRange parenRange;
315
316 if (string == nil)
317 return [NSSet set];
318
319 parts = ScanTokensFromString(string);
320 count = [parts count];
321 if (count == 0)
322 return [NSSet set];
323
324 result = [NSMutableSet setWithCapacity:count];
325 for (i = 0; i != count; ++i) {
326 role = [parts objectAtIndex:i];
327 parenRange = [role rangeOfString:@"("];
328 if (parenRange.location != NSNotFound) {
329 role = [role substringToIndex:parenRange.location];
330 }
331 [result addObject:role];
332 }
333
334 return result;
335}
unsigned count
NSMutableArray * ScanTokensFromString(NSString *values)

Referenced by OOCheckShipDataPListVerifierStage(OOPrivate)::getRoles.

Here is the caller graph for this function:

◆ run

- (void) run
implementation

Reimplemented from OOOXPVerifierStage.

Definition at line 82 of file OOCheckShipDataPListVerifierStage.m.

83{
84 OOFileScannerVerifierStage* fileScanner = nil;
85 NSAutoreleasePool* pool = nil;
86 NSEnumerator* shipEnum = nil;
87 NSString* shipKey = nil;
88 NSDictionary* shipInfo = nil;
89 NSDictionary* ooliteShipData = nil;
90 NSDictionary* settings = nil;
91 NSMutableSet* mergeSet = nil;
92 NSArray* shipList = nil;
93
94 fileScanner = [[self verifier] fileScannerStage];
95 _shipdataPList = [fileScanner plistNamed:@"shipdata.plist"
96 inFolder:@"Config"
98 checkBuiltIn:NO];
99
100 if (_shipdataPList == nil)
101 return;
102
103 // Get AI verifier stage (may be nil).
104 _aiVerifierStage = [[self verifier] stageWithName:[OOAIStateMachineVerifierStage nameForReverseDependencyForVerifier:[self verifier]]];
105
106 ooliteShipData = [ResourceManager dictionaryFromFilesNamed:@"shipdata.plist"
107 inFolder:@"Config"
108 andMerge:YES];
109
110 // Check that it's a dictionary
111 if (![_shipdataPList isKindOfClass:[NSDictionary class]]) {
112 OOLog(@"verifyOXP.shipdataPList.notDict", @"%@", @"***** ERROR: shipdata.plist is not a dictionary.");
113 return;
114 }
115
116 // Keys that apply to all ships
117 _ooliteShipNames = [NSSet setWithArray:[ooliteShipData allKeys]];
118 settings = [[self verifier] configurationDictionaryForKey:@"shipdataPListSettings"];
119 _basicKeys = [settings oo_setForKey:@"knownShipKeys"];
120
121 // Keys that apply to stations/carriers
122 mergeSet = [_basicKeys mutableCopy];
123 [mergeSet addObjectsFromArray:[settings oo_arrayForKey:@"knownStationKeys"]];
124 _stationKeys = mergeSet;
125
126 // Keys that apply to player ships
127 mergeSet = [_basicKeys mutableCopy];
128 [mergeSet addObjectsFromArray:[settings oo_arrayForKey:@"knownPlayerKeys"]];
129 _playerKeys = [[mergeSet copy] autorelease];
130
131 // Keys that apply to _any_ ship -- union of the above
132 [mergeSet unionSet:_stationKeys];
133 _allKeys = mergeSet;
134
136 [_schemaVerifier setDelegate:self];
137
138 shipList = [[_shipdataPList allKeys] sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)];
139 for (shipEnum = [shipList objectEnumerator]; (shipKey = [shipEnum nextObject]);) {
140 pool = [[NSAutoreleasePool alloc] init];
141
142 shipInfo = [_shipdataPList oo_dictionaryForKey:shipKey];
143 if (shipInfo == nil) {
144 OOLog(@"verifyOXP.shipdata.badType", @"***** ERROR: shipdata.plist entry for \"%@\" is not a dictionary.", shipKey);
145 } else {
146 [self verifyShipInfo:shipInfo withName:shipKey];
147 }
148
149 [pool release];
150 }
151
154 _basicKeys = nil;
157}
id plistNamed:inFolder:referencedFrom:checkBuiltIn:(NSString *file,[inFolder] NSString *folder,[referencedFrom] NSString *context,[checkBuiltIn] BOOL checkBuiltIn)
instancetype verifierWithSchema:(NSDictionary *schema)
NSDictionary * dictionaryFromFilesNamed:inFolder:andMerge:(NSString *fileName,[inFolder] NSString *folderName,[andMerge] BOOL mergeFiles)

References _aiVerifierStage, _allKeys, _basicKeys, _ooliteShipNames, _playerKeys, _schemaVerifier, _shipdataPList, _stationKeys, OOOXPVerifier::configurationDictionaryForKey:, ResourceManager::dictionaryFromFilesNamed:inFolder:andMerge:, OOOXPVerifier::fileScannerStage, OOAIStateMachineVerifierStage::nameForReverseDependencyForVerifier:, nil, OOLog, OOFileScannerVerifierStage::plistNamed:inFolder:referencedFrom:checkBuiltIn:, run, OOPListSchemaVerifier::setDelegate:, OOOXPVerifier::stageWithName:, OOOXPVerifierStage::verifier, OOPListSchemaVerifier::verifierWithSchema:, and verifyShipInfo:withName:.

Referenced by run.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ shouldRun

- (BOOL) shouldRun
implementation

Reimplemented from OOOXPVerifierStage.

Definition at line 71 of file OOCheckShipDataPListVerifierStage.m.

72{
73 OOFileScannerVerifierStage* fileScanner = nil;
74
75 fileScanner = [[self verifier] fileScannerStage];
76 return [fileScanner fileExists:@"shipdata.plist"
77 inFolder:@"Config"
79 checkBuiltIn:NO];
80}
BOOL fileExists:inFolder:referencedFrom:checkBuiltIn:(NSString *file,[inFolder] NSString *folder,[referencedFrom] NSString *context,[checkBuiltIn] BOOL checkBuiltIn)

References OOFileScannerVerifierStage::fileExists:inFolder:referencedFrom:checkBuiltIn:, OOOXPVerifier::fileScannerStage, nil, shouldRun, and OOOXPVerifierStage::verifier.

Referenced by shouldRun.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ verboseMessage:

- (void) verboseMessage: (NSString*) format
, (...)  
implementation

Provided by category OOCheckShipDataPListVerifierStage(OOPrivate).

Definition at line 209 of file OOCheckShipDataPListVerifierStage.m.

209 :(NSString*)format, ...
210{
211 va_list args;
212
213 if (!OOLogWillDisplayMessagesInClass(@"verifyOXP.verbose.shipData"))
214 return;
215
216 if (!_havePrintedMessage) {
217 OOLog(@"verifyOXP.shipData.firstMessage", @"Ship \"%@\":", _name);
218 OOLogIndent();
220 }
221
222 va_start(args, format);
223 OOLogWithFunctionFileAndLineAndArguments(@"verifyOXP.verbose.shipData", NULL, NULL, 0, format, args);
224 va_end(args);
225}
BOOL OOLogWillDisplayMessagesInClass(NSString *inMessageClass)
Definition OOLogging.m:136

Referenced by OOCheckShipDataPListVerifierStage(OOPrivate)::verifier:withPropertyList:named:testProperty:atPath:againstType:error:.

Here is the caller graph for this function:

◆ verifier:withPropertyList:named:failedForProperty:withError:expectedType:

- (BOOL) verifier: (OOPListSchemaVerifier*) verifier
withPropertyList: (id) rootPList
named: (NSString*) name
failedForProperty: (id) subPList
withError: (NSError*) error
expectedType: (NSDictionary*) localSchema 
implementation

Provided by category OOCheckShipDataPListVerifierStage(OOPrivate).

Definition at line 349 of file OOCheckShipDataPListVerifierStage.m.

349 :(OOPListSchemaVerifier*)verifier
350 withPropertyList:(id)rootPList
351 named:(NSString*)name
352 failedForProperty:(id)subPList
353 withError:(NSError*)error
354 expectedType:(NSDictionary*)localSchema
355{
356 // FIXME: use fancy new error codes to provide useful error descriptions.
357 [self message:@"***** ERROR: verification of ship \"%@\" failed at \"%@\": %@", name, [error plistKeyPathDescription], [error localizedFailureReason]];
358 return YES;
359}

◆ verifier:withPropertyList:named:testProperty:atPath:againstType:error:

- (BOOL) verifier: (OOPListSchemaVerifier*) verifier
withPropertyList: (id) rootPList
named: (NSString*) name
testProperty: (id) subPList
atPath: (NSArray*) keyPath
againstType: (NSString*) typeKey
error: (NSError**) outError 
implementation

Provided by category OOCheckShipDataPListVerifierStage(OOPrivate).

Definition at line 337 of file OOCheckShipDataPListVerifierStage.m.

337 :(OOPListSchemaVerifier*)verifier
338 withPropertyList:(id)rootPList
339 named:(NSString*)name
340 testProperty:(id)subPList
341 atPath:(NSArray*)keyPath
342 againstType:(NSString*)typeKey
343 error:(NSError**)outError
344{
345 [self verboseMessage:@"- Skipping verification for type %@ at %@.%@.", typeKey, _name, [OOPListSchemaVerifier descriptionForKeyPath:keyPath]];
346 return YES;
347}
NSString * descriptionForKeyPath:(NSArray *keyPath)

◆ verifyShipInfo:withName:

- (void) verifyShipInfo: (NSDictionary*) info
withName: (NSString*) name 
implementation

Provided by category OOCheckShipDataPListVerifierStage(OOPrivate).

Definition at line 163 of file OOCheckShipDataPListVerifierStage.m.

163 :(NSDictionary*)info withName:(NSString*)name
164{
165 _name = name;
166 _info = info;
169
170 [self getRoles];
171 [self checkKeys];
172 [self checkSchema];
173 [self checkModel];
174
175 NSString* aiName = [info oo_stringForKey:@"ai_type"];
176 if (aiName != nil) {
177 if (![aiName hasSuffix:@".js"]) {
178 [_aiVerifierStage stateMachineNamed:aiName usedByShip:name];
179 }
180 }
181
182 // Todo: check for pirates with 0 bounty
183
185 if (!_havePrintedMessage) {
186 OOLog(@"verifyOXP.verbose.shipData.OK", @"- ship \"%@\" OK.", _name);
187 }
188 _name = nil;
189 _info = nil;
190 _roles = nil;
191}
void OOLogPushIndent(void)
Definition OOLogging.m:301
void OOLogPopIndent(void)
Definition OOLogging.m:323

Referenced by run.

Here is the caller graph for this function:

Member Data Documentation

◆ _aiVerifierStage

- (OOAIStateMachineVerifierStage*) _aiVerifierStage
private

Definition at line 43 of file OOCheckShipDataPListVerifierStage.h.

Referenced by run.

◆ _allKeys

- (NSSet *) _allKeys
private

Definition at line 41 of file OOCheckShipDataPListVerifierStage.h.

Referenced by run.

◆ _basicKeys

- (NSSet*) _basicKeys
private

Definition at line 38 of file OOCheckShipDataPListVerifierStage.h.

Referenced by run.

◆ _havePrintedMessage

- (uint32_t) _havePrintedMessage
private

Definition at line 52 of file OOCheckShipDataPListVerifierStage.h.

◆ _info

- (NSDictionary*) _info
private

Definition at line 47 of file OOCheckShipDataPListVerifierStage.h.

◆ _isPlayer

- (uint32_t) _isPlayer
private

Definition at line 50 of file OOCheckShipDataPListVerifierStage.h.

◆ _isStation

- (uint32_t) _isStation
private

Definition at line 49 of file OOCheckShipDataPListVerifierStage.h.

◆ _isTemplate

- (uint32_t) _isTemplate
private

Definition at line 51 of file OOCheckShipDataPListVerifierStage.h.

◆ _name

- (NSString*) _name
private

Definition at line 46 of file OOCheckShipDataPListVerifierStage.h.

◆ _ooliteShipNames

- (NSSet*) _ooliteShipNames
private

Definition at line 37 of file OOCheckShipDataPListVerifierStage.h.

Referenced by run.

◆ _playerKeys

- (NSSet *) _playerKeys
private

Definition at line 40 of file OOCheckShipDataPListVerifierStage.h.

Referenced by run.

◆ _roles

- (NSSet*) _roles
private

Definition at line 48 of file OOCheckShipDataPListVerifierStage.h.

◆ _schemaVerifier

- (OOPListSchemaVerifier*) _schemaVerifier
private

Definition at line 42 of file OOCheckShipDataPListVerifierStage.h.

Referenced by run.

◆ _shipdataPList

- (NSDictionary*) _shipdataPList
private

Definition at line 36 of file OOCheckShipDataPListVerifierStage.h.

Referenced by run.

◆ _stationKeys

- (NSSet *) _stationKeys
private

Definition at line 39 of file OOCheckShipDataPListVerifierStage.h.

Referenced by run.


The documentation for this class was generated from the following files: