Исправлено приведение типов с классами элементов

This commit is contained in:
Kernell 2015-12-06 17:19:01 +03:00
parent 272f16a912
commit 915be1c34c
2 changed files with 42 additions and 3 deletions

View File

@ -70,16 +70,48 @@ CMonoClass* CMonoMTALib::GetClass( const char* szNameSpace, const char* szName )
return this->GetDomain()->FindOrAdd( mono_class_from_name( this->m_pImage, szBuffer, szName ) ); return this->GetDomain()->FindOrAdd( mono_class_from_name( this->m_pImage, szBuffer, szName ) );
} }
string CMonoMTALib::GetElementType( void* pUseData )
{
CResource* pResource = this->GetDomain()->GetResource();
assert( pResource );
string strTypeName;
if( CLuaFunctionDefinitions::IsElement( pResource->GetLua(), pUseData ) )
{
strTypeName = CLuaFunctionDefinitions::GetElementType( pResource->GetLua(), pUseData );
strTypeName[ 0 ] = toupper( strTypeName[ 0 ] );
if( strTypeName == "Root" )
{
strTypeName = "Element";
}
}
return strTypeName;
}
MonoObject* CMonoMTALib::RegisterElement( void* pUseData ) MonoObject* CMonoMTALib::RegisterElement( void* pUseData )
{ {
CMonoClass* pClass = this->GetClass( "Element" ); string strType = this->GetElementType( pUseData );
if( strType.length() == 0 )
{
return nullptr;
}
CMonoClass* pClass = this->GetClass( strType.c_str() );
if( !pClass ) if( !pClass )
{ {
return false; this->GetDomain()->GetResource()->ErrorPrintf( "[mono] Could not find the 'MultiTheftAuto.%s' class\n", strType.c_str() );
return nullptr;
} }
CMonoMethod* pMethod = pClass->GetMethod( "FindOrCreate", 0 ); CMonoMethod* pMethod = pClass->GetMethod( "Find", 0 );
if( !pMethod ) if( !pMethod )
{ {
@ -99,5 +131,10 @@ MonoObject* CMonoMTALib::RegisterElement( void* pUseData )
return nullptr; return nullptr;
} }
if( !pObject )
{
pObject = pClass->New( Args, 1 );
}
return pObject; return pObject;
} }

View File

@ -39,6 +39,8 @@ public:
CMonoClass* GetClass ( const char* szName ); CMonoClass* GetClass ( const char* szName );
CMonoClass* GetClass ( const char* szNameSpace, const char* szName ); CMonoClass* GetClass ( const char* szNameSpace, const char* szName );
string GetElementType ( void* pUserData );
MonoObject* RegisterElement ( void* pUserData ); MonoObject* RegisterElement ( void* pUserData );
CMonoDomain* GetDomain ( void ) { return this->m_pDomain; } CMonoDomain* GetDomain ( void ) { return this->m_pDomain; }