shoehorn/SPRootViewController.m
2021-11-15 02:38:00 -06:00

77 lines
2.7 KiB
Objective-C

#import "SPRootViewController.h"
#import "CALayer.h"
#import "CAPackage.h"
#import "CAState.h"
#import "CAStateController.h"
@interface SPRootViewController ()
@end
@implementation SPRootViewController
- (void)loadView {
[super loadView];
// Let's get this party started! Load our package.
NSURL *caarPath = [[NSBundle bundleForClass:NSClassFromString(@"PKPass")]
URLForResource:@"ShredderSheet"
withExtension:@"caar"];
CAPackage *package = [CAPackage packageWithContentsOfURL:caarPath
type:kCAPackageTypeArchive
options:nil
error:nil];
// Determine the frame of the unarchived root layer.
CALayer *rootLayer = [package rootLayer];
CGRect rootLayerFrame = [rootLayer frame];
// We can create a new view to harass.
// Exhilerating!
UIView *layerView = [[UIView alloc] initWithFrame:rootLayerFrame];
[[layerView layer] addSublayer:rootLayer];
[self.view addSubview:layerView];
// Ensure our package's root layer does similar, I... think.
[[package publishedObjectWithName:@"Root"] setFrame:rootLayerFrame];
// Oh, our very own state controller!
// We've grown up so quickly.
CAStateController *stateController =
[[CAStateController alloc] initWithLayer:rootLayer];
// Configure our initial state.
CAState *shreddingState = [[rootLayer states] objectAtIndex:2];
[stateController setInitialStatesOfLayer:rootLayer];
[stateController setState:shreddingState
ofLayer:rootLayer
transitionSpeed:1.0f];
// Have our wonderful, extremely 2011/2012-esque metal design.
// It's local! There's no reason not to.
[[package publishedObjectWithName:@"shredderFront"]
setContents:(id)[self getImageNamed:@"ShredderMetal"]];
[[package publishedObjectWithName:@"shredderBack"]
setContents:(id)[self getImageNamed:@"ShredderMetal"]];
// Set what we're shredding.
[[package publishedObjectWithName:@"cardFrontUnshredded"]
setContents:(id)[[UIColor redColor] CGColor]];
[[package publishedObjectWithName:@"cardFrontShredded"]
setContents:(id)[[UIColor blueColor] CGColor]];
[[package publishedObjectWithName:@"cardBackUnshredded"]
setContents:(id)[[UIColor blueColor] CGColor]];
}
- (CGImageRef)getImageNamed:(NSString *)baseName {
NSBundle *passKitBundle =
[NSBundle bundleForClass:NSClassFromString(@"PKPass")];
NSString *filename = [NSString stringWithFormat:@"%@@2x", baseName];
NSString *path = [passKitBundle pathForResource:filename ofType:@"png"];
UIImage *image = [UIImage imageWithContentsOfFile:path];
return [image CGImage];
}
@end