// /////////////////////////////////////////////////////////////////
    //
    // /////////////////////////////////////////////////////////////////
    bool SetColorFromLua(const LuaPlus::LuaObject &colorData, Vector4 &color)
    {
        if(!colorData.IsTable()) {
            return (false);
        }

        LuaPlus::LuaObject rData = colorData["r"];
        LuaPlus::LuaObject gData = colorData["g"];
        LuaPlus::LuaObject bData = colorData["b"];
        LuaPlus::LuaObject aData = colorData["a"];

        if(!rData.IsNumber() || !gData.IsNumber() || !bData.IsNumber() || !aData.IsNumber()) {
            return (false);
        }

        F32 r = static_cast<F32>(rData.GetNumber());
        F32 g = static_cast<F32>(gData.GetNumber());
        F32 b = static_cast<F32>(bData.GetNumber());
        F32 a = static_cast<F32>(aData.GetNumber());
        Clamp<F32>(r, 0.0f, 1.0f);
        Clamp<F32>(g, 0.0f, 1.0f);
        Clamp<F32>(b, 0.0f, 1.0f);
        Clamp<F32>(a, 0.0f, 1.0f);
        color.Set(r, g, b, a);

        return (true);
    }
示例#2
0
bool EvtData_StartJump::buildEventFromScript(void)
{
	if (m_eventData.IsTable())
	{
		// ID
		LuaPlus::LuaObject temp = m_eventData.GetByName("actorId");
		if (temp.IsInteger())
		{
			m_id = temp.GetInteger();
		}
		else
		{
			GCC_ERROR("Invalid id sent to EvtData_StartJump; type = " + std::string(temp.TypeName()));
			return false;
		}

		// acceleration
		temp = m_eventData.GetByName("acceleration");
		if (temp.IsNumber())
			m_acceleration = temp.GetFloat();
		else
			m_acceleration = 5.0f;  // something reasonable

		return true;
	}

	return false;
}
示例#3
0
int ant::InternalLuaScriptExports::createActor( const char* actorArchetype, LuaPlus::LuaObject luaPosition, LuaPlus::LuaObject luaRotation )
{
	if (!luaPosition.IsTable())
	{
		GCC_ERROR("Invalid object passed to createActor(); type = " + std::string(luaPosition.TypeName()));
		return INVALID_ACTOR_ID;
	}

	if (!luaRotation.IsNumber())
	{
		GCC_ERROR("Invalid object passed to createActor(); type = " + std::string(luaRotation.TypeName()));
		return INVALID_ACTOR_ID;
	}

	sf::Vector2f pos(luaPosition["x"].GetFloat(), luaPosition["y"].GetFloat());
	ant::Real rot = luaRotation.GetFloat();

	TiXmlElement *overloads = NULL;
	ActorStrongPtr actor = ant::ISFMLApp::getApp()->getGameLogic()->createActor(actorArchetype, overloads, &pos, &rot);

	if (actor)
	{
		shared_ptr<EvtData_New_Actor> pNewActorEvent(GCC_NEW EvtData_New_Actor(actor->getId()));
		IEventManager::instance()->queueEvent(pNewActorEvent);
		return actor->getId();
	}

	return INVALID_ACTOR_ID;
}
 // /////////////////////////////////////////////////////////////////
 //
 // /////////////////////////////////////////////////////////////////
 void SliderControl::SetLuaSliderPosition(const LuaPlus::LuaObject &table)
 {
     if(table.IsNumber()) {
         m_sliderPos = static_cast<F32>(table.GetNumber());
         Clamp(m_sliderPos, 0.0f, 1.0f);
     }
 }
    // /////////////////////////////////////////////////////////////////
    //
    // /////////////////////////////////////////////////////////////////
    bool SetFloatFromLua(const LuaPlus::LuaObject &numberData, F32 &number)
    {
        if(!numberData.IsNumber()) {
            return (false);
        }

        number = static_cast<F32>(numberData.GetNumber());
        return (true);
    }
    // /////////////////////////////////////////////////////////////////
    //
    // /////////////////////////////////////////////////////////////////
    bool SetVector3FromLua(const LuaPlus::LuaObject &dirData, Vector3 &direction)
    {
        if(!dirData.IsTable()) {
            return (false);
        }

        LuaPlus::LuaObject xData = dirData["x"];
        LuaPlus::LuaObject yData = dirData["y"];
        LuaPlus::LuaObject zData = dirData["z"];

        if(!xData.IsNumber() || !yData.IsNumber() || !zData.IsNumber()) {
            return (false);
        }

        F32 x = static_cast<F32>(xData.GetNumber());
        F32 y = static_cast<F32>(yData.GetNumber());
        F32 z = static_cast<F32>(zData.GetNumber());
        direction.Set(x, y, z);

        return (true);
    }
    // /////////////////////////////////////////////////////////////////
    //
    // /////////////////////////////////////////////////////////////////
    bool SetPoint3FromLua(const LuaPlus::LuaObject &posData, Point3 &position)
    {
        if(!posData.IsTable()) {
            return (false);
        }

        LuaPlus::LuaObject xData = posData["x"];
        LuaPlus::LuaObject yData = posData["y"];
        LuaPlus::LuaObject zData = posData["z"];

        if(!xData.IsNumber() || !yData.IsNumber() || !zData.IsNumber()) {
            return (false);
        }

        F32 x = static_cast<F32>(xData.GetNumber());
        F32 y = static_cast<F32>(yData.GetNumber());
        F32 z = static_cast<F32>(zData.GetNumber());
        position.Set(x, y, z);

        return (true);
    }
