Parsing for SpriteComponent JSON
This commit is contained in:
parent
9218c9a4b1
commit
15e6abc102
BIN
assets/.DS_Store
vendored
BIN
assets/.DS_Store
vendored
Binary file not shown.
BIN
src/.DS_Store
vendored
BIN
src/.DS_Store
vendored
Binary file not shown.
@ -66,8 +66,8 @@ public:
|
||||
spriteType = sType;
|
||||
if(sType == spriteAnimation)
|
||||
{
|
||||
std::string fullPath = Game::projPath + json;
|
||||
std::ifstream fin(fullPath);
|
||||
//std::string fullPath = Game::projPath + json;
|
||||
std::ifstream fin(json);
|
||||
|
||||
if(fin.fail()){
|
||||
std::cerr<<"ERROR opening json file: " << json << std::endl;
|
||||
@ -79,13 +79,15 @@ public:
|
||||
std::string aJson = tmp.str();
|
||||
cJSON * animJson = cJSON_Parse(aJson.c_str());
|
||||
std::cout << "animJson: " << std::endl;
|
||||
//std::cout << animJson << std::endl;
|
||||
//char * printOut = cJSON_Print(animJson);
|
||||
std::cout << animJson << std::endl;
|
||||
char * printOut = cJSON_Print(animJson);
|
||||
//std::cout << animJson << std::endl;
|
||||
cJSON * meta = cJSON_GetObjectItem(animJson, "meta");
|
||||
cJSON * version = cJSON_GetObjectItem(animJson, "version");
|
||||
cJSON * frameTags = cJSON_GetObjectItem(meta,"frameTags");
|
||||
cJSON * frames = cJSON_GetObjectItem(animJson, "frames");
|
||||
int tagsCount = cJSON_GetArraySize(frameTags);
|
||||
int framesCount = cJSON_GetArraySize(frames);
|
||||
//std::cout << "tagsCount: " << tagsCount << std::endl;
|
||||
//std::cout << "version: " << version << std::endl;
|
||||
const cJSON * aFrame = NULL;
|
||||
@ -94,12 +96,19 @@ public:
|
||||
cJSON_ArrayForEach(aFrame, aFrames){
|
||||
cJSON *filename = cJSON_GetObjectItemCaseSensitive(aFrame, "filename");
|
||||
if (!cJSON_IsNumber(aFrame)){
|
||||
printf("Not a number\n");
|
||||
//printf("Not a number\n");
|
||||
//printf("Json filename: %s\n",filename);
|
||||
} else {
|
||||
std::cout << "animation frame number: " << aFrame->valueint<< std::endl;
|
||||
//std::cout << "animation frame number: " << aFrame->valueint<< std::endl;
|
||||
}
|
||||
|
||||
}
|
||||
for (int f = 0; f<framesCount; f++){
|
||||
cJSON * crrntFrame = cJSON_GetArrayItem(frames, f);
|
||||
std::string fileName = cJSON_GetObjectItem(crrntFrame, "filename")->valuestring;
|
||||
std::cout << "Filename for frame is: " << fileName << std::endl;
|
||||
}
|
||||
|
||||
for (int t = 0; t < tagsCount; t++)
|
||||
{
|
||||
cJSON * animItem = cJSON_GetArrayItem(frameTags,t);
|
||||
@ -109,7 +118,7 @@ public:
|
||||
int toFrame = cJSON_GetObjectItem(animItem, "to")->valueint;
|
||||
Animation anim = Animation(fromFrame,toFrame,100);
|
||||
animations.emplace(name, anim);
|
||||
std::cout << "Animation Name: " << name << std::endl;
|
||||
std::cout << "Animation Name: " << name << "from: " << fromFrame << "to: " << toFrame << std::endl;
|
||||
Play(name);
|
||||
}
|
||||
}
|
||||
|
@ -180,7 +180,8 @@ void Game::init(const char *title, int width, int height, bool fullscreen, int g
|
||||
//ecs implementation
|
||||
|
||||
player.addComponent<TransformComponent>(150*gScale,100*gScale,32,32,globalScale,2); // 180,120
|
||||
player.addComponent<SpriteComponent>("player", SpriteComponent::spriteAnimation, "assets/textures/actors/kaijuturtle.json");
|
||||
std::string playerJson = Game::projPath + "assets/textures/actors/kaijuturtle.json";
|
||||
player.addComponent<SpriteComponent>("player", SpriteComponent::spriteAnimation, playerJson);
|
||||
|
||||
// player.addComponent<PlayerController>(0.0,0.0,false,false,Vector2D().Zero());
|
||||
player.addComponent<ColliderComponent>("player",20*globalScale,20*globalScale, true, 0*globalScale,0*globalScale, "");
|
||||
|
Loading…
Reference in New Issue
Block a user