Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename CCBReader to CCSBReader. #1573

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
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
22 changes: 11 additions & 11 deletions Documentation/5. Connecting with Cocos2d.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,36 @@
For any non-trivial use of SpriteBuilder, you will need to connect your ccb-files to your code. This section explains how to do that.

## Loading ccb-files in Code
SpriteBuilder documents, or ccb-files, need to be published into a compact binary format, ccbi, before they can be loaded into your app. To publish all your files, click on the Publish icon or choose *Publish* from the *File* menu. The ccbi-files can be loaded by calling the *load:* method in the *CCBReader* class as follows. Leave out the file extension when specifying the file name.
SpriteBuilder documents, or ccb-files, need to be published into a compact binary format, ccbi, before they can be loaded into your app. To publish all your files, click on the Publish icon or choose *Publish* from the *File* menu. The ccbi-files can be loaded by calling the *load:* method in the *CCSBReader* class as follows. Leave out the file extension when specifying the file name.

CCNode* myNode = [CCBReader load:@"MyCCBFile"];
CCNode* myNode = [CCSBReader load:@"MyCCBFile"];

You may need to cast the returned value depending on what sort of object the root node in your ccbi-file is and how you will use it in your code. For instance, if you load a CCParticleSystem, use the following code:

CCParticleSystem* myParticles = (CCParticleSystem*) [CCBReader load:@"MyParticleSystem"];
CCParticleSystem* myParticles = (CCParticleSystem*) [CCSBReader load:@"MyParticleSystem"];

For your convenience, CCBReader can also wrap your node graph in a scene. To load your ccbi-file in a scene, call *loadAsScene:*
For your convenience, CCSBReader can also wrap your node graph in a scene. To load your ccbi-file in a scene, call *loadAsScene:*

CCScene* myScene = [CCBReader sceneWithNodeGraphFromFile:@"MyScene"];
CCScene* myScene = [CCSBReader sceneWithNodeGraphFromFile:@"MyScene"];

### Passing an Owner Variable
Sometimes you need to be able to access instance variables from, and get callbacks to, an object other than the root node of a ccb-file. To do this, you will need to pass an *owner* to the CCBReader. To get the variable or callback assigned to the owner, make sure that you've selected *owner* when declaring the instance variable name or callback in SpriteBuilder. Then call the *load:owner:* or *loadAsScene:owner:* method of CCBReader when loading your file.
Sometimes you need to be able to access instance variables from, and get callbacks to, an object other than the root node of a ccb-file. To do this, you will need to pass an *owner* to the CCSBReader. To get the variable or callback assigned to the owner, make sure that you've selected *owner* when declaring the instance variable name or callback in SpriteBuilder. Then call the *load:owner:* or *loadAsScene:owner:* method of CCSBReader when loading your file.

MyCallbackClass* callbackClass = [[MyCallbackClass callbackClass alloc] init];
CCNode* myNode = [CCBReader load:@"MyNodeGraph.ccbi" owner:callbackClass];
CCNode* myNode = [CCSBReader load:@"MyNodeGraph.ccbi" owner:callbackClass];

### Accessing Variables and Callbacks in a sub ccb-file
If you are using sub ccb-files, specifying the root node as target will refer to the root node of the sub ccb-file. The owner target is the object that you pass to the CCBReader.
If you are using sub ccb-files, specifying the root node as target will refer to the root node of the sub ccb-file. The owner target is the object that you pass to the CCSBReader.

## Using Custom Classes
The most common way to link your code with SpriteBuilder is to use custom classes. To assign a custom class to a node in SpriteBuilder, select the node then enter the name of your custom class in the code connections tab of the property inspector. Remember that your custom class needs to be a sub class of the selected object. When loading the ccb-file, CCBReader will initialize your custom class using the super class's *init* method then set all of the object's properties. If you need to do any extra initialization of your object after the properties are set, CCBReader will call the *didLoadFromCCB* method.
The most common way to link your code with SpriteBuilder is to use custom classes. To assign a custom class to a node in SpriteBuilder, select the node then enter the name of your custom class in the code connections tab of the property inspector. Remember that your custom class needs to be a sub class of the selected object. When loading the ccb-file, CCSBReader will initialize your custom class using the super class's *init* method then set all of the object's properties. If you need to do any extra initialization of your object after the properties are set, CCSBReader will call the *didLoadFromCCB* method.

