Esempio n. 1
0
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");
	}
}
Esempio n. 2
0
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);
	}
}
Esempio n. 3
0
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);
	}
}
Esempio n. 4
0
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);
	}
}
Esempio n. 5
0
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;
}
Esempio n. 6
0
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;
}
Esempio n. 7
0
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");
}
Esempio n. 8
0
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);
		}
	}
}
Esempio n. 9
0
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;
	}
}
Esempio n. 10
0
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);
	}
}
Esempio n. 11
0
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");
}
Esempio n. 12
0
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;
}
Esempio n. 13
0
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;
}
Esempio n. 14
0
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;
	}
}
Esempio n. 15
0
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);
	}
}
Esempio n. 16
0
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);
	}
}
Esempio n. 17
0
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);
	}
}
Esempio n. 18
0
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;
	}
}
Esempio n. 19
0
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);
}
Esempio n. 20
0
//
// 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;
}
Esempio n. 21
0
static void LoadStaticExit(Mission *m, json_t *node, char *name)
{
	json_t *exitNode = json_find_first_label(node, name);
	if (!exitNode || !exitNode->child)
	{
		return;
	}
	exitNode = exitNode->child;
	LoadVec2i(&m->u.Static.Exit.Start, exitNode, "Start");
	LoadVec2i(&m->u.Static.Exit.End, exitNode, "End");
}
Esempio n. 22
0
static void LoadClassicPillars(Mission *m, json_t *node, char *name)
{
	json_t *child = json_find_first_label(node, name);
	if (!child || !child->child)
	{
		return;
	}
	child = child->child;
	LoadInt(&m->u.Classic.Pillars.Count, child, "Count");
	LoadInt(&m->u.Classic.Pillars.Min, child, "Min");
	LoadInt(&m->u.Classic.Pillars.Max, child, "Max");
}
Esempio n. 23
0
void LoadColor(color_t *c, json_t *node, const char *name)
{
	if (json_find_first_label(node, name) == NULL)
	{
		return;
	}
	if (!TryLoadValue(&node, name))
	{
		return;
	}
	*c = StrColor(node->text);
}
Esempio n. 24
0
static void LoadClassicDoors(Mission *m, json_t *node, char *name)
{
	json_t *child = json_find_first_label(node, name);
	if (!child || !child->child)
	{
		return;
	}
	child = child->child;
	LoadBool(&m->u.Classic.Doors.Enabled, child, "Enabled");
	LoadInt(&m->u.Classic.Doors.Min, child, "Min");
	LoadInt(&m->u.Classic.Doors.Max, child, "Max");
}
Esempio n. 25
0
void LoadSoundFromNode(Mix_Chunk **value, json_t *node, const char *name)
{
	if (json_find_first_label(node, name) == NULL)
	{
		return;
	}
	if (!TryLoadValue(&node, name))
	{
		return;
	}
	*value = StrSound(node->text);
}
Esempio n. 26
0
void ConfigLoadJSON(Config *config, const char *filename)
{
	FILE *f = fopen(filename, "r");
	json_t *root = NULL;
	int version;

	if (f == NULL)
	{
		printf("Error loading config '%s'\n", filename);
		goto bail;
	}

	if (json_stream_parse(f, &root) != JSON_OK)
	{
		printf("Error parsing config '%s'\n", filename);
		goto bail;
	}
	LoadInt(&version, root, "Version");
	LoadGameConfigNode(&config->Game, json_find_first_label(root, "Game"));
	LoadGraphicsConfigNode(&config->Graphics, json_find_first_label(root, "Graphics"));
	LoadInputConfigNode(&config->Input, json_find_first_label(root, "Input"));
	LoadInterfaceConfigNode(
		&config->Interface,
		json_find_first_label(root, "Interface"),
		version);
	LoadSoundConfigNode(&config->Sound, json_find_first_label(root, "Sound"));
	LoadQuickPlayConfigNode(&config->QuickPlay, json_find_first_label(root, "QuickPlay"));

bail:
	json_free_value(&root);
	if (f != NULL)
	{
		fclose(f);
	}
}
Esempio n. 27
0
void LoadPlayerTemplates(CArray *templates, const char *filename)
{
	json_t *root = NULL;

	// 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;
	}

	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);
		child = child->next;
		CArrayPushBack(templates, &t);
	}

bail:
	json_free_value(&root);
	if (f != NULL)
	{
		fclose(f);
	}
}
Esempio n. 28
0
static void LoadQuickPlayConfigNode(QuickPlayConfig *config, json_t *node)
{
	if (node == NULL)
	{
		return;
	}
	node = node->child;
	config->MapSize = StrQuickPlayQuantity(json_find_first_label(node, "MapSize")->child->text);
	config->WallCount = StrQuickPlayQuantity(json_find_first_label(node, "WallCount")->child->text);
	config->WallLength = StrQuickPlayQuantity(json_find_first_label(node, "WallLength")->child->text);
	config->RoomCount = StrQuickPlayQuantity(json_find_first_label(node, "RoomCount")->child->text);
	config->SquareCount = StrQuickPlayQuantity(json_find_first_label(node, "SquareCount")->child->text);
	config->EnemyCount = StrQuickPlayQuantity(json_find_first_label(node, "EnemyCount")->child->text);
	config->EnemySpeed = StrQuickPlayQuantity(json_find_first_label(node, "EnemySpeed")->child->text);
	config->EnemyHealth = StrQuickPlayQuantity(json_find_first_label(node, "EnemyHealth")->child->text);
	LoadBool(&config->EnemiesWithExplosives, node, "EnemiesWithExplosives");
	config->ItemCount = StrQuickPlayQuantity(json_find_first_label(node, "ItemCount")->child->text);
}
Esempio n. 29
0
static void LoadStaticItems(
	Mission *m, json_t *node, const char *name, const int version)
{
	json_t *items = json_find_first_label(node, name);
	if (!items || !items->child)
	{
		return;
	}
	items = items->child;
	for (items = items->child; items; items = items->next)
	{
		MapObjectPositions mop;
		mop.M = LoadMapObjectRef(items, version);
		if (mop.M == NULL)
		{
			continue;
		}
		CArrayInit(&mop.Positions, sizeof(Vec2i));
		json_t *positions = json_find_first_label(items, "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(&mop.Positions, &pos);
		}
		CArrayPushBack(&m->u.Static.Items, &mop);
	}
}
Esempio n. 30
0
void LoadBulletGuns(CArray *guns, json_t *node, const char *name)
{
	node = json_find_first_label(node, name);
	if (node == NULL || node->child == NULL)
	{
		return;
	}
	CArrayInit(guns, sizeof(const GunDescription *));
	for (json_t *gun = node->child->child; gun; gun = gun->next)
	{
		const GunDescription *g = StrGunDescription(gun->text);
		CArrayPushBack(guns, &g);
	}
}