static void AddGameConfigNode(GameConfig *config, json_t *root) { char buf[32]; json_t *subConfig = json_new_object(); json_insert_pair_into_object( subConfig, "FriendlyFire", json_new_bool(config->FriendlyFire)); sprintf(buf, "%u", config->RandomSeed); json_insert_pair_into_object( subConfig, "RandomSeed", json_new_number(buf)); JSON_UTILS_ADD_ENUM_PAIR(subConfig, "Difficulty", config->Difficulty, DifficultyStr); json_insert_pair_into_object( subConfig, "SlowMotion", json_new_bool(config->SlowMotion)); AddIntPair(subConfig, "EnemyDensity", config->EnemyDensity); AddIntPair(subConfig, "NonPlayerHP", config->NonPlayerHP); AddIntPair(subConfig, "PlayerHP", config->PlayerHP); json_insert_pair_into_object( subConfig, "Fog", json_new_bool(config->Fog)); AddIntPair(subConfig, "SightRange", config->SightRange); json_insert_pair_into_object( subConfig, "Shadows", json_new_bool(config->Shadows)); json_insert_pair_into_object( subConfig, "MoveWhenShooting", json_new_bool(config->MoveWhenShooting)); JSON_UTILS_ADD_ENUM_PAIR( subConfig, "SwitchMoveStyle", config->SwitchMoveStyle, SwitchMoveStyleStr); json_insert_pair_into_object( subConfig, "ShotsPushback", json_new_bool(config->ShotsPushback)); JSON_UTILS_ADD_ENUM_PAIR( subConfig, "AllyCollision", config->AllyCollision, AllyCollisionStr); json_insert_pair_into_object( subConfig, "HealthPickups", json_new_bool(config->HealthPickups)); json_insert_pair_into_object(root, "Game", subConfig); }
static void AddGraphicsConfigNode(GraphicsConfig *config, json_t *root) { json_t *subConfig = json_new_object(); AddIntPair(subConfig, "Brightness", config->Brightness); AddIntPair(subConfig, "ResolutionWidth", config->Res.x); AddIntPair(subConfig, "ResolutionHeight", config->Res.y); json_insert_pair_into_object( subConfig, "Fullscreen", json_new_bool(config->Fullscreen)); AddIntPair(subConfig, "ScaleFactor", config->ScaleFactor); AddIntPair(subConfig, "ShakeMultiplier", config->ShakeMultiplier); JSON_UTILS_ADD_ENUM_PAIR(subConfig, "ScaleMode", config->ScaleMode, ScaleModeStr); json_insert_pair_into_object(root, "Graphics", subConfig); }
static void ConfigSaveVisit(const Config *c, json_t *node) { switch (c->Type) { case CONFIG_TYPE_STRING: CASSERT(false, "not implemented"); break; case CONFIG_TYPE_INT: AddIntPair(node, c->Name, c->u.Int.Value); break; case CONFIG_TYPE_FLOAT: CASSERT(false, "not implemented"); break; case CONFIG_TYPE_BOOL: json_insert_pair_into_object( node, c->Name, json_new_bool(c->u.Bool.Value)); break; case CONFIG_TYPE_ENUM: JSON_UTILS_ADD_ENUM_PAIR( node, c->Name, c->u.Enum.Value, c->u.Enum.EnumToStr); break; case CONFIG_TYPE_GROUP: { json_t *child = node; // If the config has no name, then it is the root element // Add children directly to the node // Otherwise, create a new child if (c->Name != NULL) { child = json_new_object(); } CA_FOREACH(Config, cg, c->u.Group) ConfigSaveVisit(cg, child); CA_FOREACH_END() if (c->Name != NULL) { json_insert_pair_into_object(node, c->Name, child); } } break; default: CASSERT(false, "Unknown config type"); break; } }