From a8cd81969ebde206a648026572e5f26d552c2c62 Mon Sep 17 00:00:00 2001 From: Uli Kusterer Date: Sun, 17 Aug 2003 23:21:37 +0200 Subject: [PATCH] Add LSTC/OCNT fields and counter field variants. --- Cocoa/Classes/RKEditorRegistry.m | 4 - NuTemplateEditor/NuTemplateLSTCElement.h | 33 ++++ NuTemplateEditor/NuTemplateLSTCElement.m | 173 ++++++++++++++++++ NuTemplateEditor/NuTemplateLSTEElement.h | 5 + NuTemplateEditor/NuTemplateLSTEElement.m | 15 +- NuTemplateEditor/NuTemplateOCNTElement.h | 26 +++ NuTemplateEditor/NuTemplateOCNTElement.m | 134 ++++++++++++++ NuTemplateEditor/NuTemplateWindowController.m | 10 + ResKnife.pbproj/project.pbxproj | 56 ++++++ 9 files changed, 451 insertions(+), 5 deletions(-) create mode 100644 NuTemplateEditor/NuTemplateLSTCElement.h create mode 100644 NuTemplateEditor/NuTemplateLSTCElement.m create mode 100644 NuTemplateEditor/NuTemplateOCNTElement.h create mode 100644 NuTemplateEditor/NuTemplateOCNTElement.m diff --git a/Cocoa/Classes/RKEditorRegistry.m b/Cocoa/Classes/RKEditorRegistry.m index e147582..d9fc994 100644 --- a/Cocoa/Classes/RKEditorRegistry.m +++ b/Cocoa/Classes/RKEditorRegistry.m @@ -122,8 +122,6 @@ RKEditorRegistry* gRKEditorRegistryMainRegistry = nil; // Access through +mainR NSEnumerator *e = [[[NSFileManager defaultManager] directoryContentsAtPath:path] objectEnumerator]; NSString *name; - NSLog(@"Looking for plugins at %@", path); - while( name = [e nextObject] ) { name = [path stringByAppendingPathComponent:name]; @@ -132,10 +130,8 @@ RKEditorRegistry* gRKEditorRegistryMainRegistry = nil; // Access through +mainR { NSBundle *plugin = [NSBundle bundleWithPath: name]; - NSLog(@"Identifier %@", [plugin bundleIdentifier]); if( pluginClass = [plugin principalClass] ) { - NSLog(@"Found plugin: %@", name); if( [pluginClass instancesRespondToSelector:@selector(initWithResource:)] ) { NSString *resType; diff --git a/NuTemplateEditor/NuTemplateLSTCElement.h b/NuTemplateEditor/NuTemplateLSTCElement.h new file mode 100644 index 0000000..3c76956 --- /dev/null +++ b/NuTemplateEditor/NuTemplateLSTCElement.h @@ -0,0 +1,33 @@ +// +// NuTemplateLSTCElement.h +// ResKnife (PB2) +// +// Implements LSTB and LSTZ fields. +// +// Created by Uli Kusterer on Tue Aug 05 2003. +// Copyright (c) 2003 M. Uli Kusterer. All rights reserved. +// + +#import +#import "NuTemplateGroupElement.h" + + +@class NuTemplateLSTEElement; +@class NuTemplateOCNTElement; + + +@interface NuTemplateLSTCElement : NuTemplateGroupElement +{ + NuTemplateLSTEElement* endElement; // Template to create our "list end" element from. + NuTemplateOCNTElement* countElement; // Our "list counter" element. +} + +-(IBAction) showCreateResourceSheet: (id)sender; + +-(void) setEndElement: (NuTemplateLSTEElement*)e; +-(NuTemplateLSTEElement*) endElement; + +-(void) setCountElement: (NuTemplateOCNTElement*)e; +-(NuTemplateOCNTElement*) countElement; + +@end diff --git a/NuTemplateEditor/NuTemplateLSTCElement.m b/NuTemplateEditor/NuTemplateLSTCElement.m new file mode 100644 index 0000000..c5ea7d6 --- /dev/null +++ b/NuTemplateEditor/NuTemplateLSTCElement.m @@ -0,0 +1,173 @@ +// +// NuTemplateLSTCElement.m +// ResKnife (PB2) +// +// Implements LSTB and LSTZ fields. +// +// Created by Uli Kusterer on Tue Aug 05 2003. +// Copyright (c) 2003 M. Uli Kusterer. All rights reserved. +// + +#import "NuTemplateLSTCElement.h" +#import "NuTemplateLSTEElement.h" +#import "NuTemplateOCNTElement.h" + + +@implementation NuTemplateLSTCElement + +-(void) dealloc +{ + [endElement release]; + [super dealloc]; +} + + +-(void) readSubElementsFrom: (NuTemplateStream*)stream +{ + countElement = [NuTemplateOCNTElement lastParsedElement]; + + while( [stream bytesToGo] > 0 ) + { + NuTemplateElement* obj = [stream readOneElement]; + + if( [[obj type] isEqualToString: @"LSTE"] ) + { + endElement = [obj retain]; + break; + } + [subElements addObject: obj]; + } +} + + +-(void) readDataForElements: (NuTemplateStream*)stream +{ + NSEnumerator *enny = [subElements objectEnumerator]; + NuTemplateElement *el; + + while( el = [enny nextObject] ) + { + [el readDataFrom: stream]; + } +} + + +-(void) readDataFrom: (NuTemplateStream*)stream +{ + NSEnumerator *enny = [subElements objectEnumerator]; + NuTemplateElement *el, *nextItem; + unsigned int itemsToGo = 0, + itemsToGoAtStart = 0; + + countElement = [NuTemplateOCNTElement lastParsedElement]; + NSLog( @"countElement: %@", countElement ); + + itemsToGo = [countElement longValue]; + itemsToGoAtStart = itemsToGo; + NSLog( @"LSTC: Number of items: %ld", itemsToGo ); + + // Read a first item: + if( itemsToGo > 0 ) + { + [self readDataForElements: stream]; + itemsToGo--; + } + + /* Read additional elements until we have enough items, + except if we're not the first item in our list. */ + if( containing != nil ) + { + while( itemsToGo-- ) + { + // Actually read the item: + nextItem = [[self copy] autorelease]; // Make another list item just like this one. + [nextItem setContaining: nil]; // Make sure it doesn't get into this "if" clause. + [containing addObject: nextItem]; // Add it below ourselves. + [nextItem readDataFrom:stream]; // Read it the same way we were. + [nextItem setContaining: containing]; // Set "containing" *after* readDataFrom so it doesn't pass the "containing == nil" check above. + } + + // Now add a terminating 'LSTE' item: + NuTemplateLSTEElement* tlee; + tlee = [[endElement copy] autorelease]; + [containing addObject: tlee]; + [tlee setContaining: containing]; + [tlee setGroupElemTemplate: self]; + [tlee setCountElement: countElement]; + [tlee readDataFrom: stream]; // If LSTE has data to read (e.g. if we're an LSTZ, the terminating byte), let it do that! + + if( itemsToGoAtStart == 0 ) // It's an empty list. Delete this LSTC again, so we only have the empty LSTE. + { + [tlee setSubElements: subElements]; // Take over the LSTC's sub-elements. + [containing removeObject:self]; // Remove the LSTB. + } + else + [tlee setSubElements: [[subElements copy] autorelease]]; // Make a copy. So each has its own array. + } +} + + +-(NSString*) stringValue +{ + return @""; +} + + +-(id) copyWithZone: (NSZone*)zone +{ + NuTemplateLSTCElement* el = [super copyWithZone: zone]; + + [el setEndElement: [self endElement]]; + [el setCountElement: [self countElement]]; + + return el; +} + + +-(void) setEndElement: (NuTemplateLSTEElement*)e +{ + [e retain]; + [endElement release]; + endElement = e; +} + +-(NuTemplateLSTEElement*) endElement +{ + return endElement; +} + + +-(void) setCountElement: (NuTemplateOCNTElement*)e +{ + countElement = e; +} + +-(NuTemplateOCNTElement*) countElement +{ + return countElement; +} + + +-(IBAction) showCreateResourceSheet: (id)sender +{ + unsigned idx = [containing indexOfObject:self]; + NuTemplateGroupElement* te = [[self copy] autorelease]; + + [containing insertObject:te atIndex:idx+1]; + [te setContaining:containing]; + + // Update "counter" item: + [countElement setLongValue: ([countElement longValue] +1)]; +} + + +-(IBAction) clear: (id)sender +{ + [[self retain] autorelease]; // Make sure we don't go away right now. That may surprise the one who called clear, or otherwise be bad. + [containing removeObject: self]; // Remove us from the array we're in. (this releases us once) + + [countElement setLongValue: [countElement longValue] -1]; +} + + +@end diff --git a/NuTemplateEditor/NuTemplateLSTEElement.h b/NuTemplateEditor/NuTemplateLSTEElement.h index ac0e300..d0a711b 100644 --- a/NuTemplateEditor/NuTemplateLSTEElement.h +++ b/NuTemplateEditor/NuTemplateLSTEElement.h @@ -9,10 +9,12 @@ #import #import "NuTemplateGroupElement.h" +@class NuTemplateOCNTElement; @interface NuTemplateLSTEElement : NuTemplateGroupElement { NuTemplateGroupElement* groupElemTemplate; // The item of which we're to create a copy. + NuTemplateOCNTElement* countElement; // The "counter" element if we're the end of an LSTC list. BOOL writesZeroByte; // Write a terminating zero-byte when writing out this item (used by LSTZ). } @@ -24,4 +26,7 @@ -(void) setGroupElemTemplate: (NuTemplateGroupElement*)e; -(NuTemplateGroupElement*) groupElemTemplate; +-(void) setCountElement: (NuTemplateOCNTElement*)e; +-(NuTemplateOCNTElement*) countElement; + @end diff --git a/NuTemplateEditor/NuTemplateLSTEElement.m b/NuTemplateEditor/NuTemplateLSTEElement.m index 25c0c50..e7d0525 100644 --- a/NuTemplateEditor/NuTemplateLSTEElement.m +++ b/NuTemplateEditor/NuTemplateLSTEElement.m @@ -8,7 +8,7 @@ #import "NuTemplateLSTEElement.h" #import "NuTemplateLSTBElement.h" - +#import "NuTemplateOCNTElement.h" @implementation NuTemplateLSTEElement @@ -32,6 +32,17 @@ } +-(void) setCountElement: (NuTemplateOCNTElement*)e +{ + countElement = e; +} + +-(NuTemplateOCNTElement*) countElement +{ + return countElement; +} + + -(void) readSubElementsFrom: (NuTemplateStream*)stream { @@ -93,6 +104,7 @@ [el setGroupElemTemplate: [self groupElemTemplate]]; [el setWritesZeroByte: [self writesZeroByte]]; + [el setCountElement: [self countElement]]; return el; } @@ -105,6 +117,7 @@ [containing insertObject:ge atIndex:idx]; [ge setContaining: containing]; + [countElement setLongValue: ([countElement longValue] +1)]; } diff --git a/NuTemplateEditor/NuTemplateOCNTElement.h b/NuTemplateEditor/NuTemplateOCNTElement.h new file mode 100644 index 0000000..3b2b1de --- /dev/null +++ b/NuTemplateEditor/NuTemplateOCNTElement.h @@ -0,0 +1,26 @@ +// +// NuTemplateOCNTElement.h +// ResKnife (PB2) +// +// Created by Uli Kusterer on Tue Aug 05 2003. +// Copyright (c) 2003 M. Uli Kusterer. All rights reserved. +// + +#import "NuTemplateElement.h" + + +@interface NuTemplateOCNTElement : NuTemplateElement +{ + long longValue; +} + ++(NuTemplateOCNTElement*) lastParsedElement; ++(void) setLastParsedElement: (NuTemplateOCNTElement*)e; + +-(void) setLongValue: (long)n; +-(long) longValue; + +-(NSString*) stringValue; +-(void) setStringValue: (NSString*)str; + +@end diff --git a/NuTemplateEditor/NuTemplateOCNTElement.m b/NuTemplateEditor/NuTemplateOCNTElement.m new file mode 100644 index 0000000..903d28d --- /dev/null +++ b/NuTemplateEditor/NuTemplateOCNTElement.m @@ -0,0 +1,134 @@ +// +// NuTemplateOCNTElement.m +// ResKnife (PB2) +// +// Created by Uli Kusterer on Tue Aug 05 2003. +// Copyright (c) 2003 M. Uli Kusterer. All rights reserved. +// + +#import "NuTemplateOCNTElement.h" + + +static NuTemplateOCNTElement* sLastParsedElement = nil; + + +@implementation NuTemplateOCNTElement + ++(NuTemplateOCNTElement*) lastParsedElement +{ + return sLastParsedElement; +} + ++(void) setLastParsedElement: (NuTemplateOCNTElement*)e +{ + NSLog( @"[NuTemplateOCNTElement setLastParsedElement: %@]", e ); + sLastParsedElement = e; +} + + +-(id) initForType: (NSString*)t withLabel: (NSString*)l +{ + if( self = [super initForType:t withLabel:l] ) + longValue = 0; + + [[self class] setLastParsedElement:self]; + + return self; +} + +-(id) copyWithZone: (NSZone*)zone +{ + NuTemplateOCNTElement* el = [super copyWithZone: zone]; + + if( el ) + { + [el setLongValue: longValue]; + [[self class] setLastParsedElement:el]; + } + + return el; +} + + +-(void) readDataFrom: (NuTemplateStream*)stream +{ + if( [type isEqualToString: @"LCNT"] ) + [stream readAmount:4 toBuffer: &longValue]; + else if( [type isEqualToString: @"LZCT"] ) + { + short n = -1; + [stream readAmount:sizeof(n) toBuffer: &n]; + longValue = n +1; + } + else if( [type isEqualToString: @"ZCNT"] ) + { + short n = -1; + [stream readAmount:sizeof(n) toBuffer: &n]; + longValue = n +1; + } + else + { + short n = 0; + [stream readAmount:sizeof(n) toBuffer: &n]; + longValue = n; + } +} + + +-(unsigned int) sizeOnDisk +{ + if( [type isEqualToString: @"LCNT"] ) + return 4; + else if( [type isEqualToString: @"LZCT"] ) + return 4; + else + return 2; +} + +-(void) writeDataTo: (NuTemplateStream*)stream +{ + if( [type isEqualToString: @"LCNT"] ) + [stream writeAmount:4 fromBuffer: &longValue]; + else if( [type isEqualToString: @"LZCT"] ) + { + long n = longValue -1; + [stream writeAmount:sizeof(n) fromBuffer: &n]; + } + else if( [type isEqualToString: @"ZCNT"] ) + { + short n = longValue -1; + [stream writeAmount:sizeof(n) fromBuffer: &n]; + } + else + { + short n = longValue; + [stream writeAmount:sizeof(n) fromBuffer: &n]; + } +} + + +-(void) setLongValue: (long)d +{ + longValue = d; +} + +-(long) longValue +{ + return longValue; +} + + +-(NSString*) stringValue +{ + return [NSString stringWithFormat: @"%ld", longValue]; +} + + +-(void) setStringValue: (NSString*)str +{ + // Dummy out. User can't change counter this way, they have to add items. +} + + + +@end diff --git a/NuTemplateEditor/NuTemplateWindowController.m b/NuTemplateEditor/NuTemplateWindowController.m index 798d09e..1008202 100644 --- a/NuTemplateEditor/NuTemplateWindowController.m +++ b/NuTemplateEditor/NuTemplateWindowController.m @@ -32,6 +32,8 @@ #import "NuTemplateDWRDElement.h" #import "NuTemplateDLNGElement.h" #import "NuTemplateDBYTElement.h" +#import "NuTemplateOCNTElement.h" +#import "NuTemplateLSTCElement.h" #import "NuTemplateStream.h" #import "NSOutlineView-SelectedItems.h" @@ -153,6 +155,9 @@ { currElement = [[currElement copy] autorelease]; // Copy the template object. + if( [[currElement type] isEqualToString: @"OCNT"] ) + NSLog( @"Instantiated: %@", currElement ); + [resourceStructure addObject: currElement]; // Add it to our parsed resource data list. Do this right away so the element can append other items should it desire to. [currElement setContaining: resourceStructure]; [currElement readDataFrom: stream]; // Fill it with resource data. @@ -204,6 +209,11 @@ [fieldReg setObject: [NuTemplateDLNGElement class] forKey: @"DLNG"]; [fieldReg setObject: [NuTemplateDBYTElement class] forKey: @"DBYT"]; [fieldReg setObject: [NuTemplateDBYTElement class] forKey: @"CHAR"]; + [fieldReg setObject: [NuTemplateOCNTElement class] forKey: @"OCNT"]; + [fieldReg setObject: [NuTemplateOCNTElement class] forKey: @"ZCNT"]; + [fieldReg setObject: [NuTemplateOCNTElement class] forKey: @"LCNT"]; + [fieldReg setObject: [NuTemplateOCNTElement class] forKey: @"LZCT"]; + [fieldReg setObject: [NuTemplateLSTCElement class] forKey: @"LSTC"]; } // Read new fields from the template and add them to our list: diff --git a/ResKnife.pbproj/project.pbxproj b/ResKnife.pbproj/project.pbxproj index f4f7ce7..bdd627b 100644 --- a/ResKnife.pbproj/project.pbxproj +++ b/ResKnife.pbproj/project.pbxproj @@ -171,6 +171,10 @@ 3D4737B304E872DB00AF65FE, 3D4737B804E873F300AF65FE, 3D4737B704E873F300AF65FE, + 3D50046F04EF040900F3B64D, + 3D50047004EF040900F3B64D, + 3D50047404EF122000F3B64D, + 3D50047304EF122000F3B64D, ); isa = PBXGroup; name = "Field Types"; @@ -311,6 +315,8 @@ 3D0933F804DFE80500DD74B1, 3D4737B604E872DB00AF65FE, 3D4737BA04E873F300AF65FE, + 3D50047104EF040900F3B64D, + 3D50047604EF122000F3B64D, ); isa = PBXHeadersBuildPhase; runOnlyForDeploymentPostprocessing = 0; @@ -340,6 +346,8 @@ 3D0933F904DFE80500DD74B1, 3D4737B504E872DB00AF65FE, 3D4737B904E873F300AF65FE, + 3D50047204EF040900F3B64D, + 3D50047504EF122000F3B64D, ); isa = PBXSourcesBuildPhase; runOnlyForDeploymentPostprocessing = 0; @@ -783,6 +791,54 @@ settings = { }; }; + 3D50046F04EF040900F3B64D = { + fileEncoding = 30; + isa = PBXFileReference; + path = NuTemplateOCNTElement.h; + refType = 4; + }; + 3D50047004EF040900F3B64D = { + fileEncoding = 30; + isa = PBXFileReference; + path = NuTemplateOCNTElement.m; + refType = 4; + }; + 3D50047104EF040900F3B64D = { + fileRef = 3D50046F04EF040900F3B64D; + isa = PBXBuildFile; + settings = { + }; + }; + 3D50047204EF040900F3B64D = { + fileRef = 3D50047004EF040900F3B64D; + isa = PBXBuildFile; + settings = { + }; + }; + 3D50047304EF122000F3B64D = { + fileEncoding = 30; + isa = PBXFileReference; + path = NuTemplateLSTCElement.m; + refType = 4; + }; + 3D50047404EF122000F3B64D = { + fileEncoding = 30; + isa = PBXFileReference; + path = NuTemplateLSTCElement.h; + refType = 4; + }; + 3D50047504EF122000F3B64D = { + fileRef = 3D50047304EF122000F3B64D; + isa = PBXBuildFile; + settings = { + }; + }; + 3D50047604EF122000F3B64D = { + fileRef = 3D50047404EF122000F3B64D; + isa = PBXBuildFile; + settings = { + }; + }; //3D0 //3D1 //3D2