![image](code-1.png?raw=true)

Please note that CCBReader will not be able to use any custom init methods. You will need to have a working plain init method for all custom classes that you use with SpriteBuilder. You can use custom classes for any node in your ccb-file, however, the most common use is to override the root node.
Please note that CCSBReader will not be able to use any custom init methods. You will need to have a working plain init method for all custom classes that you use with SpriteBuilder. You can use custom classes for any node in your ccb-file, however, the most common use is to override the root node.

## Linking Instance Variables
References to objects in your ccb-file can be linked to instance variables when the file is loaded. These instance variables can be either in the root node of the document, in which case it must have been assigned a custom class. You can also assign them to a custom object, which is optionally passed as the *owner* object to the CCBReader. To load the ccb-file and assign instances to its owner, the node graph needs to be loaded by calling either the *load:owner:* or the *loadAsScene:owner:* method.
References to objects in your ccb-file can be linked to instance variables when the file is loaded. These instance variables can be either in the root node of the document, in which case it must have been assigned a custom class. You can also assign them to a custom object, which is optionally passed as the *owner* object to the CCSBReader. To load the ccb-file and assign instances to its owner, the node graph needs to be loaded by calling either the *load:owner:* or the *loadAsScene:owner:* method.

![image](code-2.png?raw=true)

Expand Down
2 changes: 1 addition & 1 deletion Documentation/7. Working with Animations.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ To have a timeline play in sequence, click the *No chained timeline* text and se
### Playing Back Animations in Code
To programmatically control the animations you create with SpriteBuilder you will need to retrieve the *CCAnimationManager*. The animation manager is assigned to the node when the ccbi-file is loaded.

CCNode* myNodeGraph = [CCBReader load:@"myFile.ccbi"];
CCNode* myNodeGraph = [CCSBReader load:@"myFile.ccbi"];
CCAnimationManager* animationManager = myNodeGraph.userObject;

The animation manager will be returned as an autoreleased object. To play back a specific timeline call the *runAnimationsForSequenceNamed:* method. If a timeline is currently playing, it will be immediately stopped when calling this method.
Expand Down
4 changes: 2 additions & 2 deletions Documentation/X1. Creating Node Plug-ins.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ To compile and test the plug-in, first make sure that you have built a copy of S

## Basic plug-in structure

To make a working node plug-in, you will need to add your class to the plug-in project and edit the _CCBPProperties.plist_ file. When loading your custom class, SpriteBuilder/CCBReader will create it using the _alloc_ and default _init_ methods, then assign all the object's properties. Therefore, it is required that your class can be initialized using the _init_ method only (without using a custom init-method).
To make a working node plug-in, you will need to add your class to the plug-in project and edit the _CCBPProperties.plist_ file. When loading your custom class, SpriteBuilder/CCSBReader will create it using the _alloc_ and default _init_ methods, then assign all the object's properties. Therefore, it is required that your class can be initialized using the _init_ method only (without using a custom init-method).

The classes you add to a plug-in are linked in runtime against the Cocos2d library; only the header files are included in the project. If your node-object uses more than one class, those classes shouldn't be included in other plug-ins or there may be conflicts when loading the plug-ins.

Expand Down Expand Up @@ -88,7 +88,7 @@ Most of the plug-in magic happens in the _CCBPProperties.plist_ file. It defines

## PlugInProperty

A PlugInProperty defines how a property should be displayed in SpriteBuilder and how it should be loaded into an app by CCBReader. It is a dictionary with the keys listed below. Which property _type_:s are supported and how they are serialized (for the _default_ value) is defined in the _Property Types_ document.
A PlugInProperty defines how a property should be displayed in SpriteBuilder and how it should be loaded into an app by CCSBReader. It is a dictionary with the keys listed below. Which property _type_:s are supported and how they are serialized (for the _default_ value) is defined in the _Property Types_ document.

### Required keys

Expand Down
4 changes: 2 additions & 2 deletions Documentation/X4. CCBi File Format.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# SpriteBuilder - CCBi File Format

