Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion PixelKit/PixelKit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@
/* End PBXContainerItemProxy section */

/* Begin PBXFileReference section */
17C52DAC10DC000C00A7001D /* Pixelwave.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; path = Pixelwave.xcodeproj; sourceTree = PIXELWAVE_SRC; };
17C52DAC10DC000C00A7001D /* Pixelwave.xcodeproj */ = {isa = PBXFileReference; path = Pixelwave.xcodeproj; sourceTree = PIXELWAVE_SRC; };
2D0D876912CD41BC00A887AF /* PKBox2DTouchPicker.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PKBox2DTouchPicker.h; sourceTree = "<group>"; };
2D0D876A12CD41BC00A887AF /* PKBox2DTouchPicker.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; lineEnding = 0; path = PKBox2DTouchPicker.mm; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.objcpp; };
2D74AE74143F4D2B00D7B84E /* PixelKitBox2DUtils.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PixelKitBox2DUtils.h; sourceTree = "<group>"; };
Expand Down
2 changes: 1 addition & 1 deletion Pixelwave/Classes/Loaders/PXLoader.m
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ - (BOOL) _load

if (!absPath)
{
[self _log:[NSString stringWithFormat:@"file not found."]];
// [self _log:[NSString stringWithFormat:@"file not found."]];
return NO;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//
// DRAnimationAtlasParser.h
// DinoRun
//
// Created by Marco Mustapic on 11/7/12.
// Copyright (c) 2012 Spiralstorm Games. All rights reserved.
//

#import "PXSimpleAtlasParser.h"

@interface PXAnimationAtlasParser : PXSimpleAtlasParser<PXParser>

@end
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
//
// DRAnimationAtlasParser.m
// DinoRun
//
// Created by Marco Mustapic on 11/7/12.
// Copyright (c) 2012 Spiralstorm Games. All rights reserved.
//

#import "PXAnimationAtlasParser.h"
#import "CJSONDeserializer.h"

#import "PXTextureAtlas.h"
#import "PXAtlasFrame.h"
#import "PXClipRect.h"
#import "PXTexturePadding.h"

#import "PXTextureLoader.h"
#import "PXTextureData.h"

#import "PXDebug.h"

@implementation PXAnimationAtlasParser

// Right now this just does a silly check to see if a certain string exists
// within the file to see if it's the right type. Unfortunately the JSON file
// format doesn't have any good unique features we can use.
+ (BOOL) isApplicableForData:(NSData *)data origin:(NSString *)origin
{
if (!data)
return NO;

// If this file came straight from memory (not loaded from a URL), we don't
// know what it's called and as such can't figure out the name of the image.
// This is only a restriction with the current JSON file, and can be removed
// when the file format changes.
if (!origin)
return NO;

NSString *ext = [[origin pathExtension] lowercaseString];
if (![ext isEqualToString:@"atlas"])
return NO;


return YES;
}

+ (void) appendSupportedFileExtensions:(PXLinkedList *)extensions
{
[extensions addObject:@"atlas"];
}

- (BOOL) _parseWithModifier:(id<PXTextureModifier>)modifier
{
/////////////////////////
// Parse the JSON data //
/////////////////////////

NSError *error = nil;
NSDictionary *dict = [[CJSONDeserializer deserializer] deserializeAsDictionary:data error:&error];

if (error)
{
NSString *localOrigin = self.origin;
localOrigin = [[localOrigin pathComponents] lastObject];

PXDebugLog(@"Couldn't parse file:%@ reason:%@\n", localOrigin ? localOrigin : @"JSON", error);
return NO;
}

NSDictionary *framesDict = [dict objectForKey:@"frames"];

if (!framesDict)
return NO;

int numFrames = [framesDict count];

// No frames, no service.
if (numFrames <= 0)
return NO;

[self _setupWithTotalFrames:numFrames];


////////////////////////////////
// Read the texture data info //
////////////////////////////////

// Release the old one if it exists

NSArray * bitmaps = [dict objectForKey:@"bitmaps"];
for (NSString * bitmapName in bitmaps)
{
NSString *imagePath = nil;

imagePath = [PXTextureLoader resolvePathForImageFile:bitmapName];
if (!imagePath)
return NO;

PXTextureLoader *loader = [[PXTextureLoader alloc] initWithContentsOfFile:imagePath modifier:modifier];

if (!loader)
return NO;

// Require the image to be the same contentScaleFactor as the atlas.
[loader setContentScaleFactor:contentScaleFactor];
[self _addTextureLoader:loader];
[loader release];
}

/////////////////////////
// Read the frame data //
/////////////////////////

// We'll have to divide all the coordinate values stored in the file by
// the content scale factor to convert them from PIXELS to POINTS.
float invScaleFactor = 1.0f / contentScaleFactor;

// Start parsing
PXGenericAtlasParserFrame *cFrame = NULL;

CGRect frame;

// Loop through all the names
NSString *frameName;
NSDictionary *frameDict;

for (frameName in framesDict)
{
frameDict = [framesDict objectForKey:frameName];
if (!framesDict)
return NO;

frame.origin.x = [[frameDict objectForKey:@"x"] floatValue];
frame.origin.y = [[frameDict objectForKey:@"y"] floatValue];
frame.size.width = [[frameDict objectForKey:@"width"] floatValue];
frame.size.height = [[frameDict objectForKey:@"height"] floatValue];

// Convert to points
frame.origin.x *= invScaleFactor;
frame.origin.y *= invScaleFactor;
frame.size.width *= invScaleFactor;
frame.size.height *= invScaleFactor;

// Register the name
cFrame = [self _addFrameWithName:frameName];

// Constant
cFrame->textureDataIndex = [[frameDict objectForKey:@"source"] intValue];
cFrame->anchorEnabled = NO; // These aren't supported in this format

// Dynamic
cFrame->clipRect = frame;
cFrame->rotation = 0.0f;
cFrame->paddingEnabled = NO;

++cFrame;
}

return YES;
}

@end
1 change: 1 addition & 0 deletions Pixelwave/Classes/TopLevel/DataStructures/PXObjectPool.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

/*
* _____ ___
* /\ _ `\ __ /\_ \
Expand Down
2 changes: 2 additions & 0 deletions Pixelwave/Classes/TopLevel/PXTopLevel.m
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
// PXParser - TextureAtlas
#import "PXTPAtlasParser.h"
#import "PXZwopAtlasParser.h"
#import "PXAnimationAtlasParser.h"

// Font Fusers
#import "PXFontFuser.h"
Expand Down Expand Up @@ -106,6 +107,7 @@ void _PXTopLevelInitialize( )

[PXParser registerParser:[PXTPAtlasParser class] forBaseClass:[PXTextureAtlasParser class]];
[PXParser registerParser:[PXZwopAtlasParser class] forBaseClass:[PXTextureAtlasParser class]];
[PXParser registerParser:[PXAnimationAtlasParser class] forBaseClass:[PXTextureAtlasParser class]];

////////////////////////////// Add the Fusers \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

Expand Down
2 changes: 1 addition & 1 deletion Pixelwave/Classes/Utils/TextureAtlas/PXAtlasFrame.m
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ - (void) setToTexture:(PXTexture *)texture
{
texture.textureData = textureData;
texture.clipRect = clipRect;

if (anchor)
{
[texture setAnchorWithX:anchor.x y:anchor.y];
Expand Down
8 changes: 8 additions & 0 deletions Pixelwave/Pixelwave.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,8 @@
52DE2A2B12FB26BA00E25924 /* PXTextureLoader.m in Sources */ = {isa = PBXBuildFile; fileRef = 52DE2A2912FB26BA00E25924 /* PXTextureLoader.m */; };
52DE2A2E12FB26CC00E25924 /* PXSoundLoader.h in Headers */ = {isa = PBXBuildFile; fileRef = 52DE2A2C12FB26CC00E25924 /* PXSoundLoader.h */; };
52DE2A2F12FB26CC00E25924 /* PXSoundLoader.m in Sources */ = {isa = PBXBuildFile; fileRef = 52DE2A2D12FB26CC00E25924 /* PXSoundLoader.m */; };
649D5503164AE3050032998E /* PXAnimationAtlasParser.h in Headers */ = {isa = PBXBuildFile; fileRef = 649D5501164AE3030032998E /* PXAnimationAtlasParser.h */; };
649D5504164AE3050032998E /* PXAnimationAtlasParser.m in Sources */ = {isa = PBXBuildFile; fileRef = 649D5502164AE3040032998E /* PXAnimationAtlasParser.m */; };
AACBBE4A0F95108600F1A2B1 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = AACBBE490F95108600F1A2B1 /* Foundation.framework */; };
/* End PBXBuildFile section */

