コード例 #1
0
	void deleteContributor(StaticFunctionTag*, BSFixedString characterName)
	{
		Json::Value jsonDisplayList = ReadDisplayData();
		
		for (auto & jsonDisplay : jsonDisplayList.getMemberNames())
		{
			Json::Value jsonDisplayData = jsonDisplayList[jsonDisplay.c_str()];
			Json::Value jsonContributors;
			if (jsonDisplayData.isMember("contributors"))
				jsonContributors = jsonDisplayData["contributors"];
			
			//Remove this character as a contributor
			for (int index = 0; index < jsonContributors.size(); ++index)
			{
				if (jsonContributors[index].asString() == characterName.data)
				{
					_MESSAGE("Removing %s from list of contributors.", characterName.data);
					Json::Value removed;
					jsonContributors.removeIndex(index, &removed);
					index--; //duplicate names shouldn't be a thing, but you never know
					jsonDisplayData["contributors"] = jsonContributors;
				}
			}

			//If this character was the only contributor, remove the entry entirely
			if (!jsonDisplayData.isMember("contributors") || (jsonDisplayData.isMember("contributors") && !jsonContributors.size()))
			{
				_MESSAGE("Last contributor was removed, deleting entry for %s!", jsonDisplay.c_str());
				jsonDisplayList.removeMember(jsonDisplay.c_str());
			}
			else {
				jsonDisplayList[jsonDisplay.c_str()] = jsonDisplayData;
			}
		}
		WriteDisplayData(jsonDisplayList);
	}
コード例 #2
0
bool saveDisplayStatus(Json::Value &jsonDisplayList, TESObjectREFR* pObject, const char * playerName = nullptr)
{
	std::string formString = GetJCFormString(pObject);

	Json::Value jsonDisplayData;
	if (jsonDisplayList.isMember(formString.c_str()))
		jsonDisplayData = jsonDisplayList[formString.c_str()];
	
	
	//kFlagUnk_0x800 is the Disabled flag
	if ((pObject->flags & TESForm::kFlagUnk_0x800) && jsonDisplayList.isMember(formString.c_str()))
	{
		//_MESSAGE("Display %s is disabled, but exists on the list.", formString.c_str());
		//Display is disabled, but exists on the list
		Json::Value jsonContributors;
		if (jsonDisplayData.isMember("contributors"))
			jsonContributors = jsonDisplayData["contributors"];

		//Remove this character as a contributor
		for (int index = 0; index < jsonContributors.size(); ++index)
		{
			if (jsonContributors[index].asString() == playerName)
			{
				_MESSAGE("Removing %s from list of contributors.", playerName);
				Json::Value removed;
				jsonContributors.removeIndex(index, &removed);
				index--; //duplicate names shouldn't be a thing, but you never know
				jsonDisplayData["contributors"] = jsonContributors;
			}
		}

		//If this character was the only contributor, remove the entry entirely
		if (!jsonDisplayData.isMember("contributors") || (jsonDisplayData.isMember("contributors") && !jsonContributors.size()))
		{
			_MESSAGE("Last contributor was removed, deleting entry for %s!", formString.c_str());
			jsonDisplayList.removeMember(formString.c_str());
		}
		else {
			jsonDisplayList[formString.c_str()] = jsonDisplayData;
		}
	}
	else if (!(pObject->flags & TESForm::kFlagUnk_0x800)) //If the display is NOT disabled
	{
		_MESSAGE("Display %s is enabled.", formString.c_str());
		
		std::string name = getName(pObject);
		if (name.length() > 0)
		{
			jsonDisplayData["name"] = name.c_str();
		}

		//If playerName is set, add the player's name to the list
		if (playerName)
		{
			Json::Value jsonContributors;
			if (jsonDisplayData.isMember("contributors"))
				jsonContributors = jsonDisplayData["contributors"];
			bool addMe = true;
			for (int index = 0; index < jsonContributors.size(); ++index)
			{
				if (jsonContributors[index].asString() == playerName)
				{
					_MESSAGE("  %s is already in the contributor list.", playerName);
					addMe = false;
				}
			}
			if (addMe)
			{
				_MESSAGE("  Adding %s to the contributor list.", playerName);
				jsonContributors.append(playerName);
				jsonDisplayData["contributors"] = jsonContributors;
			}
		}

		jsonDisplayList[formString.c_str()] = jsonDisplayData;
	}
	return true;
}