Checked in tools/sysdesc_key_table.plist, translation table for --export-sysdesc and --compile-sysdesc. Changed SystemDescription.dot to perform symbolic name substitution in strings when sysdesc_key_table.plist is present.

git-svn-id: http://svn.berlios.de/svnroot/repos/oolite-linux/trunk@1909 127b21dd-08f5-0310-b4b7-95ae10353056
master
Jens Ayton 2008-12-14 18:46:24 +00:00
parent a00a7f495c
commit 4b131c9a32
4 changed files with 103 additions and 31 deletions

View File

@ -17,7 +17,10 @@
NSArray *OOConvertSystemDescriptionsToArrayFormat(NSDictionary *descriptionsInDictionaryFormat, NSDictionary *indicesToKeys);
NSDictionary *OOConvertSystemDescriptionsToDictionaryFormat(NSArray *descriptionsInArrayFormat, NSDictionary *indicesToKeys);
NSString *OOStringifySystemDescriptionLine(NSString *line, NSDictionary *indicesToKeys, BOOL useFallback);
// Higher-level functions to drive the entire conversion.
void CompileSystemDescriptions(BOOL asXML);
void ExportSystemDescriptions(BOOL asXML);

View File

@ -15,7 +15,7 @@
static NSMutableDictionary *InitKeyToIndexDict(NSDictionary *dict, NSMutableSet **outUsedIndices);
static NSString *IndexToKey(OOUInteger index, NSDictionary *indicesToKeys);
static NSString *IndexToKey(OOUInteger index, NSDictionary *indicesToKeys, BOOL useFallback);
static NSArray *ConvertIndicesToKeys(NSArray *entry, NSDictionary *indicesToKeys);
static NSNumber *KeyToIndex(NSString *key, NSMutableDictionary *ioKeysToIndices, NSMutableSet *ioUsedIndicies, OOUInteger *ioSlotCache);
static NSArray *ConvertKeysToIndices(NSArray *entry, NSMutableDictionary *ioKeysToIndices, NSMutableSet *ioUsedIndicies, OOUInteger *ioSlotCache);
@ -190,7 +190,7 @@ NSDictionary *OOConvertSystemDescriptionsToDictionaryFormat(NSArray *description
for (entryEnum = [descriptionsInArrayFormat objectEnumerator]; (entry = [entryEnum nextObject]); )
{
entry = ConvertIndicesToKeys(entry, indicesToKeys);
key = IndexToKey(i, indicesToKeys);
key = IndexToKey(i, indicesToKeys, YES);
++i;
[result setObject:entry forKey:key];
@ -201,6 +201,42 @@ NSDictionary *OOConvertSystemDescriptionsToDictionaryFormat(NSArray *description
}
NSString *OOStringifySystemDescriptionLine(NSString *line, NSDictionary *indicesToKeys, BOOL useFallback)
{
OOUInteger p1, p2;
NSRange searchRange;
NSString *before = nil, *after = nil, *middle = nil;
NSString *key = nil;
searchRange.location = 0;
searchRange.length = [line length];
while ([line rangeOfString:@"[" options:NSLiteralSearch range:searchRange].location != NSNotFound)
{
p1 = [line rangeOfString:@"[" options:NSLiteralSearch range:searchRange].location;
p2 = [line rangeOfString:@"]" options:NSLiteralSearch range:searchRange].location + 1;
before = [line substringWithRange:NSMakeRange(0, p1)];
after = [line substringWithRange:NSMakeRange(p2,[line length] - p2)];
middle = [line substringWithRange:NSMakeRange(p1 + 1 , p2 - p1 - 2)];
if ([[middle stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"0123456789"]] isEqual:@""] && ![middle isEqual:@""])
{
// Found [] around integers only
key = IndexToKey([middle intValue], indicesToKeys, useFallback);
if (key != nil)
{
line = [NSString stringWithFormat:@"%@[#%@]%@", before, key, after];
}
}
searchRange.length -= p2 - searchRange.location;
searchRange.location = [line length] - searchRange.length;
}
return line;
}
static NSMutableDictionary *InitKeyToIndexDict(NSDictionary *dict, NSMutableSet **outUsedIndices)
{
NSEnumerator *keyEnum = nil;
@ -227,10 +263,10 @@ static NSMutableDictionary *InitKeyToIndexDict(NSDictionary *dict, NSMutableSet
}
static NSString *IndexToKey(OOUInteger index, NSDictionary *indicesToKeys)
static NSString *IndexToKey(OOUInteger index, NSDictionary *indicesToKeys, BOOL useFallback)
{
NSString *result = [indicesToKeys objectForKey:[NSString stringWithFormat:@"%u", index]];
if (result == nil) result = [NSString stringWithFormat:@"block_%u", index];
if (result == nil && useFallback) result = [NSString stringWithFormat:@"block_%u", index];
return result;
}
@ -240,38 +276,13 @@ static NSArray *ConvertIndicesToKeys(NSArray *entry, NSDictionary *indicesToKeys
{
NSEnumerator *lineEnum = nil;
NSString *line = nil;
OOUInteger p1, p2;
NSRange searchRange;
NSMutableArray *result = nil;
NSString *before = nil, *after = nil, *middle = nil;
result = [NSMutableArray arrayWithCapacity:[entry count]];
for (lineEnum = [entry objectEnumerator]; (line = [lineEnum nextObject]); )
{
searchRange.location = 0;
searchRange.length = [line length];
while ([line rangeOfString:@"[" options:NSLiteralSearch range:searchRange].location != NSNotFound)
{
p1 = [line rangeOfString:@"[" options:NSLiteralSearch range:searchRange].location;
p2 = [line rangeOfString:@"]" options:NSLiteralSearch range:searchRange].location + 1;
before = [line substringWithRange:NSMakeRange(0, p1)];
after = [line substringWithRange:NSMakeRange(p2,[line length] - p2)];
middle = [line substringWithRange:NSMakeRange(p1 + 1 , p2 - p1 - 2)];
if ([[middle stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"0123456789"]] isEqual:@""] && ![middle isEqual:@""])
{
// Found [] around integers only
line = [NSString stringWithFormat:@"%@[#%@]%@", before, IndexToKey([middle intValue], indicesToKeys), after];
}
searchRange.length -= p2 - searchRange.location;
searchRange.location = [line length] - searchRange.length;
}
[result addObject:line];
[result addObject:OOStringifySystemDescriptionLine(line, indicesToKeys, YES)];
}
return result;

View File

@ -8221,7 +8221,8 @@ static OOComparisonResult comparePrice(id dict1, id dict2, void * context)
subCount = [thisDesc count];
for (j = 0; j < subCount; ++j)
{
[graphViz appendFormat:@"\t\tn%u_%u [label=\"\\\"%@\\\"\"]\n", i, j, EscapedGraphVizString([thisDesc stringAtIndex:j])];
label = OOStringifySystemDescriptionLine([thisDesc stringAtIndex:j], keyMap, NO);
[graphViz appendFormat:@"\t\tn%u_%u [label=\"\\\"%@\\\"\"]\n", i, j, EscapedGraphVizString(label)];
}
[graphViz appendString:@"\t}\n"];

View File

@ -0,0 +1,57 @@
{
/* Keys beginning with tharg_ are used directly by thargoid_curses, but many are also
used by system description blocks.
Note that thargoid_curses also uses some weird combinations, like
[tharg_creature_noun_2]-[tharg_creature_noun_4] ("arts graduate-fish") and
[tharg_strange_adj] [tharg_tourist_attraction_2_noun] ("strange parking meters").
*/
// system-description-string = "[planet_root] is [planet_attr_root]."
14 = "planet_root";
22 = "planet_attr_root";
9 = "main_dispatch";
32 = "secondary_dispatch";
0 = "famous_adj";
1 = "degree_adj";
15 = "boring_adj";
16 = "planet_noun"; // planet, world, dump.
7 = "cursed_adj";
26 = "dangerous_adj"; // Used for creatures, drinks and plantation plants.
12 = "exciting_adj"; // Used for [entertainment_noun] or creature-based foods.
21 = "disaster_frequency_adj";
8 = "disaster_noun_phrase";
24 = "tharg_creature_noun_root"; // Builds a creature name frome one of the following
30 = "creature_noun_1"; // Also used as food ingredient.
31 = "tharg_creature_noun_2"; // Also used as [exciting_adj] food ingredient.
17 = "creature_noun_3";
6 = "-oid_prefix_creature_noun"; // Things always used with an -oid suffix by [tharg_creature_noun_root].
18 = "tharg_creature_noun_4"; // Art graduate, atc.
23 = "creature_attr_adj";
19 = "forest_adj";
3 = "tourist_attraction_noun";
27 = "tharg_tourist_attraction_2_noun";
2 = "tourist_attraction_adj";
29 = "plantation_1";
28 = "plantation_2";
25 = "behaviour_adj"; // used in conjunction with [tharg_behaviour_noun]
20 = "tharg_strange_adj"; // Subset of [behaviour_adj]
4 = "tharg_behaviour_noun"; // shyness, mating traditions, love/loathing of [tharg_object_of_emotion_noun]
5 = "tharg_object_of_emotion_noun";
13 = "entertainment_noun";
34 = "sport_adj"; // ice, mud, zero-G
35 = "sport_noun";
33 = "tharg_food_type_noun";
10 = "drink_type_noun";
11 = "drink_attribute";
}