diff options
Diffstat (limited to 'src/canvas.c')
-rw-r--r-- | src/canvas.c | 39 |
1 files changed, 35 insertions, 4 deletions
diff --git a/src/canvas.c b/src/canvas.c index 9c860ae..7dd7ea4 100644 --- a/src/canvas.c +++ b/src/canvas.c @@ -31,6 +31,7 @@ static void action_remove(Action *); static void action_pixcols_redo(Canvas *, Action *); static Canvas *canvas_open1(FILE *, void *); static Canvas *canvas_open2(FILE *, void *); +static Canvas *canvas_open3(FILE *, void *); static uint8 canvas_coord_get(Canvas *c, long int tx, long int ty, long int *x, long int *y) @@ -163,6 +164,7 @@ canvas_open(const char *path, void *ren) switch (ver) { case 1: c = canvas_open1(fp, ren); break; case 2: c = canvas_open2(fp, ren); break; + case 3: c = canvas_open3(fp, ren); break; default: fprintf(stderr, "Error opening file. Unkown version %u.", ver); break; @@ -195,7 +197,6 @@ canvas_open2(FILE *fp, void *ren) unsigned int w, h, lc, i; Canvas *c; fscanf(fp, "%u;%u;%u;", &w, &h, &lc); - puts("READING DATA"); c = canvas_init(w, h, ren); for (i = 1; i < lc; i++) canvas_add_layer(c, lc); @@ -211,6 +212,34 @@ canvas_open2(FILE *fp, void *ren) return c; } +static Canvas * +canvas_open3(FILE *fp, void *ren) +{ + unsigned int w, h, lc, fc, i; + Canvas *c; + fscanf(fp, "%u;%u;%u;%u;", &w, &h, &lc, &fc); + c = canvas_init(w, h, ren); + puts("TEST"); + for (i = 1; i < lc; i++) + canvas_add_layer(c, lc); + for (i = 1; i < fc; i++) + canvas_add_frame(c, fc); + + for (i = 0; i < lc; i++) { + fread(c->layers[i].name, sizeof *(c->layers[i].name), LAYERNAMELEN, fp); + c->layers[i].name[LAYERNAMELEN] = '\0'; + fscanf(fp, ";%c;", &c->layers[i].visible); + } + + for (i = 0; i < fc; i++) + fscanf(fp, "%c;", &c->frames[i].state); + + for (i = 0; i < lc * fc; i++) + fread(c->cells[i], sizeof *(c->cells[i]), c->w*c->h, fp); + + return c; +} + Canvas * canvas_import_png(const char *path, void *ren) { @@ -450,12 +479,14 @@ canvas_save(Canvas *c, const char *path, short int s) return 1; } - fprintf(fp, "2;%u;%u;%u;", c->w, c->h, c->layer_arr_cnt); + fprintf(fp, "3;%u;%u;%u;%u;", c->w, c->h, c->layer_arr_cnt, c->frame_arr_cnt); for (i = 0; i < c->layer_arr_cnt; i++) { fwrite(c->layers[i].name, sizeof *(c->layers[i].name), LAYERNAMELEN, fp); - fprintf(fp, ";"); + fprintf(fp, ";%c;", c->layers[i].visible); } - for (i = 0; i < c->layer_arr_cnt; i++) + for (i = 0; i < c->frame_arr_cnt; i++) + fprintf(fp, "%c;", c->frames[i].state); + for (i = 0; i < c->layer_arr_cnt * c->frame_arr_cnt; i++) fwrite(c->cells[i], sizeof *(c->cells[i]), c->w*c->h, fp); fclose(fp); if (s) |