Compare commits

..

4 Commits

6 changed files with 79 additions and 4 deletions

1
.gitignore vendored
View File

@ -1 +1,2 @@
output/
.DS_Store

View File

@ -38,7 +38,7 @@ font_t font_create(char *font_name, char *filename) {
toml_table_t *mapping = toml_table_in(table, "map");
font.name = name.u.s;
font.toml_filename = image_filename.u.s;
font.image_filename = image_filename.u.s;
font.bits_per_pixel = bpp.u.i;
font.width = width.u.i;
font.height = height.u.i;

View File

@ -1,3 +1,5 @@
#ifndef _SMEARGLE_FONT_H
#define _SMEARGLE_FONT_H
typedef struct map_t {
const char *glyph;
@ -8,7 +10,7 @@ typedef struct map_t {
typedef struct {
char *name;
char *toml_filename;
char *image_filename;
unsigned char bits_per_pixel;
unsigned int width;
unsigned int height;
@ -20,3 +22,5 @@ font_t font_create(char *name, char *filename);
void font_destroy(font_t font);
unsigned int map_create(toml_table_t *table, map_t **map);
void map_destroy(map_t *map);
#endif

60
src/script.c Normal file
View File

@ -0,0 +1,60 @@
#include "script.h"
#include "util.h"
script_t script_create(toml_table_t *table) {
script_t script;
font_t font;
#define TOML_GET_KEY(var, key, func) toml_datum_t (var) = func(table, (key));\
if (!(var).ok) {\
char str[200];\
snprintf(str, 200, "key '%s' missing from", (key)); \
error(str, filename); \
}
TOML_GET_KEY(filename, "filename", toml_string_in)
TOML_GET_KEY(font_name, "font", toml_string_in)
TOML_GET_KEY(min_tiles, "min_tiles_per_line", toml_int_in)
TOML_GET_KEY(max_tiles, "max_tiles_per_line", toml_int_in)
TOML_GET_KEY(tilemap_format, "tilemap_format", toml_string_in)
TOML_GET_KEY(leading_zeroes, "leading_zeroes", toml_bool_in)
TOML_GET_KEY(tile_offset, "tile_offset", toml_int_in)
TOML_GET_KEY(raw_filename, "raw_filename", toml_string_in)
TOML_GET_KEY(dedupe_filename, "dedupe_filename", toml_string_in)
TOML_GET_KEY(tilemap_filename, "tilemap_filename", toml_string_in)
TOML_GET_KEY(little_endian, "little_endian", toml_bool_in)
#undef TOML_GET_KEY
toml_table_t *fonts = toml_table_in(table, "font");
toml_datum_t font_filename = toml_string_in(fonts, font_name);
if (!font_filename.ok) {
char str[200]
snprintf(str, 200, "failed to obtain data for font %s", font_name);
error(str, "");
}
font = font_create(font_name, font_filename);
script.filename = filename.u.s;
script.font = font;
script.min_tiles_per_line = min_tiles.u.i;
script.max_tiles_per_line = max_tiles.u.i;
script.format = tilemap_format.u.s;
script.leading_zeroes = leading_zeroes.u.b;
script.tile_offset = tile_offset.u.i;
script.raw_filename = raw_filename.u.s;
script.dedupe_filename = dedupe_filename.u.s;
script.tilemap_filename = tilemap_filename.u.s;
script.little_endian = little_endian.u.b;
return script;
}
void script_destroy(script_t script) {
font_destroy(script.font);
free(script.filename);
free(script.format);
free(script.raw_filename);
free(script.dedupe_filename);
free(script.tilemap_filename);
}

View File

@ -1,9 +1,14 @@
#ifndef _SMEARGLE_SCRIPT_H
#define _SMEARGLE_SCRIPT_H
#include <stdbool.h>
#include "font.h"
typedef struct {
char *filename;
font_t *font;
font_t font;
char *format;
unsigned int min_tiles_per_line;
unsigned int max_tiles_per_line;
@ -13,4 +18,6 @@ typedef struct {
char *dedupe_filename;
char *tilemap_filename;
bool little_endian;
} script_t;
} script_t;
#endif

View File

@ -1,3 +1,5 @@
#ifndef _SMEARGLE_UTIL_H
#define _SMEARGLE_UTIL_H
#include <sys/errno.h>
#include <stdlib.h>
@ -9,3 +11,4 @@ static void error(const char *msg, const char *msg1) {
exit(1);
}
#endif