Use external key=value *.ani files to describe animation parameters
|
@ -38,6 +38,8 @@ install(DIRECTORY gfx DESTINATION ${DATA_DIR}
|
|||
FILES_MATCHING PATTERN "*.png")
|
||||
install(DIRECTORY gfx DESTINATION ${DATA_DIR}
|
||||
FILES_MATCHING PATTERN "*.ttf")
|
||||
install(DIRECTORY gfx DESTINATION ${DATA_DIR}
|
||||
FILES_MATCHING PATTERN "*.ani")
|
||||
install(DIRECTORY sfx DESTINATION ${DATA_DIR})
|
||||
install(DIRECTORY bgm DESTINATION ${DATA_DIR})
|
||||
install(DIRECTORY shader DESTINATION ${DATA_DIR})
|
||||
|
|
3
gfx/bigfairy.ani
Normal file
|
@ -0,0 +1,3 @@
|
|||
rows = 2
|
||||
cols = 2
|
||||
speed = 15
|
Before Width: | Height: | Size: 9.9 KiB After Width: | Height: | Size: 9.9 KiB |
3
gfx/cirno.ani
Normal file
|
@ -0,0 +1,3 @@
|
|||
rows = 1
|
||||
cols = 1
|
||||
speed = 10
|
Before Width: | Height: | Size: 9.6 KiB After Width: | Height: | Size: 9.6 KiB |
3
gfx/elly.ani
Normal file
|
@ -0,0 +1,3 @@
|
|||
rows = 1
|
||||
cols = 1
|
||||
speed = 10
|
Before Width: | Height: | Size: 11 KiB After Width: | Height: | Size: 11 KiB |
3
gfx/fairy.ani
Normal file
|
@ -0,0 +1,3 @@
|
|||
rows = 2
|
||||
cols = 2
|
||||
speed = 15
|
Before Width: | Height: | Size: 6.6 KiB After Width: | Height: | Size: 6.6 KiB |
3
gfx/fire.ani
Normal file
|
@ -0,0 +1,3 @@
|
|||
rows = 1
|
||||
cols = 25
|
||||
speed = 1
|
Before Width: | Height: | Size: 198 KiB After Width: | Height: | Size: 198 KiB |
3
gfx/hina.ani
Normal file
|
@ -0,0 +1,3 @@
|
|||
rows = 1
|
||||
cols = 1
|
||||
speed = 10
|
Before Width: | Height: | Size: 9.5 KiB After Width: | Height: | Size: 9.5 KiB |
3
gfx/hinabg.ani
Normal file
|
@ -0,0 +1,3 @@
|
|||
rows = 1
|
||||
cols = 25
|
||||
speed = 1
|
Before Width: | Height: | Size: 486 KiB After Width: | Height: | Size: 486 KiB |
3
gfx/iku.ani
Normal file
|
@ -0,0 +1,3 @@
|
|||
rows = 1
|
||||
cols = 1
|
||||
speed = 25
|
Before Width: | Height: | Size: 12 KiB After Width: | Height: | Size: 12 KiB |
3
gfx/kurumi.ani
Normal file
|
@ -0,0 +1,3 @@
|
|||
rows = 1
|
||||
cols = 1
|
||||
speed = 10
|
Before Width: | Height: | Size: 11 KiB After Width: | Height: | Size: 11 KiB |
3
gfx/marisa.ani
Normal file
|
@ -0,0 +1,3 @@
|
|||
rows = 2
|
||||
cols = 4
|
||||
speed = 10
|
Before Width: | Height: | Size: 15 KiB After Width: | Height: | Size: 15 KiB |
3
gfx/scuttle.ani
Normal file
|
@ -0,0 +1,3 @@
|
|||
rows = 1
|
||||
cols = 1
|
||||
speed = 10
|
Before Width: | Height: | Size: 7.3 KiB After Width: | Height: | Size: 7.3 KiB |
3
gfx/wriggle.ani
Normal file
|
@ -0,0 +1,3 @@
|
|||
rows = 1
|
||||
cols = 1
|
||||
speed = 10
|
Before Width: | Height: | Size: 8.4 KiB After Width: | Height: | Size: 8.4 KiB |
3
gfx/wriggleex.ani
Normal file
|
@ -0,0 +1,3 @@
|
|||
rows = 1
|
||||
cols = 1
|
||||
speed = 10
|
Before Width: | Height: | Size: 8.6 KiB After Width: | Height: | Size: 8.6 KiB |
3
gfx/youmu.ani
Normal file
|
@ -0,0 +1,3 @@
|
|||
rows = 2
|
||||
cols = 4
|
||||
speed = 10
|
Before Width: | Height: | Size: 11 KiB After Width: | Height: | Size: 11 KiB |
|
@ -15,48 +15,11 @@
|
|||
#include "taisei_err.h"
|
||||
|
||||
char* animation_path(const char *name) {
|
||||
DIR *dir = opendir("gfx/");
|
||||
if(dir == NULL)
|
||||
return NULL;
|
||||
|
||||
struct dirent *dp;
|
||||
|
||||
while((dp = readdir(dir)) != NULL) {
|
||||
char *filepath = strjoin("gfx/", dp->d_name, NULL);
|
||||
char *tmpname = NULL;
|
||||
|
||||
if(check_animation_path(filepath)) {
|
||||
if(!strcmp(tmpname = animation_name(filepath), name)) {
|
||||
free(tmpname);
|
||||
return filepath;
|
||||
}
|
||||
}
|
||||
|
||||
free(filepath);
|
||||
free(tmpname);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
return strjoin(ANI_PATH_PREFIX, name, ANI_EXTENSION, NULL);
|
||||
}
|
||||
|
||||
bool check_animation_path(const char *path) {
|
||||
char *base = strjoin(TEX_PATH_PREFIX, "ani_", NULL);
|
||||
bool result = strstartswith(path, base) && strendswith(path, TEX_EXTENSION);
|
||||
free(base);
|
||||
return result;
|
||||
}
|
||||
|
||||
char* animation_name(const char *filename) {
|
||||
char *name = resource_util_basename(ANI_PATH_PREFIX, filename);
|
||||
char *c = name, *newname = NULL;
|
||||
|
||||
while(c = strchr(c, '_')) {
|
||||
newname = ++c;
|
||||
}
|
||||
|
||||
newname = strdup(newname);
|
||||
free(name);
|
||||
return newname;
|
||||
return strendswith(path, ANI_EXTENSION);
|
||||
}
|
||||
|
||||
void* load_animation(const char *filename, unsigned int flags) {
|
||||
|
@ -66,20 +29,17 @@ void* load_animation(const char *filename, unsigned int flags) {
|
|||
char name[strlen(basename) + 1];
|
||||
strcpy(name, basename);
|
||||
|
||||
char *tok;
|
||||
strtok(name, "_");
|
||||
#define ANIFAIL(what) { warnx("load_animation(): bad '" what "' in animation '%s'", basename); free(basename); return NULL; }
|
||||
|
||||
#define ANIFAIL(what) { warnx("load_animation(): bad '" what "' in filename '%s'", basename); free(basename); return NULL; }
|
||||
Hashtable *ht = parse_keyvalue_file(filename);
|
||||
ani->rows = atoi((char*)hashtable_get_string(ht, "rows"));
|
||||
ani->cols = atoi((char*)hashtable_get_string(ht, "cols"));
|
||||
ani->speed = atoi((char*)hashtable_get_string(ht, "speed"));
|
||||
hashtable_foreach(ht, hashtable_iter_free_data, NULL);
|
||||
hashtable_free(ht);
|
||||
|
||||
if((tok = strtok(NULL, "_")) == NULL)
|
||||
ANIFAIL("rows")
|
||||
ani->rows = atoi(tok);
|
||||
if((tok = strtok(NULL, "_")) == NULL)
|
||||
ANIFAIL("cols")
|
||||
ani->cols = atoi(tok);
|
||||
if((tok = strtok(NULL, "_")) == NULL)
|
||||
ANIFAIL("speed")
|
||||
ani->speed = atoi(tok);
|
||||
if(ani->rows < 1) ANIFAIL("rows")
|
||||
if(ani->cols < 1) ANIFAIL("cols")
|
||||
|
||||
if(ani->speed == 0) {
|
||||
warnx("load_animation(): animation speed of %s == 0. relativity?", name);
|
||||
|
|
|
@ -27,7 +27,6 @@ typedef struct Animation {
|
|||
char* animation_path(const char *name);
|
||||
bool check_animation_path(const char *path);
|
||||
void* load_animation(const char *filename, unsigned int flags);
|
||||
char* animation_name(const char *filename);
|
||||
|
||||
Animation *get_ani(const char *name);
|
||||
|
||||
|
@ -35,5 +34,6 @@ void draw_animation(float x, float y, int row, const char *name);
|
|||
void draw_animation_p(float x, float y, int row, Animation *ani);
|
||||
|
||||
#define ANI_PATH_PREFIX TEX_PATH_PREFIX
|
||||
#define ANI_EXTENSION ".ani"
|
||||
|
||||
#endif
|
||||
|
|
|
@ -210,7 +210,7 @@ void init_resources(void) {
|
|||
);
|
||||
|
||||
register_handler(
|
||||
RES_ANIM, ANI_PATH_PREFIX, load_animation, free, animation_name, animation_path, check_animation_path, 23
|
||||
RES_ANIM, ANI_PATH_PREFIX, load_animation, free, NULL, animation_path, check_animation_path, 23
|
||||
);
|
||||
|
||||
register_handler(
|
||||
|
|
|
@ -328,7 +328,7 @@ bool parse_keyvalue_file_cb(const char *filename, KVCallback callback, void *dat
|
|||
}
|
||||
|
||||
static void kvcallback_hashtable(const char *key, const char *val, Hashtable *ht) {
|
||||
hashtable_set_string(ht, key, (void*)val);
|
||||
hashtable_set_string(ht, key, strdup((void*)val));
|
||||
}
|
||||
|
||||
Hashtable* parse_keyvalue_stream(SDL_RWops *strm) {
|
||||
|
|