예제 #1
0
/**
 @fn	void CzXomlActions_Sys::Execute(IzXomlResource* source, CzAction* action)

 @brief	The main actions executor for system related actions. All system specific actions such as LoadXOML are implemented by this method

 @param [in]	source - The source of the action
 @param [in]	action - The action to execute
 */
void CzXomlActions_Sys::Execute(IzXomlResource* source, CzAction* action)
{
	if (source == NULL)
	{
#if defined(_DEBUG)
		CzDebug::Log(CZ_DEBUG_CHANNEL_ERROR, "Source was not found for action - ", action->_MethodName.c_str(), action->Parent->getDebugInfo().c_str());
#endif
		return;
	}

	// Determine the container
	CzApp* game;
	CzScene* scene;
	CzActor* actor;
	IzXomlResource* cont = IzXomlAction::getContainer(source, game, scene, actor);

	switch (Type)
	{
	case Action_LoadXOML:
		{
			if (!action->Params[0].isEmpty())
			{
				IzXomlResource* parent = NULL;
				if (!action->Params[1].isEmpty())
					parent = scene->getResourceManager()->findResource(action->getParameter2(cont).getHash(), CzHashes::Scene_Hash);
				if (parent == NULL)
					parent = game;
				CZ_XOML->Process(parent, action->getParameter1(cont).c_str());
			}
		}
		break;
	case Action_FromTemplate:
		{
			if (!action->Params[0].isEmpty())
			{
				if (!action->Params[2].isEmpty())
				{
					CzScene* target_scene = game->findScene(action->getParameter3(cont).getHash());
					CzXomlLoad::CreateInstance(scene, target_scene, &action->getParameter1(cont), &action->getParameter2(cont));
				}
				else
					CzXomlLoad::CreateInstance(scene, scene, &action->getParameter1(cont), &action->getParameter2(cont));
			}
		}
		break;
	case Action_Launch:
		{
			if (!action->Params[0].isEmpty())
				PLATFORM_SYS->ExecuteViaOS(action->getParameter1(cont).c_str(), false);
		}
		break;
	case Action_SetBGColour:
		{
			int components[8];
			if (action->getParameter1(cont).getAsListOfInt(components) == 4)
				game->SetBackgroundColour((uint8)components[0], (uint8)components[1], (uint8)components[2], (uint8)components[3]);
			else
				CzDebug::Log(CZ_DEBUG_CHANNEL_WARNING, "Action - SetBGColour - Incorrect component count - ", action->getParameter1(cont).c_str(), action->Parent->getDebugInfo().c_str());
		}
		break;
	case Action_EnterValue:	// EnterValue Message To User, Variable to place value in
		{
			CzXomlVariable* var = CzXomlVariable::GetVariable(action->Params[1], scene);
			if (var != NULL)
			{
				const char* str = CZ_INPUT->showOnScreenKeyboard(action->getParameter1(cont).c_str(), 0, (action->getParameter3(cont) == "0") ? NULL : var->getValue().c_str());
				if (str != NULL)
					var->setValue(str);
			}
			else
				CzDebug::Log(CZ_DEBUG_CHANNEL_WARNING, "Action - Enter Value - Target variable not found - ", action->getParameter2(cont).c_str(), action->Parent->getDebugInfo().c_str());
		}
		break;
	case Action_Exit:				// Exits the app
		PLATFORM_SYS->RequestQuit();
		break;
	case Action_DebugText:
		{
			CzDebug::Log(CZ_DEBUG_CHANNEL_NONE, action->getParameter1(cont).c_str(), action->getParameter2(cont).c_str(), action->Parent->getDebugInfo().c_str());
		}
		break;
	case Action_LoadFile:	// File, blocking, filename (optional), scene (optional)
		{
			IzXomlResource* parent = NULL;
			if (!action->Params[3].isEmpty())
				scene = game->findScene(action->getParameter4(cont).getHash());
			if (!action->Params[0].isEmpty())
			{
				if (scene == NULL)
					CzDebug::Log(CZ_DEBUG_CHANNEL_ERROR, "Action - LoadFile - Scene is invalid - ", action->getParameter1(cont).c_str(), action->Parent->getDebugInfo().c_str());
				else
				{
					CzDataFile* file = (CzDataFile*)scene->getResourceManager()->findResource(action->getParameter1(cont).getHash(), CzHashes::File_Hash);
					if (file != NULL)
					{
						if (!action->Params[2].isEmpty())
						{
							// New filename was supplied so load new file contents into file
							file->Init(action->getParameter3(cont).c_str(), true, action->getParameter2(cont).getAsBool());
						}
						else
							file->Load(action->getParameter2(cont).getAsBool());
					}
					else
						CzDebug::Log(CZ_DEBUG_CHANNEL_WARNING, "Action - LoadFile - File resource could not be found - ", action->getParameter1(cont).c_str(), action->Parent->getDebugInfo().c_str());
				}
			}
		}
		break;
	case Action_PauseTime:				// Pauses / un-pauses app time
		game->setTimePaused(action->getParameter1(cont).getAsBool());
		break;
	}
}
예제 #2
0
int CzMarket::LoadFromXoml(IzXomlResource* parent, bool load_children, CzXmlNode* node)
{
	// Process market attributes
	CzString* public_key = NULL;
	CzString* simulate = NULL;

	if (EventsManager == NULL)
		EventsManager = new CzEventManager();

	for (CzXmlNode::_AttribIterator it = node->attribs_begin(); it != node->attribs_end(); it++)
	{
		unsigned int name_hash = (*it)->getName().getHash();

		if (name_hash == CzHashes::Name_Hash)
			setName((*it)->getValue().c_str());
		else
		if (name_hash == CzHashes::Tag_Hash)
			setTag((*it)->getValue().c_str());
		else
		if (name_hash == CzHashes::OnError_Hash)
			EventsManager->addEvent("OnError", (*it)->getValue().c_str(), true);
		else
		if (name_hash == CzHashes::OnUnavailable_Hash)
			EventsManager->addEvent("OnUnavailable", (*it)->getValue().c_str(), true);
		else
		if (name_hash == CzHashes::OnComplete_Hash)
			EventsManager->addEvent("OnComplete", (*it)->getValue().c_str(), true);
		else
		if (name_hash == CzHashes::OnBillingDisabled_Hash)
			EventsManager->addEvent("OnBillingDisabled", (*it)->getValue().c_str(), true);
		else
		if (name_hash == CzHashes::OnRefund_Hash)
			EventsManager->addEvent("OnRefund", (*it)->getValue().c_str(), true);
		else
		if (name_hash == CzHashes::AndroidPublicKey_Hash)
			public_key = &(*it)->getValue();
		else
		if (name_hash == CzHashes::Simulate_Hash)
			simulate = &(*it)->getValue();
	}

	CzScene* scene = NULL;
	if (parent != NULL && parent->getClassTypeHash() == CzHashes::Scene_Hash)
		scene = (CzScene*)parent;

	Init(public_key->c_str());

	// Process products
	eCzDeviceType os = PLATFORM_SYS->getDeviceType();
	for (CzXmlNode::_Iterator it2 = node->begin(); it2 != node->end(); ++it2)
	{
		bool valid = false;
		CzMarketProduct* product = new CzMarketProduct();

		unsigned int name_hash = (*it2)->GetName().getHash();
		if (name_hash == CzHashes::Product_Hash)
		{
			for (CzXmlNode::_AttribIterator it = (*it2)->attribs_begin(); it != (*it2)->attribs_end(); ++it)
			{
				unsigned int attrib_hash = (*it)->getName().getHash();

				if (attrib_hash == CzHashes::Name_Hash)
				{
					// Search for the product
					CzMarketProduct* p = findProductByName((*it)->getValue().getHash());
					if (p == NULL)
					{
						product->Name = (*it)->getValue();
						valid = true;
					}
					else
					{
						CzDebug::Log(CZ_DEBUG_CHANNEL_WARNING, "Market - Product with this name already exists - ", (*it)->getValue().c_str(), DebugInfo.c_str());
						valid = false;
						break;
					}
				}
				else
				if (attrib_hash == CzHashes::iOSId_Hash)
				{
					if (os == CzDeviceType_iPhone || os == CzDeviceType_iPad)
						product->ProductID = (*it)->getValue();
				}
				else
				if (attrib_hash == CzHashes::AndroidId_Hash)
				{
					if (os == CzDeviceType_Android)
						product->ProductID = (*it)->getValue();
				}
				else
				if (attrib_hash == CzHashes::Consumable_Hash)
					product->Consumable = (*it)->getValueAsBool();
				else
				if (attrib_hash == CzHashes::Price_Hash)
					product->Price = (*it)->getValueAsFloat();
			}
		}
		if (valid)
		{
			addProduct(product);
			product->Load();
		}
		else
			delete product;
	}

	if (simulate != NULL)
		PLATFORM_MARKET->setSimulation(simulate->getHash());

	if (scene != NULL)
		return scene->getResourceManager()->addResource(this) ? 1 : 0;
	else
		return CZ_GLOBAL_RESOURCES->getResourceManager()->addResource(this) ? 1 : 0;

	return 1;
}
예제 #3
0
int CzCamera::LoadFromXoml(IzXomlResource* parent, bool load_children, CzXmlNode* node)
{
	// Process attributes
	for (CzXmlNode::_AttribIterator it = node->attribs_begin(); it != node->attribs_end(); it++)
	{
		unsigned int name_hash = (*it)->getName().getHash();

		if (name_hash == CzHashes::Name_Hash)
			setName((*it)->getValue().c_str());
		else
		if (name_hash == CzHashes::Tag_Hash)
			setTag((*it)->getValue().c_str());
		else
		if (name_hash == CzHashes::Position_Hash)
		{
			if (!(*it)->getValueAsPoint(Position))
				CzDebug::Log(CZ_DEBUG_CHANNEL_WARNING, "Camera - Invalid value for Camera::Position", DebugInfo.c_str());
		}
		else
		if (name_hash == CzHashes::Angle_Hash)
			Angle = (*it)->getValueAsFloat();
		else
		if (name_hash == CzHashes::Scale_Hash)
			Scale = (*it)->getValueAsFloat();
		else
		if (name_hash == CzHashes::TargetX_Hash)
			setTargetX((*it)->getValue().c_str());
		else
		if (name_hash == CzHashes::TargetY_Hash)
			setTargetY((*it)->getValue().c_str());
		else
		if (name_hash == CzHashes::VelocityDamping_Hash)
		{
			if (!(*it)->getValueAsPoint(VelocityDamping))
				CzDebug::Log(CZ_DEBUG_CHANNEL_WARNING, "Camera - Invalid value for Camera::VelocityDamping", DebugInfo.c_str());
		}
		else
		if (name_hash == CzHashes::FollowSpeed_Hash)
		{
			if (!(*it)->getValueAsPoint(FollowSpeed))
				CzDebug::Log(CZ_DEBUG_CHANNEL_WARNING, "Camera - Invalid value for Camera::FollowSpeed", DebugInfo.c_str());
		}
		else
		if (name_hash == CzHashes::TouchPanX_Hash)
			setTouchPanX((*it)->getValueAsBool());
		else
		if (name_hash == CzHashes::TouchPanY_Hash)
			setTouchPanY((*it)->getValueAsBool());
		else
		if (name_hash == CzHashes::IgnoreActors_Hash)
			setIgnoreActors((*it)->getValueAsBool());
	}

	// If we are declared inside a scene then shape is local to the scene
	CzScene* scene = NULL;
	if (parent != NULL && parent->getClassTypeHash() == CzHashes::Actor_Hash)
		scene = ((CzActor*)parent)->getScene();
	else
	if (parent != NULL && parent->getClassTypeHash() == CzHashes::Scene_Hash)
		scene = (CzScene*)parent;
	Scene = scene;

	bool ret = false;
	if (scene != NULL)
		ret = scene->getResourceManager()->addResource(this);
	else
		ret = CZ_GLOBAL_RESOURCES->getResourceManager()->addResource(this);

	if (!ret)
		return 0;

	Update(0);

	return 1;
}