本文整理汇总了C++中json_find_first_label函数的典型用法代码示例。如果您正苦于以下问题:C++ json_find_first_label函数的具体用法?C++ json_find_first_label怎么用?C++ json_find_first_label使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了json_find_first_label函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: LoadPlayerTemplate
static void LoadPlayerTemplate(
PlayerTemplate *t, json_t *node, const int version)
{
strcpy(t->name, json_find_first_label(node, "Name")->child->text);
t->Class = StrCharacterClass(
json_find_first_label(node, "Face")->child->text);
CASSERT(t->Class != NULL, "cannot find character class");
if (version == 1)
{
// Version 1 used integer palettes
int skin, arms, body, legs, hair;
LoadInt(&skin, node, "Skin");
LoadInt(&arms, node, "Arms");
LoadInt(&body, node, "Body");
LoadInt(&legs, node, "Legs");
LoadInt(&hair, node, "Hair");
ConvertCharacterColors(skin, arms, body, legs, hair, &t->Colors);
}
else
{
LoadColor(&t->Colors.Skin, node, "Skin");
LoadColor(&t->Colors.Arms, node, "Arms");
LoadColor(&t->Colors.Body, node, "Body");
LoadColor(&t->Colors.Legs, node, "Legs");
LoadColor(&t->Colors.Hair, node, "Hair");
}
}
开发者ID:flags,项目名称:cdogs-sdl,代码行数:27,代码来源:player_template.c
示例2: LoadStaticKeys
static void LoadStaticKeys(Mission *m, json_t *node, char *name)
{
CArrayInit(&m->u.Static.Keys, sizeof(KeyPositions));
json_t *keys = json_find_first_label(node, name);
if (!keys || !keys->child)
{
return;
}
keys = keys->child;
for (keys = keys->child; keys; keys = keys->next)
{
KeyPositions kp;
LoadInt(&kp.Index, keys, "Index");
CArrayInit(&kp.Positions, sizeof(Vec2i));
json_t *positions = json_find_first_label(keys, "Positions");
if (!positions || !positions->child)
{
continue;
}
positions = positions->child;
for (positions = positions->child;
positions;
positions = positions->next)
{
Vec2i pos;
json_t *position = positions->child;
pos.x = atoi(position->text);
position = position->next;
pos.y = atoi(position->text);
CArrayPushBack(&kp.Positions, &pos);
}
CArrayPushBack(&m->u.Static.Keys, &kp);
}
}
开发者ID:alexmustafa,项目名称:cdogs-sdl,代码行数:35,代码来源:map_new.c
示例3: AutosaveLoad
void AutosaveLoad(Autosave *autosave, const char *filename)
{
FILE *f = fopen(filename, "r");
json_t *root = NULL;
if (f == NULL)
{
printf("Error loading autosave '%s'\n", filename);
goto bail;
}
if (json_stream_parse(f, &root) != JSON_OK)
{
printf("Error parsing autosave '%s'\n", filename);
goto bail;
}
// Note: need to load missions before LastMission because the former
// will overwrite the latter, since AutosaveAddMission also
// writes to LastMission
LoadMissionNodes(autosave, root, "Missions");
if (json_find_first_label(root, "LastMission"))
{
LoadMissionNode(
&autosave->LastMission,
json_find_first_label(root, "LastMission")->child);
}
bail:
json_free_value(&root);
if (f != NULL)
{
fclose(f);
}
}
开发者ID:NSYXin,项目名称:cdogs-sdl,代码行数:34,代码来源:autosave.c
示例4: LoadStaticCharacters
static void LoadStaticCharacters(Mission *m, json_t *node, char *name)
{
CArrayInit(&m->u.Static.Characters, sizeof(CharacterPositions));
json_t *chars = json_find_first_label(node, name);
if (!chars || !chars->child)
{
return;
}
chars = chars->child;
for (chars = chars->child; chars; chars = chars->next)
{
CharacterPositions cp;
LoadInt(&cp.Index, chars, "Index");
CArrayInit(&cp.Positions, sizeof(Vec2i));
json_t *positions = json_find_first_label(chars, "Positions");
if (!positions || !positions->child)
{
continue;
}
positions = positions->child;
for (positions = positions->child;
positions;
positions = positions->next)
{
Vec2i pos;
json_t *position = positions->child;
pos.x = atoi(position->text);
position = position->next;
pos.y = atoi(position->text);
CArrayPushBack(&cp.Positions, &pos);
}
CArrayPushBack(&m->u.Static.Characters, &cp);
}
}
开发者ID:alexmustafa,项目名称:cdogs-sdl,代码行数:35,代码来源:map_new.c
示例5: BulletLoadJSON
void BulletLoadJSON(
BulletClasses *bullets, CArray *classes, json_t *bulletNode)
{
int version;
LoadInt(&version, bulletNode, "Version");
if (version > VERSION || version <= 0)
{
CASSERT(false, "cannot read bullets file version");
return;
}
// Defaults
json_t *defaultNode = json_find_first_label(bulletNode, "DefaultBullet");
if (defaultNode != NULL)
{
BulletClassFree(&bullets->Default);
LoadBullet(&bullets->Default, defaultNode->child, NULL);
}
json_t *bulletsNode = json_find_first_label(bulletNode, "Bullets")->child;
for (json_t *child = bulletsNode->child; child; child = child->next)
{
BulletClass b;
LoadBullet(&b, child, &bullets->Default);
CArrayPushBack(classes, &b);
}
bullets->root = bulletNode;
}
开发者ID:NSYXin,项目名称:cdogs-sdl,代码行数:29,代码来源:bullet_class.c
示例6: LoadMissionNode
static void LoadMissionNode(MissionSave *m, json_t *node)
{
MissionSaveInit(m);
LoadCampaignNode(&m->Campaign, json_find_first_label(node, "Campaign")->child);
strcpy(m->Password, json_find_first_label(node, "Password")->child->text);
LoadInt(&m->MissionsCompleted, node, "MissionsCompleted");
// Check that file exists
m->IsValid = access(m->Campaign.Path, F_OK | R_OK) != -1;
}
开发者ID:NSYXin,项目名称:cdogs-sdl,代码行数:9,代码来源:autosave.c
示例7: LoadPlayerTemplate
static void LoadPlayerTemplate(PlayerTemplate *t, json_t *node)
{
strcpy(t->name, json_find_first_label(node, "Name")->child->text);
t->Looks.face = StrFaceIndex(json_find_first_label(node, "Face")->child->text);
LoadInt(&t->Looks.body, node, "Body");
LoadInt(&t->Looks.arm, node, "Arms");
LoadInt(&t->Looks.leg, node, "Legs");
LoadInt(&t->Looks.skin, node, "Skin");
LoadInt(&t->Looks.hair, node, "Hair");
}
开发者ID:Wuzzy2,项目名称:cdogs-sdl,代码行数:10,代码来源:player_template.c
示例8: WeaponLoadJSON
void WeaponLoadJSON(GunClasses *g, CArray *classes, json_t *root)
{
int version;
LoadInt(&version, root, "Version");
if (version > VERSION || version <= 0)
{
CASSERT(false, "cannot read guns file version");
return;
}
GunDescription *defaultDesc = &g->Default;
json_t *defaultNode = json_find_first_label(root, "DefaultGun");
if (defaultNode != NULL)
{
LoadGunDescription(defaultDesc, defaultNode->child, NULL);
for (int i = 0; i < GUN_COUNT; i++)
{
CArrayPushBack(&g->Guns, defaultDesc);
}
}
json_t *gunsNode = json_find_first_label(root, "Guns")->child;
for (json_t *child = gunsNode->child; child; child = child->next)
{
GunDescription gd;
LoadGunDescription(&gd, child, defaultDesc);
int idx = -1;
LoadInt(&idx, child, "Index");
CASSERT(
!(idx >= 0 && idx < GUN_COUNT && classes != &g->Guns),
"Cannot load gun with index as custom gun");
if (idx >= 0 && idx < GUN_COUNT && classes == &g->Guns)
{
memcpy(CArrayGet(&g->Guns, idx), &gd, sizeof gd);
}
else
{
CArrayPushBack(classes, &gd);
}
}
json_t *pseudoGunsNode = json_find_first_label(root, "PseudoGuns");
if (pseudoGunsNode != NULL)
{
for (json_t *child = pseudoGunsNode->child->child;
child;
child = child->next)
{
GunDescription gd;
LoadGunDescription(&gd, child, defaultDesc);
gd.IsRealGun = false;
CArrayPushBack(classes, &gd);
}
}
}
开发者ID:depoorterp,项目名称:cdogs-sdl,代码行数:53,代码来源:weapon.c
示例9: LoadMissionNodes
static void LoadMissionNodes(Autosave *a, json_t *root, const char *nodeName)
{
json_t *child;
if (json_find_first_label(root, nodeName) == NULL)
{
return;
}
child = json_find_first_label(root, nodeName)->child->child;
while (child != NULL)
{
MissionSave m;
LoadMissionNode(&m, child);
AutosaveAddMission(a, &m);
child = child->next;
}
}
开发者ID:NSYXin,项目名称:cdogs-sdl,代码行数:16,代码来源:autosave.c
示例10: MapObjectsLoadJSON
void MapObjectsLoadJSON(CArray *classes, json_t *root)
{
int version;
LoadInt(&version, root, "Version");
if (version > VERSION || version <= 0)
{
CASSERT(false, "cannot read map objects file version");
return;
}
json_t *pickupsNode = json_find_first_label(root, "MapObjects")->child;
for (json_t *child = pickupsNode->child; child; child = child->next)
{
MapObject m;
LoadMapObject(&m, child);
CArrayPushBack(classes, &m);
}
ReloadDestructibles(&gMapObjects);
// Load blood objects
CArrayClear(&gMapObjects.Bloods);
for (int i = 0;; i++)
{
char buf[CDOGS_FILENAME_MAX];
sprintf(buf, "blood%d", i);
if (StrMapObject(buf) == NULL)
{
break;
}
char *tmp;
CSTRDUP(tmp, buf);
CArrayPushBack(&gMapObjects.Bloods, &tmp);
}
}
开发者ID:carstene1ns,项目名称:cdogs-sdl,代码行数:34,代码来源:map_object.c
示例11: LoadGameConfigNode
static void LoadGameConfigNode(GameConfig *config, json_t *node)
{
if (node == NULL)
{
return;
}
node = node->child;
LoadBool(&config->FriendlyFire, node, "FriendlyFire");
config->RandomSeed = atoi(json_find_first_label(node, "RandomSeed")->child->text);
JSON_UTILS_LOAD_ENUM(config->Difficulty, node, "Difficulty", StrDifficulty);
LoadBool(&config->SlowMotion, node, "SlowMotion");
LoadInt(&config->EnemyDensity, node, "EnemyDensity");
LoadInt(&config->NonPlayerHP, node, "NonPlayerHP");
LoadInt(&config->PlayerHP, node, "PlayerHP");
LoadBool(&config->Fog, node, "Fog");
LoadInt(&config->SightRange, node, "SightRange");
LoadBool(&config->Shadows, node, "Shadows");
LoadBool(&config->MoveWhenShooting, node, "MoveWhenShooting");
JSON_UTILS_LOAD_ENUM(
config->SwitchMoveStyle, node, "SwitchMoveStyle", StrSwitchMoveStyle);
LoadBool(&config->ShotsPushback, node, "ShotsPushback");
JSON_UTILS_LOAD_ENUM(
config->AllyCollision, node, "AllyCollision", StrAllyCollision);
LoadBool(&config->HealthPickups, node, "HealthPickups");
}
开发者ID:kodephys,项目名称:cdogs-sdl,代码行数:25,代码来源:config_json.c
示例12: getFilecacheType_method
bool getFilecacheType_method(LSHandle* lshandle, LSMessage *message, void *ctx) {
LSError lserror;
LSErrorInit(&lserror);
if (access_denied(message)) return true;
char filename[MAXLINLEN];
// Extract the id argument from the message
json_t *object = json_parse_document(LSMessageGetPayload(message));
json_t *type = json_find_first_label(object, "type");
if (!type || (type->child->type != JSON_STRING) || (strspn(type->child->text, ALLOWED_CHARS) != strlen(type->child->text))) {
if (!LSMessageRespond(message,
"{\"returnValue\": false, \"errorCode\": -1, \"errorText\": \"Invalid or missing type\"}",
&lserror)) goto error;
return true;
}
sprintf(filename, "/etc/palm/filecache_types/%s", type->child->text);
return read_file(message, filename, true);
error:
LSErrorPrint(&lserror, stderr);
LSErrorFree(&lserror);
end:
return false;
}
开发者ID:rwhitby,项目名称:impostah,代码行数:28,代码来源:luna_methods.c
示例13: MapNewScanJSON
int MapNewScanJSON(json_t *root, char **title, int *numMissions)
{
int err = 0;
int version;
LoadInt(&version, root, "Version");
if (version > MAP_VERSION || version <= 0)
{
err = -1;
goto bail;
}
*title = GetString(root, "Title");
*numMissions = 0;
if (version < 3)
{
for (json_t *missionNode =
json_find_first_label(root, "Missions")->child->child;
missionNode;
missionNode = missionNode->next)
{
(*numMissions)++;
}
}
else
{
LoadInt(numMissions, root, "Missions");
}
bail:
return err;
}
开发者ID:alexmustafa,项目名称:cdogs-sdl,代码行数:30,代码来源:map_new.c
示例14: LoadInt
static const MapObject *LoadMapObjectRef(json_t *itemNode, const int version)
{
if (version <= 3)
{
int idx;
LoadInt(&idx, itemNode, "Index");
return IntMapObject(idx);
}
else
{
const char *moName =
json_find_first_label(itemNode, "MapObject")->child->text;
const MapObject *mo = StrMapObject(moName);
if (mo == NULL && version <= 11 && StrEndsWith(moName, " spawner"))
{
char buf[256];
// Old version had same name for ammo and gun spawner
char itemName[256];
strncpy(itemName, moName, strlen(moName) - strlen(" spawner"));
itemName[strlen(moName) - strlen(" spawner")] = '\0';
snprintf(buf, 256, "%s ammo spawner", itemName);
mo = StrMapObject(buf);
}
if (mo == NULL)
{
LOG(LM_MAP, LL_ERROR, "Failed to load map object (%s)", moName);
}
return mo;
}
}
开发者ID:alexmustafa,项目名称:cdogs-sdl,代码行数:30,代码来源:map_new.c
示例15: LoadPlayerTemplates
void LoadPlayerTemplates(
CArray *templates, const CharacterClasses *classes, const char *filename)
{
// Note: not used, but included in function to express dependency
CASSERT(classes->Classes.size > 0,
"cannot load player templates without character classes");
json_t *root = NULL;
int version = 1;
// initialise templates
CArrayInit(templates, sizeof(PlayerTemplate));
FILE *f = fopen(GetConfigFilePath(filename), "r");
if (!f)
{
printf("Error loading player templates '%s'\n", filename);
goto bail;
}
if (json_stream_parse(f, &root) != JSON_OK)
{
printf("Error parsing player templates '%s'\n", filename);
goto bail;
}
LoadInt(&version, root, "Version");
if (json_find_first_label(root, "PlayerTemplates") == NULL)
{
printf("Error: unknown player templates format\n");
goto bail;
}
json_t *child = json_find_first_label(root, "PlayerTemplates")->child->child;
while (child != NULL)
{
PlayerTemplate t;
LoadPlayerTemplate(&t, child, version);
child = child->next;
CArrayPushBack(templates, &t);
}
bail:
json_free_value(&root);
if (f != NULL)
{
fclose(f);
}
}
开发者ID:flags,项目名称:cdogs-sdl,代码行数:47,代码来源:player_template.c
示例16: LoadPic
void LoadPic(
const Pic **value, json_t *node, const char *name, const char *oldPicName)
{
if (json_find_first_label(node, name))
{
char *tmp = GetString(node, name);
*value = PicManagerGetPic(&gPicManager, tmp);
CFREE(tmp);
}
if ((*value == NULL || ConfigGetBool(&gConfig, "Graphics.OriginalPics")) &&
json_find_first_label(node, oldPicName))
{
int oldPic;
LoadInt(&oldPic, node, oldPicName);
*value = PicManagerGetFromOld(&gPicManager, oldPic);
}
}
开发者ID:NSYXin,项目名称:cdogs-sdl,代码行数:17,代码来源:json_utils.c
示例17: LoadPic
void LoadPic(const Pic **value, json_t *node, const char *name)
{
if (json_find_first_label(node, name))
{
char *tmp = GetString(node, name);
*value = PicManagerGetPic(&gPicManager, tmp);
CFREE(tmp);
}
}
开发者ID:ChunHungLiu,项目名称:cdogs-sdl,代码行数:9,代码来源:json_utils.c
示例18: LoadMapObject
static void LoadMapObject(MapObject *m, json_t *node)
{
memset(m, 0, sizeof *m);
m->Idx = -1;
LoadInt(&m->Idx, node, "Index");
m->Name = GetString(node, "Name");
LoadPic(&m->Normal.Pic, node, "Pic", "OldPic");
LoadPic(&m->Wreck.Pic, node, "WreckPic", "OldWreckPic");
if (m->Normal.Pic)
{
// Default offset: centered X, align bottom of tile and sprite
m->Normal.Offset = Vec2iNew(
-m->Normal.Pic->size.x / 2,
TILE_HEIGHT / 2 - m->Normal.Pic->size.y);
LoadVec2i(&m->Normal.Offset, node, "Offset");
}
if (m->Wreck.Pic)
{
m->Wreck.Offset = Vec2iScaleDiv(m->Wreck.Pic->size, -2);
LoadVec2i(&m->Wreck.Offset, node, "WreckOffset");
}
// Default tile size
m->Size = Vec2iNew(TILE_WIDTH, TILE_HEIGHT);
LoadVec2i(&m->Size, node, "Size");
LoadInt(&m->Health, node, "Health");
LoadBulletGuns(&m->DestroyGuns, node, "DestroyGuns");
json_t *flagsNode = json_find_first_label(node, "Flags");
if (flagsNode != NULL && flagsNode->child != NULL)
{
for (json_t *flagNode = flagsNode->child->child;
flagNode;
flagNode = flagNode->next)
{
m->Flags |= 1 << StrPlacementFlag(flagNode->text);
}
}
// Special types
JSON_UTILS_LOAD_ENUM(m->Type, node, "Type", StrMapObjectType);
switch (m->Type)
{
case MAP_OBJECT_TYPE_NORMAL:
// Do nothing
break;
case MAP_OBJECT_TYPE_PICKUP_SPAWNER:
{
char *tmp = GetString(node, "Pickup");
m->u.PickupClass = StrPickupClass(tmp);
CFREE(tmp);
}
break;
default:
CASSERT(false, "unknown error");
break;
}
}
开发者ID:Gokulakrishnansr,项目名称:cdogs-sdl,代码行数:57,代码来源:map_object.c
示例19: json_find_first_label
void ScriptDialog::setScript(const QString &filename)
{
json_t *root = BatDownUtils::readJsonFromFile(filename);
json_t *idNode = json_find_first_label(root, "id");
json_t *titleNode = json_find_first_label(root, "title");
json_t *urlNode = json_find_first_label(root, "url");
json_t *stepsNode = json_find_first_label(root, "steps");
json_t *seqNode = json_find_first_label(stepsNode->child, "seq");
m_id = QString(idNode->child->text);
m_title = QString::fromLocal8Bit(titleNode->child->text);
m_url = QString::fromLocal8Bit(urlNode->child->text);
json_t *item = item=seqNode->child->child;
m_stepSeq.clear();
while( item ){
m_stepSeq.append(item->text);
item = item->next;
}
item = seqNode->next;
m_steps.clear();
while( item ){
json_t *testNode = item->child->child;
json_t *scriptNode = testNode->next;
char *t = json_unescape(testNode->child->text);
char *c = json_unescape(scriptNode->child->text);
m_steps.insert( item->text, QString::fromLocal8Bit(c) );
m_stepTests.insert( item->text, QString::fromLocal8Bit(t) );
m_stepFuncs.append(
QString::fromLocal8Bit("Yew.%1=function(){%2};")
.arg(item->text)
.arg( QString::fromLocal8Bit(item->child->text) )
);
item = item->next;
}
json_free_value(&root);
m_pSeqEdit->setText(m_stepSeq.join(","));
m_pStepsEdit->addItems(m_stepSeq);
setWindowTitle(m_title);
}
开发者ID:tasosbull,项目名称:yewtic,代码行数:43,代码来源:ScriptDialog.cpp
示例20: set_debug_log_method
//
// Return a polite response.
// Called directly from webOS, and returns directly to webOS.
//
bool set_debug_log_method(LSHandle* lshandle, LSMessage *message, void *ctx)
{
log("set_debug_log_method");
LSError lserror;
LSErrorInit(&lserror);
// Extract the id argument from the message
json_t *object = json_parse_document(LSMessageGetPayload(message));
json_t *enableDebugLogging = json_find_first_label(object, "enableDebugLogging");
if(enableDebugLogging)
{
if(enableDebugLogging->child->type == JSON_TRUE)
{
log("enableDebugLogging: JSON_TRUE");
g_debugLoggingEnabled = true;
}
else if(enableDebugLogging->child->type == JSON_FALSE)
{
log("enableDebugLogging: JSON_FALSE");
g_debugLoggingEnabled = false;
remove(LOG_FILE);
}
else
{
log("enableDebugLogging: %d", enableDebugLogging->child->type);
}
}
else
{
if (!LSMessageReply(lshandle, message, "{\"returnValue\": false, \"errorCode\": -1, \"errorText\": \"Invalid or missing parameters\"}", &lserror))
{
LSErrorPrint(&lserror, stderr);
LSErrorFree(&lserror);
return false;
}
}
// Local buffer to store the reply
char reply[MAXLINLEN];
sprintf(reply, "{\"returnValue\": true, \"debugLoggingEnabled\": %s}", g_debugLoggingEnabled ? "true" : "false");
log(reply);
if (!LSMessageReply(lshandle, message, reply, &lserror))
{
LSErrorPrint(&lserror, stderr);
LSErrorFree(&lserror);
return false;
}
return true;
}
开发者ID:nicbedford,项目名称:adhoc,代码行数:59,代码来源:luna_methods.c
注:本文中的json_find_first_label函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论