Changed file loading to use cocos2d-x API.

This commit is contained in:
NathanSweet 2013-03-24 22:38:15 +01:00
parent 17394e1851
commit 6addb86a40
7 changed files with 39 additions and 26 deletions

6
.gitignore vendored
View File

@ -3,3 +3,9 @@ spine-sfml/Debug/*
spine-libgdx/bin/*
spine-libgdx/libs/*
target
*Debug.win32*
*.sdf
*.opensdf
*.user
*.suo
spine-cocos2dx/cocos2dx

View File

@ -1,10 +0,0 @@
*Debug.win32*
*.sdf
*.opensdf
*.user
*.suo
cocos2dx
spine-cocos2dx/include/spine/*
spine-cocos2dx/include/json/*
spine-cocos2dx/src/spine/*
spine-cocos2dx/src/json/*

View File

@ -17,9 +17,7 @@ CCScene* ExampleScene::scene() {
bool ExampleScene::init() {
if (!CCLayer::init()) return false;
ifstream atlasFile("../data/spineboy.atlas");
Atlas *atlas = new Atlas(atlasFile);
Atlas *atlas = new Atlas("../data/spineboy.atlas");
SkeletonJson json(atlas);
SkeletonData *skeletonData = json.readSkeletonDataFile("../data/spineboy-skeleton.json");
Animation *animation = json.readAnimationFile("../data/spineboy-walk.json", skeletonData);

View File

@ -50,9 +50,7 @@ public:
class Atlas: public BaseAtlas {
public:
Atlas (std::ifstream &file);
Atlas (std::istream &input);
Atlas (const std::string &text);
Atlas (const std::string &path);
Atlas (const char *begin, const char *end);
AtlasRegion* findRegion (const std::string &name);

View File

@ -37,6 +37,9 @@ public:
SkeletonJson (Atlas *atlas);
/** The SkeletonJson owns the attachmentLoader. */
SkeletonJson (BaseAttachmentLoader *attachmentLoader);
SkeletonData* readSkeletonDataFile (const std::string &path) const;
Animation* readAnimationFile (const std::string &path, const SkeletonData *skeletonData) const;
};
} /* namespace spine */

View File

@ -24,6 +24,7 @@
******************************************************************************/
#include <spine-cocos2dx/Atlas.h>
#include <stdexcept>
USING_NS_CC;
@ -36,16 +37,12 @@ AtlasPage::~AtlasPage () {
//
Atlas::Atlas (std::ifstream &file) {
load(file);
}
Atlas::Atlas (std::istream &input) {
load(input);
}
Atlas::Atlas (const std::string &text) {
load(text);
Atlas::Atlas (const std::string &path) {
unsigned long size;
char* data = reinterpret_cast<char*>(CCFileUtils::sharedFileUtils()->getFileData(
CCFileUtils::sharedFileUtils()->fullPathForFilename(path.c_str()).c_str(), "r", &size));
if (!data) throw std::runtime_error("Error reading atlas file: " + path);
load(data, data + size);
}
Atlas::Atlas (const char *begin, const char *end) {

View File

@ -24,7 +24,12 @@
******************************************************************************/
#include <spine-cocos2dx/SkeletonJson.h>
#include <stdexcept>
#include <spine-cocos2dx/AtlasAttachmentLoader.h>
#include "platform/CCFileUtils.h"
using cocos2d::CCFileUtils;
using std::runtime_error;
namespace spine {
@ -36,4 +41,20 @@ SkeletonJson::SkeletonJson (Atlas *atlas) :
BaseSkeletonJson(new AtlasAttachmentLoader(atlas)) {
}
SkeletonData* SkeletonJson::readSkeletonDataFile (const std::string &path) const {
unsigned long size;
char* data = reinterpret_cast<char*>(CCFileUtils::sharedFileUtils()->getFileData(
CCFileUtils::sharedFileUtils()->fullPathForFilename(path.c_str()).c_str(), "r", &size));
if (!data) throw runtime_error("Error reading skeleton file: " + path);
return readSkeletonData(data, data + size);
}
Animation* SkeletonJson::readAnimationFile (const std::string &path, const SkeletonData *skeletonData) const {
unsigned long size;
char* data = reinterpret_cast<char*>(CCFileUtils::sharedFileUtils()->getFileData(
CCFileUtils::sharedFileUtils()->fullPathForFilename(path.c_str()).c_str(), "r", &size));
if (!data) throw runtime_error("Error reading animation file: " + path);
return readAnimation(data, data + size, skeletonData);
}
} /* namespace spine */