Expand Down Expand Up @@ -1009,6 +1011,8 @@
52DE2A2912FB26BA00E25924 /* PXTextureLoader.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; lineEnding = 0; path = PXTextureLoader.m; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.objc; };
52DE2A2C12FB26CC00E25924 /* PXSoundLoader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PXSoundLoader.h; sourceTree = "<group>"; };
52DE2A2D12FB26CC00E25924 /* PXSoundLoader.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; lineEnding = 0; path = PXSoundLoader.m; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.objc; };
649D5501164AE3030032998E /* PXAnimationAtlasParser.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PXAnimationAtlasParser.h; sourceTree = "<group>"; };
649D5502164AE3040032998E /* PXAnimationAtlasParser.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PXAnimationAtlasParser.m; sourceTree = "<group>"; };
AA747D9E0F9514B9006C5449 /* Pixelwave_Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Pixelwave_Prefix.pch; sourceTree = "<group>"; };
AACBBE490F95108600F1A2B1 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
D2AAC07E0554694100DB518D /* libPixelwave.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libPixelwave.a; sourceTree = BUILT_PRODUCTS_DIR; };
Expand Down Expand Up @@ -1234,6 +1238,8 @@
2D0E8D0D1353F78100A42B3D /* TextureAtlasParsers */ = {
isa = PBXGroup;
children = (
649D5501164AE3030032998E /* PXAnimationAtlasParser.h */,
649D5502164AE3040032998E /* PXAnimationAtlasParser.m */,
2D543D2D1360F48D004AA569 /* PXSimpleAtlasParser.h */,
2D543D2E1360F48D004AA569 /* PXSimpleAtlasParser.m */,
2D0E8D1C1353F8A900A42B3D /* PXTPAtlasParser.h */,
Expand Down Expand Up @@ -2430,6 +2436,7 @@
2DFA00E9143A4B4900307EA5 /* TBXML.h in Headers */,
2DFA00EB143A4B4900307EA5 /* TBXMLNSDataAdditions.h in Headers */,
521FC507143CA6ED00D9D7BF /* PXTextureModifierPremultiplyAlpha.h in Headers */,
649D5503164AE3050032998E /* PXAnimationAtlasParser.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -2674,6 +2681,7 @@
2DFA00EA143A4B4900307EA5 /* TBXML.m in Sources */,
2DFA00EC143A4B4900307EA5 /* TBXMLNSDataAdditions.m in Sources */,
521FC508143CA6ED00D9D7BF /* PXTextureModifierPremultiplyAlpha.m in Sources */,
649D5504164AE3050032998E /* PXAnimationAtlasParser.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down