136 lines
3.8 KiB
C
136 lines
3.8 KiB
C
#include <stdlib.h>
|
|
#include "Animation.h"
|
|
#include "AnimData.h"
|
|
int cleanAnim(struct Animation *animation) {
|
|
if (animation == NULL) return 1;
|
|
animation->f = 0;
|
|
animation->fps = 0;
|
|
animation->delta = 0;
|
|
animation->anim_bool = 0;
|
|
animation->set_id = 0;
|
|
animation->face_id = 0;
|
|
animation->anim = NULL;
|
|
animation->set = NULL;
|
|
animation->face = NULL;
|
|
animation->frame = NULL;
|
|
animation->sprite = NULL;
|
|
animation->sheet = NULL;
|
|
return 0;
|
|
}
|
|
int getAnimSetId(struct Animation *animation, char *set) {
|
|
if (animation == NULL) return 1;
|
|
if (animation->anim == NULL) return 2;
|
|
int i;
|
|
for (i = 0; i < animation->anim->count; i++) {
|
|
if (strcmp(animation->anim->sets[i]->name, set) == 0) {
|
|
return i;
|
|
}
|
|
}
|
|
return -1;
|
|
}
|
|
int setAnimDefaults(struct Animation *animation) {
|
|
if (animation == NULL) return 1;
|
|
if (animation->anim == NULL) return 2;
|
|
int i;
|
|
for (i = 0; i < animation->anim->count; i++) {
|
|
if (animation->anim->sets[i] != NULL) {
|
|
animation->set = animation->anim->sets[i];
|
|
int j;
|
|
for (j = 0; j < animation->set->count; j++) {
|
|
if (animation->set->faces[j] != NULL) {
|
|
animation->face = animation->set->faces[j];
|
|
setAnimFrame(animation, 0);
|
|
if (animation->face->sheet != NULL) {
|
|
animation->sheet = animation->face->sheet;
|
|
}
|
|
}
|
|
}
|
|
break;
|
|
return 0;
|
|
}
|
|
}
|
|
return 1;
|
|
}
|
|
int setAnimSet(struct Animation *animation, char *set) {
|
|
if (animation == NULL) return 1;
|
|
if (animation->anim == NULL) return 2;
|
|
int i;
|
|
for (i = 0; i < animation->anim->count; i++) {
|
|
if (strcmp(animation->anim->sets[i]->name, set) == 0) {
|
|
animation->set = animation->anim->sets[i];
|
|
animation->set_id = i;
|
|
animation->fps = animation->anim->sets[i]->fps;
|
|
return 0;
|
|
}
|
|
}
|
|
return 1;
|
|
}
|
|
int getAnimFaceId(struct Animation *animation, char *face) {
|
|
if (animation == NULL) return 1;
|
|
if (animation->set == NULL) return 2;
|
|
int i;
|
|
for (i = 0; i < animation->set->count; i++) {
|
|
if (strcmp(animation->set->faces[i]->name, face) == 0) {
|
|
return i;
|
|
}
|
|
}
|
|
return -1;
|
|
}
|
|
int setAnimFace(struct Animation *animation, char *face) {
|
|
if (animation == NULL) return 1;
|
|
if (animation->set == NULL) return 2;
|
|
int i;
|
|
for (i = 0; i < animation->set->count; i++) {
|
|
if (strcmp(animation->set->faces[i]->name, face) == 0) {
|
|
animation->face = animation->set->faces[i];
|
|
animation->face_id = i;
|
|
animation->sheet = animation->face->sheet;
|
|
return 0;
|
|
}
|
|
}
|
|
return 1;
|
|
}
|
|
int setAnimFrame(struct Animation *animation, int frame) {
|
|
if (animation == NULL) return 1;
|
|
if (animation->face == NULL) return 2;
|
|
if (frame < 0 || frame >= animation->face->count) return 3;
|
|
animation->frame = animation->face->frames[frame];
|
|
animation->f = frame;
|
|
return 0;
|
|
}
|
|
int incAnimFrame(struct Animation *animation) {
|
|
if (animation == NULL) return 1;
|
|
if (animation->face == NULL) return 2;
|
|
if (animation->f < animation->face->count-1) {
|
|
animation->f++;
|
|
} else {
|
|
animation->f = 0;
|
|
}
|
|
animation->frame = animation->face->frames[animation->f];
|
|
return 0;
|
|
}
|
|
int addAnimDelta(struct Animation *animation, int delta_ms) {
|
|
if (animation == NULL) return 1;
|
|
if (animation->set == NULL) return 2;
|
|
animation->delta += delta_ms;
|
|
if (animation->delta >= animation->fps) {
|
|
incAnimFrame(animation);
|
|
animation->delta = 0;
|
|
}
|
|
return 0;
|
|
}
|
|
char *getAnimTag(struct Animation *animation) {
|
|
if (animation == NULL) return NULL;
|
|
if (animation->frame == NULL) return NULL;
|
|
printf("tag is %s\n", animation->frame->tag);
|
|
return animation->frame->tag;
|
|
}
|
|
int checkAnimTag(struct Animation *animation, const char *tag) {
|
|
if (animation == NULL) return 0;
|
|
if (animation->frame == NULL) return 0;
|
|
if (strcmp(animation->frame->tag, tag) == 0) {
|
|
return 1;
|
|
}
|
|
return 0;
|
|
}
|