Mercurial > molko
comparison librpg/rpg/map-file.c @ 241:76afe639fd72
misc: add support for NLS, closes #22510 @4h
While here cleanup the path functions in sys.c/sys.h
author | David Demelier <markand@malikania.fr> |
---|---|
date | Sat, 28 Nov 2020 18:00:05 +0100 |
parents | befa2e855d3b |
children |
comparison
equal
deleted
inserted
replaced
240:d7e5e02f70a1 | 241:76afe639fd72 |
---|---|
30 #include <core/error.h> | 30 #include <core/error.h> |
31 #include <core/image.h> | 31 #include <core/image.h> |
32 #include <core/trace.h> | 32 #include <core/trace.h> |
33 | 33 |
34 #include "map-file.h" | 34 #include "map-file.h" |
35 #include "rpg_p.h" | |
35 | 36 |
36 /* Create %<v>c string literal for scanf */ | 37 /* Create %<v>c string literal for scanf */ |
37 #define MAX_F(v) MAX_F_(v) | 38 #define MAX_F(v) MAX_F_(v) |
38 #define MAX_F_(v) "%" #v "c" | 39 #define MAX_F_(v) "%" #v "c" |
39 | 40 |
55 else if (strcmp(layer_name, "foreground") == 0) | 56 else if (strcmp(layer_name, "foreground") == 0) |
56 layer_type = MAP_LAYER_TYPE_FOREGROUND; | 57 layer_type = MAP_LAYER_TYPE_FOREGROUND; |
57 else if (strcmp(layer_name, "above") == 0) | 58 else if (strcmp(layer_name, "above") == 0) |
58 layer_type = MAP_LAYER_TYPE_ABOVE; | 59 layer_type = MAP_LAYER_TYPE_ABOVE; |
59 else | 60 else |
60 return errorf("invalid layer type: %s", layer_name); | 61 return errorf(_("invalid layer type: %s"), layer_name); |
61 | 62 |
62 amount = ctx->map->columns * ctx->map->rows; | 63 amount = ctx->map->columns * ctx->map->rows; |
63 current = 0; | 64 current = 0; |
64 | 65 |
65 /* | 66 /* |
86 | 87 |
87 while (fscanf(ctx->fp, "%d|%d|%u|%u|%128[^\n]\n", &x, &y, &w, &h, exec) == 5) { | 88 while (fscanf(ctx->fp, "%d|%d|%u|%u|%128[^\n]\n", &x, &y, &w, &h, exec) == 5) { |
88 struct action *act; | 89 struct action *act; |
89 | 90 |
90 if (!ctx->mf->load_action) { | 91 if (!ctx->mf->load_action) { |
91 tracef("ignoring action %d,%d,%u,%u,%s", x, y, w, h, exec); | 92 tracef(_("ignoring action %d,%d,%u,%u,%s"), x, y, w, h, exec); |
92 continue; | 93 continue; |
93 } | 94 } |
94 | 95 |
95 if ((act = ctx->mf->load_action(ctx->map, x, y, w, h, exec))) | 96 if ((act = ctx->mf->load_action(ctx->map, x, y, w, h, exec))) |
96 action_stack_add(&ctx->map->actions, act); | 97 action_stack_add(&ctx->map->actions, act); |
104 { | 105 { |
105 char layer_name[32 + 1] = {0}; | 106 char layer_name[32 + 1] = {0}; |
106 | 107 |
107 /* Check if weight/height has been specified. */ | 108 /* Check if weight/height has been specified. */ |
108 if (ctx->map->columns == 0 || ctx->map->rows == 0) | 109 if (ctx->map->columns == 0 || ctx->map->rows == 0) |
109 return errorf("missing map dimensions before layer"); | 110 return errorf(_("missing map dimensions before layer")); |
110 | 111 |
111 /* Determine layer type. */ | 112 /* Determine layer type. */ |
112 if (sscanf(line, "layer|%32s", layer_name) <= 0) | 113 if (sscanf(line, "layer|%32s", layer_name) <= 0) |
113 return errorf("missing layer type definition"); | 114 return errorf(_("missing layer type definition")); |
114 | 115 |
115 if (strcmp(layer_name, "actions") == 0) | 116 if (strcmp(layer_name, "actions") == 0) |
116 return parse_actions(ctx); | 117 return parse_actions(ctx); |
117 | 118 |
118 return parse_layer_tiles(ctx, layer_name); | 119 return parse_layer_tiles(ctx, layer_name); |
124 char path[PATH_MAX] = {0}, *p; | 125 char path[PATH_MAX] = {0}, *p; |
125 struct map_file *mf = ctx->mf; | 126 struct map_file *mf = ctx->mf; |
126 struct tileset_file *tf = &mf->tileset_file; | 127 struct tileset_file *tf = &mf->tileset_file; |
127 | 128 |
128 if (!(p = strchr(line, '|'))) | 129 if (!(p = strchr(line, '|'))) |
129 return errorf("could not parse tileset"); | 130 return errorf(_("could not parse tileset")); |
130 | 131 |
131 snprintf(path, sizeof (path), "%s/%s", ctx->basedir, p + 1); | 132 snprintf(path, sizeof (path), "%s/%s", ctx->basedir, p + 1); |
132 | 133 |
133 if (!tileset_file_open(tf, &mf->tileset, path)) | 134 if (!tileset_file_open(tf, &mf->tileset, path)) |
134 return false; | 135 return false; |
140 | 141 |
141 static bool | 142 static bool |
142 parse_title(struct context *ctx, const char *line) | 143 parse_title(struct context *ctx, const char *line) |
143 { | 144 { |
144 if (sscanf(line, "title|" MAX_F(MAP_FILE_TITLE_MAX), ctx->mf->title) != 1 || strlen(ctx->mf->title) == 0) | 145 if (sscanf(line, "title|" MAX_F(MAP_FILE_TITLE_MAX), ctx->mf->title) != 1 || strlen(ctx->mf->title) == 0) |
145 return errorf("null map title"); | 146 return errorf(_("null map title")); |
146 | 147 |
147 ctx->map->title = ctx->mf->title; | 148 ctx->map->title = ctx->mf->title; |
148 | 149 |
149 return true; | 150 return true; |
150 } | 151 } |
151 | 152 |
152 static bool | 153 static bool |
153 parse_columns(struct context *ctx, const char *line) | 154 parse_columns(struct context *ctx, const char *line) |
154 { | 155 { |
155 if (sscanf(line, "columns|%u", &ctx->map->columns) != 1 || ctx->map->columns == 0) | 156 if (sscanf(line, "columns|%u", &ctx->map->columns) != 1 || ctx->map->columns == 0) |
156 return errorf("null map columns"); | 157 return errorf(_("null map columns")); |
157 | 158 |
158 return true; | 159 return true; |
159 } | 160 } |
160 | 161 |
161 static bool | 162 static bool |
162 parse_rows(struct context *ctx, const char *line) | 163 parse_rows(struct context *ctx, const char *line) |
163 { | 164 { |
164 if (sscanf(line, "rows|%u", &ctx->map->rows) != 1 || ctx->map->rows == 0) | 165 if (sscanf(line, "rows|%u", &ctx->map->rows) != 1 || ctx->map->rows == 0) |
165 return errorf("null map rows"); | 166 return errorf(_("null map rows")); |
166 | 167 |
167 return true; | 168 return true; |
168 } | 169 } |
169 | 170 |
170 static bool | 171 static bool |
171 parse_origin(struct context *ctx, const char *line) | 172 parse_origin(struct context *ctx, const char *line) |
172 { | 173 { |
173 if (sscanf(line, "origin|%d|%d", &ctx->map->player_x, &ctx->map->player_y) != 2) | 174 if (sscanf(line, "origin|%d|%d", &ctx->map->player_x, &ctx->map->player_y) != 2) |
174 return errorf("invalid origin"); | 175 return errorf(_("invalid origin")); |
175 | 176 |
176 return true; | 177 return true; |
177 } | 178 } |
178 | 179 |
179 static bool | 180 static bool |
223 { | 224 { |
224 /* | 225 /* |
225 * Check that we have parsed every required components. | 226 * Check that we have parsed every required components. |
226 */ | 227 */ |
227 if (!map->title) | 228 if (!map->title) |
228 return errorf("missing title"); | 229 return errorf(_("missing title")); |
229 | 230 |
230 /* | 231 /* |
231 * We don't need to check width/height because parsing layers and | 232 * We don't need to check width/height because parsing layers and |
232 * tilesets already check for their presence, so only check layers. | 233 * tilesets already check for their presence, so only check layers. |
233 */ | 234 */ |
234 if (!map->layers[0].tiles) | 235 if (!map->layers[0].tiles) |
235 return errorf("missing background layer"); | 236 return errorf(_("missing background layer")); |
236 if (!map->layers[1].tiles) | 237 if (!map->layers[1].tiles) |
237 return errorf("missing foreground layer"); | 238 return errorf(_("missing foreground layer")); |
238 if (!tileset_ok(map->tileset)) | 239 if (!tileset_ok(map->tileset)) |
239 return errorf("missing tileset"); | 240 return errorf(_("missing tileset")); |
240 | 241 |
241 return true; | 242 return true; |
242 } | 243 } |
243 | 244 |
244 bool | 245 bool |