JD2022-TU1/main/extern/Soundwich/Solution/Engine/Src/Components/JustDance/JDSoundSyncOnTransition.h

195 lines
4.8 KiB
C++

#pragma once
#include "Component.h"
// region User header
// endregion
namespace Soundwich
{
class JDSoundSyncOnTransition : public Component
{
// region Class name
public:
static const Util::String& GetType( )
{
static const Util::String type = "JDSoundSyncOnTransition";
return type;
}
const Util::String& GetDerivedType( ) const
{
return GetType( );
}
// endregion
// region Data
public:
struct Data : public Component::Data
{
Data( const Util::String& soundEffect = "", int32 trackId = 0 )
{
SoundEffect = soundEffect;
TrackId = trackId;
};
Util::String SoundEffect;
int32 TrackId;
};
// endregion
// region Constructor/Destructor
public:
JDSoundSyncOnTransition( Synth* synth, const Util::String& name, const Data& data )
: Component( synth, name )
, _data( data ) { Init( ); }
JDSoundSyncOnTransition( Synth* synth, const Util::String& name )
: Component( synth, name ) { Init( ); }
~JDSoundSyncOnTransition( );
bool Init( );
static void Create( Synth* synth, const Util::String& name, Component** component )
{
*component = new JDSoundSyncOnTransition( synth, name );
}
// Binary Serialization
void Serialize( Util::BinaryWriter& writer )
{
writer.Write< Util::String >( _data.SoundEffect );
writer.Write< int32 >( _data.TrackId );
}
bool Deserialize( Util::BinaryReader& reader )
{
bool success = true;
success &= reader.Read< Util::String >( _data.SoundEffect );
success &= reader.Read< int32 >( _data.TrackId );
success &= Component::Deserialize( reader );
return success;
}
// Xml Serialization
void Serialize( Util::XmlWriter& writer )
{
writer.WriteAttribute< Util::String >( "SoundEffect", _data.SoundEffect );
writer.WriteAttribute< int32 >( "TrackId", _data.TrackId );
}
bool Deserialize( Util::XmlReader& reader )
{
bool success = true;
success &= reader.ReadAttribute< Util::String >( "SoundEffect", _data.SoundEffect );
success &= reader.ReadAttribute< int32 >( "TrackId", _data.TrackId );
success &= Component::Deserialize( reader );
return success;
}
// endregion
// region Input Events
public:
enum InputEvents
{
PlayEventIn,
StopEventIn,
eNumInputEvents
};
inline void AddEventIn( uint32 index, EventConnection* connection )
{
Assert( connection );
Assert( _inputEvents[ index ].Find( connection ) == _inputEvents[ index ].End( ) );
_inputEvents[ index ].PushBack( connection );
}
void PushEventIn( uint32 index, Component* from );
private:
Util::FixedArray< EventConnectionList, JDSoundSyncOnTransition::eNumInputEvents > _inputEvents;
int32 GetEventInIndex( const Util::String& name )
{
if( name == "Play" )
{
return PlayEventIn;
}
else if( name == "Stop" )
{
return StopEventIn;
}
else
{
AssertMessage( 0, "Unknown JDSoundSyncOnTransition port name %s", name.Chars( ) );
return -1;
}
}
const Util::String& GetEventInName( uint32 index )
{
if( index == PlayEventIn )
{
static Util::String name = "Play";
return name;
}
else if( index == StopEventIn )
{
static Util::String name = "Stop";
return name;
}
else
{
AssertMessage( 0, "Unknown JDSoundSyncOnTransition port index %d", index );
static Util::String name = "Undefined";
return name;
}
};
// endregion
// region User methods
public:
static void RegisterCallback( IJustDanceSoundEffectOnTrackTransitionCallback* cb );
static void UnregisterCallback( IJustDanceSoundEffectOnTrackTransitionCallback* cb );
void ExecutePlayCallbacks( );
void ExecuteStopCallbacks( );
// endregion
// region Member variables
private:
Data _data;
// endregion
// region User member variables
private:
static Util::DynamicArray< IJustDanceSoundEffectOnTrackTransitionCallback* > m_callbacks;
// endregion
};
}