move attribute loading into the class that owns the attribute
This commit is contained in:
+50
-10
@@ -8,6 +8,7 @@
|
||||
#include "RageLog.h"
|
||||
#include "arch/Dialog/Dialog.h"
|
||||
#include "Foreach.h"
|
||||
#include "XmlFile.h"
|
||||
|
||||
float Actor::g_fCurrentBGMTime = 0, Actor::g_fCurrentBGMBeat;
|
||||
|
||||
@@ -62,6 +63,44 @@ Actor::Actor()
|
||||
m_bFirstUpdate = true;
|
||||
}
|
||||
|
||||
void Actor::LoadFromNode( const XNode* pNode )
|
||||
{
|
||||
// Load Name, if any.
|
||||
pNode->GetAttrValue( "Name", m_sName );
|
||||
|
||||
|
||||
float f;
|
||||
if( pNode->GetAttrValue( "BaseRotationXDegrees", f ) ) SetBaseRotationX( f );
|
||||
if( pNode->GetAttrValue( "BaseRotationYDegrees", f ) ) SetBaseRotationY( f );
|
||||
if( pNode->GetAttrValue( "BaseRotationZDegrees", f ) ) SetBaseRotationZ( f );
|
||||
if( pNode->GetAttrValue( "BaseZoomX", f ) ) SetBaseZoomX( f );
|
||||
if( pNode->GetAttrValue( "BaseZoomY", f ) ) SetBaseZoomY( f );
|
||||
if( pNode->GetAttrValue( "BaseZoomZ", f ) ) SetBaseZoomZ( f );
|
||||
|
||||
|
||||
//
|
||||
// Load commands
|
||||
//
|
||||
FOREACH_CONST_Attr( pNode, a )
|
||||
{
|
||||
CString sKeyName = a->m_sName; /* "OnCommand" */
|
||||
sKeyName.MakeLower();
|
||||
|
||||
if( sKeyName.Right(7) != "command" )
|
||||
continue; /* not a command */
|
||||
|
||||
const CString &sCommands = a->m_sValue;
|
||||
Commands cmds = ParseCommands( sCommands );
|
||||
CString sCmdName;
|
||||
/* Special case: "Command=foo" -> "OnCommand=foo" */
|
||||
if( sKeyName.size() == 7 )
|
||||
sCmdName="on";
|
||||
else
|
||||
sCmdName = sKeyName.Left( sKeyName.size()-7 );
|
||||
m_mapNameToCommands[sCmdName] = cmds;
|
||||
}
|
||||
}
|
||||
|
||||
void Actor::Draw()
|
||||
{
|
||||
if( m_bHidden )
|
||||
@@ -624,13 +663,6 @@ void Actor::AddRotationR( float rot )
|
||||
RageQuatMultiply( &DestTweenState().quat, DestTweenState().quat, RageQuatFromR(rot) );
|
||||
}
|
||||
|
||||
void Actor::AddCommands( const CString sName, const Commands &cmds )
|
||||
{
|
||||
CString sKey = sName;
|
||||
sKey.MakeLower();
|
||||
m_mapNameToCommands[sKey] = cmds;
|
||||
}
|
||||
|
||||
void Actor::RunCommands( const Commands &cmds )
|
||||
{
|
||||
FOREACH_CONST( Command, cmds.v, c )
|
||||
@@ -755,10 +787,18 @@ void Actor::HandleCommand( const Command &command )
|
||||
* sent to all sub-actors (which aren't necessarily Sprites) on
|
||||
* GainFocus and LoseFocus. So, don't run EndHandleArgs
|
||||
* on these commands. */
|
||||
else if( sName=="customtexturerect" || sName=="texcoordvelocity" || sName=="scaletoclipped" ||
|
||||
sName=="stretchtexcoords" || sName=="position" || sName=="loop" ||
|
||||
sName=="rate" || sName=="propagate" )
|
||||
else if(
|
||||
sName=="customtexturerect" ||
|
||||
sName=="texcoordvelocity" ||
|
||||
sName=="scaletoclipped" ||
|
||||
sName=="stretchtexcoords" ||
|
||||
sName=="position" ||
|
||||
sName=="loop" ||
|
||||
sName=="rate" ||
|
||||
sName=="propagate" )
|
||||
{
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
CString sError = ssprintf( "Actor::HandleCommand: Unrecognized command name '%s'.", sName.c_str() );
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include "Command.h"
|
||||
#include <deque>
|
||||
#include <map>
|
||||
struct XNode;
|
||||
|
||||
#define DRAW_ORDER_BEFORE_EVERYTHING -100
|
||||
#define DRAW_ORDER_TRANSITIONS 100
|
||||
@@ -18,6 +19,7 @@ public:
|
||||
Actor();
|
||||
virtual ~Actor() {}
|
||||
virtual void Reset();
|
||||
void LoadFromNode( const XNode* pNode );
|
||||
|
||||
static void SetBGMTime( float fTime, float fBeat ) { g_fCurrentBGMTime = fTime; g_fCurrentBGMBeat = fBeat; }
|
||||
|
||||
@@ -301,7 +303,7 @@ public:
|
||||
//
|
||||
// Commands
|
||||
//
|
||||
void AddCommands( const CString sName, const Commands &cmds );
|
||||
virtual void PlayCommand( const CString &sCommandName );
|
||||
void RunCommands( const Commands &cmds );
|
||||
virtual void HandleCommand( const Command &command ); // derivable
|
||||
static float GetCommandsLengthSeconds( const Commands &cmds );
|
||||
@@ -319,7 +321,6 @@ public:
|
||||
//
|
||||
virtual void GainFocus( float fRate, bool bRewindMovie, bool bLoop ) {}
|
||||
virtual void LoseFocus() {}
|
||||
virtual void PlayCommand( const CString &sCommandName );
|
||||
|
||||
protected:
|
||||
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
#include "ActorFrame.h"
|
||||
#include "arch/Dialog/Dialog.h"
|
||||
#include "RageUtil.h"
|
||||
#include "XmlFile.h"
|
||||
#include "ActorUtil.h"
|
||||
|
||||
ActorFrame::ActorFrame()
|
||||
{
|
||||
@@ -15,6 +17,24 @@ ActorFrame::~ActorFrame()
|
||||
DeleteAllChildren();
|
||||
}
|
||||
|
||||
void ActorFrame::LoadFromNode( const CString &sDir, const XNode* pNode )
|
||||
{
|
||||
Actor::LoadFromNode( pNode );
|
||||
|
||||
//
|
||||
// Load children
|
||||
//
|
||||
const XNode* pChildren = pNode->GetChild("children");
|
||||
if( pChildren )
|
||||
{
|
||||
FOREACH_CONST_Child( pChildren, pChild )
|
||||
{
|
||||
Actor* pChildActor = LoadFromActorFile( sDir, *pChild );
|
||||
AddChild( pChildActor );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ActorFrame::AddChild( Actor* pActor )
|
||||
{
|
||||
#if _DEBUG
|
||||
|
||||
@@ -10,6 +10,9 @@ class ActorFrame : public Actor
|
||||
public:
|
||||
ActorFrame();
|
||||
virtual ~ActorFrame();
|
||||
|
||||
void LoadFromNode( const CString &sDir, const XNode* pNode );
|
||||
|
||||
virtual void AddChild( Actor* pActor );
|
||||
virtual void RemoveChild( Actor* pActor );
|
||||
virtual void MoveToTail( Actor* pActor );
|
||||
|
||||
@@ -39,11 +39,13 @@ void ActorScroller::Load(
|
||||
m_bLoaded = true;
|
||||
}
|
||||
|
||||
void ActorScroller::LoadFromNode( const CString &sFile, const XNode *pNode )
|
||||
void ActorScroller::LoadFromNode( const CString &sDir, const XNode *pNode )
|
||||
{
|
||||
ActorFrame::LoadFromNode( sDir, pNode );
|
||||
|
||||
#define REQUIRED_GET_VALUE( szName, valueOut ) \
|
||||
if( !pNode->GetAttrValue( szName, valueOut ) ) \
|
||||
Dialog::OK( ssprintf("File '%s' is missing the value Scroller::%s", sFile.c_str(), szName) );
|
||||
Dialog::OK( ssprintf("Animation in '%s' is missing the value Scroller::%s", sDir.c_str(), szName) );
|
||||
|
||||
float fSecondsPerItem = 1;
|
||||
float fNumItemsToDraw = 7;
|
||||
|
||||
@@ -22,7 +22,7 @@ public:
|
||||
virtual void Update( float fDelta );
|
||||
virtual void DrawPrimitives(); // DOES draw
|
||||
|
||||
void LoadFromNode( const CString &sFile, const XNode *pNode );
|
||||
void LoadFromNode( const CString &sDir, const XNode *pNode );
|
||||
void SetDestinationItem( int iItem ) { m_fDestinationItem = float(iItem); }
|
||||
void SetCurrentAndDestinationItem( int iItem ) { m_fCurrentItem = m_fDestinationItem = float(iItem); }
|
||||
|
||||
|
||||
@@ -230,37 +230,8 @@ retry:
|
||||
}
|
||||
|
||||
|
||||
float f;
|
||||
if( layer.GetAttrValue( "BaseRotationXDegrees", f ) ) pActor->SetBaseRotationX( f );
|
||||
if( layer.GetAttrValue( "BaseRotationYDegrees", f ) ) pActor->SetBaseRotationY( f );
|
||||
if( layer.GetAttrValue( "BaseRotationZDegrees", f ) ) pActor->SetBaseRotationZ( f );
|
||||
if( layer.GetAttrValue( "BaseZoomX", f ) ) pActor->SetBaseZoomX( f );
|
||||
if( layer.GetAttrValue( "BaseZoomY", f ) ) pActor->SetBaseZoomY( f );
|
||||
if( layer.GetAttrValue( "BaseZoomZ", f ) ) pActor->SetBaseZoomZ( f );
|
||||
|
||||
|
||||
//
|
||||
// Load commands
|
||||
//
|
||||
FOREACH_CONST_Attr( &layer, a )
|
||||
{
|
||||
CString KeyName = a->m_sName; /* "OnCommand" */
|
||||
KeyName.MakeLower();
|
||||
|
||||
if( KeyName.Right(7) != "command" )
|
||||
continue; /* not a command */
|
||||
|
||||
const CString &sCommands = a->m_sValue;
|
||||
Commands cmds = ParseCommands( sCommands );
|
||||
CString sCmdName;
|
||||
/* Special case: "Command=foo" -> "OnCommand=foo" */
|
||||
if( KeyName.size() == 7 )
|
||||
sCmdName="on";
|
||||
else
|
||||
sCmdName = KeyName.Left( KeyName.size()-7 );
|
||||
pActor->AddCommands( sCmdName, cmds );
|
||||
}
|
||||
|
||||
// TODO: LoadFromNode should be called when we still have a pointer to the derived type.
|
||||
pActor->LoadFromNode( &layer );
|
||||
|
||||
ASSERT( pActor ); // we should have filled this in above
|
||||
return pActor;
|
||||
|
||||
@@ -170,7 +170,6 @@ void BGAnimation::LoadFromNode( const CString &sDir, const XNode& node )
|
||||
{
|
||||
DEBUG_ASSERT( node.m_sName == "BGAnimation" );
|
||||
|
||||
|
||||
CString sInitCommand;
|
||||
if( node.GetAttrValue( "InitCommand", sInitCommand ) )
|
||||
{
|
||||
@@ -180,15 +179,7 @@ void BGAnimation::LoadFromNode( const CString &sDir, const XNode& node )
|
||||
this->RunCommands( ParseCommands(sInitCommand) );
|
||||
}
|
||||
|
||||
const XNode* pChildren = node.GetChild("children");
|
||||
if( pChildren )
|
||||
{
|
||||
FOREACH_CONST_Child( pChildren, pChild )
|
||||
{
|
||||
Actor* pChildActor = LoadFromActorFile( sDir, *pChild );
|
||||
AddChild( pChildActor );
|
||||
}
|
||||
}
|
||||
ActorFrame::LoadFromNode( sDir, &node );
|
||||
|
||||
Command cmd;
|
||||
cmd.Load( "PlayCommand,Init" );
|
||||
|
||||
Reference in New Issue
Block a user