当前位置: 首页>>代码示例>>C++>>正文


C++ json_find_first_label函数代码示例

本文整理汇总了C++中json_find_first_label函数的典型用法代码示例。如果您正苦于以下问题:C++ json_find_first_label函数的具体用法?C++ json_find_first_label怎么用?C++ json_find_first_label使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了json_find_first_label函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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


注:本文中的json_find_first_label函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。