示例#8
0
	// /////////////////////////////////////////////////////////////////
	// 
	// /////////////////////////////////////////////////////////////////
	bool BallActorParams::VInit(LuaPlus::LuaObject srcData, TErrorMessageList &errorMessages)
	{
		if (!Pool3dActorParams::VInit(srcData, errorMessages))
		{
			return (false);
		}

		VSetType(AT_Ball);

		LuaPlus::LuaObject rObj = srcData["Radius"];
		if(rObj.IsNumber())
		{
			m_radius = static_cast<F32>(rObj.GetNumber());
		}
		LuaPlus::LuaObject slObj = srcData["Slices"];
		if(slObj.IsInteger())
		{
			m_slices = slObj.GetInteger();
		}
		LuaPlus::LuaObject stObj = srcData["Stacks"];
		if(stObj.IsInteger())
		{
			m_stacks = stObj.GetInteger();
		}
		LuaPlus::LuaObject groupObj = srcData["Group"];
		if(groupObj.IsString())
		{
			const char *groupStr = groupObj.GetString();
			if(strcmp(groupStr, "cue") == 0)
			{
				m_group = eCue;
			}
			else if(strcmp(groupStr, "stripes") == 0)
			{
				m_group = eStripes;
			}
			else if(strcmp(groupStr, "plain") == 0)
			{
				m_group = ePlain;
			}
			else if(strcmp(groupStr, "black") == 0)
			{
				m_group = eBlack;
			}
			else
			{
				m_group = eCue;
			}
		}

		return (true);
	}
 // /////////////////////////////////////////////////////////////////
 //
 // /////////////////////////////////////////////////////////////////
 void LuaStateManager::IdentifyLuaObjectType(LuaPlus::LuaObject &objToTest)
 {
     assert(!objToTest.IsNil() && "Nil!");
     assert(!objToTest.IsBoolean() && "Boolean!");
     assert(!objToTest.IsCFunction() && "C-Function!");
     assert(!objToTest.IsFunction() && "Function!");
     assert(!objToTest.IsInteger() && "Integer!");
     assert(!objToTest.IsLightUserData() && "Light User Data!");
     assert(!objToTest.IsNone() && "None!");
     assert(!objToTest.IsNumber() && "Number!");
     assert(!objToTest.IsString() && "String!");
     assert(!objToTest.IsTable() && "Table!");
     assert(!objToTest.IsUserData() && "User Data!");
     assert(!objToTest.IsWString() && "Wide String!");
     assert(0 && "UNKNOWN!");
 }
