예제 #1
0
bool SectorParseHelper::StartElementHandler(Library::XmlParseMaster::SharedData * sharedData, std::string& name, Library::HashMap<std::string, std::string> hashmap)
{
	if (!sharedData)
	{
		return false;
	}

	ScopeSharedData * data = sharedData->As<ScopeSharedData>();
	if (data)
	{
		mStringData = std::string();
		if (name == ScopeString)
		{
			if (!bIsParsing)
			{
				bIsParsing = true;
				auto providedName = hashmap.Find(NameString);
				if (providedName != hashmap.end())
				{
					World * world = data->GetWorld()->As<World>();
					if (world)
					{
						Sector* sector = world->CreateSector(providedName->second);
						data->SetWorld(sector);
					}
					else
					{
						throw std::exception("You are not coming from a world");
					}
				}
				return true;
			}
		}
	}
	return false;
}
	bool XmlParseHelperSector::StartElementHandler(XmlParseMaster::SharedData& sharedData, const std::string& elementName, const Hashmap<std::string, std::string>& attributes)
	{
		SharedDataTable* sharedDataPtr = sharedData.As<SharedDataTable>();
		if (sharedDataPtr == nullptr)
			return false;

		if (elementName != ELEMENT_NAME)
			return false;

		if (!attributes.ContainsKey(ATTRIBUTE_NAME))
			throw std::exception("ClearScreen syntax for <sector>. Missing attribute: name");

		if (!sharedDataPtr->CheckStateTransition(SharedDataTable::ParserState::SECTOR_START))
			throw std::exception("ClearScreen script syntax");
		bool transitionToStateRouter = sharedDataPtr->CheckStateTransition(SharedDataTable::ParserState::STATE_ROUTER);
		UNREFERENCED_PARAMETER(transitionToStateRouter);
		assert(transitionToStateRouter);

		assert(sharedDataPtr->CurrentScopePtr->Is(World::TypeIdClass()));
		World* world = static_cast<World*>(sharedDataPtr->CurrentScopePtr);

		sharedDataPtr->CurrentScopePtr = &(world->CreateSector(attributes[ATTRIBUTE_NAME]));
		return true;
	}