| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
#pragma once |
| 30 |
|
| 31 |
#include <stdbool.h> |
| 32 |
|
| 33 |
#include <json/json.h> |
| 34 |
|
| 35 |
#include "pic.h" |
| 36 |
#include "sounds.h" |
| 37 |
#include "vector.h" |
| 38 |
|
| 39 |
void AddIntPair(json_t *parent, const char *name, int number); |
| 40 |
void AddBoolPair(json_t *parent, const char *name, int value); |
| 41 |
void AddStringPair(json_t *parent, const char *name, const char *s); |
| 42 |
void AddColorPair(json_t *parent, const char *name, const color_t c); |
| 43 |
void AddVec2iPair(json_t *parent, const char *name, const struct vec2i v); |
| 44 |
void AddRect2iPair(json_t *parent, const char *name, const Rect2i r); |
| 45 |
void AddIntArray(json_t *parent, const char *name, const CArray *a); |
| 46 |
|
| 47 |
void LoadBool(bool *value, json_t *node, const char *name); |
| 48 |
void LoadInt(int *value, json_t *node, const char *name); |
| 49 |
void LoadDouble(double *value, json_t *node, const char *name); |
| 50 |
void LoadFloat(float *value, json_t *node, const char *name); |
| 51 |
void LoadFullInt(float *value, json_t *node, const char *name); |
| 52 |
void LoadVec2i(struct vec2i *value, json_t *node, const char *name); |
| 53 |
void LoadVec2(struct vec2 *value, json_t *node, const char *name); |
| 54 |
void LoadRect2i(Rect2i *value, json_t *node, const char *name); |
| 55 |
void LoadIntArray(CArray *a, const json_t *node, const char *name); |
| 56 |
|
| 57 |
|
| 58 |
void LoadStr(char **value, json_t *node, const char *name); |
| 59 |
char *GetString(const json_t *node, const char *name); |
| 60 |
|
| 61 |
void LoadSoundFromNode(Mix_Chunk **value, json_t *node, const char *name); |
| 62 |
|
| 63 |
void LoadPic(const Pic **value, json_t *node, const char *name); |
| 64 |
|
| 65 |
void LoadBulletGuns(CArray *guns, json_t *node, const char *name); |
| 66 |
void LoadColor(color_t *c, json_t *node, const char *name); |
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
json_t *JSONFindNode(json_t *node, const char *path); |
| 71 |
|
| 72 |
#define JSON_UTILS_ADD_ENUM_PAIR(parent, name, value, func) \ |
| 73 |
json_insert_pair_into_object( \ |
| 74 |
(parent), (name), json_new_string(func(value))); |
| 75 |
|
| 76 |
bool TryLoadValue(json_t **node, const char *name); |
| 77 |
#define JSON_UTILS_LOAD_ENUM(value, node, name, func) \ |
| 78 |
{ \ |
| 79 |
json_t *_node = (node); \ |
| 80 |
if (TryLoadValue(&_node, (name))) \ |
| 81 |
{ \ |
| 82 |
(value) = func(_node->text); \ |
| 83 |
} \ |
| 84 |
} |
| 85 |
|
| 86 |
bool TrySaveJSONFile(json_t *node, const char *filename); |