This is a description of the SpriteBuilder export (publish) file format for Cocos2d. It is a binary file format designed to be as compact as possible and very quick to load. This document covers version 4 of the ccbi file format, released with SpriteBuilder 1. If you are implementing or porting a reader for the ccbi file format, you may want to also have a look at the CCBReader, which is the reference implementation.
This is a description of the SpriteBuilder export (publish) file format for Cocos2d. It is a binary file format designed to be as compact as possible and very quick to load. This document covers version 4 of the ccbi file format, released with SpriteBuilder 1. If you are implementing or porting a reader for the ccbi file format, you may want to also have a look at the CCSBReader, which is the reference implementation.


## Basic types
Expand Down Expand Up @@ -342,7 +342,7 @@ Represents a node or a node graph (if the node has children). Nodes that use the
<td>CSTRING</td><td>jsController</td><td>Name of the js controller; <em>only written if jsControlled is set in the HEADER</em></td>
</tr>
<tr>
<td>UINT</td><td>memberVarAssignmentType</td><td>The target this node should be assigned as a variable for. 0 = No target; 1 = document's root node; 2 = owner (as passed to CCBReader)</td>
<td>UINT</td><td>memberVarAssignmentType</td><td>The target this node should be assigned as a variable for. 0 = No target; 1 = document's root node; 2 = owner (as passed to CCSBReader)</td>
</tr>
<tr>
<td>CSTRING</td><td>memberVarAssignmentName</td><td>The name of the variable this node should be assigned to (only written if memberVarAssignmentType != 0)</td>
Expand Down
4 changes: 2 additions & 2 deletions SpriteBuilder/Cocos2D iPhone/CCBXCocos2diPhone.m
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
*/

#import "CCBXCocos2diPhone.h"
#import "CCBBinaryWriter.h"
#import "CCSBBinaryWriter.h"

@implementation CCBXCocos2diPhone

Expand All @@ -34,7 +34,7 @@ - (NSString*) extension

