Mercurial > molko
comparison libmlk-rpg/mlk/rpg/tileset-file.c @ 486:d6757c30658e
core: rework errors
author | David Demelier <markand@malikania.fr> |
---|---|
date | Tue, 28 Feb 2023 13:04:13 +0100 |
parents | ca30ff96bbe0 |
children | daf085bf8a8c |
comparison
equal
deleted
inserted
replaced
485:3ff1fe64d0cd | 486:d6757c30658e |
---|---|
26 | 26 |
27 #include <mlk/util/util.h> | 27 #include <mlk/util/util.h> |
28 | 28 |
29 #include <mlk/core/alloc.h> | 29 #include <mlk/core/alloc.h> |
30 #include <mlk/core/animation.h> | 30 #include <mlk/core/animation.h> |
31 #include <mlk/core/error.h> | |
32 #include <mlk/core/image.h> | 31 #include <mlk/core/image.h> |
33 #include <mlk/core/util.h> | 32 #include <mlk/core/util.h> |
34 | 33 |
35 #include "tileset-file.h" | 34 #include "tileset-file.h" |
36 #include "tileset.h" | 35 #include "tileset.h" |
127 | 126 |
128 static int | 127 static int |
129 parse_tilewidth(struct context *ctx, const char *line) | 128 parse_tilewidth(struct context *ctx, const char *line) |
130 { | 129 { |
131 if (sscanf(line, "tilewidth|%u", &ctx->tilewidth) != 1 || ctx->tilewidth == 0) | 130 if (sscanf(line, "tilewidth|%u", &ctx->tilewidth) != 1 || ctx->tilewidth == 0) |
132 return errorf("tilewidth is null"); | 131 return MLK_ERR_FORMAT; |
133 | 132 |
134 return 0; | 133 return 0; |
135 } | 134 } |
136 | 135 |
137 static int | 136 static int |
138 parse_tileheight(struct context *ctx, const char *line) | 137 parse_tileheight(struct context *ctx, const char *line) |
139 { | 138 { |
140 if (sscanf(line, "tileheight|%u", &ctx->tileheight) != 1 || ctx->tileheight == 0) | 139 if (sscanf(line, "tileheight|%u", &ctx->tileheight) != 1 || ctx->tileheight == 0) |
141 return errorf("tileheight is null"); | 140 return MLK_ERR_FORMAT; |
142 | 141 |
143 return 0; | 142 return 0; |
144 } | 143 } |
145 | 144 |
146 static int | 145 static int |
228 | 227 |
229 static int | 228 static int |
230 parse_image(struct context *ctx, const char *line) | 229 parse_image(struct context *ctx, const char *line) |
231 { | 230 { |
232 char *p; | 231 char *p; |
232 int err; | |
233 | 233 |
234 if (ctx->tilewidth == 0 || ctx->tileheight == 0) | 234 if (ctx->tilewidth == 0 || ctx->tileheight == 0) |
235 return errorf("missing tile dimensions before image"); | 235 return MLK_ERR_FORMAT; |
236 if (!(p = strchr(line, '|'))) | 236 if (!(p = strchr(line, '|'))) |
237 return errorf("could not parse image"); | 237 return MLK_ERR_FORMAT; |
238 | 238 if ((err = mlk_image_open(&ctx->tf->image, mlk_util_pathf("%s/%s", ctx->basedir, p + 1))) < 0) |
239 if (mlk_image_open(&ctx->tf->image, mlk_util_pathf("%s/%s", ctx->basedir, p + 1)) < 0) | 239 return err; |
240 return -1; | |
241 | 240 |
242 mlk_sprite_init(&ctx->tf->sprite, &ctx->tf->image, ctx->tilewidth, ctx->tileheight); | 241 mlk_sprite_init(&ctx->tf->sprite, &ctx->tf->image, ctx->tilewidth, ctx->tileheight); |
243 ctx->tileset->sprite = &ctx->tf->sprite; | 242 ctx->tileset->sprite = &ctx->tf->sprite; |
244 | 243 |
245 return 0; | 244 return 0; |
289 | 288 |
290 static int | 289 static int |
291 check(const struct tileset *tileset) | 290 check(const struct tileset *tileset) |
292 { | 291 { |
293 if (!tileset->sprite) | 292 if (!tileset->sprite) |
294 return errorf("missing tileset image"); | 293 return MLK_ERR_FORMAT; |
295 | 294 |
296 return 0; | 295 return 0; |
297 } | 296 } |
298 | 297 |
299 int | 298 int |