Exemplo n.º 1
0
//----------------------------------------------------------------//
void MOAIAnim::Apply ( float t0, float t1 ) {
	
	if ( t0 == t1 ) {
		this->Apply ( t0 );
		return;
	}
	
	MOAIAttrOp adder;
	
	u32 total = this->mLinks.Size ();
	for ( u32 i = 0; i < total; ++i ) {
		
		MOAIAnimLink& link = this->mLinks [ i ];
		MOAIAnimCurve* curve = link.mCurve;
		MOAINode* target = link.mTarget;
		
		if ( curve && target ) {
			
			if ( link.mRelative ) {
				float value = curve->GetFloatDelta ( t0, t1 );
				adder.SetValue ( value );
				target->ApplyAttrOp ( link.mAttrID, adder, MOAIAttrOp::ADD );
			}
			else {
				float value = curve->GetFloatValue ( t1 );
				target->SetAttributeValue < float >( link.mAttrID, value );
			}
			target->ScheduleUpdate ();
		}
	}
}
Exemplo n.º 2
0
/**	@name	seekAttr
	@text	Animate the attribute by applying a delta. Delta is computed
			given a target value. Creates and returns a MOAIEaseDriver
			initialized to apply the delta.
	
	@in		MOAINode self
	@in		number attrID	ID of the attribute to animate.
	@in		number goal		Desired resulting value for attribute.
	@in		number length	Length of animation in seconds.
	@opt	number mode		The ease mode. One of MOAIEaseType.EASE_IN, MOAIEaseType.EASE_OUT, MOAIEaseType.FLAT MOAIEaseType.LINEAR,
							MOAIEaseType.SMOOTH, MOAIEaseType.SOFT_EASE_IN, MOAIEaseType.SOFT_EASE_OUT, MOAIEaseType.SOFT_SMOOTH. Defaults to MOAIEaseType.SMOOTH.

	@out	MOAIEaseDriver easeDriver
*/
int MOAINode::_seekAttr ( lua_State* L ) {
	MOAI_LUA_SETUP ( MOAINode, "UNNN" )

	MOAIEaseDriver* action = new MOAIEaseDriver ();
	action->ReserveLinks ( 1 );
	
	u32 attrID = state.GetValue < u32 >( 2, 0 );
	if ( self->CheckAttrExists ( attrID )) {
	
		MOAIAttrOp getter;
		self->ApplyAttrOp ( attrID, getter, MOAIAttrOp::GET );
		if ( !getter.IsValid ()) return 0;
		
		float value		= state.GetValue < float >( 3, 0.0f );
		float delay		= state.GetValue < float >( 4, 0.0f );
		u32 mode		= state.GetValue < u32 >( 5, ZLInterpolate::kSmooth );
		
		action->SetLink ( 0, self, attrID, value - getter.GetValue ( 0.0f ), mode );
		
		action->SetSpan ( delay );
		action->Start ();
		action->PushLuaUserdata ( state );

		return 1;
	}
	
	MOAILog ( L, MOAILogMessages::MOAINode_AttributeNotFound );
	return 0;
}
Exemplo n.º 3
0
//----------------------------------------------------------------//
bool MOAINode::CheckAttrExists ( u32 attrID ) {

	if ( attrID == MOAIAttrOp::NULL_ATTR ) return false;

	MOAIAttrOp getter;
	this->ApplyAttrOp ( attrID, getter, MOAIAttrOp::CHECK );
	return getter.IsValid ();
}
Exemplo n.º 4
0
//----------------------------------------------------------------//
bool MOAIAnimCurve::ApplyAttrOp ( u32 attrID, MOAIAttrOp& attrOp, u32 op ) {

	if ( MOAIAnimCurveAttr::Check ( attrID )) {

		switch ( UNPACK_ATTR ( attrID )) {
			case ATTR_TIME:
				this->mTime = attrOp.Apply ( this->mTime, op, MOAINode::ATTR_READ_WRITE );
				return true;
			case ATTR_VALUE:
				this->mValue = attrOp.Apply ( this->mValue, op, MOAINode::ATTR_READ_WRITE );
				return true;
		}
	}
	return false;
}
Exemplo n.º 5
0
/**	@name	getAttr
	@text	Returns the value of the attribute if it exists or nil if it doesn't.
	
	@in		MOAINode self
	@in		number attrID
	@out	number value
*/
int MOAINode::_getAttr ( lua_State* L ) {
	MOAI_LUA_SETUP ( MOAINode, "UN" );

	u32 attrID = state.GetValue < u32 >( 2, 0 );

	MOAIAttrOp getter;
	self->ApplyAttrOp ( attrID, getter, MOAIAttrOp::GET );
	
	if ( getter.IsValid ()) {
		lua_pushnumber ( state, getter.GetValue ( 0.0f ));
		return 1;
	}
	
	MOAILog ( L, MOAILogMessages::MOAINode_AttributeNotFound );
	return 0;
}
Exemplo n.º 6
0
//----------------------------------------------------------------//
bool MOAIScriptNode::ApplyAttrOp ( u32 attrID, MOAIAttrOp& attrOp, u32 op ) {

	if ( attrID < this->mAttributes.Size ()) {
		this->mAttributes [ attrID ] = attrOp.Apply ( this->mAttributes [ attrID ], op, MOAINode::ATTR_READ_WRITE );
		return true;
	}
	return false;
}
//----------------------------------------------------------------//
bool MOAIScriptNode::ApplyAttrOp ( u32 attrID, MOAIAttrOp& attrOp, u32 op ) {
	attrID = UNPACK_ATTR(attrID);

	if ( attrID < this->mAttributes.Size ()) {
		this->mAttributes [ attrID ] = attrOp.Apply ( this->mAttributes [ attrID ], op, MOAIAttrOp::ATTR_READ_WRITE, MOAIAttrOp::ATTR_TYPE_FLOAT );
		return true;
	}
	return false;
}
Exemplo n.º 8
0
/**	@name	setAttr
	@text	Sets the value of an attribute.
	
	@in		MOAINode self
	@in		number attrID
	@in		number value
	@out	nil
*/
int MOAINode::_setAttr ( lua_State* L ) {
	MOAI_LUA_SETUP ( MOAINode, "UNN" );
	
	u32 attrID = state.GetValue < u32 >( 2, 0 );
	float value = state.GetValue < float >( 3, 0.0f );
	
	if ( self->CheckAttrExists ( attrID )) {
	
		MOAIAttrOp setter;
		setter.SetValue ( value );
	
		self->ClearAttrLink ( attrID );
		self->ApplyAttrOp ( attrID, setter, MOAIAttrOp::SET );
		self->ScheduleUpdate ();
	}
	else {
		MOAILog ( L, MOAILogMessages::MOAINode_AttributeNotFound );
	}
	
	return 0;
}
Exemplo n.º 9
0
//----------------------------------------------------------------//
u32 MOAINode::GetAttrFlags ( u32 attrID ) {

	MOAIAttrOp attrOp;
	this->ApplyAttrOp ( attrID, attrOp, MOAIAttrOp::CHECK );
	return attrOp.GetFlags ();
}
Exemplo n.º 10
0
//----------------------------------------------------------------//
void MOAIAnimCurve::ApplyValueAttrOp ( MOAIAttrOp& attrOp, u32 op ) {

	this->mValue = attrOp.Apply ( this->mValue, op, MOAIAttrOp::ATTR_READ_WRITE );
}