示例#10
0
	// /////////////////////////////////////////////////////////////////
	// 
	// /////////////////////////////////////////////////////////////////
	bool TableActorParams::VInit(LuaPlus::LuaObject srcData, TErrorMessageList &errorMessages)
	{
		if (!Pool3dActorParams::VInit(srcData, errorMessages))
		{
			return (false);
		}

		VSetType(AT_Table);

		// Table Panels data.
		LuaPlus::LuaObject obj = srcData["FrontPanelMeshName"];
		if(obj.IsString())
		{
			SetFrontPanelMeshName(obj.GetString());
		}
		obj = srcData["SidePanelMeshName"];
		if(obj.IsString())
		{
			SetSidePanelMeshName(obj.GetString());
		}
		obj = srcData["PanelTextureName"];
		if(obj.IsString())
		{
			SetPanelTextureName(obj.GetString());
		}
		obj = srcData["PanelMaterial"];
		if(obj.IsTable())
		{
			GameColor tmp;
			if(SetColorFromLua(obj["Ambient"], tmp))
			{
				m_panelMaterial.SetAmbient(tmp);
			}
			if(SetColorFromLua(obj["Diffuse"], tmp))
			{
				m_panelMaterial.SetDiffuse(tmp);
			}
			if(SetColorFromLua(obj["Specular"], tmp))
			{
				m_panelMaterial.SetSpecular(tmp);
			}
			if(SetColorFromLua(obj["Emissive"], tmp))
			{
				m_panelMaterial.SetEmissive(tmp);
			}
			F32 tmp2;
			if(SetFloatFromLua(obj["Shininess"], tmp2))
			{
				m_panelMaterial.SetSpecularPower(tmp2);
			}
		}

		// Table pockets data.
		obj = srcData["MiddlePocketMeshName"];
		if(obj.IsString())
		{
			SetMiddlePocketMeshName(obj.GetString());
		}
		obj = srcData["CornerPocketMeshName"];
		if(obj.IsString())
		{
			SetCornerPocketMeshName(obj.GetString());
		}
		obj = srcData["PocketMaterial"];
		if(obj.IsTable())
		{
			GameColor tmp;
			if(SetColorFromLua(obj["Ambient"], tmp))
			{
				m_pocketsMaterial.SetAmbient(tmp);
			}
			if(SetColorFromLua(obj["Diffuse"], tmp))
			{
				m_pocketsMaterial.SetDiffuse(tmp);
			}
			if(SetColorFromLua(obj["Specular"], tmp))
			{
				m_pocketsMaterial.SetSpecular(tmp);
			}
			if(SetColorFromLua(obj["Emissive"], tmp))
			{
				m_pocketsMaterial.SetEmissive(tmp);
			}
			F32 tmp2;
			if(SetFloatFromLua(obj["Shininess"], tmp2))
			{
				m_pocketsMaterial.SetSpecularPower(tmp2);
			}
		}
		obj = srcData["PocketTexture"];
		if(obj.IsString())
		{
			SetPocketTextureName(obj.GetString());
		}

		obj = srcData["Width"];
		if(obj.IsNumber())
		{
			SetFloatFromLua(obj, m_width);
		}
		obj = srcData["Height"];
		if(obj.IsNumber())
		{
			SetFloatFromLua(obj, m_height);
		}
		obj = srcData["Depth"];
		if(obj.IsNumber())
		{
			SetFloatFromLua(obj, m_depth);
		}
		obj = srcData["PocketRadius"];
		if(obj.IsNumber())
		{
			SetFloatFromLua(obj, m_pocketRadius);
		}

		obj = srcData["TopLeftPocketTriggerPos"];
		if(obj.IsTable())
		{
			SetPoint3FromLua(obj, m_tlpTriggerPos);
		}
		obj = srcData["TopLeftPocketTriggerId"];
		if(obj.IsInteger())
		{
			SetIntFromLua(obj, m_tlPocketId);
		}
		obj = srcData["TopRightPocketTriggerPos"];
		if(obj.IsTable())
		{
			SetPoint3FromLua(obj, m_trpTriggerPos);
		}
		obj = srcData["TopRightPocketTriggerId"];
		if(obj.IsInteger())
		{
			SetIntFromLua(obj, m_trPocketId);
		}
		obj = srcData["BottomLeftPocketTriggerPos"];
		if(obj.IsTable())
		{
			SetPoint3FromLua(obj, m_blpTriggerPos);
		}
		obj = srcData["BottomLeftPocketTriggerId"];
		if(obj.IsInteger())
		{
			SetIntFromLua(obj, m_blPocketId);
		}
		obj = srcData["BottomRightPocketTriggerPos"];
		if(obj.IsTable())
		{
			SetPoint3FromLua(obj, m_brpTriggerPos);
		}
		obj = srcData["BottomRightPocketTriggerId"];
		if(obj.IsInteger())
		{
			SetIntFromLua(obj, m_brPocketId);
		}
		obj = srcData["MiddleLeftPocketTriggerPos"];
		if(obj.IsTable())
		{
			SetPoint3FromLua(obj, m_mlpTriggerPos);
		}
		obj = srcData["MiddleLeftPocketTriggerId"];
		if(obj.IsInteger())
		{
			SetIntFromLua(obj, m_mlPocketId);
		}
		obj = srcData["MiddleRightPocketTriggerPos"];
		if(obj.IsTable())
		{
			SetPoint3FromLua(obj, m_mrpTriggerPos);
		}
		obj = srcData["MiddleRightPocketTriggerId"];
		if(obj.IsInteger())
		{
			SetIntFromLua(obj, m_mrPocketId);
		}

		return (true);
	}