Beispiel #1
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");
	ConfigLoadVisit(config, root);

	// Old config version stuff
	if (version < 5)
	{
		json_t *node = JSONFindNode(root, "Game");
		if (node != NULL)
		{
			bool moveWhenShooting = false;
			LoadBool(&moveWhenShooting, node, "MoveWhenShooting");
			Config *c = ConfigGet(config, "Game.FireMoveStyle");
			c->u.Enum.Value = moveWhenShooting ? FIREMOVE_NORMAL : FIREMOVE_STOP;
		}
	}
	if (version < 6)
	{
		json_t *node = JSONFindNode(root, "Input/Keys");
		if (node != NULL)
		{
			for (int i = 0; i < 2 && node != NULL; i++)
			{
				char buf[256];
				sprintf(buf, "Input.PlayerKeys%d", i);
				Config *c = ConfigGet(config, buf);
				ConfigLoadVisit(c, node->child);
				node = node->next;
			}
		}
	}
	if (version < 4)
	{
		json_t *node = JSONFindNode(root, "Interface");
		if (node != NULL)
		{
			bool splitscreenAlways;
			LoadBool(&splitscreenAlways, node, "SplitscreenAlways");
			Config *c = ConfigGet(config, "Interface.Splitscreen");
			c->u.Enum.Value =
				splitscreenAlways ? SPLITSCREEN_ALWAYS : SPLITSCREEN_NORMAL;
		}
	}

bail:
	json_free_value(&root);
	if (f != NULL)
	{
		fclose(f);
	}
}
Beispiel #2
0
int MapNewLoad(const char *filename, CampaignSetting *c)
{
	int err = 0;

	debug(D_NORMAL, "Loading map %s\n", filename);

	if (IsCampaignOldFile(filename))
	{
		CampaignSettingOld cOld;
		memset(&cOld, 0, sizeof cOld);
		err = LoadCampaignOld(filename, &cOld);
		if (!err)
		{
			ConvertCampaignSetting(c, &cOld);
		}
		CFREE(cOld.missions);
		CFREE(cOld.characters);
		return err;
	}

	if (strcmp(StrGetFileExt(filename), "cdogscpn") == 0 ||
		strcmp(StrGetFileExt(filename), "CDOGSCPN") == 0)
	{
		return MapNewLoadArchive(filename, c);
	}

	// try to load the new map format
	json_t *root = NULL;
	int version;
	FILE *f = fopen(filename, "r");
	if (f == NULL)
	{
		debug(D_NORMAL, "MapNewLoad - invalid path!\n");
		err = -1;
		goto bail;
	}
	if (json_stream_parse(f, &root) != JSON_OK)
	{
		printf("Error parsing campaign '%s'\n", filename);
		err = -1;
		goto bail;
	}
	LoadInt(&version, root, "Version");
	if (version > 2 || version <= 0)
	{
		assert(0 && "not implemented or unknown campaign");
		err = -1;
		goto bail;
	}
	MapNewLoadCampaignJSON(root, c);
	LoadMissions(&c->Missions, json_find_first_label(root, "Missions")->child, version);
	CharacterLoadJSON(&c->characters, root, version);

bail:
	json_free_value(&root);
	if (f != NULL)
	{
		fclose(f);
	}
	return err;
}