- (NSData *)exportDocument:(NSDictionary *)doc
{
CCBBinaryWriter * writer = [[CCBBinaryWriter alloc] init];
CCSBBinaryWriter * writer = [[CCSBBinaryWriter alloc] init];
writer.serializedProjectSettings = serializedProjectSettings;
writer.delegate = self.delegate;
[writer writeDocument:doc];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ enum {
kCCBXFloatFull
};

@interface CCBBinaryWriter : NSObject
@interface CCSBBinaryWriter : NSObject
{
NSDictionary* serializedProjectSettings;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@
* THE SOFTWARE.
*/

#import "CCBBinaryWriter.h"
#import "CCSBBinaryWriter.h"
#import "SequencerKeyframe.h"
#import "SequencerKeyframeEasing.h"
#import "CustomPropSetting.h"
#import "NSArray+Query.h"
#import "CCRendererBasicTypes.h"

@implementation CCBBinaryWriter
@implementation CCSBBinaryWriter

@synthesize data;
@synthesize serializedProjectSettings;
Expand Down
18 changes: 9 additions & 9 deletions SpriteBuilder/SpriteBuilder Tests/CCAnimation_Tests.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#import "CCBXCocos2diPhone.h"
#import "PlugInManager.h"
#import "PlugInExport.h"
#import "CCBReader.h"
#import "CCSBReader.h"
#import "CCAnimationManager.h"
#import "CCAnimationManager_Private.h"
#import "CCBSequence.h"
Expand Down Expand Up @@ -129,7 +129,7 @@ - (void)testAnimationSync1
if(!animData)
return;

CCBReader * reader = [CCBReader reader];
CCSBReader * reader = [CCSBReader reader];
CCNode * rootNode = [reader loadWithData:animData owner:callbackTest];

CCNode * node0 = rootNode.children[0];
Expand Down Expand Up @@ -190,7 +190,7 @@ -(void)testAnimationCallback1
if(!animData)
return;

CCBReader * reader = [CCBReader reader];
CCSBReader * reader = [CCSBReader reader];
CCNode * rootNode = [reader loadWithData:animData owner:callbackTest];

CCBSequence * seq = rootNode.animationManager.sequences[0];
Expand Down Expand Up @@ -246,7 +246,7 @@ -(void)testAnimationTween1
if(!animData)
return;

CCBReader * reader = [CCBReader reader];
CCSBReader * reader = [CCSBReader reader];
CCNode * rootNode = [reader loadWithData:animData owner:callbackTest];
CCNode * node0 = rootNode.children[0];

Expand Down Expand Up @@ -386,7 +386,7 @@ -(void)testAnimationLoop1
if(!animData)
return;

CCBReader * reader = [CCBReader reader];
CCSBReader * reader = [CCSBReader reader];
CCNode * rootNode = [reader loadWithData:animData owner:callbackHelper];
CCNode * node0 = rootNode.children[0];

Expand Down Expand Up @@ -449,7 +449,7 @@ -(void)testAnimationSeeking1
if(!animData)
return;

CCBReader * reader = [CCBReader reader];
CCSBReader * reader = [CCSBReader reader];
CCNode * rootNode = [reader loadWithData:animData owner:nil];
CCNode * node0 = rootNode.children[0];

Expand Down Expand Up @@ -520,7 +520,7 @@ -(void)testAnimationChaining1
if(!animData)
return;

CCBReader * reader = [CCBReader reader];
CCSBReader * reader = [CCSBReader reader];
CCNode * rootNode = [reader loadWithData:animData owner:nil];

const CGFloat kAnimationDuration = 1.0f;
Expand Down Expand Up @@ -549,7 +549,7 @@ -(void)testVisibility1
if(!animData)
return;

CCBReader * reader = [CCBReader reader];
CCSBReader * reader = [CCSBReader reader];
CCNode * rootNode = [reader loadWithData:animData owner:nil];

CCNode * node0 = rootNode.children[0];
Expand Down Expand Up @@ -581,7 +581,7 @@ -(void)testZeroDurationTimeline1
if(!animData)
return;

CCBReader * reader = [CCBReader reader];
CCSBReader * reader = [CCSBReader reader];
CCNode * rootNode = [reader loadWithData:animData owner:nil];

CCNode * node0 = rootNode.children[0];
Expand Down
4 changes: 2 additions & 2 deletions SpriteBuilder/SpriteBuilder Tests/CCBDictionaryWriter_Tests.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#import <XCTest/XCTest.h>
#import "FileSystemTestCase.h"
#import "PlugInManager.h"
#import "CCBDictionaryWriter.h"
#import "CCSBDictionaryWriter.h"

@interface CCBDictionaryWriter_Tests : FileSystemTestCase

Expand All @@ -25,7 +25,7 @@ - (void)testSerializeNode

[node addChild:sprite];

NSMutableDictionary *result = [CCBDictionaryWriter serializeNode:node];
NSMutableDictionary *result = [CCSBDictionaryWriter serializeNode:node];

NSDictionary *expectedDict =
@{
Expand Down
4 changes: 2 additions & 2 deletions SpriteBuilder/SpriteBuilder Tests/CCBReader_EffectsTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#import <XCTest/XCTest.h>
#import "Cocos2dTestHelpers.h"
#import "CCBReader.h"
#import "CCSBReader.h"

@interface CCBReader_EffectsTest : XCTestCase

Expand All @@ -35,7 +35,7 @@ - (void)testCCBRenderTest
if(!animData)
return;

CCBReader * reader = [CCBReader reader];
CCSBReader * reader = [CCSBReader reader];
[reader loadWithData:animData owner:nil];


Expand Down
6 changes: 3 additions & 3 deletions SpriteBuilder/SpriteBuilder Tests/CCBReader_Tests.m
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
//
// CCBReader.m
// CCSBReader.m
// SpriteBuilder
//
// Created by Nicky Weber on 20.05.14.
//
//

#import <XCTest/XCTest.h>
#import "CCBBinaryWriter.h"
#import "CCSBBinaryWriter.h"
#import "CCBReader_Private.h"
#import "Cocos2dTestHelpers.h"

Expand All @@ -31,7 +31,7 @@ - (void)tearDown

- (void)testCCBVersionCompatibility
{
XCTAssertEqual(kCCBVersion, kCCBBinaryVersion, @"CCB version %d read by CCBReader is incompatible with version %d written by SpriteBuilder. Is cocos2d up to date?", kCCBVersion, kCCBBinaryVersion);
XCTAssertEqual(kCCBVersion, kCCBBinaryVersion, @"CCB version %d read by CCSBReader is incompatible with version %d written by SpriteBuilder. Is cocos2d up to date?", kCCBVersion, kCCBBinaryVersion);
}

@end
Loading